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


PHP CRM_Core_BAO_Location::dataExists方法代码示例

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


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

示例1: add

 /**
  * 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
  * pairs
  *
  * @param array  $params         (reference ) an assoc array of name/value pairs
  * @param array  $ids            the array that holds all the db ids
  * @param array  $locationId     
  *
  * @return object   CRM_Core_BAO_Location object on success, null otherwise
  * @access public
  * @static
  */
 function add(&$params, &$ids, $locationId)
 {
     if (!CRM_Core_BAO_Location::dataExists($params, $locationId, $ids)) {
         return null;
     }
     $location =& new CRM_Core_BAO_Location();
     if (!isset($params['contact_id'])) {
         require_once 'CRM/Core/BAO/Domain.php';
         $location->entity_table = CRM_Core_BAO_Domain::getTableName();
         $location->entity_id = $params['domain_id'];
     } else {
         $location->entity_table = CRM_Contact_BAO_Contact::getTableName();
         $location->entity_id = $params['contact_id'];
     }
     $location->location_type_id = CRM_Utils_Array::value('location_type_id', $params['location'][$locationId]);
     $location->name = CRM_Utils_Array::value('name', $params['location'][$locationId]);
     $location->is_primary = CRM_Utils_Array::value('is_primary', $params['location'][$locationId], false);
     // check if there exists another location has is_primary set, and if so reset that
     // if no location has is_primary, make this one is_primart
     if ($location->is_primary) {
         // reset all other locations with the same entity table entity id
         $sql = "UPDATE " . CRM_Core_BAO_Location::getTableName() . "\n SET is_primary = 0 WHERE \n entity_table = '{$location->entity_table}' AND\n entity_id    = '{$location->entity_id}' ";
         CRM_Core_DAO::executeQuery($sql);
     } else {
         // make sure there is at once location with is_primary set
         $sql = "SELECT count( " . CRM_Core_BAO_Location::getTableName() . ".id )\n FROM " . CRM_Core_BAO_Location::getTableName() . " WHERE\n entity_table = '{$location->entity_table}' AND\n entity_id    = '{$location->entity_id}'    AND\n is_primary   = 1";
         $count = CRM_Core_DAO::singleValueQuery($sql);
         if ($count == 0) {
             $location->is_primary = true;
         }
     }
     $location->id = CRM_Utils_Array::value('id', $ids['location'][$locationId]);
     $location->save();
     $params['location'][$locationId]['id'] = $location->id;
     $address_object = CRM_Core_BAO_Address::add($params, $ids, $locationId);
     $location->address = $address_object;
     // set this to true if this has been made the primary IM.
     // the rule is the first entered value is the primary object
     $isPrimaryPhone = $isPrimaryEmail = $isPrimaryIM = true;
     $location->phone = array();
     $location->email = array();
     $location->im = array();
     for ($i = 1; $i <= CRM_CONTACT_FORM_LOCATION_BLOCKS; $i++) {
         $location->phone[$i] = CRM_Core_BAO_Phone::add($params, $ids, $locationId, $i, $isPrimaryPhone);
         $location->email[$i] = CRM_Core_BAO_Email::add($params, $ids, $locationId, $i, $isPrimaryEmail);
         $location->im[$i] = CRM_Core_BAO_IM::add($params, $ids, $locationId, $i, $isPrimaryIM);
     }
     return $location;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:64,代码来源:Location.php

示例2: formRule

 /**
  * global validation rules for the form
  *
  * @param array $fields posted values of the form
  * @param array $errors list of errors to be posted back to the form
  *
  * @return void
  * @static
  * @access public
  */
 function formRule(&$fields, &$errors)
 {
     $primaryEmail = null;
     // make sure that at least one field is marked is_primary
     if (array_key_exists('location', $fields) && is_array($fields['location'])) {
         $locationKeys = array_keys($fields['location']);
         $isPrimary = false;
         $dataExists = false;
         $locTypeId = false;
         foreach ($locationKeys as $locationId) {
             if (array_key_exists('is_primary', $fields['location'][$locationId])) {
                 if ($fields['location'][$locationId]['is_primary']) {
                     if ($isPrimary) {
                         $errors["location[{$locationId}][is_primary]"] = ts('Only one location can be marked as primary.');
                     }
                     $isPrimary = true;
                 }
                 // only harvest email from the primary locations
                 if (array_key_exists('email', $fields['location'][$locationId]) && is_array($fields['location'][$locationId]['email']) && empty($primaryEmail)) {
                     foreach ($fields['location'][$locationId]['email'] as $idx => $email) {
                         if (array_key_exists('email', $email)) {
                             $primaryEmail = $email['email'];
                             break;
                         }
                     }
                 }
             }
             if (CRM_Contact_Form_Edit::locationDataExists($fields['location'][$locationId])) {
                 $dataExists = true;
                 if (!CRM_Utils_Array::value('location_type_id', $fields['location'][$locationId])) {
                     $errors["location[{$locationId}][location_type_id]"] = ts('The Location Type should be set if there is any location information');
                 }
             }
             //  for checking duplicate location type.
             if (CRM_Core_BAO_Location::dataExists($fields, $locationId, $ids)) {
                 if ($locTypeId == $fields['location'][$locationId]['location_type_id']) {
                     $errors["location[{$locationId}][location_type_id]"] = ts('Two locations cannot have same location type');
                 }
                 $locTypeId = $fields['location'][$locationId]['location_type_id'];
             }
         }
         if ($dataExists && !$isPrimary) {
             $errors["location[1][is_primary]"] = ts('One location should be marked as primary.');
         }
     }
     return $primaryEmail;
 }
开发者ID:bhirsch,项目名称:voipdrupal-4.7-1.0,代码行数:57,代码来源:Edit.php


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