<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
END";
/**
- * the types of communication preferences
+ * The types of communication preferences
*
* @var array
*/
static $_commPrefs = array('do_not_phone', 'do_not_email', 'do_not_mail', 'do_not_sms', 'do_not_trade');
/**
- * types of greetings
+ * Types of greetings
*
* @var array
*/
static $_greetingTypes = array('addressee', 'email_greeting', 'postal_greeting');
/**
- * static field for all the contact information that we can potentially import
+ * Static field for all the contact information that we can potentially import
*
* @var array
* @static
static $_importableFields = array();
/**
- * static field for all the contact information that we can potentially export
+ * Static field for all the contact information that we can potentially export
*
* @var array
* @static
static $_exportableFields = NULL;
/**
- * class constructor
+ * Class constructor
*
- * @access public
* @return \CRM_Contact_DAO_Contact
*/
/**
*
*/
- function __construct() {
+ public function __construct() {
parent::__construct();
}
/**
- * takes an associative array and creates a contact object
+ * Takes an associative array and creates a contact object
*
* the function extract all the params it needs to initialize the create a
* contact object. the params array could contain additional unused name/value
*
* @param array $params (reference ) an assoc array of name/value pairs
*
- * @return object CRM_Contact_BAO_Contact object
- * @access public
+ * @return CRM_Contact_BAO_Contact object
* @static
*/
- static function add(&$params) {
+ public static function add(&$params) {
$contact = new CRM_Contact_DAO_Contact();
if (empty($params)) {
}
/**
- * Function to create contact
+ * Create contact
* takes an associative array and creates a contact object and all the associated
* derived objects (i.e. individual, location, email, phone etc)
*
* @param bool $skipDelete
*
* @throws Exception
- * @return object CRM_Contact_BAO_Contact object
- * @access public
+ * @return CRM_Contact_BAO_Contact object
* @static
*/
- static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE, $skipDelete = FALSE) {
+ public static function &create(&$params, $fixAddress = TRUE, $invokeHooks = TRUE, $skipDelete = FALSE) {
$contact = NULL;
if (empty($params['contact_type']) && empty($params['contact_id'])) {
return $contact;
* @param bool $type
*
* @return array the displayName and contactImage for this contact
- * @access public
* @static
*/
- static function getDisplayAndImage($id, $type = FALSE) {
+ public static function getDisplayAndImage($id, $type = FALSE) {
//CRM-14276 added the * on the civicrm_contact table so that we have all the contact info available
$sql = "
SELECT civicrm_contact.*,
}
/**
- *
* Get the values for pseudoconstants for name->value and reverse.
*
* @param array $defaults (reference) the default values, some of which need to be resolved.
* @param boolean $reverse true if we want to resolve the values in the reverse direction (value -> name)
*
* @return void
- * @access public
* @static
*/
- static function resolveDefaults(&$defaults, $reverse = FALSE) {
+ public static function resolveDefaults(&$defaults, $reverse = FALSE) {
// hack for birth_date
if (!empty($defaults['birth_date'])) {
if (is_array($defaults['birth_date'])) {
}
/**
- * Takes a bunch of params that are needed to match certain criteria and
- * retrieves the relevant objects. Typically the valid params are only
- * contact_id. We'll tweak this function to be more full featured over a period
- * of time. This is the inverse function of create. It also stores all the retrieved
- * values in the default array
+ * Fetch object based on array of properties
*
* @param array $params (reference ) an assoc array of name/value pairs
* @param array $defaults (reference ) an assoc array to hold the name / value pairs
* in a hierarchical manner
* @param boolean $microformat for location in microformat
*
- * @return object CRM_Contact_BAO_Contact object
- * @access public
+ * @return CRM_Contact_BAO_Contact object
* @static
*/
- static function &retrieve(&$params, &$defaults, $microformat = FALSE) {
+ public static function &retrieve(&$params, &$defaults, $microformat = FALSE) {
if (array_key_exists('contact_id', $params)) {
$params['id'] = $params['contact_id'];
}
}
/**
- * function to get the display name of a contact
+ * Get the display name of a contact
*
* @param int $id id of the contact
*
* @return null|string display name of the contact if found
* @static
- * @access public
*/
- static function displayName($id) {
+ public static function displayName($id) {
$displayName = NULL;
if ($id) {
$displayName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $id, 'display_name');
* @param bool $skipUndelete whether to force contact delete or not
*
* @return boolean true if contact deleted, false otherwise
- * @access public
* @static
*/
- static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE) {
+ public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE) {
if (!$id) {
return FALSE;
//delete the contact id from recently view
CRM_Utils_Recent::delContact($id);
- // reset the group contact cache for this group
- CRM_Contact_BAO_GroupContactCache::remove();
+ // Update the group contact cache
+ if ($restore) {
+ CRM_Contact_BAO_GroupContactCache::remove();
+ }
+ else {
+ CRM_Contact_BAO_GroupContactCache::removeContact($id);
+ }
// delete any dupe cache entry
CRM_Core_BAO_PrevNextCache::deleteItem($id);
}
/**
- * function to delete the image of a contact
+ * Delete the image of a contact
*
* @param int $id id of the contact
*
}
/**
- * function to return relative path
+ * Return relative path
* @todo make this a method of $config->userSystem (i.e. UF classes) rather than a static function
*
- * @param $absolutePath
- *
- * @internal param String $absPath absolute path
+ * @param string $absolutePath absolute path
*
* @return String $relativePath Relative url of uploaded image
*/
}
/**
- * function to return proportional height and width of the image
+ * Return proportional height and width of the image
*
* @param Integer $imageWidth width of image
*
}
/**
- * function to validate type of contact image
+ * Validate type of contact image
*
- * @param $params
+ * @param array $params
* @param String $imageIndex index of image field
- *
* @param String $statusMsg status message to be set after operation
- *
- * @param string $opType
- *
- * @internal param Array $param array of contact/profile field to be edited/added
- *
- * @opType String $opType type of operation like fatal, bounce etc
+ * @param string $opType type of operation like fatal, bounce etc
*
* @return boolean true if valid image extension
*/
}
/**
- * function to extract contact id from url for deleting contact image
+ * Extract contact id from url for deleting contact image
*/
public static function processImage() {
* @return void
* @static
*/
- static function contactTrashRestore($contact, $restore = FALSE) {
+ public static function contactTrashRestore($contact, $restore = FALSE) {
$op = ($restore ? 'restore' : 'trash');
CRM_Utils_Hook::pre($op, $contact->contact_type, $contact->id, CRM_Core_DAO::$_nullArray);
*
* @return string contact_type if $id found else null ""
*
- * @access public
*
* @static
*
*
* @return string contact_sub_type if $id found else null ""
*
- * @access public
*
* @static
*/
*
* @return array
*
- * @access public
*
* @static
*
}
/**
- * combine all the importable fields from the lower levels object
+ * Combine all the importable fields from the lower levels object
*
* The ordering is important, since currently we do not have a weight
* scheme. Adding weight is super important
* @param bool $withMultiCustomFields
*
* @return array array of importable Fields
- * @access public
* @static
*/
static function importableFields($contactType = 'Individual',
'title' => ts('Note(s)'),
'name' => 'note',
),
+ 'communication_style_id' => array(
+ 'title' => ts('Communication Style'),
+ 'name' => 'communication_style_id',
+ ),
));
}
}
/**
- * combine all the exportable fields from the lower levels object
+ * Combine all the exportable fields from the lower levels object
*
* currentlty we are using importable fields as exportable fields
*
* @param bool $withMultiRecord
*
* @return array array of exportable Fields
- * @access public
* @static
*/
- static function &exportableFields($contactType = 'Individual', $status = FALSE, $export = FALSE, $search = FALSE, $withMultiRecord = FALSE) {
+ public static function &exportableFields($contactType = 'Individual', $status = FALSE, $export = FALSE, $search = FALSE, $withMultiRecord = FALSE) {
if (empty($contactType)) {
$contactType = 'All';
}
if ($contactType != 'All') {
$fields = array_merge($fields,
- CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status, TRUE, $search, TRUE, $withMultiRecord)
+ CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status, FALSE, $search, TRUE, $withMultiRecord)
);
}
else {
}
/**
- * Function to get the all contact details(Hierarchical)
+ * Get the all contact details(Hierarchical)
*
* @param int $contactId contact id
* @param array $fields fields array
*
* @return $values array contains the contact details
* @static
- * @access public
*/
- static function getHierContactDetails($contactId, &$fields) {
+ public static function getHierContactDetails($contactId, &$fields) {
$params = array(array('contact_id', '=', $contactId, 0, 0));
$options = array();
}
/**
- * given a set of flat profile style field names, create a hierarchy
+ * Given a set of flat profile style field names, create a hierarchy
* for query to use and crete the right sql
*
* @param $fields
* @param int $contactId contact id
*
- * @internal param array $properties a flat return properties name value array
* @return array a hierarchical property tree if appropriate
- * @access public
* @static
*/
- static function &makeHierReturnProperties($fields, $contactId = NULL) {
+ public static function &makeHierReturnProperties($fields, $contactId = NULL) {
$locationTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id');
$returnProperties = array();
}
/**
- * Function to return the primary location type of a contact
+ * Return the primary location type of a contact
*
* $params int $contactId contact_id
* $params boolean $isPrimaryExist if true, return primary contact location type otherwise null
* $params boolean $skipDefaultPriamry if true, return primary contact location type otherwise null
*
- * @param $contactId
+ * @param int $contactId
* @param bool $skipDefaultPriamry
* @param null $block
*
* @return int $locationType location_type_id
- * @access public
* @static
*/
- static function getPrimaryLocationType($contactId, $skipDefaultPriamry = FALSE, $block = NULL) {
+ public static function getPrimaryLocationType($contactId, $skipDefaultPriamry = FALSE, $block = NULL) {
if($block){
$entityBlock = array('contact_id' => $contactId);
$blocks = CRM_Core_BAO_Location::getValues($entityBlock);
}
/**
- * function to get the display name, primary email and location type of a contact
+ * Get the display name, primary email and location type of a contact
*
* @param int $id id of the contact
*
* @return array of display_name, email if found, do_not_email or (null,null,null)
* @static
- * @access public
*/
- static function getContactDetails($id) {
+ public static function getContactDetails($id) {
// check if the contact type
$contactType = self::getContactType($id);
}
/**
- * function to add/edit/register contacts through profile.
- *
- * @params array $params Array of profile fields to be edited/added.
- * @params int $contactID contact_id of the contact to be edited/added.
- * @params array $fields array of fields from UFGroup
- * @params int $addToGroupID specifies the default group to which contact is added.
- * @params int $ufGroupId uf group id (profile id)
- * @param $params
- * @param $fields
- * @param null $contactID
- * @param null $addToGroupID
- * @param null $ufGroupId
- * @param string $ctype contact type
- * @param boolean $visibility basically lets us know where this request is coming from
+ * Add/edit/register contacts through profile.
+ *
+ * @param array $params Array of profile fields to be edited/added.
+ * @param array $fields Array of fields from UFGroup
+ * @param int $contactID id of the contact to be edited/added.
+ * @param int $addToGroupID specifies the default group to which contact is added.
+ * @param int $ufGroupId uf group id (profile id)
+ * @param ctype
+ * @param boolean $visibility basically lets us know where this request is coming from
* if via a profile from web, we restrict what groups are changed
*
- * @return int contact id created/edited
+ * @return int contact id created/edited
* @static
- * @access public
*/
static function createProfileContact(
&$params,
}
/**
- * @param $params
+ * @param array $params
* @param $fields
- * @param null $contactID
- * @param null $ufGroupId
+ * @param int $contactID
+ * @param int $ufGroupId
* @param null $ctype
* @param bool $skipCustom
*
}
/**
- * Function to find the get contact details
+ * Find the get contact details
* does not respect ACLs for now, which might need to be rectified at some
* stage based on how its used
*
* @return object $dao contact details
* @static
*/
- static function &matchContactOnEmail($mail, $ctype = NULL) {
+ public static function &matchContactOnEmail($mail, $ctype = NULL) {
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$mail = $strtolower(trim($mail));
$query = "
}
/**
- * Function to find the contact details associated with an OpenID
+ * Find the contact details associated with an OpenID
*
* @param string $openId openId of the contact
* @param string $ctype contact type
* @return object $dao contact details
* @static
*/
- static function &matchContactOnOpenId($openId, $ctype = NULL) {
+ public static function &matchContactOnOpenId($openId, $ctype = NULL) {
$strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower';
$openId = $strtolower(trim($openId));
$query = "
*
* @return string $dao->email email address if present else null
* @static
- * @access public
*/
public static function getPrimaryEmail($contactID) {
// fetch the primary email
*
* @return string $dao->openid OpenID if present else null
* @static
- * @access public
*/
public static function getPrimaryOpenId($contactID) {
// fetch the primary OpenID
* @param array $values output values of the object
*
* @return CRM_Contact_BAO_Contact|null the found object or null
- * @access public
* @static
*/
public static function getValues(&$params, &$values) {
* @param string $tableName optional tableName if component is custom group
*
* @return total number of count of occurence in database
- * @access public
* @static
*/
- static function getCountComponent($component, $contactId, $tableName = NULL) {
+ public static function getCountComponent($component, $contactId, $tableName = NULL) {
$object = NULL;
switch ($component) {
case 'tag':
}
/**
- * Function to process greetings and cache
+ * Process greetings and cache
*
* @param object $contact contact object after save
* @param boolean $useDefaults use default greeting values
*
* @return void
- * @access public
* @static
*/
- static function processGreetings(&$contact, $useDefaults = FALSE) {
+ public static function processGreetings(&$contact, $useDefaults = FALSE) {
if ($useDefaults) {
//retrieve default greetings
$defaultGreetings = CRM_Core_PseudoConstant::greetingDefaults();
}
/**
- * Function to retrieve loc block ids w/ given condition.
+ * Retrieve loc block ids w/ given condition.
*
* @param int $contactId contact id.
* @param array $criteria key => value pair which should be
* @return array $locBlockIds loc block ids which fulfill condition.
* @static
*/
- static function getLocBlockIds($contactId, $criteria = array(), $condOperator = 'AND') {
+ public static function getLocBlockIds($contactId, $criteria = array(), $condOperator = 'AND') {
$locBlockIds = array();
if (!$contactId) {
return $locBlockIds;
}
/**
- * Function to build context menu items.
+ * Build context menu items.
*
- * @param null $contactId
+ * @param int $contactId
*
* @return array of context menu for logged in user.
* @static
*/
- static function contextMenu($contactId = NULL) {
+ public static function contextMenu($contactId = NULL) {
$menu = array(
'view' => array(
'title' => ts('View Contact'),
}
/**
- * Function to retrieve display name of contact that address is shared
+ * Retrieve display name of contact that address is shared
* based on $masterAddressId or $contactId .
*
* @param int $masterAddressId master id.
* @param int $contactId contact id.
*
* @return display name |null the found display name or null.
- * @access public
* @static
*/
- static function getMasterDisplayName($masterAddressId = NULL, $contactId = NULL) {
+ public static function getMasterDisplayName($masterAddressId = NULL, $contactId = NULL) {
$masterDisplayName = NULL;
$sql = NULL;
if (!$masterAddressId && !$contactId) {
/**
* Get the creation/modification times for a contact
*
- * @param $contactId
+ * @param int $contactId
*
* @return array('created_date' => $, 'modified_date' => $)
*/
- static function getTimestamps($contactId) {
+ public static function getTimestamps($contactId) {
$timestamps = CRM_Core_DAO::executeQuery(
'SELECT created_date, modified_date
FROM civicrm_contact
}
}
+ /**
+ * Generate triggers to update the timestamp on the corresponding civicrm_contact row,
+ * on insert/update/delete to a table that extends civicrm_contact.
+ * Don't regenerate triggers for all such tables if only asked for one table.
+ *
+ * @param array $info
+ * Reference to the array where generated trigger information is being stored
+ * @param string|null $reqTableName
+ * Name of the table for which triggers are being generated, or NULL if all tables
+ * @param array $relatedTableNames
+ * Array of all core or all custom table names extending civicrm_contact
+ * @param string $contactRefColumn
+ * 'contact_id' if processing core tables, 'entity_id' if processing custom tables
+ * @return void
+ *
+ * @link https://issues.civicrm.org/jira/browse/CRM-15602
+ * @see triggerInfo
+ * @static
+ */
+ public static function generateTimestampTriggers(&$info, $reqTableName, $relatedTableNames, $contactRefColumn) {
+ // Safety
+ $contactRefColumn = CRM_Core_DAO::escapeString($contactRefColumn);
+ // If specific related table requested, just process that one
+ if (in_array($reqTableName, $relatedTableNames)) {
+ $relatedTableNames = array($reqTableName);
+ }
+
+ // If no specific table requested (include all related tables),
+ // or a specific related table requested (as matched above)
+ if (empty($reqTableName) || in_array($reqTableName, $relatedTableNames)) {
+ $info[] = array(
+ 'table' => $relatedTableNames,
+ 'when' => 'AFTER',
+ 'event' => array('INSERT', 'UPDATE'),
+ 'sql' => "\nUPDATE civicrm_contact SET modified_date = CURRENT_TIMESTAMP WHERE id = NEW.$contactRefColumn;\n",
+ );
+ $info[] = array(
+ 'table' => $relatedTableNames,
+ 'when' => 'AFTER',
+ 'event' => array('DELETE'),
+ 'sql' => "\nUPDATE civicrm_contact SET modified_date = CURRENT_TIMESTAMP WHERE id = OLD.$contactRefColumn;\n",
+ );
+ }
+ }
+
/**
* Get a list of triggers for the contact table
*
* @see CRM_Core_DAO::triggerRebuild
* @see http://issues.civicrm.org/jira/browse/CRM-10554
*/
- static function triggerInfo(&$info, $tableName = NULL) {
+ public static function triggerInfo(&$info, $tableName = NULL) {
//during upgrade, first check for valid version and then create triggers
//i.e the columns created_date and modified_date are introduced in 4.3.alpha1 so dont create triggers for older version
if (CRM_Core_Config::isUpgradeMode()) {
}
}
+ // Update timestamp for civicrm_contact itself
if ($tableName == NULL || $tableName == self::getTableName()) {
$info[] = array(
'table' => array(self::getTableName()),
'civicrm_phone',
'civicrm_website',
);
- $info[] = array(
- 'table' => $relatedTables,
- 'when' => 'AFTER',
- 'event' => array('INSERT', 'UPDATE'),
- 'sql' => "\nUPDATE civicrm_contact SET modified_date = CURRENT_TIMESTAMP WHERE id = NEW.contact_id;\n",
- );
- $info[] = array(
- 'table' => $relatedTables,
- 'when' => 'AFTER',
- 'event' => array('DELETE'),
- 'sql' => "\nUPDATE civicrm_contact SET modified_date = CURRENT_TIMESTAMP WHERE id = OLD.contact_id;\n",
- );
+ self::generateTimestampTriggers($info, $tableName, $relatedTables, 'contact_id');
// Update timestamp when modifying related custom-data tables
$customGroupTables = array();
$customGroupTables[] = $customGroupDAO->table_name;
}
if (!empty($customGroupTables)) {
- $info[] = array(
- 'table' => $customGroupTables,
- 'when' => 'AFTER',
- 'event' => array('INSERT', 'UPDATE'),
- 'sql' => "\nUPDATE civicrm_contact SET modified_date = CURRENT_TIMESTAMP WHERE id = NEW.entity_id;\n",
- );
- $info[] = array(
- 'table' => $customGroupTables,
- 'when' => 'AFTER',
- 'event' => array('DELETE'),
- 'sql' => "\nUPDATE civicrm_contact SET modified_date = CURRENT_TIMESTAMP WHERE id = OLD.entity_id;\n",
- );
+ self::generateTimestampTriggers($info, $tableName, $customGroupTables, 'entity_id');
}
// Update phone table to populate phone_numeric field
}
/**
- * Function to check if contact is being used in civicrm_domain
+ * Check if contact is being used in civicrm_domain
* based on $contactId
*
* @param int $contactId contact id.
*
* @return bool true if present else false.
- * @access public
* @static
*/
- static function checkDomainContact($contactId) {
+ public static function checkDomainContact($contactId) {
if (!$contactId)
return FALSE;
$domainId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Domain', $contactId, 'id', 'contact_id');
$params['condition'] = "parent_id = (SELECT id FROM civicrm_contact_type WHERE name='{$props['contact_type']}')";
}
break;
+ case 'contact_type':
+ if ($context == 'search') {
+ // CRM-15495 - EntityRef filters and basic search forms expect this format
+ // FIXME: Search builder does not
+ return CRM_Contact_BAO_ContactType::getSelectElements();
+ }
+ break;
}
return CRM_Core_PseudoConstant::get(__CLASS__, $fieldName, $params, $context);
}