/** * Set variables up before form is built. * * @return void */ public function preProcess() { parent::preProcess(); $setTab = CRM_Utils_Request::retrieve('setTab', 'Int', $this, FALSE, 0); $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => $this->_isTemplate ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID))); $reminderList = CRM_Core_BAO_ActionSchedule::getList(FALSE, $mapping, $this->_id); if ($reminderList && is_array($reminderList)) { // Add action links to each of the reminders foreach ($reminderList as &$format) { $action = CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE; if ($format['is_active']) { $action += CRM_Core_Action::DISABLE; } else { $action += CRM_Core_Action::ENABLE; } $scheduleReminder = new CRM_Admin_Page_ScheduleReminders(); $links = $scheduleReminder->links(); $links[CRM_Core_Action::DELETE]['qs'] .= "&context=event&compId={$this->_id}"; $links[CRM_Core_Action::UPDATE]['qs'] .= "&context=event&compId={$this->_id}"; $format['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $format['id']), ts('more'), FALSE, 'actionSchedule.manage.action', 'ActionSchedule', $this->_id); } } $this->assign('rows', $reminderList); $this->assign('setTab', $setTab); $this->assign('component', 'event'); // Update tab "disabled" css class $this->ajaxResponse['tabValid'] = is_array($reminderList) && count($reminderList) > 0; $this->setPageTitle(ts('Scheduled Reminder')); }
/** * Create a new Action Schedule * * @param array $params * * @return array * * {@getfields action_schedule_create} */ function civicrm_api3_action_schedule_create($params) { if (empty($params['id'])) { // an update does not require any mandatory parameters civicrm_api3_verify_one_mandatory($params, NULL, array('title', 'mapping_id', 'entity_status', 'entity_value')); } $ids = array(); if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for ID'); } if (!array_key_exists('name', $params) && !array_key_exists('id', $params)) { $params['name'] = CRM_Utils_String::munge($params['title']); } $actionSchedule = new CRM_Core_BAO_ActionSchedule(); $actionSchedule = CRM_Core_BAO_ActionSchedule::add($params, $ids); $actSchedule = array(); _civicrm_api3_object_to_array($actionSchedule, $actSchedule[$actionSchedule->id]); return civicrm_api3_create_success($actSchedule, $params, 'action_schedule', 'create', $actionSchedule); }
function mappingList1() { $params = array('mappingID'); foreach ($params as $param) { ${$param} = CRM_Utils_Array::value($param, $_POST); } if (!$mappingID) { CRM_Utils_JSON::output(array('error_msg' => 'required params missing.')); } $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection1($mappingID); extract($selectionOptions); $elements = array(); foreach ($sel5 as $id => $name) { $elements['sel5'][] = array('name' => $name, 'value' => $id); } $elements['recipientMapping'] = $recipientMapping; CRM_Utils_JSON::output($elements); }
/** * Process the form submission. * * @param array $params * @param string $type * @param array $linkedEntities * * @throws \CiviCRM_API3_Exception */ public static function postProcess($params = array(), $type, $linkedEntities = array()) { //Check entity_id not present in params take it from class variable if (empty($params['entity_id'])) { $params['entity_id'] = self::$_entityId; } //Process this function only when you get this variable if ($params['allowRepeatConfigToSubmit'] == 1) { if (!empty($params['entity_table']) && !empty($params['entity_id']) && $type) { $params['used_for'] = $type; if (empty($params['parent_entity_id'])) { $params['parent_entity_id'] = self::$_parentEntityId; } if (!empty($params['schedule_reminder_id'])) { $params['id'] = $params['schedule_reminder_id']; } else { $params['id'] = self::$_scheduleReminderID; } //Save post params to the schedule reminder table $recurobj = new CRM_Core_BAO_RecurringEntity(); $dbParams = $recurobj->mapFormValuesToDB($params); //Delete repeat configuration and rebuild if (!empty($params['id'])) { CRM_Core_BAO_ActionSchedule::del($params['id']); unset($params['id']); } $actionScheduleObj = CRM_Core_BAO_ActionSchedule::add($dbParams); //exclude dates $excludeDateList = array(); if (CRM_Utils_Array::value('exclude_date_list', $params) && CRM_Utils_Array::value('parent_entity_id', $params) && $actionScheduleObj->entity_value) { //Since we get comma separated values lets get them in array $excludeDates = explode(",", $params['exclude_date_list']); //Check if there exists any values for this option group $optionGroupIdExists = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $type . '_repeat_exclude_dates_' . $params['parent_entity_id'], 'id', 'name'); if ($optionGroupIdExists) { CRM_Core_BAO_OptionGroup::del($optionGroupIdExists); } $optionGroupParams = array('name' => $type . '_repeat_exclude_dates_' . $actionScheduleObj->entity_value, 'title' => $type . ' recursion', 'is_reserved' => 0, 'is_active' => 1); $opGroup = CRM_Core_BAO_OptionGroup::add($optionGroupParams); if ($opGroup->id) { $oldWeight = 0; $fieldValues = array('option_group_id' => $opGroup->id); foreach ($excludeDates as $val) { $optionGroupValue = array('option_group_id' => $opGroup->id, 'label' => CRM_Utils_Date::processDate($val), 'value' => CRM_Utils_Date::processDate($val), 'name' => $opGroup->name, 'description' => 'Used for recurring ' . $type, 'weight' => CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_OptionValue', $oldWeight, CRM_Utils_Array::value('weight', $params), $fieldValues), 'is_active' => 1); $excludeDateList[] = $optionGroupValue['value']; CRM_Core_BAO_OptionValue::create($optionGroupValue); } } } //Set type for API $apiEntityType = explode("_", $type); if (!empty($apiEntityType[1])) { $apiType = $apiEntityType[1]; } //Delete relations if any from recurring entity tables before inserting new relations for this entity id if ($params['entity_id']) { //If entity has any pre delete function, consider that first if (CRM_Utils_Array::value('pre_delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) { $preDeleteResult = call_user_func_array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['pre_delete_func'], array($params['entity_id'])); if (!empty($preDeleteResult)) { call_user_func(array(CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['helper_class'], $preDeleteResult)); } } //Ready to execute delete on entities if it has delete function set if (CRM_Utils_Array::value('delete_func', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]) && CRM_Utils_Array::value('helper_class', CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']])) { //Check if pre delete function has some ids to be deleted if (!empty(CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted)) { foreach (CRM_Core_BAO_RecurringEntity::$_entitiesToBeDeleted as $eid) { $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $eid)); if ($result['error']) { CRM_Core_Error::statusBounce('Error creating recurring list'); } } } else { $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table'], FALSE); foreach ($getRelatedEntities as $key => $value) { $result = civicrm_api3(ucfirst(strtolower($apiType)), CRM_Core_BAO_RecurringEntity::$_recurringEntityHelper[$params['entity_table']]['delete_func'], array('sequential' => 1, 'id' => $value['id'])); if ($result['error']) { CRM_Core_Error::statusBounce('Error creating recurring list'); } } } } // find all entities from the recurring set. At this point we 'll get entities which were not deleted // for e.g due to participants being present. We need to delete them from recurring tables anyway. $pRepeatingEntities = CRM_Core_BAO_RecurringEntity::getEntitiesFor($params['entity_id'], $params['entity_table']); foreach ($pRepeatingEntities as $val) { CRM_Core_BAO_RecurringEntity::delEntity($val['id'], $val['table'], TRUE); } } $recursion = new CRM_Core_BAO_RecurringEntity(); $recursion->dateColumns = $params['dateColumns']; $recursion->scheduleId = $actionScheduleObj->id; if (!empty($excludeDateList)) { $recursion->excludeDates = $excludeDateList; $recursion->excludeDateRangeColumns = $params['excludeDateRangeColumns']; } if (!empty($params['intervalDateColumns'])) { $recursion->intervalDateColumns = $params['intervalDateColumns']; } $recursion->entity_id = $params['entity_id']; $recursion->entity_table = $params['entity_table']; if (!empty($linkedEntities)) { $recursion->linkedEntities = $linkedEntities; } $recursion->generate(); $status = ts('Repeat Configuration has been saved'); CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); } } }
/** * Send the scheduled reminders for all contacts (either for activities or events) * * @param array $params (reference ) input parameters * now - the time to use, in YmdHis format * - makes testing a bit simpler since we can simulate past/future time * * @return boolean true if success, else false * @static void * @access public * */ function civicrm_api3_job_send_reminder($params) { $lock = new CRM_Core_Lock('civimail.job.EmailProcessor'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another EmailProcessor process is running'); } $result = CRM_Core_BAO_ActionSchedule::processQueue(CRM_Utils_Array::value('now', $params), $params); $lock->release(); if ($result['is_error'] == 0) { return civicrm_api3_create_success(); } else { return civicrm_api3_create_error($result['messages']); } }
/** * Browse all Scheduled Reminders settings. * * @param null $action * * @return void */ public function browse($action = NULL) { // Get list of configured reminders $reminderList = CRM_Core_BAO_ActionSchedule::getList(); if (is_array($reminderList)) { // Add action links to each of the reminders foreach ($reminderList as &$format) { $action = array_sum(array_keys($this->links())); if ($format['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $format['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $format['id']), ts('more'), FALSE, 'actionSchedule.manage.action', 'ActionSchedule', $format['id']); } } $this->assign('rows', $reminderList); }
/** * Process the form submission. */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { // delete reminder CRM_Core_BAO_ActionSchedule::del($this->_id); CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success'); if ($this->_context == 'event' && $this->_compId) { $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } return; } $values = $this->controller->exportValues($this->getName()); $bao = $this->parseActionSchedule($values)->save(); // we need to set this on the form so that hooks can identify the created entity $this->set('id', $bao->id); $bao->free(); $status = ts("Your new Reminder titled %1 has been saved.", array(1 => "<strong>{$values['title']}</strong>")); if ($this->_action) { if ($this->_action & CRM_Core_Action::UPDATE) { $status = ts("Your Reminder titled %1 has been updated.", array(1 => "<strong>{$values['title']}</strong>")); } if ($this->_context == 'event' && $this->_compId) { $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } } CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); }
/** * Browse all Scheduled Reminders settings. * * @param null $action * * @return void */ public function browse($action = NULL) { //CRM-16777: Do not permit access to user, for page 'Administer->Communication->Schedule Reminder', //when do not have 'administer CiviCRM' permission. if (!CRM_Core_Permission::check('administer CiviCRM')) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } // Get list of configured reminders $reminderList = CRM_Core_BAO_ActionSchedule::getList(); if (is_array($reminderList)) { // Add action links to each of the reminders foreach ($reminderList as &$format) { $action = array_sum(array_keys($this->links())); if ($format['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } $format['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $format['id']), ts('more'), FALSE, 'actionSchedule.manage.action', 'ActionSchedule', $format['id']); } } $this->assign('rows', $reminderList); }
public function run($now = NULL) { require_once 'CRM/Core/BAO/ActionSchedule.php'; CRM_Core_BAO_ActionSchedule::processQueue($now); }
/** * Send the scheduled reminders for all contacts (either for activities or events). * * @param array $params * (reference ) input parameters. * now - the time to use, in YmdHis format * - makes testing a bit simpler since we can simulate past/future time * * @return array */ function civicrm_api3_job_send_reminder($params) { //note that $params['rowCount' can be overridden by one of the preferred syntaxes ($options['limit'] = x //It's not clear whether than syntax can be passed in via the UI config - but this keeps the pre 4.4.4 behaviour // in that case (ie. makes it non-configurable via the UI). Another approach would be to set a default of 0 // in the _spec function - but since that is a deprecated value it seems more contentious than this approach $params['rowCount'] = 0; $lock = Civi::lockManager()->acquire('worker.core.ActionSchedule'); if (!$lock->isAcquired()) { return civicrm_api3_create_error('Could not acquire lock, another ActionSchedule process is running'); } $result = CRM_Core_BAO_ActionSchedule::processQueue(CRM_Utils_Array::value('now', $params), $params); $lock->release(); if ($result['is_error'] == 0) { return civicrm_api3_create_success(); } else { return civicrm_api3_create_error($result['messages']); } }
/** * @param int $mappingID * @param $recipientType * * @return array */ public static function getRecipientListing($mappingID, $recipientType) { if (!$mappingID) { return array(); } /** @var \Civi\ActionSchedule\Mapping $mapping */ $mapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => $mappingID))); return $mapping->getRecipientListing($recipientType); }
/** * Send the scheduled reminders for all contacts (either for activities or events) * * @param array $params (reference ) input parameters * now - the time to use, in YmdHis format * - makes testing a bit simpler since we can simulate past/future time * * @return boolean true if success, else false * @static void * @access public * */ function civicrm_api3_job_send_reminder($params) { require_once 'CRM/Core/BAO/ActionSchedule.php'; $result = CRM_Core_BAO_ActionSchedule::processQueue(CRM_Utils_Array::value('now', $params)); if ($result['is_error'] == 0) { return civicrm_api3_create_success(); } else { return civicrm_api3_create_error($result['messages']); } }
/** * @param CRM_Event_Form_ManageEvent $form * * @return array * @throws Exception */ public static function process(&$form) { if ($form->getVar('_id') <= 0) { return NULL; } $default = array('link' => NULL, 'valid' => TRUE, 'active' => TRUE, 'current' => FALSE, 'class' => 'ajaxForm'); $tabs = array(); $tabs['settings'] = array('title' => ts('Info and Settings'), 'class' => 'ajaxForm livePage') + $default; $tabs['location'] = array('title' => ts('Event Location')) + $default; $tabs['fee'] = array('title' => ts('Fees')) + $default; $tabs['registration'] = array('title' => ts('Online Registration')) + $default; if (CRM_Core_Permission::check('administer CiviCRM') || CRM_Event_BAO_Event::checkPermission(NULL, CRM_Core_Permission::EDIT)) { $tabs['reminder'] = array('title' => ts('Schedule Reminders'), 'class' => 'livePage') + $default; } $tabs['conference'] = array('title' => ts('Conference Slots')) + $default; $tabs['friend'] = array('title' => ts('Tell a Friend')) + $default; $tabs['pcp'] = array('title' => ts('Personal Campaigns')) + $default; $tabs['repeat'] = array('title' => ts('Repeat')) + $default; // Repeat tab must refresh page when switching repeat mode so js & vars will get set-up if (!$form->_isRepeatingEvent) { unset($tabs['repeat']['class']); } // 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'); if (!$enableCart) { unset($tabs['conference']); } $eventID = $form->getVar('_id'); if ($eventID) { // disable tabs based on their configuration status $eventNameMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID))); $sql = "\nSELECT e.loc_block_id as is_location, e.is_online_registration, e.is_monetary, taf.is_active, pcp.is_active as is_pcp, sch.id as is_reminder, re.id as is_repeating_event\nFROM civicrm_event e\nLEFT JOIN civicrm_tell_friend taf ON ( taf.entity_table = 'civicrm_event' AND taf.entity_id = e.id )\nLEFT JOIN civicrm_pcp_block pcp ON ( pcp.entity_table = 'civicrm_event' AND pcp.entity_id = e.id )\nLEFT JOIN civicrm_action_schedule sch ON ( sch.mapping_id = %2 AND sch.entity_value = %1 )\nLEFT JOIN civicrm_recurring_entity re ON ( e.id = re.entity_id AND re.entity_table = 'civicrm_event' )\nWHERE e.id = %1\n"; //Check if repeat is configured $eventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($eventID, 'civicrm_event'); $params = array(1 => array($eventID, 'Integer'), 2 => array($eventNameMapping->getId(), 'Integer')); $dao = CRM_Core_DAO::executeQuery($sql, $params); if (!$dao->fetch()) { CRM_Core_Error::fatal(); } if (!$dao->is_location) { $tabs['location']['valid'] = FALSE; } if (!$dao->is_online_registration) { $tabs['registration']['valid'] = FALSE; } if (!$dao->is_monetary) { $tabs['fee']['valid'] = FALSE; } if (!$dao->is_active) { $tabs['friend']['valid'] = FALSE; } if (!$dao->is_pcp) { $tabs['pcp']['valid'] = FALSE; } if (!$dao->is_reminder) { $tabs['reminder']['valid'] = FALSE; } if (!$dao->is_repeating_event) { $tabs['repeat']['valid'] = FALSE; } } // see if any other modules want to add any tabs // note: status of 'valid' flag of any injected tab, needs to be taken care in the hook implementation. CRM_Utils_Hook::tabset('civicrm/event/manage', $tabs, array('event_id' => $eventID)); $fullName = $form->getVar('_name'); $className = CRM_Utils_String::getClassName($fullName); $new = ''; // hack for special cases. switch ($className) { case 'Event': $attributes = $form->getVar('_attributes'); $class = strtolower(basename(CRM_Utils_Array::value('action', $attributes))); break; case 'EventInfo': $class = 'settings'; break; case 'ScheduleReminders': $class = 'reminder'; break; default: $class = strtolower($className); break; } if (array_key_exists($class, $tabs)) { $tabs[$class]['current'] = TRUE; $qfKey = $form->get('qfKey'); if ($qfKey) { $tabs[$class]['qfKey'] = "&qfKey={$qfKey}"; } } if ($eventID) { $reset = !empty($_GET['reset']) ? 'reset=1&' : ''; foreach ($tabs as $key => $value) { if (!isset($tabs[$key]['qfKey'])) { $tabs[$key]['qfKey'] = NULL; } $action = 'update'; if ($key == 'reminder') { $action = 'browse'; } $link = "civicrm/event/manage/{$key}"; $query = "{$reset}action={$action}&id={$eventID}&component=event{$tabs[$key]['qfKey']}"; $tabs[$key]['link'] = isset($value['link']) ? $value['link'] : CRM_Utils_System::url($link, $query); } } return $tabs; }
/** * (Scheduled Reminders) Get the list of possible recipient filters. * * Ex: GET /civicrm/ajax/recipientListing?mappingID=contribpage&recipientType= */ public static function recipientListing() { $mappingID = filter_input(INPUT_GET, 'mappingID', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^[a-zA-Z0-9_\\-]+$/'))); $recipientType = filter_input(INPUT_GET, 'recipientType', FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => '/^[a-zA-Z0-9_\\-]+$/'))); CRM_Utils_JSON::output(array('recipients' => CRM_Utils_Array::toKeyValueRows(CRM_Core_BAO_ActionSchedule::getRecipientListing($mappingID, $recipientType)))); }
/** * 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); }
/** * Process the form submission. * * * @return void */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { // delete reminder CRM_Core_BAO_ActionSchedule::del($this->_id); CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success'); if ($this->_context == 'event' && $this->_compId) { $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } return; } $values = $this->controller->exportValues($this->getName()); $keys = array('title', 'subject', 'absolute_date', 'group_id', 'record_activity', 'limit_to', 'mode', 'sms_provider_id', 'from_name', 'from_email'); foreach ($keys as $key) { $params[$key] = CRM_Utils_Array::value($key, $values); } $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0); $moreKeys = array('start_action_offset', 'start_action_unit', 'start_action_condition', 'start_action_date', 'repetition_frequency_unit', 'repetition_frequency_interval', 'end_frequency_unit', 'end_frequency_interval', 'end_action', 'end_date'); if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) { $params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate); $params['is_repeat'] = 0; foreach ($moreKeys as $mkey) { $params[$mkey] = 'null'; } } else { $params['absolute_date'] = 'null'; foreach ($moreKeys as $mkey) { $params[$mkey] = CRM_Utils_Array::value($mkey, $values); } } $params['body_text'] = CRM_Utils_Array::value('text_message', $values); $params['sms_body_text'] = CRM_Utils_Array::value('sms_text_message', $values); $params['body_html'] = CRM_Utils_Array::value('html_message', $values); if (CRM_Utils_Array::value('recipient', $values) == 'manual') { $params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values); $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null'; } elseif (CRM_Utils_Array::value('recipient', $values) == 'group') { $params['group_id'] = $values['group_id']; $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null'; } elseif (!CRM_Utils_System::isNull($values['recipient_listing']) && !CRM_Utils_System::isNull($values['limit_to'])) { $params['recipient'] = CRM_Utils_Array::value('recipient', $values); $params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values)); $params['group_id'] = $params['recipient_manual'] = 'null'; } else { $params['recipient'] = CRM_Utils_Array::value('recipient', $values); $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null'; } if (!empty($this->_mappingID) && !empty($this->_compId)) { $params['mapping_id'] = $this->_mappingID; $params['entity_value'] = $this->_compId; $params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $values['entity']); } else { $params['mapping_id'] = $values['entity'][0]; $entity_value = $values['entity'][1]; $entity_status = $values['entity'][2]; if ($params['mapping_id'] == 1) { $params['limit_to'] = 1; } foreach (array('entity_value', 'entity_status') as $key) { $params[$key] = implode(CRM_Core_DAO::VALUE_SEPARATOR, ${$key}); } } $params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0); if (CRM_Utils_Array::value('is_repeat', $values) == 0) { $params['repetition_frequency_unit'] = 'null'; $params['repetition_frequency_interval'] = 'null'; $params['end_frequency_unit'] = 'null'; $params['end_frequency_interval'] = 'null'; $params['end_action'] = 'null'; $params['end_date'] = 'null'; } if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } elseif ($this->_action & CRM_Core_Action::ADD) { // we do this only once, so name never changes $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64); } $modePrefixes = array('Mail' => NULL, 'SMS' => 'SMS'); if ($params['mode'] == 'Email' || empty($params['sms_provider_id'])) { unset($modePrefixes['SMS']); } elseif ($params['mode'] == 'SMS') { unset($modePrefixes['Mail']); } //TODO: handle postprocessing of SMS and/or Email info based on $modePrefixes $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName'); $msgTemplate = NULL; //mail template is composed foreach ($modePrefixes as $prefix) { $composeParams = array(); foreach ($composeFields as $key) { $key = $prefix . $key; if (!empty($values[$key])) { $composeParams[$key] = $values[$key]; } } if (!empty($composeParams[$prefix . 'updateTemplate'])) { $templateParams = array('is_active' => TRUE); if ($prefix == 'SMS') { $templateParams += array('msg_text' => $params['sms_body_text'], 'is_sms' => TRUE); } else { $templateParams += array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject']); } $templateParams['id'] = $values[$prefix . 'template']; $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); } if (!empty($composeParams[$prefix . 'saveTemplate'])) { $templateParams = array('is_active' => TRUE); if ($prefix == 'SMS') { $templateParams += array('msg_text' => $params['sms_body_text'], 'is_sms' => TRUE); } else { $templateParams += array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject']); } $templateParams['msg_title'] = $composeParams[$prefix . 'saveTemplateName']; $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); } if ($prefix == 'SMS') { if (isset($msgTemplate->id)) { $params['sms_template_id'] = $msgTemplate->id; } else { $params['sms_template_id'] = CRM_Utils_Array::value('SMStemplate', $values); } } else { if (isset($msgTemplate->id)) { $params['msg_template_id'] = $msgTemplate->id; } else { $params['msg_template_id'] = CRM_Utils_Array::value('template', $values); } } } $bao = CRM_Core_BAO_ActionSchedule::add($params); // we need to set this on the form so that hooks can identify the created entity $this->set('id', $bao->id); $bao->free(); $status = ts("Your new Reminder titled %1 has been saved.", array(1 => "<strong>{$values['title']}</strong>")); if ($this->_action) { if ($this->_action & CRM_Core_Action::UPDATE) { $status = ts("Your Reminder titled %1 has been updated.", array(1 => "<strong>{$values['title']}</strong>")); } if ($this->_context == 'event' && $this->_compId) { $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=browse&id={$this->_compId}&component={$this->_context}&setTab=1"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } } CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); }
/** * Test that the various repetition units work correctly. * CRM-17028 */ public function testRepetitionFrequencyUnit() { $membershipTypeParams = array('duration_interval' => '1', 'duration_unit' => 'year', 'is_active' => 1, 'period_type' => 'rolling'); $membershipType = $this->createTestObject('CRM_Member_DAO_MembershipType', $membershipTypeParams); $interval_units = array('hour', 'day', 'week', 'month', 'year'); foreach ($interval_units as $interval_unit) { $membershipEndDate = DateTime::createFromFormat('Y-m-d H:i:s', "2013-03-15 00:00:00"); $contactParams = array('contact_type' => 'Individual', 'first_name' => 'Test', 'last_name' => "Interval {$interval_unit}", 'is_deceased' => 0); $contact = $this->createTestObject('CRM_Contact_DAO_Contact', $contactParams); $this->assertTrue(is_numeric($contact->id)); $emailParams = array('contact_id' => $contact->id, 'email' => "test-member-{$interval_unit}@example.com", 'location_type_id' => 1); $email = $this->createTestObject('CRM_Core_DAO_Email', $emailParams); $this->assertTrue(is_numeric($email->id)); $membershipParams = array('membership_type_id' => $membershipType->id, 'contact_id' => $contact->id, 'join_date' => '20120315', 'start_date' => '20120315', 'end_date' => '20130315', 'is_override' => 0, 'status_id' => 2); $membershipParams['status-id'] = 1; $membership = $this->createTestObject('CRM_Member_DAO_Membership', $membershipParams); $actionScheduleParams = $this->fixtures['sched_on_membership_end_date_repeat_interval']; $actionScheduleParams['entity_value'] = $membershipType->id; $actionScheduleParams['repetition_frequency_unit'] = $interval_unit; $actionScheduleParams['repetition_frequency_interval'] = 2; $actionSchedule = CRM_Core_BAO_ActionSchedule::add($actionScheduleParams); $this->assertTrue(is_numeric($actionSchedule->id)); $beforeEndDate = $this->createModifiedDateTime($membershipEndDate, '-1 day'); $beforeFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+1 {$interval_unit}"); $afterFirstUnit = $this->createModifiedDateTime($membershipEndDate, "+2 {$interval_unit}"); $cronRuns = array(array('time' => $beforeEndDate->format('Y-m-d H:i:s'), 'recipients' => array()), array('time' => $membershipEndDate->format('Y-m-d H:i:s'), 'recipients' => array(array("test-member-{$interval_unit}@example.com"))), array('time' => $beforeFirstUnit->format('Y-m-d H:i:s'), 'recipients' => array()), array('time' => $afterFirstUnit->format('Y-m-d H:i:s'), 'recipients' => array(array("test-member-{$interval_unit}@example.com")))); $this->assertCronRuns($cronRuns); $actionSchedule->delete(); $membership->delete(); } }
function mappingList() { if (empty($_GET['mappingID'])) { CRM_Utils_JSON::output(array('status' => 'error', 'error_msg' => 'required params missing.')); } $selectionOptions = CRM_Core_BAO_ActionSchedule::getSelection1($_GET['mappingID']); $output = array('sel4' => array(), 'sel5' => array(), 'recipientMapping' => $selectionOptions['recipientMapping']); foreach (array(4, 5) as $sel) { foreach ($selectionOptions["sel{$sel}"] as $id => $name) { $output["sel{$sel}"][] = array('value' => $name, 'key' => $id); } } CRM_Utils_JSON::output($output); }
/** * Function to get events Summary * * @static * * @return array Array of event summary values */ static function getEventSummary() { $eventSummary = $eventIds = array(); $config = CRM_Core_Config::singleton(); // get permission and include them here // does not scale, but rearranging code for now // FIXME in a future release $permissions = CRM_Event_BAO_Event::checkPermission(); $validEventIDs = ''; if (empty($permissions[CRM_Core_Permission::VIEW])) { $eventSummary['total_events'] = 0; return $eventSummary; } else { $validEventIDs = " AND civicrm_event.id IN ( " . implode(',', array_values($permissions[CRM_Core_Permission::VIEW])) . " ) "; } // We're fetching recent and upcoming events (where start date is 7 days ago OR later) $query = "\nSELECT count(id) as total_events\nFROM civicrm_event\nWHERE civicrm_event.is_active = 1 AND\n ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND\n civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )\n {$validEventIDs}"; $dao = CRM_Core_DAO::executeQuery($query); if ($dao->fetch()) { $eventSummary['total_events'] = $dao->total_events; } if (empty($eventSummary) || $dao->total_events == 0) { return $eventSummary; } //get the participant status type values. $cpstObject = new CRM_Event_DAO_ParticipantStatusType(); $cpst = $cpstObject->getTableName(); $query = "SELECT id, name, label, class FROM {$cpst}"; $status = CRM_Core_DAO::executeQuery($query); $statusValues = array(); while ($status->fetch()) { $statusValues[$status->id]['id'] = $status->id; $statusValues[$status->id]['name'] = $status->name; $statusValues[$status->id]['label'] = $status->label; $statusValues[$status->id]['class'] = $status->class; } // Get the Id of Option Group for Event Types $optionGroupDAO = new CRM_Core_DAO_OptionGroup(); $optionGroupDAO->name = 'event_type'; $optionGroupId = NULL; if ($optionGroupDAO->find(TRUE)) { $optionGroupId = $optionGroupDAO->id; } // Get the event summary display preferences $show_max_events = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'show_events'); // default to 10 if no option is set if (is_null($show_max_events)) { $show_max_events = 10; } // show all events if show_events is set to a negative value if ($show_max_events >= 0) { $event_summary_limit = "LIMIT 0, {$show_max_events}"; } else { $event_summary_limit = ""; } $query = "\nSELECT civicrm_event.id as id, civicrm_event.title as event_title, civicrm_event.is_public as is_public,\n civicrm_event.max_participants as max_participants, civicrm_event.start_date as start_date,\n civicrm_event.end_date as end_date, civicrm_event.is_online_registration, civicrm_event.is_monetary, civicrm_event.is_show_location,civicrm_event.is_map as is_map, civicrm_option_value.label as event_type, civicrm_tell_friend.is_active as is_friend_active,\n civicrm_event.slot_label_id,\n civicrm_event.summary as summary,\n civicrm_pcp_block.id as is_pcp_enabled\nFROM civicrm_event\nLEFT JOIN civicrm_option_value ON (\n civicrm_event.event_type_id = civicrm_option_value.value AND\n civicrm_option_value.option_group_id = %1 )\nLEFT JOIN civicrm_tell_friend ON ( civicrm_tell_friend.entity_id = civicrm_event.id AND civicrm_tell_friend.entity_table = 'civicrm_event' )\nLEFT JOIN civicrm_pcp_block ON ( civicrm_pcp_block.entity_id = civicrm_event.id AND civicrm_pcp_block.entity_table = 'civicrm_event')\nWHERE civicrm_event.is_active = 1 AND\n ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0) AND\n civicrm_event.start_date >= DATE_SUB( NOW(), INTERVAL 7 day )\n {$validEventIDs}\nGROUP BY civicrm_event.id\nORDER BY civicrm_event.start_date ASC\n{$event_summary_limit}\n"; $eventParticipant = array(); $properties = array('id' => 'id', 'eventTitle' => 'event_title', 'isPublic' => 'is_public', 'maxParticipants' => 'max_participants', 'startDate' => 'start_date', 'endDate' => 'end_date', 'eventType' => 'event_type', 'isMap' => 'is_map', 'participants' => 'participants', 'notCountedDueToRole' => 'notCountedDueToRole', 'notCountedDueToStatus' => 'notCountedDueToStatus', 'notCountedParticipants' => 'notCountedParticipants'); $params = array(1 => array($optionGroupId, 'Integer')); $mappingID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_ActionMapping', 'civicrm_event', 'id', 'entity_value'); $dao = CRM_Core_DAO::executeQuery($query, $params); while ($dao->fetch()) { foreach ($properties as $property => $name) { $set = NULL; switch ($name) { case 'is_public': if ($dao->{$name}) { $set = 'Yes'; } else { $set = 'No'; } $eventSummary['events'][$dao->id][$property] = $set; break; case 'is_map': if ($dao->{$name} && $config->mapAPIKey) { $values = array(); $ids = array(); $params = array('entity_id' => $dao->id, 'entity_table' => 'civicrm_event'); $values['location'] = CRM_Core_BAO_Location::getValues($params, TRUE); if (is_numeric(CRM_Utils_Array::value('geo_code_1', $values['location']['address'][1])) || $config->mapGeoCoding && !empty($values['location']['address'][1]['city']) && !empty($values['location']['address'][1]['state_province_id'])) { $set = CRM_Utils_System::url('civicrm/contact/map/event', "reset=1&eid={$dao->id}"); } } $eventSummary['events'][$dao->id][$property] = $set; if (in_array($dao->id, $permissions[CRM_Core_Permission::EDIT])) { $eventSummary['events'][$dao->id]['configure'] = CRM_Utils_System::url('civicrm/admin/event', "action=update&id={$dao->id}&reset=1"); } break; case 'end_date': case 'start_date': $eventSummary['events'][$dao->id][$property] = CRM_Utils_Date::customFormat($dao->{$name}, NULL, array('d')); break; case 'participants': case 'notCountedDueToRole': case 'notCountedDueToStatus': case 'notCountedParticipants': $set = NULL; $propertyCnt = 0; if ($name == 'participants') { $propertyCnt = self::getParticipantCount($dao->id); if ($propertyCnt) { $set = CRM_Utils_System::url('civicrm/event/search', "reset=1&force=1&event={$dao->id}&status=true&role=true"); } } elseif ($name == 'notCountedParticipants') { $propertyCnt = self::getParticipantCount($dao->id, TRUE, FALSE, TRUE, FALSE); if ($propertyCnt) { // FIXME : selector fail to search w/ OR operator. // $set = CRM_Utils_System::url( 'civicrm/event/search', // "reset=1&force=1&event=$dao->id&status=false&role=false" ); } } elseif ($name == 'notCountedDueToStatus') { $propertyCnt = self::getParticipantCount($dao->id, TRUE, FALSE, FALSE, FALSE); if ($propertyCnt) { $set = CRM_Utils_System::url('civicrm/event/search', "reset=1&force=1&event={$dao->id}&status=false"); } } else { $propertyCnt = self::getParticipantCount($dao->id, FALSE, FALSE, TRUE, FALSE); if ($propertyCnt) { $set = CRM_Utils_System::url('civicrm/event/search', "reset=1&force=1&event={$dao->id}&role=false"); } } $eventSummary['events'][$dao->id][$property] = $propertyCnt; $eventSummary['events'][$dao->id][$name . '_url'] = $set; break; default: $eventSummary['events'][$dao->id][$property] = $dao->{$name}; break; } } // prepare the area for per-status participant counts $statusClasses = array('Positive', 'Pending', 'Waiting', 'Negative'); $eventSummary['events'][$dao->id]['statuses'] = array_fill_keys($statusClasses, array()); $eventSummary['events'][$dao->id]['friend'] = $dao->is_friend_active; $eventSummary['events'][$dao->id]['is_monetary'] = $dao->is_monetary; $eventSummary['events'][$dao->id]['is_online_registration'] = $dao->is_online_registration; $eventSummary['events'][$dao->id]['is_show_location'] = $dao->is_show_location; $eventSummary['events'][$dao->id]['is_subevent'] = $dao->slot_label_id; $eventSummary['events'][$dao->id]['is_pcp_enabled'] = $dao->is_pcp_enabled; $eventSummary['events'][$dao->id]['reminder'] = CRM_Core_BAO_ActionSchedule::isConfigured($dao->id, $mappingID); $statusTypes = CRM_Event_PseudoConstant::participantStatus(); foreach ($statusValues as $statusId => $statusValue) { if (!array_key_exists($statusId, $statusTypes)) { continue; } $class = $statusValue['class']; $statusCount = self::eventTotalSeats($dao->id, "( participant.status_id = {$statusId} )"); if ($statusCount) { $urlString = "reset=1&force=1&event={$dao->id}&status={$statusId}"; $statusInfo = array('url' => CRM_Utils_System::url('civicrm/event/search', $urlString), 'name' => $statusValue['name'], 'label' => $statusValue['label'], 'count' => $statusCount); $eventSummary['events'][$dao->id]['statuses'][$class][] = $statusInfo; } } } $countedRoles = CRM_Event_PseudoConstant::participantRole(NULL, 'filter = 1'); $nonCountedRoles = CRM_Event_PseudoConstant::participantRole(NULL, '( filter = 0 OR filter IS NULL )'); $countedStatus = CRM_Event_PseudoConstant::participantStatus(NULL, 'is_counted = 1'); $nonCountedStatus = CRM_Event_PseudoConstant::participantStatus(NULL, '( is_counted = 0 OR is_counted IS NULL )'); $countedStatusANDRoles = array_merge($countedStatus, $countedRoles); $nonCountedStatusANDRoles = array_merge($nonCountedStatus, $nonCountedRoles); $eventSummary['nonCountedRoles'] = implode('/', array_values($nonCountedRoles)); $eventSummary['nonCountedStatus'] = implode('/', array_values($nonCountedStatus)); $eventSummary['countedStatusANDRoles'] = implode('/', array_values($countedStatusANDRoles)); $eventSummary['nonCountedStatusANDRoles'] = implode('/', array_values($nonCountedStatusANDRoles)); return $eventSummary; }
public function testContactCustomDate_Anniv() { $group = array('title' => 'Test_Group now', 'name' => 'test_group_now', 'extends' => array('Individual'), 'style' => 'Inline', 'is_multiple' => FALSE, 'is_active' => 1); $createGroup = $this->callAPISuccess('custom_group', 'create', $group); $field = array('label' => 'Graduation', 'data_type' => 'Date', 'html_type' => 'Select Date', 'custom_group_id' => $createGroup['id']); $createField = $this->callAPISuccess('custom_field', 'create', $field); $contactParams = $this->fixtures['contact']; $contactParams["custom_{$createField['id']}"] = '2013-12-16'; $contact = $this->callAPISuccess('Contact', 'create', $contactParams); $this->_testObjects['CRM_Contact_DAO_Contact'][] = $contact['id']; $actionSchedule = $this->fixtures['sched_contact_grad_anniv']; $actionSchedule['entity_value'] = "custom_{$createField['id']}"; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); $this->assertCronRuns(array(array('time' => '2014-03-07 01:00:00', 'recipients' => array()), array('time' => '2018-12-23 20:00:00', 'recipients' => array(array('*****@*****.**'))))); $this->callAPISuccess('custom_group', 'delete', array('id' => $createGroup['id'])); }
/** * @param $mappingID * @param $now * * @throws CRM_Core_Exception */ static function sendMailings($mappingID, $now) { $domainValues = CRM_Core_BAO_Domain::getNameAndEmail(); $fromEmailAddress = "{$domainValues['0']} <{$domainValues['1']}>"; $mapping = new CRM_Core_DAO_ActionMapping(); $mapping->id = $mappingID; $mapping->find(TRUE); $actionSchedule = new CRM_Core_DAO_ActionSchedule(); $actionSchedule->mapping_id = $mappingID; $actionSchedule->is_active = 1; $actionSchedule->find(FALSE); $tokenFields = array(); $session = CRM_Core_Session::singleton(); while ($actionSchedule->fetch()) { $extraSelect = $extraJoin = $extraWhere = $extraOn = ''; if ($actionSchedule->from_email) { $fromEmailAddress = "{$actionSchedule->from_name} <{$actionSchedule->from_email}>"; } if ($actionSchedule->record_activity) { if ($mapping->entity == 'civicrm_membership') { $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Membership Renewal Reminder', 'name'); } else { $activityTypeID = CRM_Core_OptionGroup::getValue('activity_type', 'Reminder Sent', 'name'); } $activityStatusID = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'); } if ($mapping->entity == 'civicrm_activity') { $tokenEntity = 'activity'; $tokenFields = array('activity_id', 'activity_type', 'subject', 'details', 'activity_date_time'); $extraSelect = ', ov.label as activity_type, e.id as activity_id'; $extraJoin = "\nINNER JOIN civicrm_option_group og ON og.name = 'activity_type'\nINNER JOIN civicrm_option_value ov ON e.activity_type_id = ov.value AND ov.option_group_id = og.id"; $extraOn = ' AND e.is_current_revision = 1 AND e.is_deleted = 0 '; if ($actionSchedule->limit_to == 0) { $extraJoin = "\nLEFT JOIN civicrm_option_group og ON og.name = 'activity_type'\nLEFT JOIN civicrm_option_value ov ON e.activity_type_id = ov.value AND ov.option_group_id = og.id"; } } if ($mapping->entity == 'civicrm_participant') { $tokenEntity = 'event'; $tokenFields = array('event_type', 'title', 'event_id', 'start_date', 'end_date', 'summary', 'description', 'location', 'info_url', 'registration_url', 'fee_amount', 'contact_email', 'contact_phone', 'balance'); $extraSelect = ', ov.label as event_type, ev.title, ev.id as event_id, ev.start_date, ev.end_date, ev.summary, ev.description, address.street_address, address.city, address.state_province_id, address.postal_code, email.email as contact_email, phone.phone as contact_phone '; $extraJoin = "\nINNER JOIN civicrm_event ev ON e.event_id = ev.id\nINNER JOIN civicrm_option_group og ON og.name = 'event_type'\nINNER JOIN civicrm_option_value ov ON ev.event_type_id = ov.value AND ov.option_group_id = og.id\nLEFT JOIN civicrm_loc_block lb ON lb.id = ev.loc_block_id\nLEFT JOIN civicrm_address address ON address.id = lb.address_id\nLEFT JOIN civicrm_email email ON email.id = lb.email_id\nLEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id\n"; if ($actionSchedule->limit_to == 0) { $extraJoin = "\nLEFT JOIN civicrm_event ev ON e.event_id = ev.id\nLEFT JOIN civicrm_option_group og ON og.name = 'event_type'\nLEFT JOIN civicrm_option_value ov ON ev.event_type_id = ov.value AND ov.option_group_id = og.id\nLEFT JOIN civicrm_loc_block lb ON lb.id = ev.loc_block_id\nLEFT JOIN civicrm_address address ON address.id = lb.address_id\nLEFT JOIN civicrm_email email ON email.id = lb.email_id\nLEFT JOIN civicrm_phone phone ON phone.id = lb.phone_id\n"; } } if ($mapping->entity == 'civicrm_membership') { $tokenEntity = 'membership'; $tokenFields = array('fee', 'id', 'join_date', 'start_date', 'end_date', 'status', 'type'); $extraSelect = ', mt.minimum_fee as fee, e.id as id , e.join_date, e.start_date, e.end_date, ms.name as status, mt.name as type'; $extraJoin = ' INNER JOIN civicrm_membership_type mt ON e.membership_type_id = mt.id INNER JOIN civicrm_membership_status ms ON e.status_id = ms.id'; if ($actionSchedule->limit_to == 0) { $extraJoin = ' LEFT JOIN civicrm_membership_type mt ON e.membership_type_id = mt.id LEFT JOIN civicrm_membership_status ms ON e.status_id = ms.id'; } } if ($mapping->entity == 'civicrm_contact') { $tokenEntity = 'contact'; //TODO: get full list somewhere! $tokenFields = array('birth_date', 'last_name'); //TODO: is there anything to add here? } $entityJoinClause = "INNER JOIN {$mapping->entity} e ON e.id = reminder.entity_id"; if ($actionSchedule->limit_to == 0) { $entityJoinClause = "LEFT JOIN {$mapping->entity} e ON e.id = reminder.entity_id"; $extraWhere .= " AND (e.id = reminder.entity_id OR reminder.entity_table = 'civicrm_contact')"; } $entityJoinClause .= $extraOn; $query = "\nSELECT reminder.id as reminderID, reminder.contact_id as contactID, reminder.*, e.id as entityID, e.* {$extraSelect}\nFROM civicrm_action_log reminder\n{$entityJoinClause}\n{$extraJoin}\nWHERE reminder.action_schedule_id = %1 AND reminder.action_date_time IS NULL\n{$extraWhere}"; $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($actionSchedule->id, 'Integer'))); while ($dao->fetch()) { $entityTokenParams = array(); foreach ($tokenFields as $field) { if ($field == 'location') { $loc = array(); $stateProvince = CRM_Core_PseudoConstant::stateProvince(); $loc['street_address'] = $dao->street_address; $loc['city'] = $dao->city; $loc['state_province'] = CRM_Utils_Array::value($dao->state_province_id, $stateProvince); $loc['postal_code'] = $dao->postal_code; $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_Address::format($loc); } elseif ($field == 'info_url') { $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_System::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id, TRUE, NULL, FALSE); } elseif ($field == 'registration_url') { $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id, TRUE, NULL, FALSE); } elseif (in_array($field, array('start_date', 'end_date', 'join_date', 'activity_date_time'))) { $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_Date::customFormat($dao->{$field}); } elseif ($field == 'balance') { $info = CRM_Contribute_BAO_Contribution::getPaymentInfo($dao->entityID, 'event'); $balancePay = CRM_Utils_Array::value('balance', $info); $balancePay = CRM_Utils_Money::format($balancePay); $entityTokenParams["{$tokenEntity}." . $field] = $balancePay; } elseif ($field == 'fee_amount') { $entityTokenParams["{$tokenEntity}." . $field] = CRM_Utils_Money::format($dao->{$field}); } else { $entityTokenParams["{$tokenEntity}." . $field] = $dao->{$field}; } } $isError = 0; $errorMsg = $toEmail = $toPhoneNumber = ''; if ($actionSchedule->mode == 'SMS' or $actionSchedule->mode == 'User_Preference') { $filters = array('is_deceased' => 0, 'is_deleted' => 0, 'do_not_sms' => 0); $toPhoneNumbers = CRM_Core_BAO_Phone::allPhones($dao->contactID, FALSE, 'Mobile', $filters); //to get primary mobile ph,if not get a first mobile phONE if (!empty($toPhoneNumbers)) { $toPhoneNumberDetails = reset($toPhoneNumbers); $toPhoneNumber = CRM_Utils_Array::value('phone', $toPhoneNumberDetails); //contact allows to send sms $toDoNotSms = 0; } } if ($actionSchedule->mode == 'Email' or $actionSchedule->mode == 'User_Preference') { $toEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($dao->contactID); } if ($toEmail || !(empty($toPhoneNumber) or $toDoNotSms)) { $to['email'] = $toEmail; $to['phone'] = $toPhoneNumber; $result = CRM_Core_BAO_ActionSchedule::sendReminder($dao->contactID, $to, $actionSchedule->id, $fromEmailAddress, $entityTokenParams); if (!$result || is_a($result, 'PEAR_Error')) { // we could not send an email, for now we ignore, CRM-3406 $isError = 1; } } else { $isError = 1; $errorMsg = "Couldn\\'t find recipient\\'s email address."; } // update action log record $logParams = array('id' => $dao->reminderID, 'is_error' => $isError, 'message' => $errorMsg ? $errorMsg : "null", 'action_date_time' => $now); CRM_Core_BAO_ActionLog::create($logParams); // insert activity log record if needed if ($actionSchedule->record_activity) { $activityParams = array('subject' => $actionSchedule->title, 'details' => $actionSchedule->body_html, 'source_contact_id' => $session->get('userID') ? $session->get('userID') : $dao->contactID, 'target_contact_id' => $dao->contactID, 'activity_date_time' => date('YmdHis'), 'status_id' => $activityStatusID, 'activity_type_id' => $activityTypeID, 'source_record_id' => $dao->entityID); $activity = CRM_Activity_BAO_Activity::create($activityParams); } } $dao->free(); } }
/** * Check API for ACL permission. * * @param array $apiRequest * * @return bool */ public function checkACLPermission($apiRequest) { switch ($apiRequest['entity']) { case 'UFGroup': case 'UFField': $ufGroups = \CRM_Core_PseudoConstant::get('CRM_Core_DAO_UFField', 'uf_group_id'); $aclCreate = \CRM_ACL_API::group(\CRM_Core_Permission::CREATE, NULL, 'civicrm_uf_group', $ufGroups); $aclEdit = \CRM_ACL_API::group(\CRM_Core_Permission::EDIT, NULL, 'civicrm_uf_group', $ufGroups); $ufGroupId = $apiRequest['entity'] == 'UFGroup' ? $apiRequest['params']['id'] : $apiRequest['params']['uf_group_id']; if (in_array($ufGroupId, $aclEdit) or $aclCreate) { return TRUE; } break; //CRM-16777: Disable schedule reminder with ACLs. //CRM-16777: Disable schedule reminder with ACLs. case 'ActionSchedule': $events = \CRM_Event_BAO_Event::getEvents(); $aclEdit = \CRM_ACL_API::group(\CRM_Core_Permission::EDIT, NULL, 'civicrm_event', $events); $param = array('id' => $apiRequest['params']['id']); $eventId = \CRM_Core_BAO_ActionSchedule::retrieve($param, $value = array()); if (in_array($eventId->entity_value, $aclEdit)) { return TRUE; } break; } return FALSE; }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { // delete reminder CRM_Core_BAO_ActionSchedule::del($this->_id); CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.')); if ($this->_context == 'event' && $this->_eventId) { $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=update&id={$this->_eventId}"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } return; } $values = $this->controller->exportValues($this->getName()); $keys = array('title', 'subject', 'absolute_date', 'group_id'); foreach ($keys as $key) { $params[$key] = CRM_Utils_Array::value($key, $values); } $moreKeys = array('start_action_offset', 'start_action_unit', 'start_action_condition', 'start_action_date', 'repetition_frequency_unit', 'repetition_frequency_interval', 'end_frequency_unit', 'end_frequency_interval', 'end_action', 'end_date'); if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) { $params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate); foreach ($moreKeys as $mkey) { $params[$mkey] = 'null'; } } else { $params['absolute_date'] = 'null'; foreach ($moreKeys as $mkey) { $params[$mkey] = CRM_Utils_Array::value($mkey, $values); } } $params['body_text'] = CRM_Utils_Array::value('text_message', $values); $params['body_html'] = CRM_Utils_Array::value('html_message', $values); if (CRM_Utils_Array::value('recipient', $values) == 'manual') { $params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values); $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null'; } elseif (CRM_Utils_Array::value('recipient', $values) == 'group') { $params['group_id'] = $values['group_id']; $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null'; } elseif (!CRM_Utils_System::isNull($values['recipient_listing'])) { $params['recipient'] = CRM_Utils_Array::value('recipient', $values); $params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values)); $params['group_id'] = $params['recipient_manual'] = 'null'; } else { $params['recipient'] = CRM_Utils_Array::value('recipient', $values); $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null'; } $params['mapping_id'] = $values['entity'][0]; $entity_value = $values['entity'][1]; $entity_status = $values['entity'][2]; //force recording activity for membership reminder if ($params['mapping_id'] == 4) { $params['record_activity'] = 1; } foreach (array('entity_value', 'entity_status') as $key) { $params[$key] = implode(CRM_Core_DAO::VALUE_SEPARATOR, ${$key}); } $params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0); $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0); if (CRM_Utils_Array::value('is_repeat', $values) == 0) { $params['repetition_frequency_unit'] = 'null'; $params['repetition_frequency_interval'] = 'null'; $params['end_frequency_unit'] = 'null'; $params['end_frequency_interval'] = 'null'; $params['end_action'] = 'null'; $params['end_date'] = 'null'; } if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } elseif ($this->_action & CRM_Core_Action::ADD) { // we do this only once, so name never changes $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64); } $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName'); $msgTemplate = NULL; //mail template is composed $composeParams = array(); foreach ($composeFields as $key) { if (CRM_Utils_Array::value($key, $values)) { $composeParams[$key] = $values[$key]; } } if (CRM_Utils_Array::value('updateTemplate', $composeParams)) { $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE); $templateParams['id'] = $values['template']; $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams); } if (CRM_Utils_Array::value('saveTemplate', $composeParams)) { $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE); $templateParams['msg_title'] = $composeParams['saveTemplateName']; $msgTemplate = CRM_Core_BAO_MessageTemplates::add($templateParams); } if (isset($msgTemplate->id)) { $params['msg_template_id'] = $msgTemplate->id; } else { $params['msg_template_id'] = CRM_Utils_Array::value('template', $values); } CRM_Core_BAO_ActionSchedule::add($params, $ids); $status = ts("Your new Reminder titled %1 has been saved.", array(1 => "<strong>{$values['title']}</strong>")); if ($this->_action & CRM_Core_Action::UPDATE) { $status = ts("Your Reminder titled %1 has been updated.", array(1 => "<strong>{$values['title']}</strong>")); if ($this->_context == 'event' && $this->_eventId) { $url = CRM_Utils_System::url('civicrm/event/manage/reminder', "reset=1&action=update&id={$this->_eventId}"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); } } CRM_Core_Session::setStatus($status); }
/** * make a copy of a Event, including * all the fields in the event Wizard * * @param int $id * The event id to copy. * boolean $afterCreate call to copy after the create function * @param null $newEvent * @param bool $afterCreate * * @return CRM_Event_DAO_Event */ public static function copy($id, $newEvent = NULL, $afterCreate = FALSE) { $eventValues = array(); //get the require event values. $eventParams = array('id' => $id); $returnProperties = array('loc_block_id', 'is_show_location', 'default_fee_id', 'default_discount_fee_id', 'is_template'); CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties); // since the location is sharable, lets use the same loc_block_id. $locBlockId = CRM_Utils_Array::value('loc_block_id', $eventValues); $fieldsFix = $afterCreate ? array() : array('prefix' => array('title' => ts('Copy of') . ' ')); if (empty($eventValues['is_show_location'])) { $fieldsFix['prefix']['is_show_location'] = 0; } if ($newEvent && is_a($newEvent, 'CRM_Event_DAO_Event')) { $copyEvent = $newEvent; } if (!isset($copyEvent)) { $copyEvent =& CRM_Core_DAO::copyGeneric('CRM_Event_DAO_Event', array('id' => $id), array('loc_block_id' => $locBlockId ? $locBlockId : NULL), $fieldsFix); } CRM_Price_BAO_PriceSet::copyPriceSet('civicrm_event', $id, $copyEvent->id); $copyUF =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_UFJoin', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); $copyTellFriend =& CRM_Core_DAO::copyGeneric('CRM_Friend_DAO_Friend', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id)); $copyPCP =& CRM_Core_DAO::copyGeneric('CRM_PCP_DAO_PCPBlock', array('entity_id' => $id, 'entity_table' => 'civicrm_event'), array('entity_id' => $copyEvent->id), array('replace' => array('target_entity_id' => $copyEvent->id))); $oldMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => $eventValues['is_template'] ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID))); $copyMapping = CRM_Utils_Array::first(CRM_Core_BAO_ActionSchedule::getMappings(array('id' => $copyEvent->is_template == 1 ? CRM_Event_ActionMapping::EVENT_TPL_MAPPING_ID : CRM_Event_ActionMapping::EVENT_NAME_MAPPING_ID))); $copyReminder =& CRM_Core_DAO::copyGeneric('CRM_Core_DAO_ActionSchedule', array('entity_value' => $id, 'mapping_id' => $oldMapping->getId()), array('entity_value' => $copyEvent->id, 'mapping_id' => $copyMapping->getId())); if (!$afterCreate) { //copy custom data $extends = array('event'); $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, NULL, $extends); if ($groupTree) { foreach ($groupTree as $groupID => $group) { $table[$groupTree[$groupID]['table_name']] = array('entity_id'); foreach ($group['fields'] as $fieldID => $field) { $table[$groupTree[$groupID]['table_name']][] = $groupTree[$groupID]['fields'][$fieldID]['column_name']; } } foreach ($table as $tableName => $tableColumns) { $insert = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $tableColumns) . ') '; $tableColumns[0] = $copyEvent->id; $select = 'SELECT ' . implode(', ', $tableColumns); $from = ' FROM ' . $tableName; $where = " WHERE {$tableName}.entity_id = {$id}"; $query = $insert . $select . $from . $where; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); } } } $copyEvent->save(); CRM_Utils_System::flushCache(); if (!$afterCreate) { CRM_Utils_Hook::copy('Event', $copyEvent); } return $copyEvent; }
/** * Function to process the form * * @access public * * @return void */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { // delete reminder CRM_Core_BAO_ActionSchedule::del($this->_id); CRM_Core_Session::setStatus(ts('Selected Reminder has been deleted.'), ts('Record Deleted'), 'success'); return; } $values = $this->controller->exportValues($this->getName()); $keys = array('title', 'subject', 'absolute_date', 'group_id', 'record_activity', 'limit_to'); foreach ($keys as $key) { $params[$key] = CRM_Utils_Array::value($key, $values); } $moreKeys = array('start_action_offset', 'start_action_unit', 'start_action_condition', 'start_action_date', 'repetition_frequency_unit', 'repetition_frequency_interval', 'end_frequency_unit', 'end_frequency_interval', 'end_action', 'end_date'); if ($absoluteDate = CRM_Utils_Array::value('absolute_date', $params)) { $params['absolute_date'] = CRM_Utils_Date::processDate($absoluteDate); foreach ($moreKeys as $mkey) { $params[$mkey] = 'null'; } } else { $params['absolute_date'] = 'null'; foreach ($moreKeys as $mkey) { $params[$mkey] = CRM_Utils_Array::value($mkey, $values); } } $params['body_text'] = CRM_Utils_Array::value('text_message', $values); $params['body_html'] = CRM_Utils_Array::value('html_message', $values); if (CRM_Utils_Array::value('recipient', $values) == 'manual') { $params['recipient_manual'] = CRM_Utils_Array::value('recipient_manual_id', $values); $params['group_id'] = $params['recipient'] = $params['recipient_listing'] = 'null'; } elseif (CRM_Utils_Array::value('recipient', $values) == 'group') { $params['group_id'] = $values['group_id']; $params['recipient_manual'] = $params['recipient'] = $params['recipient_listing'] = 'null'; } elseif (!CRM_Utils_System::isNull($values['recipient_listing'])) { $params['recipient'] = CRM_Utils_Array::value('recipient', $values); $params['recipient_listing'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('recipient_listing', $values)); $params['group_id'] = $params['recipient_manual'] = 'null'; } else { $params['recipient'] = CRM_Utils_Array::value('recipient', $values); $params['group_id'] = $params['recipient_manual'] = $params['recipient_listing'] = 'null'; } $params['mapping_id'] = $this->_mappingID; $params['entity_value'] = $this->_id; $params['entity_status'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, $values['entity']); $params['is_active'] = CRM_Utils_Array::value('is_active', $values, 0); $params['is_repeat'] = CRM_Utils_Array::value('is_repeat', $values, 0); if (CRM_Utils_Array::value('is_repeat', $values) == 0) { $params['repetition_frequency_unit'] = 'null'; $params['repetition_frequency_interval'] = 'null'; $params['end_frequency_unit'] = 'null'; $params['end_frequency_interval'] = 'null'; $params['end_action'] = 'null'; $params['end_date'] = 'null'; } $params['name'] = CRM_Utils_String::munge($params['title'], '_', 64); $composeFields = array('template', 'saveTemplate', 'updateTemplate', 'saveTemplateName'); $msgTemplate = NULL; //mail template is composed $composeParams = array(); foreach ($composeFields as $key) { if (!empty($values[$key])) { $composeParams[$key] = $values[$key]; } } if (!empty($composeParams['updateTemplate'])) { $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE); $templateParams['id'] = $values['template']; $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); } if (!empty($composeParams['saveTemplate'])) { $templateParams = array('msg_text' => $params['body_text'], 'msg_html' => $params['body_html'], 'msg_subject' => $params['subject'], 'is_active' => TRUE); $templateParams['msg_title'] = $composeParams['saveTemplateName']; $msgTemplate = CRM_Core_BAO_MessageTemplate::add($templateParams); } if (isset($msgTemplate->id)) { $params['msg_template_id'] = $msgTemplate->id; } else { $params['msg_template_id'] = CRM_Utils_Array::value('template', $values); } CRM_Core_BAO_ActionSchedule::add($params, $ids); $status = ts("Your new Reminder titled %1 has been saved.", array(1 => "<strong>{$values['title']}</strong>")); CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); parent::endPostProcess(); }
/** * For contacts/members which match schedule based on end date, * an email should be sent. */ function testMembershipEndDate_NoMatch() { // creates membership with end_date = 20120615 $membership = $this->createTestObject('CRM_Member_DAO_Membership', array_merge($this->fixtures['rolling_membership_past'], array('status_id' => 3))); $this->assertTrue(is_numeric($membership->id)); $result = civicrm_api('Email', 'create', array('contact_id' => $membership->contact_id, 'email' => '*****@*****.**', 'version' => 3)); $contact = civicrm_api('contact', 'create', array_merge($this->fixtures['contact'], array('contact_id' => $membership->contact_id))); $this->assertAPISuccess($result); $actionSchedule = $this->fixtures['sched_membership_end_2month']; $actionSchedule['entity_value'] = $membership->membership_type_id; $actionScheduleDao = CRM_Core_BAO_ActionSchedule::add($actionSchedule); $this->assertTrue(is_numeric($actionScheduleDao->id)); // end_date=2012-06-15 ; schedule is 2 weeks before end_date $this->assertCronRuns(array(array('time' => '2012-05-31 01:00:00', 'recipients' => array()), array('time' => '2013-05-01 01:00:00', 'recipients' => array()))); }