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
19 class CRM_Report_Form_Register
extends CRM_Core_Form
{
21 protected $_values = NULL;
23 public function preProcess() {
24 $this->_action
= CRM_Utils_Request
::retrieve('action', 'String', $this, FALSE);
25 $this->_id
= CRM_Utils_Request
::retrieve('id', 'String', $this, FALSE);
27 CRM_Utils_System
::setTitle(ts('Report Template'));
29 if ($this->_action
& CRM_Core_Action
::DELETE
) {
33 $this->_opID
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup',
34 'report_template', 'id', 'name'
41 * This virtual function is used to set the default values of.
42 * various form elements
47 * reference to the array of default values
49 public function setDefaultValues() {
51 if ($this->_action
& CRM_Core_Action
::DELETE
) {
55 $params = ['id' => $this->_id
];
57 CRM_Core_DAO
::commonRetrieve('CRM_Core_DAO_OptionValue', $params, $defaults);
60 $defaults['weight'] = CRM_Utils_Weight
::getDefaultWeight('CRM_Core_DAO_OptionValue',
61 ['option_group_id' => $this->_opID
]
67 public function buildQuickForm() {
68 if ($this->_action
& CRM_Core_Action
::DELETE
) {
72 'name' => ts('Delete'),
73 'spacing' => ' ',
78 'name' => ts('Cancel'),
84 $this->add('text', 'label', ts('Title'), ['size' => 40], TRUE);
85 $this->add('text', 'value', ts('URL'), ['size' => 40], TRUE);
86 $this->add('text', 'name', ts('Class'), ['size' => 40], TRUE);
87 $element = $this->add('number', 'weight', ts('Order'), ['size' => 4], TRUE);
88 // $element->freeze( );
89 $this->add('text', 'description', ts('Description'), ['size' => 40], TRUE);
91 $this->add('checkbox', 'is_active', ts('Enabled?'));
92 $this->_components
= CRM_Core_Component
::getComponents();
93 //unset the report component
94 unset($this->_components
['CiviReport']);
97 foreach ($this->_components
as $name => $object) {
98 $components[$object->componentID
] = $object->info
['translatedName'];
101 $this->add('select', 'component_id', ts('Component'), ['' => ts('Contact')] +
$components);
106 'name' => ts('Save'),
107 'spacing' => ' ',
112 'name' => ts('Cancel'),
115 $this->addFormRule(['CRM_Report_Form_Register', 'formRule'], $this);
125 public static function formRule($fields, $files, $self) {
128 $reportUrl = new CRM_Core_DAO_OptionValue();
129 $reportUrl->option_group_id
= $self->_opID
;
130 $reportUrl->value
= $fields['value'];
132 if ($reportUrl->find(TRUE) && $self->_id
!= $reportUrl->id
) {
133 $errors['value'] = ts('Url already exists in Database.');
135 if ($reportUrl->name
== $fields['name']) {
140 $reportClass = new CRM_Core_DAO_OptionValue();
141 $reportClass->option_group_id
= $self->_opID
;
142 $reportClass->name
= $fields['name'];
143 if ($reportClass->find(TRUE) && $self->_id
!= $reportClass->id
) {
149 $errors['name'] = ts('Class already exists in Database.');
155 * Process the form submission.
160 public function postProcess() {
161 if ($this->_action
& CRM_Core_Action
::DELETE
) {
163 if (CRM_Core_BAO_OptionValue
::del($this->_id
)) {
164 CRM_Core_Session
::setStatus(ts('Selected %1 Report has been deleted.', [1 => $this->_GName
]), ts('Record Deleted'), 'success');
165 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));
168 CRM_Core_Session
::setStatus(ts('Selected %1 type has not been deleted.', [1 => $this->_GName
]), '', 'info');
169 CRM_Utils_Weight
::correctDuplicateWeights('CRM_Core_DAO_OptionValue', $fieldValues);
173 // get the submitted form values.
174 $params = $this->controller
->exportValues($this->_name
);
176 $optionValue = CRM_Core_OptionValue
::addOptionValue($params, 'report_template', $this->_action
, $this->_id
);
177 CRM_Core_Session
::setStatus(ts('The %1 \'%2\' has been saved.', [
178 1 => 'Report Template',
179 2 => $optionValue->label
,
180 ]), ts('Saved'), 'success');
181 CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/report/options/report_template', "reset=1"));