Exemple #1
0
 /**
  * Set variables up before form is built.
  *
  *
  * @return void
  */
 public function preProcess()
 {
     // current set id
     $this->_id = $this->get('id');
     if ($this->_id && ($isReserved = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_id, 'is_reserved', 'id'))) {
         CRM_Core_Error::fatal("You cannot edit the settings of a reserved custom field-set.");
     }
     // setting title for html page
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
         CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $title)));
     } elseif ($this->_action == CRM_Core_Action::VIEW) {
         $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
         CRM_Utils_System::setTitle(ts('Preview %1', array(1 => $title)));
     } else {
         CRM_Utils_System::setTitle(ts('New Custom Field Set'));
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_CustomGroup::retrieve($params, $this->_defaults);
         $subExtends = CRM_Utils_Array::value('extends_entity_column_value', $this->_defaults);
         if (!empty($subExtends)) {
             $this->_subtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subExtends, 1, -1));
         }
     }
 }
 /**
  * set up variables to build the form
  *
  * @return void
  * @acess protected
  */
 function preProcess()
 {
     $this->_id = $this->get('id');
     $defaults = array();
     $params = array('id' => $this->_id);
     CRM_Core_BAO_CustomGroup::retrieve($params, $defaults);
     $this->_title = $defaults['title'];
     $this->assign('name', $this->_title);
     CRM_Utils_System::setTitle(ts('Confirm Custom Group Delete'));
 }
