/** * This function sets the default values for the form. * * @access public * * @return void */ public function setDefaultValues() { $defaults = array(); if (isset($this->_id)) { $defaults['entity_table'] = 'civicrm_event'; $defaults['entity_id'] = $this->_id; CRM_Friend_BAO_Friend::getValues($defaults); if (!empty($defaults['id'])) { $defaults['tf_id'] = CRM_Utils_Array::value('id', $defaults); $this->_friendId = $defaults['tf_id']; // lets unset the 'id' since it conflicts with eventID (or contribID) // CRM-12667 unset($defaults['id']); } $defaults['tf_title'] = CRM_Utils_Array::value('title', $defaults); $defaults['tf_is_active'] = CRM_Utils_Array::value('is_active', $defaults); $defaults['tf_thankyou_title'] = CRM_Utils_Array::value('thankyou_title', $defaults); $defaults['tf_thankyou_text'] = CRM_Utils_Array::value('thankyou_text', $defaults); } if (!$this->_friendId) { $defaults['intro'] = ts('Help us spread the word about this event. Use the space below to personalize your email message - let your friends know why you\'re attending. Then fill in the name(s) and email address(es) and click \'Send Your Message\'.'); $defaults['suggested_message'] = ts('Thought you might be interested in checking out this event. I\'m planning on attending.'); $defaults['tf_thankyou_text'] = ts('Thanks for spreading the word about this event to your friends.'); $defaults['tf_title'] = ts('Tell a Friend'); $defaults['tf_thankyou_title'] = ts('Thanks for Spreading the Word'); } return $defaults; }
/** * This function sets the default values for the form. Note that in edit/view mode * the default values are retrieved from the database * * @access public * @return None */ public function setDefaultValues() { $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title'); CRM_Utils_System::setTitle(ts('Tell a Friend') . " ({$title})"); $defaults = array(); if (isset($this->_id)) { $defaults['entity_table'] = 'civicrm_contribution_page'; $defaults['entity_id'] = $this->_id; CRM_Friend_BAO_Friend::getValues($defaults); $this->_friendId = CRM_Utils_Array::value('id', $defaults); $defaults['tf_title'] = CRM_Utils_Array::value('title', $defaults); $defaults['tf_is_active'] = CRM_Utils_Array::value('is_active', $defaults); } if (!$this->_friendId) { $defaults['intro'] = ts('Help us spread the word and leverage the power of your contribution by telling your friends. Use the space below to personalize your email message - let your friends know why you support us. Then fill in the name(s) and email address(es) and click \'Send Your Message\'.'); $defaults['suggested_message'] = ts('Thought you might be interested in learning about and helping this organization. I think they do important work.'); $defaults['thankyou_text'] = ts('Thanks for telling your friends about us and supporting our efforts. Together we can make a difference.'); $defaults['tf_title'] = ts('Tell a Friend'); $defaults['thankyou_title'] = ts('Thanks for Spreading the Word'); } return $defaults; }
/** * Process the form submission. * * * @return void */ public function postProcess() { // get the submitted form values. $formValues = $this->controller->exportValues($this->_name); $formValues['entity_id'] = $this->_entityId; $formValues['entity_table'] = $this->_entityTable; $formValues['source_contact_id'] = $this->_contactID; $formValues['is_test'] = $this->_action ? 1 : 0; $formValues['title'] = $this->_title; $formValues['campaign_id'] = $this->_campaignId; CRM_Friend_BAO_Friend::create($formValues); $this->assign('status', 'thankyou'); $defaults = array(); $defaults['entity_id'] = $this->_entityId; $defaults['entity_table'] = $this->_entityTable; CRM_Friend_BAO_Friend::getValues($defaults); if ($this->_entityTable == 'civicrm_pcp') { $defaults['thankyou_text'] = $defaults['thankyou_title'] = ts('Thank you for your support'); $defaults['thankyou_text'] = ts('Thanks for supporting this campaign by spreading the word to your friends.'); } elseif ($this->_entityTable == 'civicrm_contribution_page') { // If this is tell a friend after contributing, give donor link to create their own fundraising page if ($linkText = CRM_PCP_BAO_PCP::getPcpBlockStatus($defaults['entity_id'], $defaults['entity_table'])) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$defaults['entity_id']}&component=contribute", FALSE, NULL, TRUE, TRUE); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $linkText); } } elseif ($this->_entityTable == 'civicrm_event') { // If this is tell a friend after registering for an event, give donor link to create their own fundraising page require_once 'CRM/PCP/BAO/PCP.php'; if ($linkText = CRM_PCP_BAO_PCP::getPcpBlockStatus($defaults['entity_id'], $defaults['entity_table'])) { $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$defaults['entity_id']}&component=event", FALSE, NULL, TRUE, TRUE); $this->assign('linkTextUrl', $linkTextUrl); $this->assign('linkText', $linkText); } } CRM_Utils_System::setTitle($defaults['thankyou_title']); $this->assign('thankYouText', $defaults['thankyou_text']); }
/** * Browse all events. * * @return void */ public function browse() { Civi::resources()->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header'); $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this); $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0); if (strtolower($this->_sortByCharacter) == 'all' || !empty($_POST)) { $this->_sortByCharacter = ''; $this->set('sortByCharacter', ''); } $this->_force = $this->_searchResult = NULL; $this->search(); $params = array(); $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, FALSE); $this->_searchResult = CRM_Utils_Request::retrieve('searchResult', 'Boolean', $this); $whereClause = $this->whereClause($params, FALSE, $this->_force); $this->pagerAToZ($whereClause, $params); $params = array(); $whereClause = $this->whereClause($params, TRUE, $this->_force); // because is_template != 1 would be to simple $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)'; $this->pager($whereClause, $params); list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); // get all custom groups sorted by weight $manageEvent = array(); $query = "\n SELECT *\n FROM civicrm_event\n WHERE {$whereClause}\nORDER BY start_date desc\n LIMIT {$offset}, {$rowCount}"; $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Event_DAO_Event'); $permissions = CRM_Event_BAO_Event::checkPermission(); //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); // get the list of active event pcps $eventPCPS = array(); $pcpDao = new CRM_PCP_DAO_PCPBlock(); $pcpDao->entity_table = 'civicrm_event'; $pcpDao->find(); while ($pcpDao->fetch()) { $eventPCPS[$pcpDao->entity_id] = $pcpDao->entity_id; } // check if we're in shopping cart mode for events $enableCart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart'); $this->assign('eventCartEnabled', $enableCart); $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID))); $eventType = CRM_Core_OptionGroup::values('event_type'); while ($dao->fetch()) { if (in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])) { $manageEvent[$dao->id] = array(); $repeat = CRM_Core_BAO_RecurringEntity::getPositionAndCount($dao->id, 'civicrm_event'); $manageEvent[$dao->id]['repeat'] = ''; if ($repeat) { $manageEvent[$dao->id]['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1])); } CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]); // form all action links $action = array_sum(array_keys($this->links())); if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if (!in_array($dao->id, $permissions[CRM_Core_Permission::DELETE])) { $action -= CRM_Core_Action::DELETE; } if (!in_array($dao->id, $permissions[CRM_Core_Permission::EDIT])) { $action -= CRM_Core_Action::UPDATE; } $manageEvent[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), TRUE, 'event.manage.list', 'Event', $dao->id); $params = array('entity_id' => $dao->id, 'entity_table' => 'civicrm_event', 'is_active' => 1); $defaults['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); $manageEvent[$dao->id]['friend'] = CRM_Friend_BAO_Friend::getValues($params); if (isset($defaults['location']['address'][1]['city'])) { $manageEvent[$dao->id]['city'] = $defaults['location']['address'][1]['city']; } if (isset($defaults['location']['address'][1]['state_province_id'])) { $manageEvent[$dao->id]['state_province'] = CRM_Core_PseudoConstant::stateProvince($defaults['location']['address'][1]['state_province_id']); } //show campaigns on selector. $manageEvent[$dao->id]['campaign'] = CRM_Utils_Array::value($dao->campaign_id, $allCampaigns); $manageEvent[$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mapping->getId()); $manageEvent[$dao->id]['is_pcp_enabled'] = CRM_Utils_Array::value($dao->id, $eventPCPS); $manageEvent[$dao->id]['event_type'] = CRM_Utils_Array::value($manageEvent[$dao->id]['event_type_id'], $eventType); $manageEvent[$dao->id]['is_repeating_event'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_RecurringEntity', $dao->id, 'parent_id', 'entity_id'); // allow hooks to set 'field' value which allows configuration pop-up to show a tab as enabled/disabled CRM_Utils_Hook::tabset('civicrm/event/manage/rows', $manageEvent, array('event_id' => $dao->id)); } } $manageEvent['tab'] = self::tabs($enableCart); $this->assign('rows', $manageEvent); $statusTypes = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 0'); $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); $this->assign('findParticipants', $findParticipants); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //format params $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); $params['end_date'] = CRM_Utils_Date::processDate($params['end_date'], $params['end_date_time'], true); $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, false); $params['is_map'] = CRM_Utils_Array::value('is_map', $params, false); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); $params['is_public'] = CRM_Utils_Array::value('is_public', $params, false); $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, false); $params['id'] = $this->_id; //new event, so lets set the created_id if ($this->_action & CRM_Core_Action::ADD) { $session =& CRM_Core_Session::singleton(); $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $customFields = CRM_Core_BAO_CustomField::getFields('Event', false, false, CRM_Utils_Array::value('event_type_id', $params)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event'); require_once 'CRM/Event/BAO/Event.php'; // copy all not explicitely set $params keys from the template (if it should be sourced) if (CRM_Utils_Array::value('template_id', $params)) { $defaults = array(); $templateParams = array('id' => $params['template_id']); CRM_Event_BAO_Event::retrieve($templateParams, $defaults); unset($defaults['id']); unset($defaults['default_fee_id']); unset($defaults['default_discount_fee_id']); foreach ($defaults as $key => $value) { if (!isset($params[$key])) { $params[$key] = $value; } } } $event = CRM_Event_BAO_Event::create($params); // now that we have the event’s id, do some more template-based stuff if (CRM_Utils_Array::value('template_id', $params)) { // copy event fees $ogParams = array('name' => "civicrm_event.amount.{$event->id}"); $defaults = array(); require_once 'CRM/Core/BAO/OptionGroup.php'; if (is_null(CRM_Core_BAO_OptionGroup::retrieve($ogParams, $defaults))) { // Copy the Main Event Fees CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id); // Copy the Discount option Group and Values require_once 'CRM/Core/BAO/Discount.php'; $optionGroupIds = CRM_Core_BAO_Discount::getOptionGroup($params['template_id'], "civicrm_event"); foreach ($optionGroupIds as $id) { $discountSuffix = '.discount.' . CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $id, 'label'); CRM_Core_BAO_OptionGroup::copyValue('event', $params['template_id'], $event->id, false, $discountSuffix); } } // copy price sets if any require_once 'CRM/Price/BAO/Set.php'; $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']); if ($priceSetId) { CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId); } // link profiles if none linked $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); require_once 'CRM/Core/BAO/UFJoin.php'; if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) { CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id)); } // if no Tell-a-Friend defined, check whether there’s one for template and copy if so $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); require_once 'CRM/Friend/BAO/Friend.php'; if (!CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $params['template_id']; if (CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $event->id; CRM_Friend_BAO_Friend::addTellAFriend($tafParams); } } } $this->set('id', $event->id); if ($this->_action & CRM_Core_Action::ADD) { $urlParam = "action=update&reset=1&subPage=Location&id={$event->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == "_qf_EventInfo_upload_done") { $urlParam = "action=update&reset=1&id={$event->id}"; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle()))); } CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $urlParam)); } parent::endPostProcess(); }
/** * Build the form object. * * @return void */ public function buildQuickForm() { if (isset($this->_id)) { $defaults['entity_table'] = 'civicrm_contribution_page'; $defaults['entity_id'] = $this->_id; CRM_Friend_BAO_Friend::getValues($defaults); $this->_friendId = CRM_Utils_Array::value('id', $defaults); } CRM_Friend_BAO_Friend::buildFriendForm($this); parent::buildQuickForm(); }
/** * browse all events * * @return void */ function browse() { $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this); $createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, false, 0); if ($this->_sortByCharacter == 1 || !empty($_POST)) { $this->_sortByCharacter = ''; $this->set('sortByCharacter', ''); } $this->_force = $this->_searchResult = null; $this->search(); $config = CRM_Core_Config::singleton(); $params = array(); $this->_force = CRM_Utils_Request::retrieve('force', 'Boolean', $this, false); $this->_searchResult = CRM_Utils_Request::retrieve('searchResult', 'Boolean', $this); $whereClause = $this->whereClause($params, false, $this->_force); $this->pagerAToZ($whereClause, $params); $params = array(); $whereClause = $this->whereClause($params, true, $this->_force); $whereClause .= ' AND (is_template = 0 OR is_template IS NULL)'; // because is_template != 1 would be to simple $this->pager($whereClause, $params); list($offset, $rowCount) = $this->_pager->getOffsetAndRowCount(); // get all custom groups sorted by weight $manageEvent = array(); $query = "\n SELECT *\n FROM civicrm_event\n WHERE {$whereClause}\nORDER BY start_date desc\n LIMIT {$offset}, {$rowCount}"; $dao = CRM_Core_DAO::executeQuery($query, $params, true, 'CRM_Event_DAO_Event'); $permissions = CRM_Event_BAO_Event::checkPermission(); while ($dao->fetch()) { if (in_array($dao->id, $permissions[CRM_Core_Permission::VIEW])) { $manageEvent[$dao->id] = array(); CRM_Core_DAO::storeValues($dao, $manageEvent[$dao->id]); // form all action links $action = array_sum(array_keys($this->links())); if ($dao->is_active) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } if (!in_array($dao->id, $permissions[CRM_Core_Permission::DELETE])) { $action -= CRM_Core_Action::DELETE; } if (!in_array($dao->id, $permissions[CRM_Core_Permission::EDIT])) { $action -= CRM_Core_Action::UPDATE; } $manageEvent[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), true); $params = array('entity_id' => $dao->id, 'entity_table' => 'civicrm_event', 'is_active' => 1); require_once 'CRM/Core/BAO/Location.php'; $defaults['location'] = CRM_Core_BAO_Location::getValues($params, true); require_once 'CRM/Friend/BAO/Friend.php'; $manageEvent[$dao->id]['friend'] = CRM_Friend_BAO_Friend::getValues($params); if (isset($defaults['location']['address'][1]['city'])) { $manageEvent[$dao->id]['city'] = $defaults['location']['address'][1]['city']; } if (isset($defaults['location']['address'][1]['state_province_id'])) { $manageEvent[$dao->id]['state_province'] = CRM_Core_PseudoConstant::stateProvince($defaults['location']['address'][1]['state_province_id']); } } } $this->assign('rows', $manageEvent); require_once 'CRM/Event/PseudoConstant.php'; $statusTypes = CRM_Event_PseudoConstant::participantStatus(null, 'is_counted = 1'); $statusTypesPending = CRM_Event_PseudoConstant::participantStatus(null, 'is_counted = 0'); $findParticipants['statusCounted'] = implode(', ', array_values($statusTypes)); $findParticipants['statusNotCounted'] = implode(', ', array_values($statusTypesPending)); $this->assign('findParticipants', $findParticipants); }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); //format params $params['start_date'] = CRM_Utils_Date::processDate($params['start_date'], $params['start_date_time']); $params['end_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $params), CRM_Utils_Array::value('end_date_time', $params), TRUE); $params['has_waitlist'] = CRM_Utils_Array::value('has_waitlist', $params, FALSE); $params['is_map'] = CRM_Utils_Array::value('is_map', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['is_public'] = CRM_Utils_Array::value('is_public', $params, FALSE); $params['is_share'] = CRM_Utils_Array::value('is_share', $params, FALSE); $params['default_role_id'] = CRM_Utils_Array::value('default_role_id', $params, FALSE); $params['id'] = $this->_id; $customFields = CRM_Core_BAO_CustomField::getFields('Event', FALSE, FALSE, CRM_Utils_Array::value('event_type_id', $params)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_id, 'Event'); //merge params with defaults from templates if (CRM_Utils_Array::value('template_id', $params)) { $params = array_merge(CRM_Event_BAO_Event::getTemplateDefaultValues($params['template_id']), $params); } $event = CRM_Event_BAO_Event::create($params); // now that we have the event’s id, do some more template-based stuff if (CRM_Utils_Array::value('template_id', $params)) { // copy price sets if any $priceSetId = CRM_Price_BAO_Set::getFor('civicrm_event', $params['template_id']); if ($priceSetId) { $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Set', $priceSetId, 'is_quick_config'); if ($isQuickConfig) { $copyPriceSet =& CRM_Price_BAO_Set::copy($priceSetId); $priceSetId = $copyPriceSet->id; } CRM_Price_BAO_Set::addTo('civicrm_event', $event->id, $priceSetId); } // link profiles if none linked $ufParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); if (!CRM_Core_BAO_UFJoin::findUFGroupId($ufParams)) { CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id)); } // if no Tell-a-Friend defined, check whether there’s one for template and copy if so $tafParams = array('entity_table' => 'civicrm_event', 'entity_id' => $event->id); if (!CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $params['template_id']; if (CRM_Friend_BAO_Friend::getValues($tafParams)) { $tafParams['entity_id'] = $event->id; if (isset($tafParams['id'])) { unset($tafParams['id']); } CRM_Friend_BAO_Friend::addTellAFriend($tafParams); } } //copy pcp settings CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $params['template_id'], 'entity_table' => 'civicrm_event'), array('entity_id' => $event->id), array('replace' => array('target_entity_id' => $event->id))); //copy event schedule remainder CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', array('entity_value' => $params['template_id']), array('entity_value' => $event->id)); } $this->set('id', $event->id); if ($this->_action & CRM_Core_Action::ADD) { $url = 'civicrm/event/manage/location'; $urlParams = "action=update&reset=1&id={$event->id}"; // special case for 'Save and Done' consistency. if ($this->controller->getButtonName('submit') == '_qf_EventInfo_upload_done') { $url = 'civicrm/event/manage'; $urlParams = 'reset=1'; CRM_Core_Session::setStatus(ts("'%1' information has been saved.", array(1 => $this->getTitle()))); } CRM_Utils_System::redirect(CRM_Utils_System::url($url, $urlParams)); } parent::endPostProcess(); }