function validate() { parent::validate(); if ($this->_errors) { return FALSE; } $this->cart->load_associations(); $fields = $this->_submitValues; foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) { $price_set_id = CRM_Event_BAO_Event::usesPriceSet($event_in_cart->event_id); if ($price_set_id) { $priceField = new CRM_Price_DAO_PriceField(); $priceField->price_set_id = $price_set_id; $priceField->find(); $check = array(); while ($priceField->fetch()) { if (!empty($fields["event_{$event_in_cart->event_id}_price_{$priceField->id}"])) { $check[] = $priceField->id; } } //XXX if (empty($check)) { $this->_errors['_qf_default'] = ts("Select at least one option from Price Levels."); } $lineItem = array(); if (is_array($this->_values['fee']['fields'])) { CRM_Price_BAO_PriceSet::processAmount($this->_values['fee']['fields'], $fields, $lineItem); //XXX total... if ($fields['amount'] < 0) { $this->_errors['_qf_default'] = ts("Price Levels can not be less than zero. Please select the options accordingly"); } } } foreach ($event_in_cart->participants as $mer_participant) { $participant_fields = $fields['event'][$event_in_cart->event_id]['participant'][$mer_participant->id]; //TODO what to do when profile responses differ for the same contact? $contact_id = self::find_contact($participant_fields); if ($contact_id) { $participant = new CRM_Event_BAO_Participant(); $participant->event_id = $event_in_cart->event_id; $participant->contact_id = $contact_id; $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); $participant->find(); while ($participant->fetch()) { if (array_key_exists($participant->status_id, $statusTypes)) { $form = $mer_participant->get_form(); $this->_errors[$form->html_field_name('email')] = ts("The participant %1 is already registered for %2 (%3).", array(1 => $participant_fields['email'], 2 => $event_in_cart->event->title, 3 => $event_in_cart->event->start_date)); } } } } } return empty($this->_errors); }
/** * Returns all the rows in the given offset and rowCount. * * @param string $action * The action being performed. * @param int $offset * The row number to start from. * @param int $rowCount * The number of rows to return. * @param string $sort * The sql string that describes the sort order. * @param string $output * What should the result set include (web/email/csv). * * @return array * rows in the given offset and rowCount */ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_eventClause); // process the result of the query $rows = array(); //lets handle view, edit and delete separately. CRM-4418 $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('edit event participants')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviEvent')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); $statusTypes = CRM_Event_PseudoConstant::participantStatus(); $statusClasses = CRM_Event_PseudoConstant::participantStatusClass(); $participantRoles = CRM_Event_PseudoConstant::participantRole(); $sep = CRM_Core_DAO::VALUE_SEPARATOR; //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); while ($result->fetch()) { $row = array(); // the columns we are interested in foreach (self::$_properties as $property) { if (isset($result->{$property})) { $row[$property] = $result->{$property}; } } //carry campaign on selectors. $row['campaign'] = CRM_Utils_Array::value($result->participant_campaign_id, $allCampaigns); $row['campaign_id'] = $result->participant_campaign_id; // gross hack to show extra information for pending status $statusClass = NULL; if (isset($row['participant_status_id']) && ($statusId = array_search($row['participant_status_id'], $statusTypes))) { $statusClass = $statusClasses[$statusId]; } $row['showConfirmUrl'] = $statusClass == 'Pending' ? TRUE : FALSE; if (!empty($row['participant_is_test'])) { $row['participant_status'] .= ' (' . ts('test') . ')'; } $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->participant_id; $links = self::links($this->_key, $this->_context, $this->_compContext); if ($statusTypes[$row['participant_status_id']] == 'Partially paid') { $links[CRM_Core_Action::ADD] = array('name' => ts('Record Payment'), 'url' => 'civicrm/payment', 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event', 'title' => ts('Record Payment')); } if ($statusTypes[$row['participant_status_id']] == 'Pending refund') { $links[CRM_Core_Action::ADD] = array('name' => ts('Record Refund'), 'url' => 'civicrm/payment', 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=add&component=event', 'title' => ts('Record Refund')); } $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->participant_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'participant.selector.row', 'Participant', $result->participant_id); $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); $row['paid'] = CRM_Event_BAO_Event::isMonetary($row['event_id']); if (!empty($row['participant_fee_level'])) { CRM_Event_BAO_Participant::fixEventLevel($row['participant_fee_level']); } 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']); } if (!empty($row['participant_role_id'])) { $viewRoles = array(); foreach (explode($sep, $row['participant_role_id']) as $k => $v) { $viewRoles[] = $participantRoles[$v]; } $row['participant_role_id'] = implode(', ', $viewRoles); } $rows[] = $row; } CRM_Core_Selector_Controller::$_template->assign_by_ref('lineItems', $lineItems); return $rows; }
/** * 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); } }
/** * Set default values. * * @return array */ public function setDefaultValues() { $this->loadCart(); $defaults = array(); foreach ($this->cart->get_main_event_participants() as $participant) { $form = $participant->get_form(); if (empty($participant->email) && !CRM_Event_Cart_Form_Cart::is_administrator() && $participant->get_participant_index() == 1 && $this->cid != 0) { $defaults = array(); $params = array('id' => $this->cid); $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults); $participant->contact_id = $this->cid; $participant->save(); $participant->email = self::primary_email_from_contact($contact); } elseif ($this->cid == 0 && $participant->contact_id == self::getContactID()) { $participant->email = NULL; $participant->contact_id = self::find_or_create_contact($this->getContactID()); } $defaults += $form->setDefaultValues(); //Set price defaults if any foreach ($this->cart->get_main_events_in_carts() as $event_in_cart) { $event_id = $event_in_cart->event_id; $price_set_id = CRM_Event_BAO_Event::usesPriceSet($event_in_cart->event_id); if ($price_set_id) { $price_sets = CRM_Price_BAO_PriceSet::getSetDetail($price_set_id, TRUE, TRUE); $price_set = $price_sets[$price_set_id]; foreach ($price_set['fields'] as $field) { $options = CRM_Utils_Array::value('options', $field); if (!is_array($options)) { continue; } $field_name = "event_{$event_id}_price_{$field['id']}"; foreach ($options as $value) { if ($value['is_default']) { if ($field['html_type'] == 'Checkbox') { $defaults[$field_name] = 1; } else { $defaults[$field_name] = $value['id']; } } } } } } } return $defaults; }
/** * 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))); }
/** * returns all the rows in the given offset and rowCount * * @param enum $action the action being performed * @param int $offset the row number to start from * @param int $rowCount the number of rows to return * @param string $sort the sql string that describes the sort order * @param enum $output what should the result set include (web/email/csv) * * @return array rows in the given offset and rowCount */ function &getRows($action, $offset, $rowCount, $sort, $output = null) { $result = $this->_query->searchQuery($offset, $rowCount, $sort, false, false, false, false, false, $this->_eventClause); // process the result of the query $rows = array(); //lets handle view, edit and delete separately. CRM-4418 $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('edit event participants')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviEvent')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); require_once 'CRM/Event/BAO/Event.php'; require_once 'CRM/Event/PseudoConstant.php'; $statusTypes = CRM_Event_PseudoConstant::participantStatus(); $statusClasses = CRM_Event_PseudoConstant::participantStatusClass(); while ($result->fetch()) { $row = array(); // the columns we are interested in foreach (self::$_properties as $property) { if (isset($result->{$property})) { $row[$property] = $result->{$property}; } } // gross hack to show extra information for pending status $statusClass = null; if ($statusId = array_search($row['participant_status_id'], $statusTypes)) { $statusClass = $statusClasses[$statusId]; } $extraInfo = array(); $row['showConfirmUrl'] = false; if ($statusClass == 'Pending') { $row['showConfirmUrl'] = true; } if (CRM_Utils_Array::value('participant_is_test', $row)) { $extraInfo[] = ts('test'); } if ($extraInfo) { $row['participant_status_id'] .= ' (' . implode(', ', $extraInfo) . ')'; } $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->participant_id; $row['action'] = CRM_Core_Action::formLink(self::links(), $mask, array('id' => $result->participant_id, 'cid' => $result->contact_id, 'cxt' => $this->_context)); require_once 'CRM/Contact/BAO/Contact/Utils.php'; $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type); $row['paid'] = CRM_Event_BAO_Event::isMonetary($row['event_id']); if (CRM_Utils_Array::value('participant_fee_level', $row)) { CRM_Event_BAO_Participant::fixEventLevel($row['participant_fee_level']); } 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']); } $rows[] = $row; } CRM_Core_Selector_Controller::$_template->assign_by_ref('lineItems', $lineItems); return $rows; }