/** * Test system flush. */ public function testFlush() { // Note: this operation actually flushes several different caches; we don't // check all of them -- just enough to make sure that the API is doing // something $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); $data = 'abc'; CRM_Core_BAO_Cache::setItem($data, self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH); $this->assertEquals('abc', CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); $params = array(); $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush'); $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); }
public function testSetGetItem() { $originalValue = array('abc' => 'def'); CRM_Core_BAO_Cache::setItem($originalValue, __CLASS__, 'testSetGetItem'); $return_1 = CRM_Core_BAO_Cache::getItem(__CLASS__, 'testSetGetItem'); $this->assertEquals($originalValue, $return_1); // Wipe out any in-memory copies of the cache. Check to see if the SQL // read is correct. CRM_Core_BAO_Cache::$_cache = NULL; CRM_Utils_Cache::$_singleton = NULL; $return_2 = CRM_Core_BAO_Cache::getItem(__CLASS__, 'testSetGetItem'); $this->assertEquals($originalValue, $return_2); }
/** * Returns total number of rows for the query. * * @param * * @return int Total number of rows * @access public */ function getTotalCount($action) { // Use count from cache during paging/sorting if (!empty($_GET['crmPID']) || !empty($_GET['crmSID'])) { $count = CRM_Core_BAO_Cache::getItem('Search Results Count', $this->_key); } if (empty($count)) { $count = $this->_query->searchQuery(0, 0, NULL, TRUE); CRM_Core_BAO_Cache::setItem($count, 'Search Results Count', $this->_key); } return $count; }
/** * This function sets the default values for the form. * * @access public * * @return None */ function setDefaultValues() { if (empty($this->_fields)) { return; } // for add mode set smart defaults if ($this->_action & CRM_Core_Action::ADD) { list($currentDate, $currentTime) = CRM_Utils_Date::setDateDefaults(NULL, 'activityDateTime'); //get all status $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); $completeStatus = array_search('Completed', $allStatus); $specialFields = array('join_date' => $currentDate, 'receive_date' => $currentDate, 'receive_date_time' => $currentTime, 'contribution_status_id' => $completeStatus); for ($rowNumber = 1; $rowNumber <= $this->_batchInfo['item_count']; $rowNumber++) { foreach ($specialFields as $key => $value) { $defaults['field'][$rowNumber][$key] = $value; } } } else { // get the existing batch values from cache table $cacheKeyString = CRM_Core_BAO_Batch::getCacheKeyForBatch($this->_batchId); $defaults = CRM_Core_BAO_Cache::getItem('batch entry', $cacheKeyString); } return $defaults; }
/** * Get formatted menu list * * @return array $navigations returns associated array * @static */ static function getNavigationList() { $cacheKeyString = "navigationList "; $whereClause = ''; $config = CRM_Core_Config::singleton(); if ($config->userFramework == 'Joomla') { $whereClause = " AND name NOT IN ('Access Control') "; $cacheKeyString .= "_1"; } // check if we can retrieve from database cache require_once 'CRM/Core/BAO/Cache.php'; $navigations =& CRM_Core_BAO_Cache::getItem('navigation', $cacheKeyString); if (!$navigations) { $domainID = CRM_Core_Config::domainID(); $query = "\nSELECT id, label, parent_id, weight, is_active, name \nFROM civicrm_navigation WHERE domain_id = {$domainID} {$whereClause} ORDER BY parent_id, weight ASC"; $result = CRM_Core_DAO::executeQuery($query); $pidGroups = array(); while ($result->fetch()) { $pidGroups[$result->parent_id][$result->label] = $result->id; } foreach ($pidGroups[''] as $label => $val) { $pidGroups[''][$label] = self::_getNavigationValue($val, $pidGroups); } $navigations = array(); self::_getNavigationLabel($pidGroups[''], $navigations); CRM_Core_BAO_Cache::setItem($navigations, 'navigation', $cacheKeyString); } return $navigations; }
function get($key) { if (!array_key_exists($key, $this->frontCache)) { $this->frontCache[$key] = CRM_Core_BAO_Cache::getItem($this->group, $key, $this->componentID); } return $this->frontCache[$key]; }
/** * This provides information about the setting - similar to the fields concept for DAO information. * As the setting is serialized code creating validation setting input needs to know the data type * This also helps move information out of the form layer into the data layer where people can interact with * it via the API or other mechanisms. In order to keep this consistent it is important the form layer * also leverages it. * * Note that this function should never be called when using the runtime getvalue function. Caching works * around the expectation it will be called during setting administration * * Function is intended for configuration rather than runtime access to settings * * The following params will filter the result. If none are passed all settings will be returns * * @param int $componentID * Id of relevant component. * @param array $filters * @param int $domainID * @param null $profile * * @return array * the following information as appropriate for each setting * - name * - type * - default * - add (CiviCRM version added) * - is_domain * - is_contact * - description * - help_text */ public static function getSettingSpecification($componentID = NULL, $filters = array(), $domainID = NULL, $profile = NULL) { $cacheString = 'settingsMetadata_' . $domainID . '_' . $profile; foreach ($filters as $filterField => $filterString) { $cacheString .= "_{$filterField}_{$filterString}"; } $cached = 1; // the caching into 'All' seems to be a duplicate of caching to // settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook $settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Specs', $cacheString, $componentID); if ($settingsMetadata === NULL) { $settingsMetadata = CRM_Core_BAO_Cache::getItem('CiviCRM setting Spec', 'All', $componentID); if (empty($settingsMetadata)) { global $civicrm_root; $metaDataFolders = array($civicrm_root . '/settings'); CRM_Utils_Hook::alterSettingsFolders($metaDataFolders); $settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders); CRM_Core_BAO_Cache::setItem($settingsMetadata, 'CiviCRM setting Spec', 'All', $componentID); } $cached = 0; } CRM_Utils_Hook::alterSettingsMetaData($settingsMetadata, $domainID, $profile); self::_filterSettingsSpecification($filters, $settingsMetadata); if (!$cached) { // this is a bit 'heavy' if you are using hooks but this function // is expected to only be called during setting administration // it should not be called by 'getvalue' or 'getitem CRM_Core_BAO_Cache::setItem($settingsMetadata, 'CiviCRM setting Specs', $cacheString, $componentID); } return $settingsMetadata; }
/** * Store and return an array of all active custom fields. * * @param string $customDataType type of Custom Data * @param boolean $showAll If true returns all fields (includes disabled fields) * @param boolean $inline If true returns all inline fields (includes disabled fields) * @param int $customDataSubType Custom Data sub type value * @param int $customDataSubName Custom Data sub name value * @param boolean $onlyParent return only top level custom data, for eg, only Participant and ignore subname and subtype * * @return array $fields - an array of active custom fields. * * @access public * @static */ public static function &getFields($customDataType = 'Individual', $showAll = false, $inline = false, $customDataSubType = null, $customDataSubName = null, $onlyParent = false) { $onlySubType = false; if ($customDataType && !is_array($customDataType)) { if (in_array($customDataType, CRM_Contact_BAO_ContactType::subTypes())) { // This is the case when getFieldsForImport() requires fields // limited strictly to a subtype. $customDataSubType = $customDataType; $customDataType = CRM_Contact_BAO_ContactType::getBasicType($customDataType); $onlySubType = true; } if (in_array($customDataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) { // this makes the method flexible to support retrieving fields // for multiple extends value. $customDataType = array($customDataType); } } if (is_array($customDataType)) { $cacheKey = implode('_', $customDataType); } else { $cacheKey = $customDataType; } $cacheKey .= $customDataSubType ? "{$customDataSubType}_" : "_0"; $cacheKey .= $customDataSubName ? "{$customDataSubName}_" : "_0"; $cacheKey .= $showAll ? "_1" : "_0"; $cacheKey .= $inline ? "_1_" : "_0_"; $cacheKey .= $onlyParent ? "_1_" : "_0_"; $cacheKey .= $onlySubType ? "_1_" : "_0_"; $cgTable = CRM_Core_DAO_CustomGroup::getTableName(); // also get the permission stuff here require_once 'CRM/Core/Permission.php'; $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}."); // lets md5 permission clause and take first 8 characters $cacheKey .= substr(md5($permissionClause), 0, 8); if (strlen($cacheKey) > 40) { $cacheKey = md5($cacheKey); } if (!self::$_importFields || CRM_Utils_Array::value($cacheKey, self::$_importFields) === null) { if (!self::$_importFields) { self::$_importFields = array(); } // check if we can retrieve from database cache require_once 'CRM/Core/BAO/Cache.php'; $fields =& CRM_Core_BAO_Cache::getItem('contact fields', "custom importableFields {$cacheKey}"); if ($fields === null) { $cfTable = self::getTableName(); $extends = ''; if (is_array($customDataType)) { $value = null; foreach ($customDataType as $dataType) { if (in_array($dataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) { if (in_array($dataType, array('Individual', 'Household', 'Organization'))) { $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "', 'Contact' "; } else { $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "'"; } $value = $value ? $value . ", {$val}" : $val; } } if ($value) { $extends = "AND {$cgTable}.extends IN ( {$value} ) "; } } if ($onlyParent) { $extends .= " AND {$cgTable}.extends_entity_column_value IS NULL AND {$cgTable}.extends_entity_column_id IS NULL "; } $query = "SELECT {$cfTable}.id, {$cfTable}.label,\n {$cgTable}.title,\n {$cfTable}.data_type, {$cfTable}.html_type,\n {$cfTable}.options_per_line,\n {$cgTable}.extends, {$cfTable}.is_search_range,\n {$cgTable}.extends_entity_column_value,\n {$cgTable}.extends_entity_column_id,\n {$cfTable}.is_view,\n {$cfTable}.option_group_id,\n {$cfTable}.date_format,\n {$cfTable}.time_format,\n {$cgTable}.is_multiple\n FROM {$cfTable}\n INNER JOIN {$cgTable}\n ON {$cfTable}.custom_group_id = {$cgTable}.id\n WHERE ( 1 ) "; if (!$showAll) { $query .= " AND {$cfTable}.is_active = 1 AND {$cgTable}.is_active = 1 "; } if ($inline) { $query .= " AND {$cgTable}.style = 'Inline' "; } //get the custom fields for specific type in //combination with fields those support any type. if ($customDataSubType) { $customDataSubType = CRM_Core_DAO::VALUE_SEPARATOR . $customDataSubType . CRM_Core_DAO::VALUE_SEPARATOR; $query .= " AND ( {$cgTable}.extends_entity_column_value LIKE '%{$customDataSubType}%'"; if (!$onlySubType) { $query .= " OR {$cgTable}.extends_entity_column_value IS NULL"; } $query .= " )"; } if ($customDataSubName) { $query .= " AND ( {$cgTable}.extends_entity_column_id = {$customDataSubName} ) "; } // also get the permission stuff here require_once 'CRM/Core/Permission.php'; $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}.", true); $query .= " {$extends} AND {$permissionClause}\n ORDER BY {$cgTable}.weight, {$cgTable}.title,\n {$cfTable}.weight, {$cfTable}.label"; $dao =& CRM_Core_DAO::executeQuery($query); $fields = array(); while ($dao->fetch() != null) { $fields[$dao->id]['label'] = $dao->label; $fields[$dao->id]['groupTitle'] = $dao->title; $fields[$dao->id]['data_type'] = $dao->data_type; $fields[$dao->id]['html_type'] = $dao->html_type; $fields[$dao->id]['options_per_line'] = $dao->options_per_line; $fields[$dao->id]['extends'] = $dao->extends; $fields[$dao->id]['is_search_range'] = $dao->is_search_range; $fields[$dao->id]['extends_entity_column_value'] = $dao->extends_entity_column_value; $fields[$dao->id]['extends_entity_column_id'] = $dao->extends_entity_column_id; $fields[$dao->id]['is_view'] = $dao->is_view; $fields[$dao->id]['is_multiple'] = $dao->is_multiple; $fields[$dao->id]['option_group_id'] = $dao->option_group_id; $fields[$dao->id]['date_format'] = $dao->date_format; $fields[$dao->id]['time_format'] = $dao->time_format; } CRM_Core_BAO_Cache::setItem($fields, 'contact fields', "custom importableFields {$cacheKey}"); } self::$_importFields[$cacheKey] = $fields; } return self::$_importFields[$cacheKey]; }
/** * Combine all the exportable fields from the lower levels object. * * Currently we are using importable fields as exportable fields * * @param int|string $contactType contact Type * @param bool $status * True while exporting primary contacts. * @param bool $export * True when used during export. * @param bool $search * True when used during search, might conflict with export param?. * * @param bool $withMultiRecord * * @return array * array of exportable Fields */ public static function &exportableFields($contactType = 'Individual', $status = FALSE, $export = FALSE, $search = FALSE, $withMultiRecord = FALSE) { if (empty($contactType)) { $contactType = 'All'; } $cacheKeyString = "exportableFields {$contactType}"; $cacheKeyString .= $export ? '_1' : '_0'; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $search ? '_1' : '_0'; //CRM-14501 it turns out that the impact of permissioning here is sometimes inconsistent. The field that //calculates custom fields takes into account the logged in user & caches that for all users //as an interim fix we will cache the fields by contact $cacheKeyString .= '_' . CRM_Core_Session::getLoggedInContactID(); if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } // check if we can retrieve from database cache $fields = CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString); if (!$fields) { $fields = CRM_Contact_DAO_Contact::export(); // The fields are meant for contact types. if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } // add current employer for individuals $fields = array_merge($fields, array('current_employer' => array('name' => 'organization_name', 'title' => ts('Current Employer')))); $locationType = array('location_type' => array('name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => ts('Location Type'))); $IMProvider = array('im_provider' => array('name' => 'im_provider', 'where' => 'civicrm_im.provider_id', 'title' => ts('IM Provider'))); $locationFields = array_merge($locationType, CRM_Core_DAO_Address::export(), CRM_Core_DAO_Phone::export(), CRM_Core_DAO_Email::export(), $IMProvider, CRM_Core_DAO_IM::export(TRUE), CRM_Core_DAO_OpenID::export()); $locationFields = array_merge($locationFields, CRM_Core_BAO_CustomField::getFieldsForImport('Address')); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = TRUE; } $fields = array_merge($fields, $locationFields); //add world region $fields = array_merge($fields, CRM_Core_DAO_Worldregion::export()); $fields = array_merge($fields, CRM_Contact_DAO_Contact::export()); //website fields $fields = array_merge($fields, CRM_Core_DAO_Website::export()); if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status, FALSE, $search, TRUE, $withMultiRecord)); } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, FALSE, FALSE, $search, TRUE, $withMultiRecord)); } } //fix for CRM-791 if ($export) { $fields = array_merge($fields, array('groups' => array('title' => ts('Group(s)'), 'name' => 'groups'), 'tags' => array('title' => ts('Tag(s)'), 'name' => 'tags'), 'notes' => array('title' => ts('Note(s)'), 'name' => 'notes'))); } else { $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)'), 'name' => 'group'), 'tag' => array('title' => ts('Tag(s)'), 'name' => 'tag'), 'note' => array('title' => ts('Note(s)'), 'name' => 'note'))); } //Sorting fields in alphabetical order(CRM-1507) foreach ($fields as $k => $v) { $sortArray[$k] = CRM_Utils_Array::value('title', $v); } $fields = array_merge($sortArray, $fields); //unset the field which are not related to their contact type. if ($contactType != 'All') { $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom'), 'Household' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date', 'current_employer', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'prefix_id', 'suffix_id'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'household_name', 'email_greeting_custom', 'postal_greeting_custom', 'prefix_id', 'suffix_id', 'gender_id', 'addressee_custom', 'is_deceased', 'deceased_date', 'current_employer')); foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_exportableFields[$cacheKeyString] = $fields; } if (!$status) { $fields = self::$_exportableFields[$cacheKeyString]; } else { $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_exportableFields[$cacheKeyString]); } return $fields; }
/** * Store and return an array of all active custom fields. * * @param string $customDataType * Type of Custom Data; empty is a synonym for "all contact data types". * @param bool $showAll * If true returns all fields (includes disabled fields). * @param bool $inline * If true returns all inline fields (includes disabled fields). * @param int $customDataSubType * Custom Data sub type value. * @param int $customDataSubName * Custom Data sub name value. * @param bool $onlyParent * Return only top level custom data, for eg, only Participant and ignore subname and subtype. * @param bool $onlySubType * Return only custom data for subtype. * @param bool $checkPermission * If false, do not include permissioning clause. * * @return array * an array of active custom fields. * */ public static function &getFields($customDataType = 'Individual', $showAll = FALSE, $inline = FALSE, $customDataSubType = NULL, $customDataSubName = NULL, $onlyParent = FALSE, $onlySubType = FALSE, $checkPermission = TRUE) { if (empty($customDataType)) { $customDataType = array('Contact', 'Individual', 'Organization', 'Household'); } if ($customDataType && !is_array($customDataType)) { if (in_array($customDataType, CRM_Contact_BAO_ContactType::subTypes())) { // This is the case when getFieldsForImport() requires fields // limited strictly to a subtype. $customDataSubType = $customDataType; $customDataType = CRM_Contact_BAO_ContactType::getBasicType($customDataType); $onlySubType = TRUE; } if (in_array($customDataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) { // this makes the method flexible to support retrieving fields // for multiple extends value. $customDataType = array($customDataType); } } $customDataSubType = CRM_Utils_Array::explodePadded($customDataSubType); if (is_array($customDataType)) { $cacheKey = implode('_', $customDataType); } else { $cacheKey = $customDataType; } $cacheKey .= !empty($customDataSubType) ? '_' . implode('_', $customDataSubType) : '_0'; $cacheKey .= $customDataSubName ? "{$customDataSubName}_" : '_0'; $cacheKey .= $showAll ? '_1' : '_0'; $cacheKey .= $inline ? '_1_' : '_0_'; $cacheKey .= $onlyParent ? '_1_' : '_0_'; $cacheKey .= $onlySubType ? '_1_' : '_0_'; $cacheKey .= $checkPermission ? '_1_' : '_0_'; $cgTable = CRM_Core_DAO_CustomGroup::getTableName(); // also get the permission stuff here if ($checkPermission) { $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}."); } else { $permissionClause = '(1)'; } // lets md5 permission clause and take first 8 characters $cacheKey .= substr(md5($permissionClause), 0, 8); if (strlen($cacheKey) > 40) { $cacheKey = md5($cacheKey); } if (!self::$_importFields || CRM_Utils_Array::value($cacheKey, self::$_importFields) === NULL) { if (!self::$_importFields) { self::$_importFields = array(); } // check if we can retrieve from database cache $fields = CRM_Core_BAO_Cache::getItem('contact fields', "custom importableFields {$cacheKey}"); if ($fields === NULL) { $cfTable = self::getTableName(); $extends = ''; if (is_array($customDataType)) { $value = NULL; foreach ($customDataType as $dataType) { if (in_array($dataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) { if (in_array($dataType, array('Individual', 'Household', 'Organization'))) { $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "', 'Contact' "; } else { $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "'"; } $value = $value ? $value . ", {$val}" : $val; } } if ($value) { $extends = "AND {$cgTable}.extends IN ( {$value} ) "; } } if (!empty($customDataType) && empty($extends)) { // $customDataType specified a filter, but there is no corresponding SQL ($extends) self::$_importFields[$cacheKey] = array(); return self::$_importFields[$cacheKey]; } if ($onlyParent) { $extends .= " AND {$cgTable}.extends_entity_column_value IS NULL AND {$cgTable}.extends_entity_column_id IS NULL "; } $query = "SELECT {$cfTable}.id, {$cfTable}.label,\n {$cgTable}.title,\n {$cfTable}.data_type,\n {$cfTable}.html_type,\n {$cfTable}.default_value,\n {$cfTable}.options_per_line, {$cfTable}.text_length,\n {$cfTable}.custom_group_id,\n {$cfTable}.is_required,\n {$cgTable}.extends, {$cfTable}.is_search_range,\n {$cgTable}.extends_entity_column_value,\n {$cgTable}.extends_entity_column_id,\n {$cfTable}.is_view,\n {$cfTable}.option_group_id,\n {$cfTable}.date_format,\n {$cfTable}.time_format,\n {$cgTable}.is_multiple,\n og.name as option_group_name\n FROM {$cfTable}\n INNER JOIN {$cgTable}\n ON {$cfTable}.custom_group_id = {$cgTable}.id\n LEFT JOIN civicrm_option_group og\n ON {$cfTable}.option_group_id = og.id\n WHERE ( 1 ) "; if (!$showAll) { $query .= " AND {$cfTable}.is_active = 1 AND {$cgTable}.is_active = 1 "; } if ($inline) { $query .= " AND {$cgTable}.style = 'Inline' "; } //get the custom fields for specific type in //combination with fields those support any type. if (!empty($customDataSubType)) { $subtypeClause = array(); foreach ($customDataSubType as $subtype) { $subtype = CRM_Core_DAO::VALUE_SEPARATOR . $subtype . CRM_Core_DAO::VALUE_SEPARATOR; $subtypeClause[] = "{$cgTable}.extends_entity_column_value LIKE '%{$subtype}%'"; } if (!$onlySubType) { $subtypeClause[] = "{$cgTable}.extends_entity_column_value IS NULL"; } $query .= " AND ( " . implode(' OR ', $subtypeClause) . " )"; } if ($customDataSubName) { $query .= " AND ( {$cgTable}.extends_entity_column_id = {$customDataSubName} ) "; } // also get the permission stuff here if ($checkPermission) { $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}.", TRUE); } else { $permissionClause = '(1)'; } $query .= " {$extends} AND {$permissionClause}\n ORDER BY {$cgTable}.weight, {$cgTable}.title,\n {$cfTable}.weight, {$cfTable}.label"; $dao = CRM_Core_DAO::executeQuery($query); $fields = array(); while ($dao->fetch() != NULL) { $fields[$dao->id]['label'] = $dao->label; $fields[$dao->id]['groupTitle'] = $dao->title; $fields[$dao->id]['data_type'] = $dao->data_type; $fields[$dao->id]['html_type'] = $dao->html_type; $fields[$dao->id]['default_value'] = $dao->default_value; $fields[$dao->id]['text_length'] = $dao->text_length; $fields[$dao->id]['options_per_line'] = $dao->options_per_line; $fields[$dao->id]['custom_group_id'] = $dao->custom_group_id; $fields[$dao->id]['extends'] = $dao->extends; $fields[$dao->id]['is_search_range'] = $dao->is_search_range; $fields[$dao->id]['extends_entity_column_value'] = $dao->extends_entity_column_value; $fields[$dao->id]['extends_entity_column_id'] = $dao->extends_entity_column_id; $fields[$dao->id]['is_view'] = $dao->is_view; $fields[$dao->id]['is_multiple'] = $dao->is_multiple; $fields[$dao->id]['option_group_id'] = $dao->option_group_id; $fields[$dao->id]['date_format'] = $dao->date_format; $fields[$dao->id]['time_format'] = $dao->time_format; $fields[$dao->id]['is_required'] = $dao->is_required; self::getOptionsForField($fields[$dao->id], $dao->option_group_name); } CRM_Core_BAO_Cache::setItem($fields, 'contact fields', "custom importableFields {$cacheKey}"); } self::$_importFields[$cacheKey] = $fields; } return self::$_importFields[$cacheKey]; }
/** * Gets all the variables in the current session scope * and stuffs them in an associate array * * * @param array $vars * Associative array to store name/value pairs. * @param string $prefix * Will be stripped from the key before putting it in the return. * * @return void */ public function getVars(&$vars, $prefix = '') { // create session scope $this->createScope($prefix, TRUE); if (empty($prefix)) { $values =& $this->_session[$this->_key]; } else { $values = CRM_Core_BAO_Cache::getItem('CiviCRM Session', "CiviCRM_{$prefix}"); } if ($values) { foreach ($values as $name => $value) { $vars[$name] = $value; } } }
/** * Get all groups that are children of the parent group * (iterate through all levels) * * @param integer $groupID * @param boolean $includeParent * @return array:child groups */ function _multisite_get_all_child_groups($groupID, $includeParent = TRUE) { static $_cache = array(); if (!array_key_exists($groupID, $_cache)) { $childGroups =& CRM_Core_BAO_Cache::getItem('descendant groups for an org', $groupID); if (empty($childGroups)) { $childGroups = array(); $query = "\nSELECT children\nFROM civicrm_group\nWHERE children IS NOT NULL\nAND id IN "; if (!is_array($groupID)) { $groupIDs = array($groupID); } while (!empty($groupIDs)) { $groupIDString = implode(',', $groupIDs); $realQuery = $query . " ( {$groupIDString} )"; $dao = CRM_Core_DAO::executeQuery($realQuery); $groupIDs = array(); while ($dao->fetch()) { if ($dao->children) { $childIDs = explode(',', $dao->children); foreach ($childIDs as $childID) { if (!array_key_exists($childID, $childGroups)) { $childGroups[$childID] = 1; $groupIDs[] = $childID; } } } } } CRM_Core_BAO_Cache::setItem($childGroups, 'descendant groups for an org', $groupID); } $_cache[$groupID] = $childGroups; } if ($includeParent || CRM_Core_Permission::check('administer Multiple Organizations')) { return array_keys(array($groupID => 1) + $_cache[$groupID]); } else { return array_keys($_cache[$groupID]); } }
/** * @return string */ static function json() { $tree = CRM_Core_BAO_Cache::getItem('contact groups', 'nestable tree hierarchy'); if ($tree === NULL) { self::update(); $tree = CRM_Core_BAO_Cache::getItem('contact groups', 'nestable tree hierarchy'); } // get all the groups $groups = CRM_Core_PseudoConstant::group(); foreach ($groups as $id => $name) { $string = "id:'{$id}', name:'{$name}'"; if (isset($tree[$id])) { $children = array(); if (!empty($tree[$id]['children'])) { foreach ($tree[$id]['children'] as $child) { $children[] = "{_reference:'{$child}'}"; } $children = implode(',', $children); $string .= ", children:[{$children}]"; if (empty($tree[$id]['parents'])) { $string .= ", type:'rootGroup'"; } else { $string .= ", type:'middleGroup'"; } } else { $string .= ", type:'leafGroup'"; } } else { $string .= ", children:[], type:'rootGroup'"; } $values[] = "{ {$string} }"; } $items = implode(",\n", $values); $json = "{\n identifier:'id',\n label:'name',\n items:[ {$items} ]\n}"; return $json; }
/** * combine all the exportable fields from the lower levels object * * currentlty we are using importable fields as exportable fields * * @param int $contactType contact Type * $param boolean $status true while exporting primary contacts * $param boolean $export true when used during export * * @return array array of exportable Fields * @access public */ function &exportableFields($contactType = 'Individual', $status = false, $export = false) { if (empty($contactType)) { $contactType = 'All'; } $cacheKeyString = "exportableFields {$contactType}"; $cacheKeyString .= $export ? "_1" : "_0"; $cacheKeyString .= $status ? "_1" : "_0"; if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } // check if we can retrieve from database cache require_once 'CRM/Core/BAO/Cache.php'; $fields =& CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString); if (!$fields) { $fields = array(); $fields = array_merge($fields, CRM_Contact_DAO_Contact::export()); // the fields are meant for contact types if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { require_once 'CRM/Core/OptionValue.php'; $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } // add current employer for individuals $fields = array_merge($fields, array('current_employer' => array('name' => 'organization_name', 'title' => ts('Current Employer')))); $locationType = array(); if ($status) { $locationType['location_type'] = array('name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => ts('Location Type')); } $IMProvider = array(); if ($status) { $IMProvider['im_provider'] = array('name' => 'im_provider', 'where' => 'im_provider.name', 'title' => ts('IM Provider')); } $locationFields = array_merge($locationType, CRM_Core_DAO_Address::export(), CRM_Core_DAO_Phone::export(), CRM_Core_DAO_Email::export(), $IMProvider, CRM_Core_DAO_IM::export(true), CRM_Core_DAO_OpenID::export()); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = true; } $fields = array_merge($fields, $locationFields); //add world region require_once "CRM/Core/DAO/Worldregion.php"; $fields = array_merge($fields, CRM_Core_DAO_Worldregion::export()); $fields = array_merge($fields, CRM_Contact_DAO_Contact::export()); if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status, true)); } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type)); } } //fix for CRM-791 if ($export) { $fields = array_merge($fields, array('groups' => array('title' => ts('Group(s)')), 'tags' => array('title' => ts('Tag(s)')), 'notes' => array('title' => ts('Note(s)')))); } else { $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)')), 'tag' => array('title' => ts('Tag(s)')), 'note' => array('title' => ts('Note(s)')))); } //Sorting fields in alphabetical order(CRM-1507) foreach ($fields as $k => $v) { $sortArray[$k] = CRM_Utils_Array::value('title', $v); } $fields = array_merge($sortArray, $fields); //unset the field which are not related to their contact type. if ($contactType != 'All') { $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom'), 'Household' => array('first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date', 'current_employer', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'individual_prefix', 'individual_suffix', 'gender'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'job_title', 'gender_id', 'birth_date', 'household_name', 'email_greeting', 'postal_greeting', 'email_greeting_custom', 'postal_greeting_custom', 'individual_prefix', 'individual_suffix', 'gender', 'addressee_custom', 'is_deceased', 'deceased_date', 'current_employer')); foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_exportableFields[$cacheKeyString] = $fields; } if (!$status) { $fields = self::$_exportableFields[$cacheKeyString]; } else { $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_exportableFields[$cacheKeyString]); } return $fields; }
/** * Gets all the variables in the current session scope * and stuffs them in an associate array * * @access public * @param array vars : associative array to store name/value pairs * @param string Strip prefix from the key before putting it in the return * @return void * */ function getVars(&$vars, $prefix = '') { // create session scope $this->create(); $this->createScope($prefix); if (empty($prefix)) { $values =& $this->_session[$this->_key]; } else { require_once 'CRM/Core/BAO/Cache.php'; $values = CRM_Core_BAO_Cache::getItem('CiviCRM Session', "CiviCRM_{$prefix}"); } if ($values) { foreach ($values as $name => $value) { $vars[$name] = $value; } } }
/** * Function returns formatted groupTree, sothat form can be easily build in template * * @param array $groupTree * @param int $groupCount * Group count by default 1, but can varry for multiple value custom data. * @param object $form * * @return array */ public static function formatGroupTree(&$groupTree, $groupCount = 1, &$form = NULL) { $formattedGroupTree = array(); $uploadNames = $formValues = array(); // retrieve qf key from url $qfKey = CRM_Utils_Request::retrieve('qf', 'String'); // fetch submitted custom field values later use to set as a default values if ($qfKey) { $submittedValues = CRM_Core_BAO_Cache::getItem('custom data', $qfKey); } foreach ($groupTree as $key => $value) { if ($key === 'info') { continue; } // add group information $formattedGroupTree[$key]['name'] = CRM_Utils_Array::value('name', $value); $formattedGroupTree[$key]['title'] = CRM_Utils_Array::value('title', $value); $formattedGroupTree[$key]['help_pre'] = CRM_Utils_Array::value('help_pre', $value); $formattedGroupTree[$key]['help_post'] = CRM_Utils_Array::value('help_post', $value); $formattedGroupTree[$key]['collapse_display'] = CRM_Utils_Array::value('collapse_display', $value); $formattedGroupTree[$key]['collapse_adv_display'] = CRM_Utils_Array::value('collapse_adv_display', $value); $formattedGroupTree[$key]['style'] = CRM_Utils_Array::value('style', $value); // this params needed of bulding multiple values $formattedGroupTree[$key]['is_multiple'] = CRM_Utils_Array::value('is_multiple', $value); $formattedGroupTree[$key]['extends'] = CRM_Utils_Array::value('extends', $value); $formattedGroupTree[$key]['extends_entity_column_id'] = CRM_Utils_Array::value('extends_entity_column_id', $value); $formattedGroupTree[$key]['extends_entity_column_value'] = CRM_Utils_Array::value('extends_entity_column_value', $value); $formattedGroupTree[$key]['subtype'] = CRM_Utils_Array::value('subtype', $value); $formattedGroupTree[$key]['max_multiple'] = CRM_Utils_Array::value('max_multiple', $value); // add field information foreach ($value['fields'] as $k => $properties) { $properties['element_name'] = "custom_{$k}_-{$groupCount}"; if ($value = CRM_Utils_Request::retrieve($properties['element_name'], 'String', $form, FALSE, NULL, 'POST')) { $formValues[$properties['element_name']] = $value; } elseif (isset($submittedValues[$properties['element_name']])) { $properties['element_value'] = $submittedValues[$properties['element_name']]; } if (isset($properties['customValue']) && !CRM_Utils_System::isNull($properties['customValue']) && !isset($properties['element_value'])) { if (isset($properties['customValue'][$groupCount])) { $properties['element_name'] = "custom_{$k}_{$properties['customValue'][$groupCount]['id']}"; $formattedGroupTree[$key]['table_id'] = $properties['customValue'][$groupCount]['id']; if ($properties['data_type'] == 'File') { $properties['element_value'] = $properties['customValue'][$groupCount]; $uploadNames[] = $properties['element_name']; } else { $properties['element_value'] = $properties['customValue'][$groupCount]['data']; } } } unset($properties['customValue']); $formattedGroupTree[$key]['fields'][$k] = $properties; } } if ($form) { if (count($formValues)) { $qf = $form->get('qfKey'); $form->assign('qfKey', $qf); CRM_Core_BAO_Cache::setItem($formValues, 'custom data', $qf); } // hack for field type File $formUploadNames = $form->get('uploadNames'); if (is_array($formUploadNames)) { $uploadNames = array_unique(array_merge($formUploadNames, $uploadNames)); } $form->set('uploadNames', $uploadNames); } return $formattedGroupTree; }