3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Report_Form_Register
extends CRM_Core_Form
{
19 protected $_values = NULL;
21 public function preProcess() {
22 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
23 $this->_id
= CRM_Utils_Request
::retrieve('id', 'String', $this, FALSE);
25 $this->setTitle(ts('Report Template'));
27 if ($this->_action
& CRM_Core_Action
::DELETE
) {
31 $this->_opID
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
32 'report_template', 'id', 'name'
39 * This virtual function is used to set the default values of.
40 * various form elements
45 * reference to the array of default values
47 public function setDefaultValues() {
49 if ($this->_action
& CRM_Core_Action
::DELETE
) {
53 $params = ['id' => $this->_id
];
55 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_OptionValue', $params, $defaults);
58 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
59 ['option_group_id' => $this->_opID
]
65 public function buildQuickForm() {
66 if ($this->_action
& CRM_Core_Action
::DELETE
) {
70 'name' => ts('Delete'),
71 'spacing' => ' ',
76 'name' => ts('Cancel'),
82 $this->add('text', 'label', ts('Title'), ['size' => 40], TRUE);
83 $this->add('text', 'value', ts('URL'), ['size' => 40], TRUE);
84 $this->add('text', 'name', ts('Class'), ['size' => 40], TRUE);
85 $element = $this->add('number', 'weight', ts('Order'), ['size' => 4], TRUE);
86 // $element->freeze( );
87 $this->add('text', 'description', ts('Description'), ['size' => 40], TRUE);
89 $this->add('checkbox', 'is_active', ts('Enabled?'));
90 $this->_components
= CRM_Core_Component
::getComponents();
91 //unset the report component
92 unset($this->_components
['CiviReport']);
95 foreach ($this->_components
as $name => $object) {
96 $components[$object->componentID
] = $object->info
['translatedName'];
99 $this->add('select', 'component_id', ts('Component'), ['' => ts('Contact')] +
$components);
104 'name' => ts('Save'),
105 'spacing' => ' ',
110 'name' => ts('Cancel'),
113 $this->addFormRule(['CRM_Report_Form_Register', 'formRule'], $this);
123 public static function formRule($fields, $files, $self) {
126 $reportUrl = new CRM_Core_DAO_OptionValue();
127 $reportUrl->option_group_id
= $self->_opID
;
128 $reportUrl->value
= $fields['value'];
130 if ($reportUrl->find(TRUE) && $self->_id
!= $reportUrl->id
) {
131 $errors['value'] = ts('Url already exists in Database.');
133 if ($reportUrl->name
== $fields['name']) {
138 $reportClass = new CRM_Core_DAO_OptionValue();
139 $reportClass->option_group_id
= $self->_opID
;
140 $reportClass->name
= $fields['name'];
141 if ($reportClass->find(TRUE) && $self->_id
!= $reportClass->id
) {
147 $errors['name'] = ts('Class already exists in Database.');
153 * Process the form submission.
158 public function postProcess() {
159 if ($this->_action
& CRM_Core_Action
::DELETE
) {
161 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
162 CRM_Core_Session
::setStatus(ts('Selected %1 Report has been deleted.', [1 => $this->_GName
]), ts('Record Deleted'), 'success');
163 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));
166 CRM_Core_Session
::setStatus(ts('Selected %1 type has not been deleted.', [1 => $this->_GName
]), '', 'info');
167 CRM_Utils_Weight
::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
171 // get the submitted form values.
172 $params = $this->controller
->exportValues($this->_name
);
174 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, 'report_template', $this->_action
, $this->_id
);
175 CRM_Core_Session
::setStatus(ts('The %1 \'%2\' has been saved.', [
176 1 => 'Report Template',
177 2 => $optionValue->label
,
178 ]), ts('Saved'), 'success');
179 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));