Esempio n. 1
0
 static function importableFields($contactType = 'HRJobContractRevision', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE)
 {
     if (empty($contactType)) {
         $contactType = 'HRJobContractRevision';
     }
     $cacheKeyString = "";
     $cacheKeyString .= $status ? '_1' : '_0';
     $cacheKeyString .= $showAll ? '_1' : '_0';
     $cacheKeyString .= $isProfile ? '_1' : '_0';
     $cacheKeyString .= $checkPermission ? '_1' : '_0';
     $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields);
     if (!$fields) {
         $fields = CRM_Hrjobcontract_DAO_HRJobContractRevision::import();
         $fields = array_merge($fields, CRM_Hrjobcontract_DAO_HRJobContractRevision::import());
         //Sorting fields in alphabetical order(CRM-1507)
         $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title');
         $fields = CRM_Utils_Array::index(array('name'), $fields);
         CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString);
     }
     self::$_importableFields[$cacheKeyString] = $fields;
     if (!$isProfile) {
         $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]);
     }
     return $fields;
 }
Esempio n. 2
0
 /**
  * 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 int     $contactType     contact Type
  * @param boolean $status          status is used to manipulate first title
  * @param boolean $showAll         if true returns all fields (includes disabled fields)
  * @param boolean $isProfile       if its profile mode
  * @param boolean $checkPermission if false, do not include permissioning clause (for custom data)
  *
  * @return array array of importable Fields
  * @access public
  * @static
  */
 static function importableFields($contactType = 'HRJobLeave', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE)
 {
     if (empty($contactType)) {
         $contactType = 'HRJobLeave';
     }
     $cacheKeyString = "";
     $cacheKeyString .= $status ? '_1' : '_0';
     $cacheKeyString .= $showAll ? '_1' : '_0';
     $cacheKeyString .= $isProfile ? '_1' : '_0';
     $cacheKeyString .= $checkPermission ? '_1' : '_0';
     $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields);
     if (!$fields) {
         $fields = CRM_HRJob_DAO_HRJobLeave::import();
         $fields = array_merge($fields, CRM_HRJOB_DAO_HRJOBLEAVE::import());
         foreach ($fields as $key => $v) {
             $fields[$key]['hasLocationType'] = TRUE;
         }
         //Sorting fields in alphabetical order
         $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title');
         $fields = CRM_Utils_Array::index(array('name'), $fields);
         CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString);
     }
     self::$_importableFields[$cacheKeyString] = $fields;
     if (!$isProfile) {
         $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]);
     }
     return $fields;
 }
 /**
  * @param int $version
  *   API version.
  * @param string $entity
  *   API entity.
  * @param array $fields
  *   List of fields in this fake entity.
  * @param array $perms
  *   Array(string $action => string $perm).
  * @param array $records
  *   List of mock records to be read/updated by API calls.
  */
 public function __construct($version, $entity, $fields, $perms = array(), $records = array())
 {
     parent::__construct($version, $entity);
     $perms = array_merge(array('create' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, 'get' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION, 'delete' => \CRM_Core_Permission::ALWAYS_ALLOW_PERMISSION), $perms);
     $this->records = \CRM_Utils_Array::index(array('id'), $records);
     $this->fields = $fields;
     $this->addAction('create', $perms['create'], array($this, 'doCreate'));
     $this->addAction('get', $perms['get'], array($this, 'doGet'));
     $this->addAction('delete', $perms['delete'], array($this, 'doDelete'));
 }
Esempio n. 4
0
 function testIndexArray()
 {
     $inputs = array();
     $inputs[] = array('lang' => 'en', 'msgid' => 'greeting', 'familiar' => FALSE, 'value' => 'Hello');
     $inputs[] = array('lang' => 'en', 'msgid' => 'parting', 'value' => 'Goodbye');
     $inputs[] = array('lang' => 'fr', 'msgid' => 'greeting', 'value' => 'Bon jour');
     $inputs[] = array('lang' => 'fr', 'msgid' => 'parting', 'value' => 'Au revoir');
     $inputs[] = array('lang' => 'en', 'msgid' => 'greeting', 'familiar' => TRUE, 'value' => 'Hey');
     $byLangMsgid = CRM_Utils_Array::index(array('lang', 'msgid'), $inputs);
     $this->assertEquals($inputs[4], $byLangMsgid['en']['greeting']);
     $this->assertEquals($inputs[1], $byLangMsgid['en']['parting']);
     $this->assertEquals($inputs[2], $byLangMsgid['fr']['greeting']);
     $this->assertEquals($inputs[3], $byLangMsgid['fr']['parting']);
 }
