/** * build all the data structures needed to build the form * * @param * @return void * @access public */ function preProcess() { $this->_participantIds = array(); $values = $this->controller->exportValues('Search'); $this->_task = $values['task']; $eventTasks = CRM_Event_Task::tasks(); $this->assign('taskName', $eventTasks[$this->_task]); $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $this->get('queryParams'); $query =& new CRM_Contact_BAO_Query($queryParams, null, null, false, false, CRM_Contact_BAO_Query::MODE_EVENT); $result = $query->searchQuery(0, 0, null); while ($result->fetch()) { $ids[] = $result->participant_id; } } if (!empty($ids)) { $this->_componentClause = ' civicrm_participant.id IN ( ' . implode(',', $ids) . ' ) '; $this->assign('totalSelectedParticipants', count($ids)); } $this->_participantIds = $this->_componentIds = $ids; //set the context for redirection for any task actions $session =& CRM_Core_Session::singleton(); $session->replaceUserContext(CRM_Utils_System::url('civicrm/event/search', 'force=1')); }
/** * Determine the form name based on the action. This allows us * to avoid using conditional state machine, much more efficient * and simpler * * @param CRM_Core_Controller $controller the controller object * * @return string the name of the form that will handle the task * @access protected */ function taskName($controller, $formName = 'Search') { // total hack, check POST vars and then session to determine stuff $value = CRM_Utils_Array::value('task', $_POST); if (!isset($value)) { $value = $this->_controller->get('task'); } $this->_controller->set('task', $value); return CRM_Event_Task::getTask($value); }
/** * These tasks are the core set of tasks that the user can perform * on a contact / group of contacts * * @return array the set of tasks for a group of contacts * @static * @access public */ static function &tasks() { if (!self::$_tasks) { self::$_tasks = array(1 => ts('Delete Participants'), 3 => ts('Export Participants'), 4 => ts('Batch Update Participants Via Profile'), 5 => ts('Cancel Registration'), 13 => ts('New Smart Group'), 6 => ts('Send Email to Contacts'), 15 => ts('Change Participant Status')); //CRM-4418, check for delete if (!CRM_Core_Permission::check('delete in CiviEvent')) { unset(self::$_tasks[1]); } } asort(self::$_tasks); return self::$_tasks; }
/** * These tasks are the core set of tasks that the user can perform * on a contact / group of contacts * * @return array the set of tasks for a group of contacts * @static * @access public */ static function &tasks() { if (!self::$_tasks) { self::$_tasks = array(1 => array('title' => ts('Delete Participants'), 'class' => 'CRM_Event_Form_Task_Delete', 'result' => FALSE), 2 => array('title' => ts('Print Selected Rows'), 'class' => 'CRM_Event_Form_Task_Print', 'result' => FALSE), 3 => array('title' => ts('Export Participants'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), 4 => array('title' => ts('Batch Update Participants Via Profile'), 'class' => array('CRM_Event_Form_Task_PickProfile', 'CRM_Event_Form_Task_Batch'), 'result' => TRUE), 5 => array('title' => ts('Cancel Registration'), 'class' => 'CRM_Event_Form_Task_Cancel', 'result' => FALSE), 6 => array('title' => ts('Send Email to Contacts'), 'class' => 'CRM_Event_Form_Task_Email', 'result' => TRUE), 13 => array('title' => ts('New Smart Group'), 'class' => 'CRM_Event_Form_Task_SaveSearch', 'result' => TRUE), 14 => array('title' => ts('Update Smart Group'), 'class' => 'CRM_Event_Form_Task_SaveSearch_Update', 'result' => TRUE), 15 => array('title' => ts('Change Participant Status'), 'class' => 'CRM_Event_Form_Task_ParticipantStatus', 'result' => TRUE), 16 => array('title' => ts('Print Event Name Badges'), 'class' => 'CRM_Event_Form_Task_Badge', 'result' => FALSE)); //CRM-4418, check for delete if (!CRM_Core_Permission::check('delete in CiviEvent')) { unset(self::$_tasks[1]); } } CRM_Utils_Hook::searchTasks('event', self::$_tasks); asort(self::$_tasks); return self::$_tasks; }
/** * These tasks are the core set of tasks that the user can perform * on a contact / group of contacts * * @return array * the set of tasks for a group of contacts */ public static function &tasks() { if (!self::$_tasks) { self::$_tasks = array(1 => array('title' => ts('Delete participants from event'), 'class' => 'CRM_Event_Form_Task_Delete', 'result' => FALSE), 2 => array('title' => ts('Print selected rows'), 'class' => 'CRM_Event_Form_Task_Print', 'result' => FALSE), 3 => array('title' => ts('Export participants'), 'class' => array('CRM_Export_Form_Select', 'CRM_Export_Form_Map'), 'result' => FALSE), 4 => array('title' => ts('Update multiple participants'), 'class' => array('CRM_Event_Form_Task_PickProfile', 'CRM_Event_Form_Task_Batch'), 'result' => TRUE), 5 => array('title' => ts('Cancel registration'), 'class' => 'CRM_Event_Form_Task_Cancel', 'result' => FALSE), 6 => array('title' => ts('Email - send now'), 'class' => 'CRM_Event_Form_Task_Email', 'result' => TRUE), 13 => array('title' => ts('Group - create smart group'), 'class' => 'CRM_Event_Form_Task_SaveSearch', 'result' => TRUE), 14 => array('title' => ts('Group - update smart group'), 'class' => 'CRM_Event_Form_Task_SaveSearch_Update', 'result' => TRUE), 15 => array('title' => ts('Participant status - change (emails sent)'), 'class' => 'CRM_Event_Form_Task_ParticipantStatus', 'result' => TRUE), 16 => array('title' => ts('Name badges - print'), 'class' => 'CRM_Event_Form_Task_Badge', 'result' => FALSE), 17 => array('title' => ts('PDF letter - print for participants'), 'class' => 'CRM_Event_Form_Task_PDF', 'result' => TRUE), 20 => array('title' => ts('Group - add contacts'), 'class' => 'CRM_Event_Form_Task_AddToGroup', 'result' => FALSE)); //CRM-4418, check for delete if (!CRM_Core_Permission::check('delete in CiviEvent')) { unset(self::$_tasks[1]); } //CRM-12920 - check for edit permission if (!CRM_Core_Permission::check('edit event participants')) { unset(self::$_tasks[4], self::$_tasks[5], self::$_tasks[15]); } } CRM_Utils_Hook::searchTasks('event', self::$_tasks); return self::$_tasks; }
/** * @param CRM_Core_Form $form * @param bool $useTable */ public static function preProcessCommon(&$form, $useTable = FALSE) { $form->_participantIds = array(); $values = $form->controller->exportValues($form->get('searchFormName')); $form->_task = $values['task']; $eventTasks = CRM_Event_Task::tasks(); $form->assign('taskName', $eventTasks[$form->_task]); $ids = array(); if ($values['radio_ts'] == 'ts_sel') { foreach ($values as $name => $value) { if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) { $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN); } } } else { $queryParams = $form->get('queryParams'); $sortOrder = NULL; if ($form->get(CRM_Utils_Sort::SORT_ORDER)) { $sortOrder = $form->get(CRM_Utils_Sort::SORT_ORDER); } $query = new CRM_Contact_BAO_Query($queryParams, NULL, NULL, FALSE, FALSE, CRM_Contact_BAO_Query::MODE_EVENT); $query->_distinctComponentClause = "civicrm_participant.id"; $query->_groupByComponentClause = " GROUP BY civicrm_participant.id "; $result = $query->searchQuery(0, 0, $sortOrder); while ($result->fetch()) { $ids[] = $result->participant_id; } } if (!empty($ids)) { $form->_componentClause = ' civicrm_participant.id IN ( ' . implode(',', $ids) . ' ) '; $form->assign('totalSelectedParticipants', count($ids)); } $form->_participantIds = $form->_componentIds = $ids; //set the context for redirection for any task actions $session = CRM_Core_Session::singleton(); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlParams = 'force=1'; if (CRM_Utils_Rule::qfKey($qfKey)) { $urlParams .= "&qfKey={$qfKey}"; } $searchFormName = strtolower($form->get('searchFormName')); if ($searchFormName == 'search') { $session->replaceUserContext(CRM_Utils_System::url('civicrm/event/search', $urlParams)); } else { $session->replaceUserContext(CRM_Utils_System::url("civicrm/contact/search/{$searchFormName}", $urlParams)); } }
/** * Determine the form name based on the action. This allows us * to avoid using conditional state machine, much more efficient * and simpler * * @param CRM_Core_Controller $controller the controller object * * @return string the name of the form that will handle the task * @access protected */ function taskName($controller, $formName = 'Search') { // total hack, check POST vars and then session to determine stuff // fix value if print button is pressed if (CRM_Utils_Array::value('_qf_' . $formName . '_next_print', $_POST)) { $value = CRM_Event_Task::PRINT_EVENTS; } else { $value = CRM_Utils_Array::value('task', $_POST); } if (!isset($value)) { $value = $this->_controller->get('task'); } $this->_controller->set('task', $value); return CRM_Event_Task::getTask($value); }
/** * Build the form object. * * * @return void */ public function buildQuickForm() { parent::buildQuickForm(); $this->addSortNameField(); if (CRM_Core_Permission::check('access deleted contacts') and Civi::settings()->get('contact_undelete')) { $this->addElement('checkbox', 'deleted_contacts', ts('Search in Trash') . '<br />' . ts('(deleted contacts)')); } CRM_Event_BAO_Query::buildSearchForm($this); $rows = $this->get('rows'); if (is_array($rows)) { $lineItems = $eventIds = array(); if (!$this->_single) { $this->addRowSelectors($rows); } foreach ($rows as $row) { $eventIds[$row['event_id']] = $row['event_id']; if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) { // add line item details if applicable $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']); } } //get actual count only when we are dealing w/ single event. $participantCount = 0; if (count($eventIds) == 1) { //convert form values to clause. $seatClause = array(); if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') { $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )"; } if (!empty($this->_formValues['participant_status_id'])) { $seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", '=', $this->_formValues['participant_status_id'], 'Int'); if ($status = CRM_Utils_Array::value('IN', $this->_formValues['participant_status_id'])) { $this->_formValues['participant_status_id'] = $status; } } if (!empty($this->_formValues['participant_role_id'])) { $escapedRoles = array(); foreach ((array) $this->_formValues['participant_role_id'] as $participantRole) { $escapedRoles[] = CRM_Utils_Type::escape($participantRole, 'String'); } $seatClause[] = "( participant.role_id IN ( '" . implode("' , '", $escapedRoles) . "' ) )"; } // CRM-15379 if (!empty($this->_formValues['participant_fee_id'])) { $participant_fee_id = $this->_formValues['participant_fee_id']; foreach ($participant_fee_id as $k => &$val) { $val = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label'); $val = CRM_Core_DAO::escapeString(trim($val)); } $feeLabel = implode('|', $participant_fee_id); $seatClause[] = "( participant.fee_level REGEXP '{$feeLabel}' )"; } $seatClause = implode(' AND ', $seatClause); $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $seatClause); } $this->assign('participantCount', $participantCount); $this->assign('lineItems', $lineItems); $permission = CRM_Core_Permission::getPermission(); $tasks = CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } $this->addTaskMenu($tasks); } }
/** * Build the form object. * * * @return void */ public function buildQuickForm() { parent::buildQuickForm(); $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); CRM_Event_BAO_Query::buildSearchForm($this); $rows = $this->get('rows'); if (is_array($rows)) { $lineItems = $eventIds = array(); if (!$this->_single) { $this->addRowSelectors($rows); } foreach ($rows as $row) { $eventIds[$row['event_id']] = $row['event_id']; if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) { // add line item details if applicable $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']); } } //get actual count only when we are dealing w/ single event. $participantCount = 0; if (count($eventIds) == 1) { //convert form values to clause. $seatClause = array(); if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') { $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )"; } if (!empty($this->_formValues['participant_status_id'])) { $seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", '=', $this->_formValues['participant_status_id'], 'Int'); if ($status = CRM_Utils_Array::value('IN', $this->_formValues['participant_status_id'])) { $this->_formValues['participant_status_id'] = $status; } } if (!empty($this->_formValues['participant_role_id'])) { $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', (array) $this->_formValues['participant_role_id']) . ' ) )'; } // CRM-15379 if (!empty($this->_formValues['participant_fee_id'])) { $participant_fee_id = $this->_formValues['participant_fee_id']; $feeLabel = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $participant_fee_id, 'label'); $feeLabel = CRM_Core_DAO::escapeString(trim($feeLabel)); $seatClause[] = "( participant.fee_level LIKE '%{$feeLabel}%' )"; } $seatClause = implode(' AND ', $seatClause); $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $seatClause); } $this->assign('participantCount', $participantCount); $this->assign('lineItems', $lineItems); $permission = CRM_Core_Permission::getPermission(); $tasks = CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } $this->addTaskMenu($tasks); } }
/** * Build the form * * @access public * * @return void */ function buildQuickForm() { $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); CRM_Event_BAO_Query::buildSearchForm($this); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $lineItems = $eventIds = array(); if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); } foreach ($rows as $row) { $eventIds[$row['event_id']] = $row['event_id']; if (!$this->_single) { $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")); } if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) { // add line item details if applicable $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']); } } //get actual count only when we are dealing w/ single event. $participantCount = 0; if (count($eventIds) == 1) { //convert form values to clause. $seatClause = array(); // Filter on is_test if specified in search form if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0') { $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )"; } if (CRM_Utils_Array::value('participant_status_id', $this->_formValues)) { $statuses = array_keys($this->_formValues['participant_status_id']); $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )'; } if (CRM_Utils_Array::value('participant_role_id', $this->_formValues)) { $roles = array_keys($this->_formValues['participant_role_id']); $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )'; } $clause = NULL; if (!empty($seatClause)) { $clause = implode(' AND ', $seatClause); } $participantCount = CRM_Event_BAO_Event::eventTotalSeats(array_pop($eventIds), $clause); } $this->assign('participantCount', $participantCount); $this->assign('lineItems', $lineItems); $total = $cancel = 0; $permission = CRM_Core_Permission::getPermission(); $tasks = array('' => ts('- actions -')) + CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);")); $this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked')); $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );")); } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => TRUE))); }
/** * Build the form * * @access public * @return void */ function buildQuickForm() { $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')); require_once 'CRM/Event/BAO/Query.php'; CRM_Event_BAO_Query::buildSearchForm($this); /* * add form checkboxes for each row. This is needed out here to conform to QF protocol * of all elements being declared in builQuickForm */ $rows = $this->get('rows'); if (is_array($rows)) { $lineItems = array(); require_once 'CRM/Event/BAO/Event.php'; if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', null, null, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); } foreach ($rows as $row) { if (!$this->_single) { $this->addElement('checkbox', $row['checkbox'], null, null, array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "', '" . $this->getName() . "');")); } if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) { // add line item details if applicable require_once 'CRM/Price/BAO/LineItem.php'; $lineItems[$row['participant_id']] = CRM_Price_BAO_LineItem::getLineItems($row['participant_id']); } } $this->assign('lineItems', $lineItems); $total = $cancel = 0; require_once "CRM/Core/Permission.php"; $permission = CRM_Core_Permission::getPermission(); require_once 'CRM/Event/Task.php'; $tasks = array('' => ts('- more actions -')) + CRM_Event_Task::permissionedTaskTitles($permission); if (isset($this->_ssID)) { if ($permission == CRM_Core_Permission::EDIT) { require_once "CRM/Contact/Task.php"; $tasks = $tasks + CRM_Event_Task::optionalTaskTitle(); } $savedSearchValues = array('id' => $this->_ssID, 'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title')); $this->assign_by_ref('savedSearch', $savedSearchValues); $this->assign('ssID', $this->_ssID); } $this->add('select', 'task', ts('Actions:') . ' ', $tasks); $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'form-submit', 'id' => 'Go', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);")); $this->add('submit', $this->_printButtonName, ts('Print'), array('class' => 'form-submit', 'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);")); // need to perform tasks on all or selected items ? using radio_ts(task selection) for it $this->addElement('radio', 'radio_ts', null, '', 'ts_sel', array('checked' => 'checked')); $this->addElement('radio', 'radio_ts', null, '', 'ts_all', array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );")); } // add buttons $this->addButtons(array(array('type' => 'refresh', 'name' => ts('Search'), 'isDefault' => true))); }