Exemple #3
0
 /**
  * Function to test retrieve()
  */
 function testRetrieve()
 {
     $customGrouptitle = 'My Custom Group';
     $groupParams = array('title' => $customGrouptitle, 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'help_pre' => 'Custom Group Help Pre', 'help_post' => 'Custom Group Help Post', 'is_active' => 1, 'collapse_display' => 1, 'weight' => 2);
     $customGroup = Custom::createGroup($groupParams);
     $customGroupId = $customGroup->id;
     $params = array('id' => $customGroupId);
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults);
     $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id', 'Database check for custom group record.');
     $this->assertEquals($customGrouptitle, $dbCustomGroupTitle);
     //check retieve values
     $this->assertAttributesEquals($groupParams, $dafaults);
     //cleanup DB by deleting customGroup
     Custom::deleteGroup($customGroup);
 }
 /**
  * set up variables to build the form
  *
  * @return void
  * @acess protected
  */
 function preProcess()
 {
     $this->_id = $this->get('id');
     $defaults = array();
     $params = array('id' => $this->_id);
     CRM_Core_BAO_CustomGroup::retrieve($params, $defaults);
     $this->_title = $defaults['title'];
     //check wheter this contain any custom fields
     $customField = new CRM_Core_DAO_CustomField();
     $customField->custom_group_id = $this->_id;
     if ($customField->find(TRUE)) {
         CRM_Core_Session::setStatus(ts("The Group '%1' cannot be deleted! You must Delete all custom fields in this group prior to deleting the group.", array(1 => $this->_title)), ts('Deletion Error'), 'error');
         $url = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1");
         CRM_Utils_System::redirect($url);
         return TRUE;
     }
     $this->assign('title', $this->_title);
     CRM_Utils_System::setTitle(ts('Confirm Custom Group Delete'));
 }
 /**
  * @param $mappingID
  * @param $now
  * @param array $params
  *
  * @throws API_Exception
  */
 static function buildRecipientContacts($mappingID, $now, $params = array())
 {
     $actionSchedule = new CRM_Core_DAO_ActionSchedule();
     $actionSchedule->mapping_id = $mappingID;
     $actionSchedule->is_active = 1;
     if (!empty($params)) {
         _civicrm_api3_dao_set_filter($actionSchedule, $params, FALSE, 'ActionSchedule');
     }
     $actionSchedule->find();
     while ($actionSchedule->fetch()) {
         $mapping = new CRM_Core_DAO_ActionMapping();
         $mapping->id = $mappingID;
         $mapping->find(TRUE);
         // note: $where - this filtering applies for both
         // 'limit to' and 'addition to' options
         // $limitWhere - this filtering applies only for
         // 'limit to' option
         $select = $join = $where = $limitWhere = array();
         $limitTo = $actionSchedule->limit_to;
         $value = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($actionSchedule->entity_value, CRM_Core_DAO::VALUE_SEPARATOR));
         $value = implode(',', $value);
         $status = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($actionSchedule->entity_status, CRM_Core_DAO::VALUE_SEPARATOR));
         $status = implode(',', $status);
         $anniversary = false;
         if (!CRM_Utils_System::isNull($mapping->entity_recipient)) {
             $recipientOptions = CRM_Core_OptionGroup::values($mapping->entity_recipient, FALSE, FALSE, FALSE, NULL, 'name');
         }
         $from = "{$mapping->entity} e";
         if ($mapping->entity == 'civicrm_activity') {
             $contactField = 'r.contact_id';
             $table = 'civicrm_activity e';
             $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
             $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
             $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts);
             $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts);
             if ($limitTo == 0) {
                 // including the activity target contacts if 'in addition' is defined
                 $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$targetID}";
             } else {
                 switch (CRM_Utils_Array::value($actionSchedule->recipient, $recipientOptions)) {
                     case 'Activity Assignees':
                         $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$assigneeID}";
                         break;
                     case 'Activity Source':
                         $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$sourceID}";
                         break;
                     default:
                     case 'Activity Targets':
                         $join[] = "INNER JOIN civicrm_activity_contact r ON r.activity_id = e.id AND record_type_id = {$targetID}";
                         break;
                 }
             }
             // build where clause
             if (!empty($value)) {
                 $where[] = "e.activity_type_id IN ({$value})";
             } else {
                 $where[] = "e.activity_type_id IS NULL";
             }
             if (!empty($status)) {
                 $where[] = "e.status_id IN ({$status})";
             }
             $where[] = ' e.is_current_revision = 1 ';
             $where[] = ' e.is_deleted = 0 ';
             $dateField = 'e.activity_date_time';
         }
         if ($mapping->entity == 'civicrm_participant') {
             $table = 'civicrm_event r';
             $contactField = 'e.contact_id';
             $join[] = 'INNER JOIN civicrm_event r ON e.event_id = r.id';
             if ($actionSchedule->recipient_listing && $limitTo) {
                 $rList = explode(CRM_Core_DAO::VALUE_SEPARATOR, trim($actionSchedule->recipient_listing, CRM_Core_DAO::VALUE_SEPARATOR));
                 $rList = implode(',', $rList);
                 switch ($recipientOptions[$actionSchedule->recipient]) {
                     case 'participant_role':
                         $where[] = "e.role_id IN ({$rList})";
                         break;
                     default:
                         break;
                 }
             }
             // build where clause
             if (!empty($value)) {
                 $where[] = $mapping->entity_value == 'event_type' ? "r.event_type_id IN ({$value})" : "r.id IN ({$value})";
             } else {
                 $where[] = $mapping->entity_value == 'event_type' ? "r.event_type_id IS NULL" : "r.id IS NULL";
             }
             // participant status criteria not to be implemented
             // for additional recipients
             if (!empty($status)) {
                 $limitWhere[] = "e.status_id IN ({$status})";
             }
             $where[] = 'r.is_active = 1';
             $where[] = 'r.is_template = 0';
             $dateField = str_replace('event_', 'r.', $actionSchedule->start_action_date);
         }
         $notINClause = '';
         if ($mapping->entity == 'civicrm_membership') {
             $contactField = 'e.contact_id';
             $table = 'civicrm_membership e';
             // build where clause
             if ($status == 2) {
                 //auto-renew memberships
                 $where[] = "e.contribution_recur_id IS NOT NULL ";
             } elseif ($status == 1) {
                 $where[] = "e.contribution_recur_id IS NULL ";
             }
             // build where clause
             if (!empty($value)) {
                 $where[] = "e.membership_type_id IN ({$value})";
             } else {
                 $where[] = "e.membership_type_id IS NULL";
             }
             $where[] = "( e.is_override IS NULL OR e.is_override = 0 )";
             $dateField = str_replace('membership_', 'e.', $actionSchedule->start_action_date);
             $notINClause = self::permissionedRelationships($contactField);
             $membershipStatus = CRM_Member_PseudoConstant::membershipStatus(NULL, "(is_current_member = 1 OR name = 'Expired')", 'id');
             $mStatus = implode(',', $membershipStatus);
             $where[] = "e.status_id IN ({$mStatus})";
         }
         if ($mapping->entity == 'civicrm_contact') {
             if ($value == 'birth_date') {
                 $dateDBField = 'birth_date';
                 $table = 'civicrm_contact e';
                 $contactField = 'e.id';
                 $where[] = 'e.is_deleted = 0';
                 $where[] = 'e.is_deceased = 0';
             } else {
                 //custom field
                 $customFieldParams = array('id' => substr($value, 7));
                 $customGroup = $customField = array();
                 CRM_Core_BAO_CustomField::retrieve($customFieldParams, $customField);
                 $dateDBField = $customField['column_name'];
                 $customGroupParams = array('id' => $customField['custom_group_id'], $customGroup);
                 CRM_Core_BAO_CustomGroup::retrieve($customGroupParams, $customGroup);
                 $from = $table = "{$customGroup['table_name']} e";
                 $contactField = 'e.entity_id';
                 $where[] = '1';
                 // possible to have no "where" in this case
             }
             $status_ = explode(',', $status);
             if (in_array(2, $status_)) {
                 // anniversary mode:
                 $dateField = 'DATE_ADD(e.' . $dateDBField . ', INTERVAL ROUND(DATEDIFF(DATE(' . $now . '), e.' . $dateDBField . ') / 365) YEAR)';
                 $anniversary = true;
             } else {
                 // regular mode:
                 $dateField = 'e.' . $dateDBField;
             }
             // TODO get this working
             // TODO: Make sure everything's provided for repetition, etc.
         }
         // CRM-13577 Introduce Smart Groups Handling
         if ($actionSchedule->group_id) {
             // Need to check if its a smart group or not
             // Then decide which table to join onto the query
             $group = CRM_Contact_DAO_Group::getTableName();
             // Get the group information
             $sql = "\nSELECT     {$group}.id, {$group}.cache_date, {$group}.saved_search_id, {$group}.children\nFROM       {$group}\nWHERE      {$group}.id = {$actionSchedule->group_id}\n";
             $groupDAO = CRM_Core_DAO::executeQuery($sql);
             $isSmartGroup = FALSE;
             if ($groupDAO->fetch() && !empty($groupDAO->saved_search_id)) {
                 // Check that the group is in place in the cache and up to date
                 CRM_Contact_BAO_GroupContactCache::check($actionSchedule->group_id);
                 // Set smart group flag
                 $isSmartGroup = TRUE;
             }
         }
         // CRM-13577 End Introduce Smart Groups Handling
         if ($limitTo) {
             if ($actionSchedule->group_id) {
                 // CRM-13577 If smart group then use Cache table
                 if ($isSmartGroup) {
                     $join[] = "INNER JOIN civicrm_group_contact_cache grp ON {$contactField} = grp.contact_id";
                     $where[] = "grp.group_id IN ({$actionSchedule->group_id})";
                 } else {
                     $join[] = "INNER JOIN civicrm_group_contact grp ON {$contactField} = grp.contact_id AND grp.status = 'Added'";
                     $where[] = "grp.group_id IN ({$actionSchedule->group_id})";
                 }
             } elseif (!empty($actionSchedule->recipient_manual)) {
                 $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String');
                 $where[] = "{$contactField} IN ({$rList})";
             }
         } else {
             $addGroup = $addWhere = '';
             if ($actionSchedule->group_id) {
                 // CRM-13577 If smart group then use Cache table
                 if ($isSmartGroup) {
                     $addGroup = " INNER JOIN civicrm_group_contact_cache grp ON c.id = grp.contact_id";
                     $addWhere = " grp.group_id IN ({$actionSchedule->group_id})";
                 } else {
                     $addGroup = " INNER JOIN civicrm_group_contact grp ON c.id = grp.contact_id AND grp.status = 'Added'";
                     $addWhere = " grp.group_id IN ({$actionSchedule->group_id})";
                 }
             }
             if (!empty($actionSchedule->recipient_manual)) {
                 $rList = CRM_Utils_Type::escape($actionSchedule->recipient_manual, 'String');
                 $addWhere = "c.id IN ({$rList})";
             }
         }
         $select[] = "{$contactField} as contact_id";
         $select[] = 'e.id as entity_id';
         $select[] = "'{$mapping->entity}' as entity_table";
         $select[] = "{$actionSchedule->id} as action_schedule_id";
         $reminderJoinClause = "civicrm_action_log reminder ON reminder.contact_id = {$contactField} AND\nreminder.entity_id          = e.id AND\nreminder.entity_table       = '{$mapping->entity}' AND\nreminder.action_schedule_id = %1";
         if ($anniversary) {
             // only consider reminders less than 11 months ago
             $reminderJoinClause .= " AND reminder.action_date_time > DATE_SUB({$now}, INTERVAL 11 MONTH)";
         }
         if ($table != 'civicrm_contact e') {
             $join[] = "INNER JOIN civicrm_contact c ON c.id = {$contactField} AND c.is_deleted = 0 AND c.is_deceased = 0 ";
         }
         if ($actionSchedule->start_action_date) {
             $startDateClause = array();
             $op = $actionSchedule->start_action_condition == 'before' ? '<=' : '>=';
             $operator = $actionSchedule->start_action_condition == 'before' ? 'DATE_SUB' : 'DATE_ADD';
             $date = $operator . "({$dateField}, INTERVAL {$actionSchedule->start_action_offset} {$actionSchedule->start_action_unit})";
             $startDateClause[] = "'{$now}' >= {$date}";
             if ($mapping->entity == 'civicrm_participant') {
                 $startDateClause[] = $operator . "({$now}, INTERVAL 1 DAY ) {$op} " . $dateField;
             } else {
                 $startDateClause[] = "DATE_SUB({$now}, INTERVAL 1 DAY ) <= {$date}";
             }
             $startDate = implode(' AND ', $startDateClause);
         } elseif ($actionSchedule->absolute_date) {
             $startDate = "DATEDIFF(DATE('{$now}'),'{$actionSchedule->absolute_date}') = 0";
         }
         // ( now >= date_built_from_start_time ) OR ( now = absolute_date )
         $dateClause = "reminder.id IS NULL AND {$startDate}";
         // start composing query
         $selectClause = 'SELECT ' . implode(', ', $select);
         $fromClause = "FROM {$from}";
         $joinClause = !empty($join) ? implode(' ', $join) : '';
         $whereClause = 'WHERE ' . implode(' AND ', $where);
         $limitWhereClause = '';
         if (!empty($limitWhere)) {
             $limitWhereClause = ' AND ' . implode(' AND ', $limitWhere);
         }
         $query = "\nINSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id)\n{$selectClause}\n{$fromClause}\n{$joinClause}\nLEFT JOIN {$reminderJoinClause}\n{$whereClause} {$limitWhereClause} AND {$dateClause} {$notINClause}\n";
         CRM_Core_DAO::executeQuery($query, array(1 => array($actionSchedule->id, 'Integer')));
         if ($limitTo == 0) {
             $additionWhere = ' WHERE ';
             if ($actionSchedule->start_action_date) {
                 $additionWhere = $whereClause . ' AND ';
             }
             $contactTable = "civicrm_contact c";
             $addSelect = "SELECT c.id as contact_id, c.id as entity_id, 'civicrm_contact' as entity_table, {$actionSchedule->id} as action_schedule_id";
             $additionReminderClause = "civicrm_action_log reminder ON reminder.contact_id = c.id AND\n          reminder.entity_id          = c.id AND\n          reminder.entity_table       = 'civicrm_contact' AND\n          reminder.action_schedule_id = {$actionSchedule->id}";
             $addWhereClause = '';
             if ($addWhere) {
                 $addWhereClause = "AND {$addWhere}";
             }
             $insertAdditionalSql = "\nINSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id)\n{$addSelect}\nFROM ({$contactTable})\nLEFT JOIN {$additionReminderClause}\n{$addGroup}\nWHERE c.is_deleted = 0 AND c.is_deceased = 0\n{$addWhereClause}\n\nAND c.id NOT IN (\n     SELECT rem.contact_id\n     FROM civicrm_action_log rem INNER JOIN {$mapping->entity} e ON rem.entity_id = e.id\n     WHERE rem.action_schedule_id = {$actionSchedule->id}\n      AND rem.entity_table = '{$mapping->entity}'\n    )\nGROUP BY c.id\n";
             CRM_Core_DAO::executeQuery($insertAdditionalSql);
         }
         // if repeat is turned ON:
         if ($actionSchedule->is_repeat) {
             $repeatEvent = ($actionSchedule->end_action == 'before' ? 'DATE_SUB' : 'DATE_ADD') . "({$dateField}, INTERVAL {$actionSchedule->end_frequency_interval} {$actionSchedule->end_frequency_unit})";
             if ($actionSchedule->repetition_frequency_unit == 'day') {
                 $hrs = 24 * $actionSchedule->repetition_frequency_interval;
             } elseif ($actionSchedule->repetition_frequency_unit == 'week') {
                 $hrs = 24 * $actionSchedule->repetition_frequency_interval * 7;
             } elseif ($actionSchedule->repetition_frequency_unit == 'month') {
                 $hrs = "24*(DATEDIFF(DATE_ADD(latest_log_time, INTERVAL 1 MONTH ), latest_log_time))";
             } elseif ($actionSchedule->repetition_frequency_unit == 'year') {
                 $hrs = "24*(DATEDIFF(DATE_ADD(latest_log_time, INTERVAL 1 YEAR ), latest_log_time))";
             } else {
                 $hrs = $actionSchedule->repetition_frequency_interval;
             }
             // (now <= repeat_end_time )
             $repeatEventClause = "'{$now}' <= {$repeatEvent}";
             // diff(now && logged_date_time) >= repeat_interval
             $havingClause = "HAVING TIMEDIFF({$now}, latest_log_time) >= TIME('{$hrs}:00:00')";
             $groupByClause = 'GROUP BY reminder.contact_id, reminder.entity_id, reminder.entity_table';
             $selectClause .= ', MAX(reminder.action_date_time) as latest_log_time';
             $sqlInsertValues = "{$selectClause}\n{$fromClause}\n{$joinClause}\nINNER JOIN {$reminderJoinClause}\n{$whereClause} {$limitWhereClause} AND {$repeatEventClause}\n{$groupByClause}\n{$havingClause}";
             $valsqlInsertValues = CRM_Core_DAO::executeQuery($sqlInsertValues, array(1 => array($actionSchedule->id, 'Integer')));
             $arrValues = array();
             while ($valsqlInsertValues->fetch()) {
                 $arrValues[] = "( {$valsqlInsertValues->contact_id}, {$valsqlInsertValues->entity_id}, '{$valsqlInsertValues->entity_table}',{$valsqlInsertValues->action_schedule_id} )";
             }
             $valString = implode(',', $arrValues);
             if ($valString) {
                 $query = '
           INSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id) VALUES ' . $valString;
                 CRM_Core_DAO::executeQuery($query, array(1 => array($actionSchedule->id, 'Integer')));
             }
             if ($limitTo == 0) {
                 $addSelect .= ', MAX(reminder.action_date_time) as latest_log_time';
                 $sqlEndEventCheck = "\nSELECT * FROM {$table}\n{$whereClause} AND {$repeatEventClause} LIMIT 1";
                 $daoCheck = CRM_Core_DAO::executeQuery($sqlEndEventCheck);
                 if ($daoCheck->fetch()) {
                     $valSqlAdditionInsert = "\n{$addSelect}\nFROM  {$contactTable}\n{$addGroup}\nINNER JOIN {$additionReminderClause}\nWHERE {$addWhere} AND c.is_deleted = 0 AND c.is_deceased = 0\nGROUP BY reminder.contact_id\n{$havingClause}\n";
                     $daoForVals = CRM_Core_DAO::executeQuery($valSqlAdditionInsert);
                     $addValues = array();
                     while ($daoForVals->fetch()) {
                         $addValues[] = "( {$daoForVals->contact_id}, {$daoForVals->entity_id}, '{$daoForVals->entity_table}',{$daoForVals->action_schedule_id} )";
                     }
                     $valString = implode(',', $addValues);
                     if ($valString) {
                         $query = '
             INSERT INTO civicrm_action_log (contact_id, entity_id, entity_table, action_schedule_id) VALUES ' . $valString;
                         CRM_Core_DAO::executeQuery($query);
                     }
                 }
             }
         }
     }
 }
 /**
  * Test retrieve() with Inalid Params
  */
 public function testRetrieveInvalidParams()
 {
     $params = array('id' => 99);
     $customGroup = CRM_Core_BAO_CustomGroup::retrieve($params, $dafaults);
     $this->assertNull($customGroup, 'Check that no custom Group is retreived');
 }