Esempio n. 5
0
 /**
  * View details of a relationship.
  */
 public function view()
 {
     $viewRelationship = CRM_Contact_BAO_Relationship::getRelationship($this->_contactId, NULL, NULL, NULL, $this->_id);
     //To check whether selected contact is a contact_id_a in
     //relationship type 'a_b' in relationship table, if yes then
     //revert the permissionship text in template
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->id = $viewRelationship[$this->_id]['id'];
     if ($relationship->find(TRUE)) {
         if ($viewRelationship[$this->_id]['rtype'] == 'a_b' && $this->_contactId == $relationship->contact_id_a) {
             $this->assign("is_contact_id_a", TRUE);
         }
     }
     $relType = $viewRelationship[$this->_id]['civicrm_relationship_type_id'];
     $this->assign('viewRelationship', $viewRelationship);
     $employerId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_contactId, 'employer_id');
     $this->assign('isCurrentEmployer', FALSE);
     $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
     if ($viewRelationship[$this->_id]['employer_id'] == $this->_contactId) {
         $this->assign('isCurrentEmployer', TRUE);
     } elseif ($relType == $relTypes['Employee of']['id'] && $viewRelationship[$this->_id]['cid'] == $employerId) {
         // make sure we are viewing employee of relationship
         $this->assign('isCurrentEmployer', TRUE);
     }
     $viewNote = CRM_Core_BAO_Note::getNote($this->_id);
     $this->assign('viewNote', $viewNote);
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Relationship', $this, $this->_id, 0, $relType);
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $this->_id);
     $rType = CRM_Utils_Array::value('rtype', $viewRelationship[$this->_id]);
     // add viewed contribution to recent items list
     $url = CRM_Utils_System::url('civicrm/contact/view/rel', "action=view&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&context=home");
     $session = CRM_Core_Session::singleton();
     $recentOther = array();
     if ($session->get('userID') == $this->_contactId || CRM_Contact_BAO_Contact_Permission::allow($this->_contactId, CRM_Core_Permission::EDIT)) {
         $recentOther = array('editUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', "action=update&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"), 'deleteUrl' => CRM_Utils_System::url('civicrm/contact/view/rel', "action=delete&reset=1&id={$viewRelationship[$this->_id]['id']}&cid={$this->_contactId}&rtype={$rType}&context=home"));
     }
     $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
     $this->assign('displayName', $displayName);
     CRM_Utils_System::setTitle(ts('View Relationship for') . ' ' . $displayName);
     $title = $displayName . ' (' . $viewRelationship[$this->_id]['relation'] . ' ' . CRM_Contact_BAO_Contact::displayName($viewRelationship[$this->_id]['cid']) . ')';
     // add the recently viewed Relationship
     CRM_Utils_Recent::add($title, $url, $viewRelationship[$this->_id]['id'], 'Relationship', $this->_contactId, NULL, $recentOther);
 }
