/** * Run the page. * * This method is called after the page is created. */ public function run() { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $cgId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $customRecId = CRM_Utils_Request::retrieve('customRecId', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1, $_REQUEST); $cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', CRM_Core_DAO::$_nullObject, FALSE, 1, $_REQUEST); //custom groups Inline $entityType = CRM_Contact_BAO_Contact::getContactType($contactId); $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType); $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $contactId); //get the fields of single custom group record if ($customRecId == 1) { $fields = reset($details[$cgId]); } else { $fields = CRM_Utils_Array::value($customRecId, $details[$cgId]); } $this->assign('cgcount', $cgcount); $this->assign('customRecId', $customRecId); $this->assign('contactId', $contactId); $this->assign('customGroupId', $cgId); $this->assign_by_ref('cd_edit', $fields); // check logged in user permission CRM_Contact_Page_View::checkUserPermission($this, $contactId); // finally call parent parent::run(); }
/** * Call preprocess. */ public function preProcess() { parent::preProcess(); $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE, NULL, $_REQUEST); $this->assign('customGroupId', $this->_groupID); $customRecId = CRM_Utils_Request::retrieve('customRecId', 'Positive', $this, FALSE, 1, $_REQUEST); $cgcount = CRM_Utils_Request::retrieve('cgcount', 'Positive', $this, FALSE, 1, $_REQUEST); $subType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','); CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, $cgcount, $this->_contactType, $this->_contactId); }
/** * call preprocess */ public function preProcess() { //get all the existing email addresses $this->_contactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, TRUE, NULL, $_REQUEST); $this->assign('contactId', $this->_contactId); $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE, NULL, $_REQUEST); $this->assign('customGroupId', $this->_groupID); $type = CRM_Contact_BAO_Contact::getContactType($this->_contactId); $subType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ','); CRM_Custom_Form_CustomData::preProcess($this, null, $subType, 1, $type, $this->_contactId); }
static function relatedContactInfo($contactId) { $return = array(); if (empty($contactId)) { return $return; } $phone = CRM_Core_BAO_Phone::allPhones($contactId, TRUE, NULL, array('is_primary' => 1)); $contactSubType = CRM_Contact_BAO_Contact::getContactSubType($contactId); $contactType = CRM_Contact_BAO_ContactType::getLabel($contactSubType[0]); $gid = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'PCP_Supporter_Profile', 'id', 'name'); $updateURL = CRM_Utils_System::url('civicrm/profile/edit', "reset=1&gid={$gid}&cid={$contactId}"); // $updateURL =CRM_Utils_System::url('civicrm/pcp/support', "action=browse&component=event&id={$params['pcpId']}"); $return = array('name' => CRM_Contact_BAO_Contact::displayName($contactId), 'type' => $contactType, 'email' => CRM_Contact_BAO_Contact::getPrimaryEmail($contactId), 'phone' => !empty($phone) && isset($phone[1]['phone']) ? $phone[1]['phone'] : NULL, 'action' => "<a href={$updateURL}>Update Contact Information</a>"); return $return; }
/** * Run the page. * * This method is called after the page is created. * * @return void * @access public * */ function run() { // get the emails for this contact $contactId = CRM_Utils_Request::retrieve('cid', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); $cgId = CRM_Utils_Request::retrieve('groupID', 'Positive', CRM_Core_DAO::$_nullObject, TRUE, NULL, $_REQUEST); //custom groups Inline $entityType = CRM_Contact_BAO_Contact::getContactType($contactId); $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($contactId); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $contactId, $cgId, $entitySubType); $details = CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); $fields = array_pop($details[$cgId]); $this->assign('contactId', $contactId); $this->assign('customGroupId', $cgId); $this->assign_by_ref('cd_edit', $fields); // check logged in user permission CRM_Contact_Page_View::checkUserPermission($this, $contactId); // finally call parent parent::run(); }
/** * Create or update a Contact. * * @param array $params * Input parameters. * * @throws API_Exception * * @return array * API Result Array */ function civicrm_api3_contact_create($params) { $contactID = CRM_Utils_Array::value('contact_id', $params, CRM_Utils_Array::value('id', $params)); if ($contactID && !empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::EDIT)) { throw new \Civi\API\Exception\UnauthorizedException('Permission denied to modify contact record'); } $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE); $values = _civicrm_api3_contact_check_params($params, $dupeCheck); if ($values) { return $values; } if (!$contactID) { // If we get here, we're ready to create a new contact if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) { $defLocType = CRM_Core_BAO_LocationType::getDefault(); $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1)); } } if (!empty($params['home_url'])) { $websiteTypes = CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'); $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $params['home_url'])); } _civicrm_api3_greeting_format_params($params); $values = array(); if (empty($params['contact_type']) && $contactID) { $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($contactID); } if (!isset($params['contact_sub_type']) && $contactID) { $params['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($contactID); } _civicrm_api3_custom_format_params($params, $values, $params['contact_type'], $contactID); $params = array_merge($params, $values); //@todo we should just call basic_create here - but need to make contact:create accept 'id' on the bao $contact = _civicrm_api3_contact_update($params, $contactID); if (is_a($contact, 'CRM_Core_Error')) { throw new API_Exception($contact->_errors[0]['message']); } else { $values = array(); _civicrm_api3_object_to_array_unique_fields($contact, $values[$contact->id]); } return civicrm_api3_create_success($values, $params, 'Contact', 'create'); }
/** * Method processAction to execute the action * * @param CRM_Civirules_EventData_EventData $eventData * @access public * */ public function processAction(CRM_Civirules_EventData_EventData $eventData) { $contactId = $eventData->getContactId(); $subTypes = CRM_Contact_BAO_Contact::getContactSubType($contactId); $contactType = CRM_Contact_BAO_Contact::getContactType($contactId); $changed = false; $action_params = $this->getActionParameters(); foreach ($action_params['sub_type'] as $sub_type) { if (CRM_Contact_BAO_ContactType::isExtendsContactType($sub_type, $contactType)) { $subTypes[] = $sub_type; $changed = true; } } if ($changed) { $params['id'] = $contactId; $params['contact_id'] = $contactId; $params['contact_type'] = $contactType; $params['contact_sub_type'] = $subTypes; CRM_Contact_BAO_Contact::add($params); } }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @access public * * @param object $page - the view page which created this one * * @return none * @static * */ function run() { $this->preProcess(); //set the userContext stack $doneURL = 'civicrm/contact/view'; $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE); // get permission detail view or edit $permUser = CRM_Core_Permission::getPermission(); $editCustomData = CRM_Core_Permission::VIEW == $permUser ? 0 : 1; $this->assign('editCustomData', $editCustomData); //allow to edit own customdata CRM-5518 $editOwnCustomData = FALSE; if ($session->get('userID') == $this->_contactId) { $editOwnCustomData = TRUE; } $this->assign('editOwnCustomData', $editOwnCustomData); if ($this->_action == CRM_Core_Action::BROWSE) { //Custom Groups Inline $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, $this->_groupId, $entitySubType); CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree); } else { $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', ts('Custom Data'), $this->_action); $controller->setEmbedded(TRUE); $controller->set('tableId', $this->_contactId); $controller->set('groupId', $this->_groupId); $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId)); $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',')); $controller->process(); $controller->run(); } return parent::run(); }
/** * Pre processing work done here. * * Gets session variables for table name, id of entity in table, type of entity and stores them. */ public function preProcess() { $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', FALSE); $this->_multiRecordDisplay = CRM_Utils_Request::retrieve('multiRecordDisplay', 'String', $this); if ($this->_cdType || $this->_multiRecordDisplay == 'single') { if ($this->_cdType) { $this->assign('cdType', TRUE); } // NOTE : group id is not stored in session from within CRM_Custom_Form_CustomData::preProcess func // this is due to some condition inside it which restricts it from saving in session // so doing this for multi record edit action $entityId = CRM_Utils_Request::retrieve('entityID', 'Positive', $this); if (!empty($entityId)) { $subType = CRM_Contact_BAO_Contact::getContactSubType($entityId, ','); } CRM_Custom_Form_CustomData::preProcess($this, NULL, $subType, NULL, NULL, $entityId); if ($this->_multiRecordDisplay) { $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this); $this->_tableID = $this->_entityId; $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); $mode = CRM_Utils_Request::retrieve('mode', 'String', $this); $hasReachedMax = CRM_Core_BAO_CustomGroup::hasReachedMaxLimit($this->_groupID, $this->_tableID); if ($hasReachedMax && $mode == 'add') { CRM_Core_Error::statusBounce(ts('The maximum record limit is reached')); } $this->_copyValueId = CRM_Utils_Request::retrieve('copyValueId', 'Positive', $this); $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupID); $mode = CRM_Utils_Request::retrieve('mode', 'String', CRM_Core_DAO::$_nullObject, FALSE, NULL, 'GET'); $mode = ucfirst($mode); CRM_Utils_System::setTitle(ts('%1 %2 Record', array(1 => $mode, 2 => $groupTitle))); if (!empty($_POST['hidden_custom'])) { $this->assign('postedInfo', TRUE); } } return; } $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, TRUE); $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); $this->_contactSubType = CRM_Contact_BAO_Contact::getContactSubType($this->_tableID, ','); $this->assign('contact_type', $this->_contactType); $this->assign('contact_subtype', $this->_contactSubType); list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_tableID); CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { for ($i = 1; $i <= $_POST['hidden_custom_group_count'][$this->_groupID]; $i++) { CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_contactSubType, $i, $this->_contactType, $this->_tableID); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } } }
/** * Create or update a contact (note you should always call this via civicrm_api() & never directly) * * @param array $params input parameters * * Allowed @params array keys are: * {@getfields contact_create} * * * @example ContactCreate.php Example of Create Call * * @return array API Result Array * * @static void * @access public */ function civicrm_api3_contact_create($params) { $contactID = CRM_Utils_Array::value('contact_id', $params, CRM_Utils_Array::value('id', $params)); $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE); $values = _civicrm_api3_contact_check_params($params, $dupeCheck); if ($values) { return $values; } if (empty($contactID)) { // If we get here, we're ready to create a new contact if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) { require_once 'CRM/Core/BAO/LocationType.php'; $defLocType = CRM_Core_BAO_LocationType::getDefault(); $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1)); } } if (CRM_Utils_Array::value('home_url', $params)) { require_once 'CRM/Core/PseudoConstant.php'; $websiteTypes = CRM_Core_PseudoConstant::websiteType(); $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $params['home_url'])); } if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) { $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix()); } if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) { $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix()); } if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) { $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender()); } $error = _civicrm_api3_greeting_format_params($params); if (civicrm_error($error)) { return $error; } $values = array(); $entityId = $contactID; if (!CRM_Utils_Array::value('contact_type', $params) && $entityId) { $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($entityId); } if (!isset($params['contact_sub_type']) && $entityId) { require_once 'CRM/Contact/BAO/Contact.php'; $params['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($entityId); } _civicrm_api3_custom_format_params($params, $values, $params['contact_type'], $entityId); $params = array_merge($params, $values); $contact = _civicrm_api3_contact_update($params, $contactID); if (is_a($contact, 'CRM_Core_Error')) { return civicrm_api3_create_error($contact->_errors[0]['message']); } else { $values = array(); _civicrm_api3_object_to_array_unique_fields($contact, $values[$contact->id]); } return civicrm_api3_create_success($values, $params, 'Contact', 'create'); }
/** * @todo Write sth * @todo Serious FIXMES in the code! File issues. */ function civicrm_contact_update(&$params, $create_new = FALSE) { _civicrm_initialize(); try { civicrm_api_check_permission(__FUNCTION__, $params, TRUE); } catch (Exception $e) { return civicrm_create_error($e->getMessage()); } require_once 'CRM/Utils/Array.php'; $entityId = CRM_Utils_Array::value('contact_id', $params, NULL); if (!CRM_Utils_Array::value('contact_type', $params) && $entityId) { $params['contact_type'] = CRM_Contact_BAO_Contact::getContactType($entityId); } $dupeCheck = CRM_Utils_Array::value('dupe_check', $params, FALSE); $values = civicrm_contact_check_params($params, $dupeCheck); if ($values) { return $values; } if ($create_new) { // Make sure nothing is screwed up before we create a new contact if (!empty($entityId)) { return civicrm_create_error('Cannot create new contact when contact_id is present'); } if (empty($params['contact_type'])) { return civicrm_create_error('Contact Type not specified'); } // If we get here, we're ready to create a new contact if (($email = CRM_Utils_Array::value('email', $params)) && !is_array($params['email'])) { require_once 'CRM/Core/BAO/LocationType.php'; $defLocType = CRM_Core_BAO_LocationType::getDefault(); $params['email'] = array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => $defLocType->id ? $defLocType->id : 1)); } } if ($homeUrl = CRM_Utils_Array::value('home_url', $params)) { require_once 'CRM/Core/PseudoConstant.php'; $websiteTypes = CRM_Core_PseudoConstant::websiteType(); $params['website'] = array(1 => array('website_type_id' => key($websiteTypes), 'url' => $homeUrl)); } // FIXME: Some legacy support cruft, should get rid of this in 3.1 $change = array('individual_prefix' => 'prefix', 'prefix' => 'prefix_id', 'individual_suffix' => 'suffix', 'suffix' => 'suffix_id', 'gender' => 'gender_id'); foreach ($change as $field => $changeAs) { if (array_key_exists($field, $params)) { $params[$changeAs] = $params[$field]; unset($params[$field]); } } // End legacy support cruft if (isset($params['suffix_id']) && !is_numeric($params['suffix_id'])) { $params['suffix_id'] = array_search($params['suffix_id'], CRM_Core_PseudoConstant::individualSuffix()); } if (isset($params['prefix_id']) && !is_numeric($params['prefix_id'])) { $params['prefix_id'] = array_search($params['prefix_id'], CRM_Core_PseudoConstant::individualPrefix()); } if (isset($params['gender_id']) && !is_numeric($params['gender_id'])) { $params['gender_id'] = array_search($params['gender_id'], CRM_Core_PseudoConstant::gender()); } $error = _civicrm_greeting_format_params($params); if (civicrm_error($error)) { return $error; } $values = array(); if (!($csType = CRM_Utils_Array::value('contact_sub_type', $params)) && $entityId) { require_once 'CRM/Contact/BAO/Contact.php'; $csType = CRM_Contact_BAO_Contact::getContactSubType($entityId); } $customValue = civicrm_contact_check_custom_params($params, $csType); if ($customValue) { return $customValue; } _civicrm_custom_format_params($params, $values, $params['contact_type'], $entityId); $params = array_merge($params, $values); $contact =& _civicrm_contact_update($params, $entityId); if (is_a($contact, 'CRM_Core_Error')) { return civicrm_create_error($contact->_errors[0]['message']); } else { $values = array(); $values['contact_id'] = $contact->id; $values['is_error'] = 0; } return $values; }
/** * Add the whereAdd clause for the DAO depending on the type of entity * the custom group is extending. * * @param object CRM_Core_DAO_CustomGroup (reference) - Custom Group DAO. * @param string $entityType - what entity are we extending here ? * * @return void * * @access private * @static * */ private static function _addWhereAdd(&$customGroupDAO, $entityType, $entityID = null) { $addSubtypeClause = false; switch ($entityType) { case 'Contact': // if contact, get all related to contact $extendList = "'Contact','Individual','Household','Organization'"; $customGroupDAO->whereAdd("extends IN ( {$extendList} )"); $addSubtypeClause = true; break; case 'Individual': case 'Household': case 'Organization': // is I/H/O then get I/H/O and contact $extendList = "'Contact','{$entityType}'"; $customGroupDAO->whereAdd("extends IN ( {$extendList} )"); $addSubtypeClause = true; break; case 'Location': case 'Address': $customGroupDAO->whereAdd("extends IN ('{$entityType}')"); break; } if ($addSubtypeClause) { require_once 'CRM/Contact/BAO/Contact.php'; $csType = is_numeric($entityID) ? CRM_Contact_BAO_Contact::getContactSubType($entityID) : false; if ($csType) { $csType = CRM_Core_DAO::VALUE_SEPARATOR . $csType . CRM_Core_DAO::VALUE_SEPARATOR; $customGroupDAO->whereAdd("( extends_entity_column_value LIKE '%{$csType}%' OR extends_entity_column_value IS NULL )"); } else { $customGroupDAO->whereAdd("extends_entity_column_value IS NULL"); } } }
/** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * * @return void */ public function run() { $this->preProcess(); //set the userContext stack $doneURL = 'civicrm/contact/view'; $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url($doneURL, 'action=browse&selectedChild=custom_' . $this->_groupId), FALSE); // get permission detail view or edit // use a comtact id specific function which gives us much better granularity // CRM-12646 $editCustomData = CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT); $this->assign('editCustomData', $editCustomData); //allow to edit own customdata CRM-5518 $editOwnCustomData = FALSE; if ($session->get('userID') == $this->_contactId) { $editOwnCustomData = TRUE; } $this->assign('editOwnCustomData', $editOwnCustomData); if ($this->_action == CRM_Core_Action::BROWSE) { //Custom Groups Inline $entityType = CRM_Contact_BAO_Contact::getContactType($this->_contactId); $entitySubType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); $groupTree =& CRM_Core_BAO_CustomGroup::getTree($entityType, $this, $this->_contactId, $this->_groupId, $entitySubType); $displayStyle = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->_groupId, 'style'); if ($this->_multiRecordDisplay != 'single') { $id = "custom_{$this->_groupId}"; $this->ajaxResponse['tabCount'] = CRM_Contact_BAO_Contact::getCountComponent($id, $this->_contactId, $groupTree[$this->_groupId]['table_name']); } if ($displayStyle === 'Tab with table' && $this->_multiRecordDisplay != 'single') { $ctype = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'contact_type'); $this->assign('displayStyle', 'tableOriented'); // here the multi custom data listing code will go $multiRecordFieldListing = TRUE; $page = new CRM_Profile_Page_MultipleRecordFieldsListing(); $page->set('contactId', $this->_contactId); $page->set('customGroupId', $this->_groupId); $page->set('action', CRM_Core_Action::BROWSE); $page->set('multiRecordFieldListing', $multiRecordFieldListing); $page->set('pageViewType', 'customDataView'); $page->set('contactType', $ctype); $page->run(); } else { $recId = NULL; if ($this->_multiRecordDisplay == 'single') { $groupTitle = CRM_Core_BAO_CustomGroup::getTitle($this->_groupId); CRM_Utils_System::setTitle(ts('View %1 Record', array(1 => $groupTitle))); $recId = $this->_recId; $this->assign('multiRecordDisplay', $this->_multiRecordDisplay); $this->assign('skipTitle', 1); } CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, $recId); } } else { $controller = new CRM_Core_Controller_Simple('CRM_Contact_Form_CustomData', ts('Custom Data'), $this->_action); $controller->setEmbedded(TRUE); $controller->set('tableId', $this->_contactId); $controller->set('groupId', $this->_groupId); $controller->set('entityType', CRM_Contact_BAO_Contact::getContactType($this->_contactId)); $controller->set('entitySubType', CRM_Contact_BAO_Contact::getContactSubType($this->_contactId, ',')); $controller->process(); $controller->run(); } return parent::run(); }
/** * pre processing work done here. * * gets session variables for table name, id of entity in table, type of entity and stores them. * * @param * @return void * * @access public * */ function preProcess() { $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', false); if ($this->_cdType) { $this->assign('cdType', true); return CRM_Custom_Form_CustomData::preProcess($this); } $this->_groupID = CRM_Utils_Request::retrieve('groupId', 'Positive', $this, true); $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, true); require_once "CRM/Contact/BAO/Contact.php"; $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); $this->_contactSubType = CRM_Contact_BAO_Contact::getContactSubType($this->_tableID); $this->assign('contact_type', $this->_contactType); $this->assign('contact_subtype', $this->_contactSubType); list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_tableID); CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); // when custom data is included in this page if (CRM_Utils_Array::value("hidden_custom", $_POST)) { for ($i; $i <= $_POST['hidden_custom_group_count'][$this->_groupID]; $i++) { CRM_Custom_Form_CustomData::preProcess($this, null, null, $i); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } } }
/** * Add the whereAdd clause for the DAO depending on the type of entity * the custom group is extending. * * @param object $customGroupDAO * @param string $entityType * What entity are we extending here ?. * * @param int $entityID * @param bool $allSubtypes */ private static function _addWhereAdd(&$customGroupDAO, $entityType, $entityID = NULL, $allSubtypes = FALSE) { $addSubtypeClause = FALSE; switch ($entityType) { case 'Contact': // if contact, get all related to contact $extendList = "'Contact','Individual','Household','Organization'"; $customGroupDAO->whereAdd("extends IN ( {$extendList} )"); if (!$allSubtypes) { $addSubtypeClause = TRUE; } break; case 'Individual': case 'Household': case 'Organization': // is I/H/O then get I/H/O and contact $extendList = "'Contact','{$entityType}'"; $customGroupDAO->whereAdd("extends IN ( {$extendList} )"); if (!$allSubtypes) { $addSubtypeClause = TRUE; } break; case 'Case': case 'Location': case 'Address': case 'Activity': case 'Contribution': case 'Membership': case 'Participant': $customGroupDAO->whereAdd("extends IN ('{$entityType}')"); break; } if ($addSubtypeClause) { $csType = is_numeric($entityID) ? CRM_Contact_BAO_Contact::getContactSubType($entityID) : FALSE; if (!empty($csType)) { $subtypeClause = array(); foreach ($csType as $subtype) { $subtype = CRM_Core_DAO::VALUE_SEPARATOR . $subtype . CRM_Core_DAO::VALUE_SEPARATOR; $subtypeClause[] = "extends_entity_column_value LIKE '%{$subtype}%'"; } $subtypeClause[] = "extends_entity_column_value IS NULL"; $customGroupDAO->whereAdd("( " . implode(' OR ', $subtypeClause) . " )"); } else { $customGroupDAO->whereAdd("extends_entity_column_value IS NULL"); } } }
/** * pre processing work done here. * * gets session variables for table name, id of entity in table, type of entity and stores them. * * @param * * @return void * * @access public * */ function preProcess() { $this->_cdType = CRM_Utils_Array::value('type', $_GET); $this->assign('cdType', FALSE); if ($this->_cdType) { $this->assign('cdType', TRUE); return CRM_Custom_Form_CustomData::preProcess($this); } $this->_groupID = CRM_Utils_Request::retrieve('groupID', 'Positive', $this, TRUE); $this->_tableID = CRM_Utils_Request::retrieve('tableId', 'Positive', $this, TRUE); $this->_contactType = CRM_Contact_BAO_Contact::getContactType($this->_tableID); $this->_contactSubType = CRM_Contact_BAO_Contact::getContactSubType($this->_tableID, ','); $this->assign('contact_type', $this->_contactType); $this->assign('contact_subtype', $this->_contactSubType); list($displayName, $contactImage) = CRM_Contact_BAO_Contact::getDisplayAndImage($this->_tableID); CRM_Utils_System::setTitle($displayName, $contactImage . ' ' . $displayName); // when custom data is included in this page if (!empty($_POST['hidden_custom'])) { for ($i = 0; $i <= $_POST['hidden_custom_group_count'][$this->_groupID]; $i++) { CRM_Custom_Form_CustomData::preProcess($this, NULL, NULL, $i); CRM_Custom_Form_CustomData::buildQuickForm($this); CRM_Custom_Form_CustomData::setDefaultValues($this); } } }
/** * Function to check if the relationship type selected between two contacts is correct * * @param int $contact_a 1st contact id * @param int $contact_b 2nd contact id * @param int $relationshipTypeId relationship type id * * @return boolean true if it is valid relationship else false * @access public * @static */ static function checkRelationshipType($contact_a, $contact_b, $relationshipTypeId) { $relationshipType =& new CRM_Contact_DAO_RelationshipType(); $relationshipType->id = $relationshipTypeId; $relationshipType->selectAdd(); $relationshipType->selectAdd('contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b'); if ($relationshipType->find(true)) { require_once 'CRM/Contact/BAO/Contact.php'; $contact_type_a = CRM_Contact_BAO_Contact::getContactType($contact_a); $contact_type_b = CRM_Contact_BAO_Contact::getContactType($contact_b); $contact_sub_type_a = CRM_Contact_BAO_Contact::getContactSubType($contact_a); $contact_sub_type_b = CRM_Contact_BAO_Contact::getContactSubType($contact_b); if ((!$relationshipType->contact_type_a || $relationshipType->contact_type_a == $contact_type_a) && (!$relationshipType->contact_type_b || $relationshipType->contact_type_b == $contact_type_b) && (!$relationshipType->contact_sub_type_a || $relationshipType->contact_sub_type_a == $contact_sub_type_a) && (!$relationshipType->contact_sub_type_b || $relationshipType->contact_sub_type_b == $contact_sub_type_b)) { return true; } else { return false; } } return false; }
function getTemplateFileName() { if ($this->_contactId) { $csType = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); if ($csType) { $templateFile = "CRM/Contact/Page/View/{$csType}.tpl"; $template =& CRM_Core_Page::getTemplate(); if ($template->template_exists($templateFile)) { return $templateFile; } } } return parent::getTemplateFileName(); }
/** * test case for getContactSubType( ) * */ function testgetContactSubType() { //get the contact params $params = $this->contactParams(); $params['contact_sub_type'] = 'Individual'; //create contact require_once 'CRM/Contact/BAO/Contact.php'; $contact = CRM_Contact_BAO_Contact::create($params); $contactId = $contact->id; //get contact sub type. $contactType = CRM_Contact_BAO_Contact::getContactSubType($contactId); $this->assertEquals($contactType, $params['contact_sub_type'], 'Check For Contact Sub Type'); //cleanup DB by deleting the contact Contact::delete($contactId); }
/** * Check if the relationship type selected between two contacts is correct. * * @param int $contact_a * 1st contact id. * @param int $contact_b * 2nd contact id. * @param int $relationshipTypeId * Relationship type id. * * @return bool * true if it is valid relationship else false */ public static function checkRelationshipType($contact_a, $contact_b, $relationshipTypeId) { $relationshipType = new CRM_Contact_DAO_RelationshipType(); $relationshipType->id = $relationshipTypeId; $relationshipType->selectAdd(); $relationshipType->selectAdd('contact_type_a, contact_type_b, contact_sub_type_a, contact_sub_type_b'); if ($relationshipType->find(TRUE)) { $contact_type_a = CRM_Contact_BAO_Contact::getContactType($contact_a); $contact_type_b = CRM_Contact_BAO_Contact::getContactType($contact_b); $contact_sub_type_a = CRM_Contact_BAO_Contact::getContactSubType($contact_a); $contact_sub_type_b = CRM_Contact_BAO_Contact::getContactSubType($contact_b); if ((!$relationshipType->contact_type_a || $relationshipType->contact_type_a == $contact_type_a) && (!$relationshipType->contact_type_b || $relationshipType->contact_type_b == $contact_type_b) && (!$relationshipType->contact_sub_type_a || in_array($relationshipType->contact_sub_type_a, $contact_sub_type_a)) && (!$relationshipType->contact_sub_type_b || in_array($relationshipType->contact_sub_type_b, $contact_sub_type_b))) { return TRUE; } else { return FALSE; } } return FALSE; }
/** * Process the form when submitted. * * @return void */ public function postProcess() { $params = $this->exportValues(); $params['entity_id'] = $this->_id; $params['entity_table'] = CRM_Core_BAO_Domain::getTableName(); $domain = CRM_Core_BAO_Domain::edit($params, $this->_id); $defaultLocationType = CRM_Core_BAO_LocationType::getDefault(); if (isset($this->_locationDefaults['address'][1]['location_type_id'])) { $params['address'][1]['location_type_id'] = $this->_locationDefaults['address'][1]['location_type_id']; } else { $params['address'][1]['location_type_id'] = $defaultLocationType->id; } if (isset($this->_locationDefaults['phone'][1]['location_type_id'])) { $params['phone'][1]['location_type_id'] = $this->_locationDefaults['phone'][1]['location_type_id']; } else { $params['phone'][1]['location_type_id'] = $defaultLocationType->id; } if (isset($this->_locationDefaults['email'][1]['location_type_id'])) { $params['email'][1]['location_type_id'] = $this->_locationDefaults['email'][1]['location_type_id']; } else { $params['email'][1]['location_type_id'] = $defaultLocationType->id; } $params += array('contact_id' => $this->_contactId); $contactParams = array('sort_name' => $domain->name, 'display_name' => $domain->name, 'legal_name' => $domain->name, 'organization_name' => $domain->name, 'contact_id' => $this->_contactId, 'contact_type' => 'Organization'); if ($this->_contactId) { $contactParams['contact_sub_type'] = CRM_Contact_BAO_Contact::getContactSubType($this->_contactId); } CRM_Contact_BAO_Contact::add($contactParams); CRM_Core_BAO_Location::create($params, TRUE); CRM_Core_BAO_Domain::edit($params, $this->_id); //set domain from email address, CRM-3552 $emailName = '"' . $params['email_name'] . '" <' . $params['email_address'] . '>'; $emailParams = array('label' => $emailName, 'description' => $params['description'], 'is_active' => 1, 'is_default' => 1); $groupParams = array('name' => 'from_email_address'); //get the option value wt. if ($this->_fromEmailId) { $action = $this->_action; $emailParams['weight'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $this->_fromEmailId, 'weight'); } else { //add from email address. $action = CRM_Core_Action::ADD; $grpId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'from_email_address', 'id', 'name'); $fieldValues = array('option_group_id' => $grpId); $emailParams['weight'] = CRM_Utils_Weight::getDefaultWeight('CRM_Core_DAO_OptionValue', $fieldValues); } //reset default within domain. $emailParams['reset_default_for'] = array('domain_id' => CRM_Core_Config::domainID()); CRM_Core_OptionValue::addOptionValue($emailParams, $groupParams, $action, $this->_fromEmailId); CRM_Core_Session::setStatus(ts("Domain information for '%1' has been saved.", array(1 => $domain->name)), ts('Saved'), 'success'); $session = CRM_Core_Session::singleton(); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1')); }