Exemple #7
0
 /**
  * Validation rule for custom data extends entity column values.
  *
  * @param Object $customField
  *   Custom field.
  * @param int $gid
  *   Group Id.
  * @param string $fieldType
  *   Group type of the field.
  * @param array $errors
  *   Collect errors.
  *
  * @return array
  *   list of errors to be posted back to the form
  */
 public static function formRuleCustomDataExtentColumnValue($customField, $gid, $fieldType, &$errors)
 {
     // fix me : check object $customField
     if (in_array($fieldType, array('Participant', 'Contribution', 'Membership', 'Activity', 'Case'))) {
         $params = array('id' => $customField->custom_group_id);
         $customGroup = array();
         CRM_Core_BAO_CustomGroup::retrieve($params, $customGroup);
         if ($fieldType != CRM_Utils_Array::value('extends', $customGroup) || empty($customGroup['extends_entity_column_value'])) {
             return $errors;
         }
         $extendsColumnValues = array();
         foreach (explode(CRM_Core_DAO::VALUE_SEPARATOR, $customGroup['extends_entity_column_value']) as $val) {
             if ($val) {
                 $extendsColumnValues[] = $val;
             }
         }
         if (empty($extendsColumnValues)) {
             return $errors;
         }
         $fieldTypeValues = CRM_Core_BAO_UFGroup::groupTypeValues($gid, $fieldType);
         if (empty($fieldTypeValues[$fieldType])) {
             return;
         }
         $disallowedTypes = array_diff($extendsColumnValues, $fieldTypeValues[$fieldType]);
         if (!empty($disallowedTypes)) {
             $errors['field_name'] = ts('Profile is already having custom fields extending different group types, you can not add or update this custom field.');
         }
     }
 }
 /**
  * Generate a query to locate recipients who match the given
  * schedule.
  *
  * @param \CRM_Core_DAO_ActionSchedule $schedule
  *   The schedule as configured by the administrator.
  * @param string $phase
  *   See, e.g., RecipientBuilder::PHASE_RELATION_FIRST.
  * @param array $defaultParams
  *
  * @return \CRM_Utils_SQL_Select
  * @throws \CRM_Core_Exception
  * @see RecipientBuilder
  */
 public function createQuery($schedule, $phase, $defaultParams)
 {
     $selectedValues = (array) \CRM_Utils_Array::explodePadded($schedule->entity_value);
     $selectedStatuses = (array) \CRM_Utils_Array::explodePadded($schedule->entity_status);
     // FIXME: This assumes that $values only has one field, but UI shows multiselect.
     // Properly supporting multiselect would require total rewrite of this function.
     if (count($selectedValues) != 1 || !isset($selectedValues[0])) {
         throw new \CRM_Core_Exception("Error: Scheduled reminders may only have one contact field.");
     } elseif (in_array($selectedValues[0], $this->contactDateFields)) {
         $dateDBField = $selectedValues[0];
         $query = \CRM_Utils_SQL_Select::from("{$this->entity} e")->param($defaultParams);
         $query->param(array('casAddlCheckFrom' => 'civicrm_contact e', 'casContactIdField' => 'e.id', 'casEntityIdField' => 'e.id', 'casContactTableAlias' => 'e'));
         $query->where('e.is_deleted = 0 AND e.is_deceased = 0');
     } else {
         //custom field
         $customFieldParams = array('id' => substr($selectedValues[0], 7));
         $customGroup = $customField = array();
         \CRM_Core_BAO_CustomField::retrieve($customFieldParams, $customField);
         $dateDBField = $customField['column_name'];
         $customGroupParams = array('id' => $customField['custom_group_id'], $customGroup);
         \CRM_Core_BAO_CustomGroup::retrieve($customGroupParams, $customGroup);
         $query = \CRM_Utils_SQL_Select::from("{$customGroup['table_name']} e")->param($defaultParams);
         $query->param(array('casAddlCheckFrom' => "{$customGroup['table_name']} e", 'casContactIdField' => 'e.entity_id', 'casEntityIdField' => 'e.id', 'casContactTableAlias' => NULL));
         $query->where('1');
         // possible to have no "where" in this case
     }
     $query['casDateField'] = 'e.' . $dateDBField;
     if (in_array(2, $selectedStatuses)) {
         $query['casAnniversaryMode'] = 1;
         $query['casDateField'] = 'DATE_ADD(' . $query['casDateField'] . ', INTERVAL ROUND(DATEDIFF(DATE(' . $query['casNow'] . '), ' . $query['casDateField'] . ') / 365) YEAR)';
     }
     return $query;
 }