Esempio n. 6
0
 /**
  * Create / updating field
  */
 public function testReplaceUFFields()
 {
     $baseFields = array();
     $baseFields[] = array('field_name' => 'first_name', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', 'weight' => 3, 'label' => 'Test First Name', 'is_searchable' => 1, 'is_active' => 1);
     $baseFields[] = array('field_name' => 'country', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', 'weight' => 2, 'label' => 'Test Country', 'is_searchable' => 1, 'is_active' => 1, 'location_type_id' => 1);
     $baseFields[] = array('field_name' => 'phone', 'field_type' => 'Contact', 'visibility' => 'Public Pages and Listings', 'weight' => 1, 'label' => 'Test Phone', 'is_searchable' => 1, 'is_active' => 1, 'location_type_id' => 1, 'phone_type_id' => 1);
     $params = array('uf_group_id' => $this->_ufGroupId, 'option.autoweight' => FALSE, 'values' => $baseFields, 'check_permissions' => TRUE);
     $result = $this->callAPIAndDocument('uf_field', 'replace', $params, __FUNCTION__, __FILE__);
     $inputsByName = CRM_Utils_Array::index(array('field_name'), $params['values']);
     $this->assertEquals(count($params['values']), count($result['values']));
     foreach ($result['values'] as $outUfField) {
         $this->assertTrue(is_string($outUfField['field_name']));
         $inUfField = $inputsByName[$outUfField['field_name']];
         foreach ($inUfField as $key => $inValue) {
             $this->assertEquals($inValue, $outUfField[$key], sprintf("field_name=[%s] key=[%s] expected=[%s] actual=[%s]", $outUfField['field_name'], $key, $inValue, $outUfField[$key]));
         }
     }
 }
Esempio n. 7
0
 /**
  * Class constructor
  */
 public function __construct()
 {
     // initialize all the vars
     $this->numIndividual = self::INDIVIDUAL_PERCENT * self::NUM_CONTACT / 100;
     $this->numHousehold = self::HOUSEHOLD_PERCENT * self::NUM_CONTACT / 100;
     $this->numOrganization = self::ORGANIZATION_PERCENT * self::NUM_CONTACT / 100;
     $this->numStrictIndividual = $this->numIndividual - $this->numHousehold * self::NUM_INDIVIDUAL_PER_HOUSEHOLD;
     // Parse data file
     foreach ((array) simplexml_load_file(self::DATA_FILENAME) as $key => $val) {
         $val = (array) $val;
         $this->sampleData[$key] = (array) $val['item'];
     }
     // Init DB
     $config = CRM_Core_Config::singleton();
     // Relationship types indexed by name_a_b from the table civicrm_relationship_type
     $this->relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
 }
Esempio n. 8
0
 /**
  * Delete current employer relationship.
  *
  * @param int $id
  * @param int $action
  *
  * @return CRM_Contact_DAO_Relationship
  */
 public static function clearCurrentEmployer($id, $action)
 {
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->id = $id;
     $relationship->find(TRUE);
     //to delete relationship between household and individual                                                                                          \
     //or between individual and organization
     if ($action & CRM_Core_Action::DISABLE || $action & CRM_Core_Action::DELETE) {
         $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
         if (isset($relTypes['Employee of']) && $relationship->relationship_type_id == $relTypes['Employee of']['id'] || isset($relTypes['Household Member of']) && $relationship->relationship_type_id == $relTypes['Household Member of']['id']) {
             $sharedContact = new CRM_Contact_DAO_Contact();
             $sharedContact->id = $relationship->contact_id_a;
             $sharedContact->find(TRUE);
             // CRM-15881 UPDATES
             // changed FROM "...relationship->relationship_type_id == 4..." TO "...relationship->relationship_type_id == 5..."
             // As the system should be looking for type "employer of" (id 5) and not "sibling of" (id 4)
             // As suggested by @davecivicrm, the employee relationship type id is fetched using the CRM_Core_DAO::getFieldValue() class and method, since these ids differ from system to system.
             $employerRelTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', 'Employee of', 'id', 'name_a_b');
             if ($relationship->relationship_type_id == $employerRelTypeId && $relationship->contact_id_b == $sharedContact->employer_id) {
                 CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a);
             }
         }
     }
     return $relationship;
 }
Esempio n. 9
0
 /**
  * Get a list of all activities in the case (indexed by some property/properties)
  *
  * @param array $keys list of properties by which to index activities
  * @return array list of activity records (api/v3 format), indexed by $keys
  */
 public function getActivityIndex($keys)
 {
     $key = implode(";", $keys);
     if (!$this->indices) {
         $this->indices = CRM_Utils_Array::index(array('activity_type_id', 'status_id'), $this->getActivities());
     }
     return $this->indices;
 }
 /**
  * For any records in $toTable that originated with this query,
  * append file information.
  *
  * @param string $toTable
  * @param string $parentIdColumn
  * @param array $files see return format of CRM_Core_FileSearchInterface::search
  */
 public function moveFileIDs($toTable, $parentIdColumn, $files)
 {
     if (empty($files)) {
         return;
     }
     $filesIndex = CRM_Utils_Array::index(array('xparent_id', 'file_id'), $files);
     // ex: $filesIndex[$xparent_id][$file_id] = array(...the file record...);
     $dao = CRM_Core_DAO::executeQuery("\n      SELECT distinct {$parentIdColumn}\n      FROM {$toTable}\n      WHERE table_name = %1\n    ", array(1 => array($this->getName(), 'String')));
     while ($dao->fetch()) {
         if (empty($filesIndex[$dao->{$parentIdColumn}])) {
             continue;
         }
         CRM_Core_DAO::executeQuery("UPDATE {$toTable}\n        SET file_ids = %1\n        WHERE table_name = %2 AND {$parentIdColumn} = %3\n      ", array(1 => array(implode(',', array_keys($filesIndex[$dao->{$parentIdColumn}])), 'String'), 2 => array($this->getName(), 'String'), 3 => array($dao->{$parentIdColumn}, 'Int')));
     }
 }
Esempio n. 11
0
 /**
  * Setup default dashlets for new users.
  *
  * When a user accesses their dashboard for the first time, set up
  * the default dashlets.
  *
  * @param bool $flatFormat
  *
  * @return array
  *    Array of dashboard_id's
  * @throws \CiviCRM_API3_Exception
  */
 public static function initializeDashlets($flatFormat = FALSE)
 {
     $dashlets = array();
     $getDashlets = civicrm_api3("Dashboard", "get", array('domain_id' => CRM_Core_Config::domainID(), 'option.limit' => 0));
     $contactID = CRM_Core_Session::singleton()->getLoggedInContactID();
     $allDashlets = CRM_Utils_Array::index(array('name'), $getDashlets['values']);
     $defaultDashlets = array();
     $defaults = array('blog' => 1, 'getting-started' => '0');
     foreach ($defaults as $name => $column) {
         if (!empty($allDashlets[$name])) {
             $defaultDashlets[$name] = array('dashboard_id' => $allDashlets[$name]['id'], 'is_active' => 1, 'column_no' => $column, 'contact_id' => $contactID);
         }
     }
     CRM_Utils_Hook::dashboard_defaults($allDashlets, $defaultDashlets);
     if (is_array($defaultDashlets) && !empty($defaultDashlets)) {
         foreach ($defaultDashlets as $id => $defaultDashlet) {
             $dashboard_id = $defaultDashlet['dashboard_id'];
             if (!self::checkPermission($getDashlets['values'][$dashboard_id]['permission'], CRM_Utils_Array::value('permission_operator', $getDashlets['values'][$dashboard_id]))) {
                 continue;
             } else {
                 $assignDashlets = civicrm_api3("dashboard_contact", "create", $defaultDashlet);
                 if (!$flatFormat) {
                     $values = $assignDashlets['values'][$assignDashlets['id']];
                     $dashlets[$values['column_no']][$values['weight'] - $values['dashboard_id']] = $values['is_minimized'];
                 } else {
                     $dashlets[$dashboard_id] = $defaultDashlet['dashboard_id'];
                 }
             }
         }
     }
     return $dashlets;
 }
Esempio n. 12
0
 /**
  * Get a list of all activities in the case (indexed by some property/properties)
  *
  * @param array $keys
  *   List of properties by which to index activities.
  * @return array
  *   list of activity records (api/v3 format), indexed by $keys
  */
 public function getActivityIndex($keys)
 {
     $key = implode(";", $keys);
     if (!isset($this->indices[$key])) {
         $this->indices[$key] = \CRM_Utils_Array::index($keys, $this->getActivities());
     }
     return $this->indices[$key];
 }
 /**
  * @param int $id
  *   e.g. file ID.
  * @return array
  *   (0 => bool $isValid, 1 => string $entityTable, 2 => int $entityId)
  * @throws \Exception
  */
 public function getDelegate($id)
 {
     $query = \CRM_Core_DAO::executeQuery($this->lookupDelegateSql, array(1 => array($id, 'Positive')));
     if ($query->fetch()) {
         if (!preg_match('/^civicrm_value_/', $query->entity_table)) {
             // A normal attachment directly on its entity.
             return array($query->is_valid, $query->entity_table, $query->entity_id);
         }
         // Ex: Translate custom-field table ("civicrm_value_foo_4") to
         // entity table ("civicrm_activity").
         $tblIdx = \CRM_Utils_Array::index(array('table_name'), $this->getCustomFields());
         if (isset($tblIdx[$query->entity_table])) {
             return array($query->is_valid, $tblIdx[$query->entity_table]['entity_table'], $query->entity_id);
         }
         throw new \Exception('Failed to lookup entity table for custom field.');
     } else {
         return array(FALSE, NULL, NULL);
     }
 }
Esempio n. 14
0
 /**
  * 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 int     $contactType     contact Type
  * @param boolean $status          status is used to manipulate first title
  * @param boolean $showAll         if true returns all fields (includes disabled fields)
  * @param boolean $isProfile       if its profile mode
  * @param boolean $checkPermission if false, do not include permissioning clause (for custom data)
  *
  * @return array array of importable Fields
  * @access public
  * @static
  */
 static function importableFields($contactType = 'Individual', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE)
 {
     $cacheKeyString = "";
     $cacheKeyString .= $status ? '_1' : '_0';
     $cacheKeyString .= $showAll ? '_1' : '_0';
     $cacheKeyString .= $isProfile ? '_1' : '_0';
     $cacheKeyString .= $checkPermission ? '_1' : '_0';
     $contactType = 'Individual';
     $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields);
     if (!$fields) {
         $fields = CRM_Appraisals_DAO_AppraisalCycle::import();
         $tmpContactField = $contactFields = array();
         $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL);
         // Using new Dedupe rule.
         $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised');
         $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams);
         if (is_array($fieldsArray)) {
             foreach ($fieldsArray as $value) {
                 $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name');
                 $value = $customFieldId ? 'custom_' . $customFieldId : $value;
                 $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields);
                 if (!$status) {
                     $title = $tmpContactField[trim($value)]['title'] . ' (match to contact)';
                 } else {
                     $title = $tmpContactField[trim($value)]['title'];
                 }
                 $tmpContactField[trim($value)]['title'] = $title;
             }
         }
         $extIdentifier = CRM_Utils_Array::value('external_identifier', $contactFields);
         if ($extIdentifier) {
             $tmpContactField['external_identifier'] = $extIdentifier;
             $tmpContactField['external_identifier']['title'] = CRM_Utils_Array::value('title', $extIdentifier) . ' (match to contact)';
         }
         $fields = array_merge($fields, $tmpContactField);
         //Sorting fields in alphabetical order(CRM-1507)
         $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title');
         $fields = CRM_Utils_Array::index(array('name'), $fields);
         CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString);
     }
     self::$_importableFields[$cacheKeyString] = $fields;
     if (!$isProfile) {
         $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]);
     }
     return $fields;
 }
