Commit 6ed6766b authored by mattwire's avatar mattwire
Browse files

Various fixes to search, protected functions etc.

parent fb9acc32
......@@ -244,7 +244,7 @@ class CRM_AdvancedEvents_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntit
'start_date' => $newParams['start_date'],
'end_date' => CRM_Utils_Array::value('end_date', $newParams),
'template_id' => $templateId,
'title' => $eventTemplate['title'],
'title' => $eventTemplate['title'] ?? $eventTemplate['template_title'],
];
// Now create the event
$newEvent = civicrm_api3('Event', 'create', $params);
......
......@@ -272,7 +272,7 @@ class CRM_AdvancedEvents_Form_Search extends CRM_Core_Form_Search {
}
}
private function getSortId() {
protected function getSortId() {
$sortID = NULL;
if ($this->get(CRM_Utils_Sort::SORT_ID)) {
$sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
......
<?php
/*--------------------------------------------------------------------+
| CiviCRM version 5.0 |
+------------------------------0--------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+------------------------------0--------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+-------------------------------------------------------------------*/
use CRM_AdvancedEvents_ExtensionUtil as E;
/**
* Form controller class
*
* @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
*/
class CRM_AdvancedEvents_Form_Settings extends CRM_Core_Form {
function buildQuickForm() {
parent::buildQuickForm();
$className = E::CLASS_PREFIX . '_Settings';
CRM_Utils_System::setTitle($className::TITLE . ' - ' . E::ts('Settings'));
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'buildQuickFormPre')) {
$className::buildQuickFormPre($this);
}
$settings = $this->getFormSettings();
foreach ($settings as $name => $setting) {
if (isset($setting['html_type'])) {
Switch (strtolower($setting['html_type'])) {
case 'text':
$this->addElement('text', $name, ts($setting['description']), $setting['html_attributes'], []);
break;
case 'checkbox':
$this->addElement('checkbox', $name, ts($setting['description']), '', '');
break;
case 'datepicker':
foreach ($setting['html_extra'] as $key => $value) {
if ($key == 'minDate') {
$minDate = new DateTime('now');
$minDate->modify($value);
$setting['html_extra'][$key] = $minDate->format('Y-m-d');
}
}
$this->add('datepicker', $name, ts($setting['description']), $setting['html_attributes'], FALSE, $setting['html_extra']);
break;
case 'select2':
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'addSelect2Element')) {
$className::addSelect2Element($this, $name, $setting);
}
break;
case 'select':
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'addSelectElement')) {
$className::addSelectElement($this, $name, $setting);
}
break;
case 'hidden':
$hidden = TRUE;
}
if (isset($hidden)) {
continue;
}
$adminGroup = isset($setting['admin_group']) ? $setting['admin_group'] : 'default';
$elementGroups[$adminGroup]['elementNames'][] = $name;
// Title and description may not be defined on all elements (they only need to be on one)
if (!empty($setting['admin_grouptitle'])) {
$elementGroups[$setting['admin_group']]['title'] = $setting['admin_grouptitle'];
}
if (!empty($setting['admin_groupdescription'])) {
$elementGroups[$setting['admin_group']]['description'] = $setting['admin_groupdescription'];
}
}
}
$this->addButtons([
[
'type' => 'submit',
'name' => ts('Submit'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
]
]);
// export form elements
$this->assign('elementGroups', $elementGroups);
}
function postProcess() {
$className = E::CLASS_PREFIX . '_Settings';
$changed = $this->_submitValues;
$settings = $this->getFormSettings(TRUE);
foreach ($settings as &$setting) {
if ($setting['html_type'] == 'Checkbox') {
$setting = false;
}
else {
$setting = NULL;
}
}
// Make sure we have all settings elements set (boolean settings will be unset by default and wouldn't be saved)
$settingsToSave = array_merge($settings, array_intersect_key($changed, $settings));
$className::save($settingsToSave);
parent::postProcess();
CRM_Core_Session::singleton()->setStatus('Configuration Updated', $className::TITLE, 'success');
}
/**
* Get the settings we are going to allow to be set on this form.
*
* @return array
*/
function getFormSettings($metadata=TRUE) {
$className = E::CLASS_PREFIX . '_Settings';
$unprefixedSettings = [];
$settings = civicrm_api3('setting', 'getfields', ['filters' => $className::getFilter()]);
if (!empty($settings['values'])) {
foreach ($settings['values'] as $name => $values) {
if ($metadata) {
$unprefixedSettings[$className::getName($name, FALSE)] = $values;
}
else {
$unprefixedSettings[$className::getName($name, FALSE)] = NULL;
}
}
}
return $unprefixedSettings;
}
/**
* Set defaults for form.
*
* @see CRM_Core_Form::setDefaultValues()
*/
function setDefaultValues() {
$className = E::CLASS_PREFIX . '_Settings';
$settings = $this->getFormSettings(FALSE);
$defaults = [];
$existing = $className::get(array_keys($settings));
if ($existing) {
foreach ($existing as $name => $value) {
$defaults[$name] = $value;
}
}
return $defaults;
}
}
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
use CRM_AdvancedEvents_ExtensionUtil as E;
/**
* Form controller class
*
* @see http://wiki.civicrm.org/confluence/display/CRMDOC43/QuickForm+Reference
*/
class CRM_AdvancedEvents_Form_Settings extends CRM_Core_Form {
function buildQuickForm() {
parent::buildQuickForm();
$className = E::CLASS_PREFIX . '_Settings';
CRM_Utils_System::setTitle($className::TITLE . ' - ' . E::ts('Settings'));
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'buildQuickFormPre')) {
$className::buildQuickFormPre($this);
}
$settings = $this->getFormSettings();
foreach ($settings as $name => $setting) {
if (isset($setting['html_type'])) {
Switch (strtolower($setting['html_type'])) {
case 'text':
$this->addElement('text', $name, ts($setting['description']), $setting['html_attributes'], []);
break;
case 'checkbox':
$this->addElement('checkbox', $name, ts($setting['description']), '', '');
break;
case 'datepicker':
foreach ($setting['html_extra'] as $key => $value) {
if ($key == 'minDate') {
$minDate = new DateTime('now');
$minDate->modify($value);
$setting['html_extra'][$key] = $minDate->format('Y-m-d');
}
}
$this->add('datepicker', $name, ts($setting['description']), $setting['html_attributes'], FALSE, $setting['html_extra']);
break;
case 'select2':
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'addSelect2Element')) {
$className::addSelect2Element($this, $name, $setting);
}
break;
case 'select':
$className = E::CLASS_PREFIX . '_Form_SettingsCustom';
if (method_exists($className, 'addSelectElement')) {
$className::addSelectElement($this, $name, $setting);
}
break;
case 'hidden':
$hidden = TRUE;
}
if (isset($hidden)) {
continue;
}
$adminGroup = isset($setting['admin_group']) ? $setting['admin_group'] : 'default';
$elementGroups[$adminGroup]['elementNames'][] = $name;
// Title and description may not be defined on all elements (they only need to be on one)
if (!empty($setting['admin_grouptitle'])) {
$elementGroups[$setting['admin_group']]['title'] = $setting['admin_grouptitle'];
}
if (!empty($setting['admin_groupdescription'])) {
$elementGroups[$setting['admin_group']]['description'] = $setting['admin_groupdescription'];
}
}
}
$this->addButtons([
[
'type' => 'submit',
'name' => ts('Submit'),
'isDefault' => TRUE,
],
[
'type' => 'cancel',
'name' => ts('Cancel'),
]
]);
// export form elements
$this->assign('elementGroups', $elementGroups);
}
function postProcess() {
$className = E::CLASS_PREFIX . '_Settings';
$changed = $this->_submitValues;
$settings = $this->getFormSettings(TRUE);
foreach ($settings as &$setting) {
if ($setting['html_type'] == 'Checkbox') {
$setting = false;
}
else {
$setting = NULL;
}
}
// Make sure we have all settings elements set (boolean settings will be unset by default and wouldn't be saved)
$settingsToSave = array_merge($settings, array_intersect_key($changed, $settings));
$className::save($settingsToSave);
parent::postProcess();
CRM_Core_Session::singleton()->setStatus('Configuration Updated', $className::TITLE, 'success');
}
/**
* Get the settings we are going to allow to be set on this form.
*
* @return array
*/
function getFormSettings($metadata=TRUE) {
$className = E::CLASS_PREFIX . '_Settings';
$unprefixedSettings = [];
$settings = civicrm_api3('setting', 'getfields', ['filters' => $className::getFilter()]);
if (!empty($settings['values'])) {
foreach ($settings['values'] as $name => $values) {
if ($metadata) {
$unprefixedSettings[$className::getName($name, FALSE)] = $values;
}
else {
$unprefixedSettings[$className::getName($name, FALSE)] = NULL;
}
}
}
return $unprefixedSettings;
}
/**
* Set defaults for form.
*
* @see CRM_Core_Form::setDefaultValues()
*/
function setDefaultValues() {
$className = E::CLASS_PREFIX . '_Settings';
$settings = $this->getFormSettings(FALSE);
$defaults = [];
$existing = $className::get(array_keys($settings));
if ($existing) {
foreach ($existing as $name => $value) {
$defaults[$name] = $value;
}
}
return $defaults;
}
}
......@@ -61,7 +61,7 @@ class CRM_AdvancedEvents_Form_Task extends CRM_Core_Form_Task {
$eventSearch = new CRM_AdvancedEvents_Selector_Search($queryParams);
$eventSearch->query();
$ids = CRM_Utils_Array::collect('id', $eventSearch->_rows);
$ids = CRM_Utils_Array::collect('id', $eventSearch->getRowsArray());
}
if (!empty($ids)) {
......
......@@ -30,7 +30,7 @@ class CRM_AdvancedEvents_Page_ManageEventTemplate extends CRM_Core_Page {
* @return string
*/
public function getDefaultEntity() {
return 'Relationship';
return 'Event';
}
/**
......@@ -265,7 +265,7 @@ class CRM_AdvancedEvents_Page_ManageEventTemplate extends CRM_Core_Page {
return CRM_Event_PseudoConstant::eventType($fieldValue);
case 'participant_listing_id':
return CRM_Event_PseudoConstant::participantListing($fieldValue);
return CRM_Core_OptionGroup::values('participant_listing')[$fieldValue];
case 'default_role_id':
return CRM_Event_PseudoConstant::participantRole($fieldValue);
......
......@@ -71,6 +71,11 @@ class CRM_AdvancedEvents_Selector_Search extends CRM_Core_Selector_Base implemen
*/
protected $_rows;
/**
* @var int The event template IDs
*/
protected $_templateIDs = [];
/**
* Class constructor.
*
......@@ -221,14 +226,16 @@ class CRM_AdvancedEvents_Selector_Search extends CRM_Core_Selector_Base implemen
case 'event_template_id':
if (strpos($queryParam[2], ',') === FALSE) {
$this->_templateId = $queryParam[2];
$this->_apiParams['template_id'] = $this->_templateId;
// We have one event template ID to search for
$this->addEventTemplateID($queryParam[2]);
$templateTitle = civicrm_api3('Event', 'getvalue', ['id' => $queryParam[2], 'return' => 'template_title']);
$this->_qill['OR'][] = "Template is $templateTitle";
}
else {
// We have multiple event template IDs to search for
$templateIds = explode(',', $queryParam[2]);
foreach ($templateIds as $templateId) {
$this->addEventTemplateID($templateId);
try {
$templateTitle = civicrm_api3('Event', 'getvalue', [
'id' => $templateId,
......@@ -238,9 +245,8 @@ class CRM_AdvancedEvents_Selector_Search extends CRM_Core_Selector_Base implemen
}
catch (Exception $e) {}
}
$this->templateId = ['IN' => $templateIds];
$this->_apiParams['template_id'] = $this->_templateId;
}
$this->_apiParams['template_id'] = ['IN' => $this->getEventTemplateIDs()];
break;
default:
......@@ -413,8 +419,12 @@ class CRM_AdvancedEvents_Selector_Search extends CRM_Core_Selector_Base implemen
return $result;
}
protected function getEventTemplateId() {
return isset($this->_templateId) ? $this->_templateId : NULL;
protected function getEventTemplateIDs() {
return $this->_templateIDs ?? NULL;
}
protected function addEventTemplateID($templateID) {
$this->_templateIDs[$templateID] = $templateID;
}
/**
......@@ -464,7 +474,7 @@ class CRM_AdvancedEvents_Selector_Search extends CRM_Core_Selector_Base implemen
// Get details of all events linked to this template
$templateParams = [
'template_id' => $this->getEventTemplateId(),
'template_id' => ['IN' => $this->getEventTemplateIDs()],
'options' => ['limit' => 0],
];
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment