当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Utils_Array::collect方法代码示例

本文整理汇总了PHP中CRM_Utils_Array::collect方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Utils_Array::collect方法的具体用法?PHP CRM_Utils_Array::collect怎么用?PHP CRM_Utils_Array::collect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Utils_Array的用法示例。


在下文中一共展示了CRM_Utils_Array::collect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPeriods

 /**
  * @return array (int id => string title)
  */
 public static function getPeriods()
 {
     $periods = civicrm_api3('HRAbsencePeriod', 'get', array());
     $result = CRM_Utils_Array::collect('title', $periods['values']);
     asort($result);
     return $result;
 }
开发者ID:JoeMurray,项目名称:civihr,代码行数:10,代码来源:HRAbsencePeriod.php

示例2: __construct

 public function __construct()
 {
     $tokens = CRM_Utils_Array::subset(CRM_Utils_Array::collect('title', CRM_Contribute_DAO_Contribution::fields()), $this->getPassthruTokens());
     $tokens['id'] = ts('Contribution ID');
     $tokens['payment_instrument'] = ts('Payment Instrument');
     $tokens['source'] = ts('Contribution Source');
     $tokens['status'] = ts('Contribution Status');
     $tokens['type'] = ts('Financial Type');
     parent::__construct('contribution', $tokens);
 }
开发者ID:rameshrr99,项目名称:civicrm-core,代码行数:10,代码来源:Tokens.php

示例3: testCollect

 function testCollect()
 {
     $arr = array(array('catWord' => 'cat', 'dogWord' => 'dog'), array('catWord' => 'chat', 'dogWord' => 'chien'), array('catWord' => 'gato'));
     $expected = array('cat', 'chat', 'gato');
     $this->assertEquals($expected, CRM_Utils_Array::collect('catWord', $arr));
     $arr = array();
     $arr['en'] = (object) array('catWord' => 'cat', 'dogWord' => 'dog');
     $arr['fr'] = (object) array('catWord' => 'chat', 'dogWord' => 'chien');
     $arr['es'] = (object) array('catWord' => 'gato');
     $expected = array('en' => 'cat', 'fr' => 'chat', 'es' => 'gato');
     $this->assertEquals($expected, CRM_Utils_Array::collect('catWord', $arr));
 }
开发者ID:archcidburnziso,项目名称:civicrm-core,代码行数:12,代码来源:ArrayTest.php

示例4: createManagedRelationshipTypes

 /**
  * Get a list of managed relationship-types by searching CiviCase XML files.
  *
  * @param \CRM_Case_XMLRepository $xmlRepo
  * @param \CRM_Core_ManagedEntities $me
  *
  * @return array
  * @see CRM_Utils_Hook::managed
  */
 public static function createManagedRelationshipTypes(CRM_Case_XMLRepository $xmlRepo, CRM_Core_ManagedEntities $me)
 {
     $result = array();
     if (!isset(Civi::$statics[__CLASS__]['reltypes'])) {
         $relationshipInfo = CRM_Core_PseudoConstant::relationshipType('label', TRUE, NULL);
         Civi::$statics[__CLASS__]['reltypes'] = CRM_Utils_Array::collect(CRM_Case_XMLProcessor::REL_TYPE_CNAME, $relationshipInfo);
     }
     $validRelTypes = Civi::$statics[__CLASS__]['reltypes'];
     $relTypes = $xmlRepo->getAllDeclaredRelationshipTypes();
     foreach ($relTypes as $relType) {
         $managed = array('module' => 'civicrm', 'name' => "civicase:rel:{$relType}", 'entity' => 'RelationshipType', 'update' => 'never', 'cleanup' => 'unused', 'params' => array('version' => 3, 'name_a_b' => "{$relType} is", 'name_b_a' => $relType, 'label_a_b' => "{$relType} is", 'label_b_a' => $relType, 'description' => $relType, 'contact_type_a' => 'Individual', 'contact_type_b' => 'Individual', 'contact_sub_type_a' => NULL, 'contact_sub_type_b' => NULL));
         // We'll create managed-entity if this record doesn't exist yet
         // or if we previously decided to manage this record.
         if (!in_array($relType, $validRelTypes)) {
             $result[] = $managed;
         } elseif ($me->get($managed['module'], $managed['name'])) {
             $result[] = $managed;
         }
     }
     return $result;
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:30,代码来源:ManagedEntities.php

示例5: testContactReference

 /**
  * Test to check contact reference field
  */
 public function testContactReference()
 {
     //create group
     $groupId1 = $this->groupCreate();
     $groupId2 = $this->groupCreate(array('name' => 'Test Group 2', 'domain_id' => 1, 'title' => 'New Test Group2 Created', 'description' => 'New Test Group2 Created', 'is_active' => 1, 'visibility' => 'User and User Admin Only'));
     $contactIds = array();
     foreach (array($groupId1, $groupId2) as $groupId) {
         $this->groupContactCreate($groupId);
         $contactIds = array_merge($contactIds, CRM_Contact_BAO_Group::getGroupContacts($groupId));
     }
     $contactIds = CRM_Utils_Array::collect('contact_id', $contactIds);
     // create custom group with contact reference field
     $customGroup = $this->customGroupCreate(array('extends' => 'Contact', 'title' => 'select_test_group'));
     $params = array('custom_group_id' => $customGroup['id'], 'name' => 'Worker_Lookup', 'label' => 'Worker Lookup', 'filter' => "action=lookup&group={$groupId1},{$groupId2}", 'html_type' => 'Autocomplete-Select', 'data_type' => 'ContactReference', 'weight' => 4, 'is_searchable' => 1, 'is_active' => 1);
     $customField = $this->callAPISuccess('custom_field', 'create', $params);
     $_GET = array('id' => $customField['id'], 'is_unit_test' => TRUE);
     $contactList = CRM_Contact_Page_AJAX::contactReference();
     $contactList = CRM_Utils_Array::collect('id', $contactList);
     //assert each returned contact id to be present in group contact
     foreach ($contactList as $contactId) {
         $this->assertTrue(in_array($contactId, $contactIds));
     }
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:26,代码来源:AjaxTest.php

示例6: findConstantsByClass

 /**
  * Scan for a list of pseudo-constants. A pseudo-constant is recognized by listing
  * any static properties which have corresponding static methods.
  *
  * This may be inefficient and should generally be avoided.
  *
  * @param $class
  *
  * @return array
  *   Array of string, constant names
  */
 public static function findConstantsByClass($class)
 {
     $clazz = new ReflectionClass($class);
     $classConstants = array_intersect(CRM_Utils_Array::collect('name', $clazz->getProperties(ReflectionProperty::IS_STATIC)), CRM_Utils_Array::collect('name', $clazz->getMethods(ReflectionMethod::IS_STATIC)));
     return $classConstants;
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:17,代码来源:PseudoConstant.php

示例7: assertRecipients

 /**
  * Assert that $expectedRecipients (and no else) have received emails
  *
  * @param array $expectedRecipients array($msgPos => array($recipPos => $emailAddr))
  */
 function assertRecipients($expectedRecipients)
 {
     $recipients = array();
     foreach ($this->getAllMessages('ezc') as $message) {
         $recipients[] = CRM_Utils_Array::collect('email', $message->to);
     }
     sort($recipients);
     sort($expectedRecipients);
     $this->_ut->assertEquals($expectedRecipients, $recipients, "Incorrect recipients: " . print_r(array('expected' => $expectedRecipients, 'actual' => $recipients), TRUE));
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:15,代码来源:CiviMailUtils.php

示例8: testGet

 /**
  * @param $getParams
  * @param $expectedNames
  * @dataProvider okGetProvider
  */
 public function testGet($getParams, $expectedNames)
 {
     foreach (array(123, 456) as $entity_id) {
         foreach (array('text/plain' => '.txt', 'text/csv' => '.csv') as $mime => $ext) {
             $this->callAPISuccess('Attachment', 'create', array('name' => self::getFilePrefix() . 'example_' . $entity_id . $ext, 'mime_type' => $mime, 'description' => 'My test description', 'content' => 'My test content', 'entity_table' => 'civicrm_activity', 'entity_id' => $entity_id));
         }
     }
     $getResult = $this->callAPISuccess('Attachment', 'get', $getParams);
     $actualNames = array_values(CRM_Utils_Array::collect('name', $getResult['values']));
     sort($actualNames);
     sort($expectedNames);
     $this->assertEquals($expectedNames, $actualNames);
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:18,代码来源:AttachmentTest.php

示例9: assertRecipients

 /**
  * Assert that $expectedRecipients (and no else) have received emails
  *
  * @param array $expectedRecipients
  *   Array($msgPos => array($recipPos => $emailAddr)).
  */
 public function assertRecipients($expectedRecipients)
 {
     $recipients = array();
     foreach ($this->getAllMessages('ezc') as $message) {
         $recipients[] = CRM_Utils_Array::collect('email', $message->to);
     }
     $cmp = function ($a, $b) {
         if ($a[0] == $b[0]) {
             return 0;
         }
         return $a[0] < $b[0] ? 1 : -1;
     };
     usort($recipients, $cmp);
     usort($expectedRecipients, $cmp);
     $this->_ut->assertEquals($expectedRecipients, $recipients, "Incorrect recipients: " . print_r(array('expected' => $expectedRecipients, 'actual' => $recipients), TRUE));
 }
开发者ID:FundingWorks,项目名称:civicrm-core,代码行数:22,代码来源:CiviMailUtils.php

示例10: addProfileSelector

 /**
  * Add a widget for selecting/editing/creating/copying a profile form
  *
  * @param string $name
  *   HTML form-element name.
  * @param string $label
  *   Printable label.
  * @param string $allowCoreTypes
  *   Only present a UFGroup if its group_type includes a subset of $allowCoreTypes; e.g. 'Individual', 'Activity'.
  * @param string $allowSubTypes
  *   Only present a UFGroup if its group_type is compatible with $allowSubypes.
  * @param array $entities
  * @param bool $default
  *   //CRM-15427.
  */
 public function addProfileSelector($name, $label, $allowCoreTypes, $allowSubTypes, $entities, $default = FALSE, $usedFor = NULL)
 {
     // Output widget
     // FIXME: Instead of adhoc serialization, use a single json_encode()
     CRM_UF_Page_ProfileEditor::registerProfileScripts();
     CRM_UF_Page_ProfileEditor::registerSchemas(CRM_Utils_Array::collect('entity_type', $entities));
     $this->add('text', $name, $label, array('class' => 'crm-profile-selector', 'data-group-type' => CRM_Core_BAO_UFGroup::encodeGroupType($allowCoreTypes, $allowSubTypes, ';;'), 'data-entities' => json_encode($entities), 'data-default' => $default, 'data-usedfor' => json_encode($usedFor)));
 }
开发者ID:hoegrammer,项目名称:civicrm-core,代码行数:23,代码来源:Form.php

示例11: buildQuickForm

 /**
  * Build form for related contacts / on behalf of organization.
  *
  * @param CRM_Core_Form $form
  *
  */
 public static function buildQuickForm(&$form)
 {
     $form->assign('fieldSetTitle', ts('Organization Details'));
     $form->assign('buildOnBehalfForm', TRUE);
     $contactID = $form->_contactID;
     if ($contactID && count($form->_employers) >= 1) {
         $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
         $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $form->_employers));
         $orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
         $form->addRadio('org_option', ts('options'), $orgOptions);
         $form->setDefaults(array('org_option' => 0));
         $form->add('checkbox', 'mode', '');
     }
     $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_profileId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
     $fieldTypes = array('Contact', 'Organization');
     $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
     $fieldTypes = array_merge($fieldTypes, $contactSubType);
     if (is_array($form->_membershipBlock) && !empty($form->_membershipBlock)) {
         $fieldTypes = array_merge($fieldTypes, array('Membership'));
     } else {
         $fieldTypes = array_merge($fieldTypes, array('Contribution'));
     }
     foreach ($profileFields as $name => $field) {
         if (in_array($field['field_type'], $fieldTypes)) {
             list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
                 $field['is_required'] = 1;
             }
             CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, 'onbehalf');
         }
     }
     $form->assign('onBehalfOfFields', $profileFields);
     $form->addElement('hidden', 'hidden_onbehalf_profile', 1);
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:40,代码来源:OnBehalfOf.php

示例12: buildQuickForm

 /**
  * Build form elements based on the above metadata.
  */
 public function buildQuickForm()
 {
     CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.insert-shortcode.js');
     $components = CRM_Utils_Array::collect('label', $this->components);
     $data = CRM_Utils_Array::collect('select', $this->components);
     $this->add('select', 'component', NULL, $components, FALSE, array('class' => 'crm-select2', 'data-key' => 'component', 'data-entities' => json_encode($data)));
     $this->add('text', 'entity', NULL, array('placeholder' => ts('- select -')));
     $options = $defaults = array();
     foreach ($this->options as $num => $field) {
         $this->addRadio("option_{$num}", CRM_Utils_Array::value('label', $field), $field['options'], array('allowClear' => FALSE, 'data-key' => $field['key']));
         if ($field['components'] === TRUE) {
             $field['components'] = array_keys($this->components);
         }
         $options["option_{$num}"] = $field;
         // Select 1st option as default
         $keys = array_keys($field['options']);
         $defaults["option_{$num}"] = $keys[0];
     }
     $this->assign('options', $options);
     $this->assign('selects', array_keys(array_filter($data)));
     $this->setDefaults($defaults);
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:25,代码来源:ShortCode.php

示例13: del

 /**
  * @param int $caseTypeId
  *
  * @throws CRM_Core_Exception
  * @return mixed
  */
 public static function del($caseTypeId)
 {
     $caseType = new CRM_Case_DAO_CaseType();
     $caseType->id = $caseTypeId;
     $refCounts = $caseType->getReferenceCounts();
     $total = array_sum(CRM_Utils_Array::collect('count', $refCounts));
     if ($total) {
         throw new CRM_Core_Exception(ts("You can not delete this case type -- it is assigned to %1 existing case record(s). If you do not want this case type to be used going forward, consider disabling it instead.", array(1 => $total)));
     }
     $result = $caseType->delete();
     CRM_Case_XMLRepository::singleton(TRUE);
     return $result;
 }
开发者ID:kcristiano,项目名称:civicrm-core,代码行数:19,代码来源:CaseType.php

示例14: buildQuickForm

 /**
  * Function to build form for related contacts / on behalf of organization.
  *
  * @param $form              object  invoking Object
  * @param $contactType       string  contact type
  * @param $title             string  fieldset title
  *
  * @static
  */
 static function buildQuickForm(&$form)
 {
     $form->assign('fieldSetTitle', ts('Organization Details'));
     $form->assign('buildOnBehalfForm', TRUE);
     $contactID = $form->_contactID;
     if ($contactID && count($form->_employers) >= 1) {
         $form->add('text', 'organization_id', ts('Select an existing related Organization OR enter a new one'));
         $form->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $form->_employers));
         $orgOptions = array(0 => ts('Select an existing organization'), 1 => ts('Enter a new organization'));
         $form->addRadio('org_option', ts('options'), $orgOptions);
         $form->setDefaults(array('org_option' => 0));
         $form->add('checkbox', 'mode', '');
     }
     $profileFields = CRM_Core_BAO_UFGroup::getFields($form->_profileId, FALSE, CRM_Core_Action::VIEW, NULL, NULL, FALSE, NULL, FALSE, NULL, CRM_Core_Permission::CREATE, NULL);
     $fieldTypes = array('Contact', 'Organization');
     $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
     $fieldTypes = array_merge($fieldTypes, $contactSubType);
     if (is_array($form->_membershipBlock) && !empty($form->_membershipBlock)) {
         $fieldTypes = array_merge($fieldTypes, array('Membership'));
     } else {
         $fieldTypes = array_merge($fieldTypes, array('Contribution'));
     }
     $stateCountryMap = array();
     foreach ($profileFields as $name => $field) {
         if (in_array($field['field_type'], $fieldTypes)) {
             list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
             if (in_array($prefixName, array('state_province', 'country', 'county'))) {
                 if (!array_key_exists($index, $stateCountryMap)) {
                     $stateCountryMap[$index] = array();
                 }
                 $stateCountryMap[$index][$prefixName] = 'onbehalf[' . $name . ']';
             } elseif (in_array($prefixName, array('organization_name', 'email')) && !CRM_Utils_Array::value('is_required', $field)) {
                 $field['is_required'] = 1;
             }
             CRM_Core_BAO_UFGroup::buildProfile($form, $field, NULL, NULL, FALSE, TRUE);
         }
     }
     if (!empty($stateCountryMap)) {
         CRM_Core_BAO_Address::addStateCountryMap($stateCountryMap);
         // now fix all state country selectors
         CRM_Core_BAO_Address::fixAllStateSelects($form, CRM_Core_DAO::$_nullArray);
     }
     $form->assign('onBehalfOfFields', $profileFields);
     $form->addElement('hidden', 'hidden_onbehalf_profile', 1);
 }
开发者ID:hguru,项目名称:224Civi,代码行数:54,代码来源:OnBehalfOf.php

示例15: testDefault

 /**
  * Execute the default schedule, without any special recipient selections.
  *
  * @dataProvider createTestCases
  *
  * @param string $targetDate
  * @param string $setupFuncs
  * @param array $expectMessages
  *
  * @throws \Exception
  */
 public function testDefault($targetDate, $setupFuncs, $expectMessages)
 {
     $this->targetDate = $targetDate;
     foreach (explode(' ', $setupFuncs) as $setupFunc) {
         $this->{$setupFunc}();
     }
     $this->schedule->save();
     $actualMessages = array();
     foreach ($this->cronTimes() as $time) {
         \CRM_Utils_Time::setTime($time);
         $this->callAPISuccess('job', 'send_reminder', array());
         foreach ($this->mut->getAllMessages('ezc') as $message) {
             /** @var \ezcMail $message */
             $simpleMessage = array('time' => $time, 'to' => \CRM_Utils_Array::collect('email', $message->to), 'subject' => $message->subject);
             sort($simpleMessage['to']);
             $actualMessages[] = $simpleMessage;
             $this->mut->clearMessages();
         }
     }
     $errorText = "Incorrect messages: " . print_r(array('actualMessages' => $actualMessages, 'expectMessages' => $expectMessages), 1);
     $this->assertEquals(count($expectMessages), count($actualMessages), $errorText);
     usort($expectMessages, array(__CLASS__, 'compareSimpleMsgs'));
     usort($actualMessages, array(__CLASS__, 'compareSimpleMsgs'));
     foreach ($expectMessages as $offset => $expectMessage) {
         $actualMessage = $actualMessages[$offset];
         $this->assertApproxEquals(strtotime($expectMessage['time']), strtotime($actualMessage['time']), $this->dateTolerance, $errorText);
         if (isset($expectMessage['to'])) {
             sort($expectMessage['to']);
             $this->assertEquals($expectMessage['to'], $actualMessage['to'], $errorText);
         }
         if (isset($expectMessage['subject'])) {
             $this->assertRegExp($expectMessage['subject'], $actualMessage['subject'], $errorText);
         }
     }
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:46,代码来源:AbstractMappingTest.php


注:本文中的CRM_Utils_Array::collect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。