Esempio n. 15
0
 /**
  * Test get ref api - gets a list of references to an entity.
  */
 public function testGetReferenceCounts()
 {
     $result = $this->callAPISuccess('Contact', 'create', array('first_name' => 'Testily', 'last_name' => 'McHaste', 'contact_type' => 'Individual', 'api.Address.replace' => array('values' => array()), 'api.Email.replace' => array('values' => array(array('email' => '*****@*****.**', 'is_primary' => 0, 'location_type_id' => 1))), 'api.Phone.replace' => array('values' => array(array('phone' => '234-567-0001', 'is_primary' => 1, 'location_type_id' => 1), array('phone' => '234-567-0002', 'is_primary' => 0, 'location_type_id' => 1)))));
     //$dao = new CRM_Contact_BAO_Contact();
     //$dao->id = $result['id'];
     //$this->assertTrue((bool) $dao->find(TRUE));
     //
     //$refCounts = $dao->getReferenceCounts();
     //$this->assertTrue(is_array($refCounts));
     //$refCountsIdx = CRM_Utils_Array::index(array('name'), $refCounts);
     $refCounts = $this->callAPISuccess('Contact', 'getrefcount', array('id' => $result['id']));
     $refCountsIdx = CRM_Utils_Array::index(array('name'), $refCounts['values']);
     $this->assertEquals(1, $refCountsIdx['sql:civicrm_email:contact_id']['count']);
     $this->assertEquals('civicrm_email', $refCountsIdx['sql:civicrm_email:contact_id']['table']);
     $this->assertEquals(2, $refCountsIdx['sql:civicrm_phone:contact_id']['count']);
     $this->assertEquals('civicrm_phone', $refCountsIdx['sql:civicrm_phone:contact_id']['table']);
     $this->assertTrue(!isset($refCountsIdx['sql:civicrm_address:contact_id']));
 }