Exemple #9
0
 /**
  * Function to set variables up before form is built
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function preProcess()
 {
     require_once 'CRM/Core/BAO/CustomGroup.php';
     // current set id
     $this->_id = $this->get('id');
     // setting title for html page
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
         CRM_Utils_System::setTitle(ts('Edit %1', array(1 => $title)));
     } else {
         if ($this->_action == CRM_Core_Action::VIEW) {
             $title = CRM_Core_BAO_CustomGroup::getTitle($this->_id);
             CRM_Utils_System::setTitle(ts('Preview %1', array(1 => $title)));
         } else {
             CRM_Utils_System::setTitle(ts('New Custom Field Set'));
         }
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_CustomGroup::retrieve($params, $this->_defaults);
         $subExtends = CRM_Utils_Array::value('extends_entity_column_value', $this->_defaults);
         if (!empty($subExtends)) {
             $this->_subtypes = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subExtends, 1, -1));
         }
     }
 }
Exemple #10
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @param null
  * 
  * @return array   array of default values
  * @access public
  */
 function setDefaultValues()
 {
     $defaults = array();
     if ($this->_action == CRM_CORE_ACTION_ADD) {
         $defGroup =& new CRM_Core_DAO_CustomGroup();
         $defGroup->domain_id = CRM_Core_Config::domainID();
         $defGroup->orderBy('weight DESC');
         $defGroup->find();
         if ($defGroup->fetch()) {
             $defaults['weight'] = $defGroup->weight + 1;
         } else {
             $defaults['weight'] = 1;
         }
     }
     if (isset($this->_id)) {
         $params = array('id' => $this->_id);
         CRM_Core_BAO_CustomGroup::retrieve($params, $defaults);
     } else {
         $defaults['is_active'] = 1;
         $defaults['style'] = 'Inline';
     }
     return $defaults;
 }