Esempio n. 16
0
 static function clearCurrentEmployer($id, $action)
 {
     $relationship = new CRM_Contact_DAO_Relationship();
     $relationship->id = $id;
     $relationship->find(TRUE);
     //to delete relationship between household and individual                                                                                          \
     //or between individual and orgnization
     if ($action & CRM_Core_Action::DISABLE || $action & CRM_Core_Action::DELETE) {
         $relTypes = CRM_Utils_Array::index(array('name_a_b'), CRM_Core_PseudoConstant::relationshipType('name'));
         if ($relationship->relationship_type_id == $relTypes['Employee of']['id'] || $relationship->relationship_type_id == $relTypes['Household Member of']['id']) {
             $sharedContact = new CRM_Contact_DAO_Contact();
             $sharedContact->id = $relationship->contact_id_a;
             $sharedContact->find(TRUE);
             if ($relationship->relationship_type_id == 4 && $relationship->contact_id_b == $sharedContact->employer_id) {
                 CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($relationship->contact_id_a);
             }
         }
     }
     return $relationship;
 }
<?php

civicrm_initialize();
// -----------------------------
// Get a list of users to update
if (!getenv('INSTALL_DASHBOARD_USERS')) {
    throw new RuntimeException('Missing environment variable: INSTALL_DASHBOARD_USERS');
}
$users = explode(';', getenv('INSTALL_DASHBOARD_USERS'));
CRM_Core_BAO_CMSUser::synchronize(FALSE);
// ------------------------------
// Get list of available dashlets
$reportInstanceResult = civicrm_api3('ReportInstance', 'get', array('option.limit' => 0));
$reportInstanceNames = CRM_Utils_Array::index(array('report_id'), $reportInstanceResult['values']);
$dashletTypeResult = civicrm_api3('Dashboard', 'get', array('domain_id' => CRM_Core_Config::domainID()));
$dashletTypes = CRM_Utils_Array::index(array('name'), $dashletTypeResult['values']);
// ---------------------------------------
// Build list of specific dashlets to add
$dashlets = array(array('dashboard_id' => $dashletTypes['report/' . $reportInstanceNames['event/summary']['id']]['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 1), array('dashboard_id' => $dashletTypes['report/' . $reportInstanceNames['contribute/topDonor']['id']]['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 3), array('dashboard_id' => $dashletTypes['report/' . $reportInstanceNames['contribute/summary']['id']]['id'], 'column_no' => 0, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 4), array('dashboard_id' => $dashletTypes['activity']['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 10), array('dashboard_id' => $dashletTypes['myCases']['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 11), array('dashboard_id' => $dashletTypes['report/' . $reportInstanceNames['member/summary']['id']]['id'], 'column_no' => 1, 'is_minimized' => 0, 'is_fullscreen' => 1, 'weight' => 12));
// -------------------
// Insert the dashlets
$tx = new CRM_Core_Transaction();
try {
    foreach ($users as $user) {
        foreach ($dashlets as $dashlet) {
            $dashlet['contact_id'] = "@user:{$user}";
            $dashlet['is_active'] = 1;
            $dashlet['debug'] = 1;
            civicrm_api3('dashboard_contact', 'create', $dashlet);
        }
    }
Esempio n. 18
0
 /**
  * @param $hasDashlets
  *
  * @return bool
  * @throws CiviCRM_API3_Exception
  */
 static function initializeDashlets($hasDashlets)
 {
     $getDashlets = civicrm_api3("Dashboard", "get", array('domain_id' => CRM_Core_Config::domainID()));
     $contactID = CRM_Core_Session::singleton()->get('userID');
     $allDashlets = CRM_Utils_Array::index(array('name'), $getDashlets['values']);
     $defaultDashlets = array();
     if (!$hasDashlets && !empty($allDashlets['blog'])) {
         $defaultDashlets['blog'] = array('dashboard_id' => $allDashlets['blog']['id'], 'is_active' => 1, 'column_no' => 1, 'contact_id' => $contactID, 'domain_id' => CRM_Core_Config::domainID());
     }
     CRM_Utils_Hook::dashboard_defaults($allDashlets, $defaultDashlets);
     if (is_array($defaultDashlets) && !empty($defaultDashlets)) {
         foreach ($defaultDashlets as $defaultDashlet) {
             if (!self::checkPermission($getDashlets['values'][$defaultDashlet['dashboard_id']]['permission'], $getDashlets['values'][$defaultDashlet['dashboard_id']]['permission_operator'])) {
                 unset($defaultDashlets[$defaultDashlet]);
                 continue;
             } else {
                 $assignDashlets = civicrm_api3("dashboard_contact", "create", $defaultDashlet);
                 $dashlets[$defaultDashlet['dashboard_id']] = $defaultDashlet['dashboard_id'];
             }
         }
         return $dashlets;
     }
     return FALSE;
 }