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


PHP Location_Model::instance方法代码示例

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


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

示例1:

 /**
  * 单例模式
  * @return Location_Model
  */
 public static function &instance()
 {
     if (!isset(self::$instance)) {
         // Create a new instance
         self::$instance = new Location_Model();
     }
     return self::$instance;
 }
开发者ID:momoim,项目名称:momo-api,代码行数:12,代码来源:location.php

示例2: array_to_Group_contact

 /**
  * 过滤输入、创建群联系人对象
  * @param array $data 联系人信息
  * @return Group_Contact $contact
  */
 public function array_to_Group_contact($data)
 {
     $contact = new Group_Contact();
     $location_model = Location_Model::instance();
     $bjx_arr = Kohana::config_load('bjx');
     foreach ($data as $type => $value) {
         switch ($type) {
             case 'tels':
                 if (!empty($value)) {
                     $values = $tmp = array();
                     foreach ($value as $val) {
                         if (!in_array(trim($val['value']), $tmp)) {
                             $tmp[] = trim($val['value']);
                             $values[] = array('value' => trim($val['value']), 'type' => $val['type'], 'city' => $location_model->get_tel_location(trim($val['value'])), 'pref' => !empty($val['pref']) ? (int) $val['pref'] : 0);
                         }
                     }
                     call_user_func(array($contact, 'set_' . $type), $values);
                 }
                 break;
             case 'ims':
                 if (!empty($value)) {
                     $values = $tmp = $protocols = array();
                     foreach ($value as $val) {
                         $val['protocol'] = strtolower($val['protocol']);
                         $keys = array_keys($tmp, trim($val['value']));
                         $key = isset($keys[0]) ? $keys[0] : -1;
                         if ($key < 0 or $protocols[$key] != $val['protocol']) {
                             $tmp[] = trim($val['value']);
                             $protocols[] = $val['protocol'];
                             $values[] = array('value' => trim($val['value']), 'protocol' => $val['protocol'], 'type' => $val['type']);
                         }
                     }
                     call_user_func(array($contact, 'set_' . $type), $values);
                 }
                 break;
             case 'addresses':
                 if (!empty($value)) {
                     $values = $tmp = array();
                     $t = '';
                     foreach ($value as $val) {
                         $t = trim($val['country']) . '|' . trim($val['region']) . '|' . trim($val['city']) . '|' . trim($val['street']) . '|' . trim($val['postal']);
                         if (!in_array($t, $tmp)) {
                             $values[] = array('country' => trim($val['country']), 'region' => trim($val['region']), 'city' => trim($val['city']), 'street' => trim($val['street']), 'postal' => trim($val['postal']), 'type' => $val['type']);
                             $tmp[] = $t;
                         }
                     }
                     call_user_func(array($contact, 'set_' . $type), $values);
                 }
                 break;
             case 'emails':
             case 'urls':
             case 'events':
             case 'relations':
                 if (!empty($value)) {
                     $values = $tmp = array();
                     foreach ($value as $val) {
                         if (!in_array(trim($val['value']), $tmp)) {
                             $tmp[] = trim($val['value']);
                             $values[] = array('value' => trim($val['value']), 'type' => $val['type']);
                         }
                     }
                     call_user_func(array($contact, 'set_' . $type), $values);
                 }
                 break;
             case 'birthday':
                 $contactModel = Contact_Model::instance();
                 call_user_func(array($contact, 'set_' . $type), !empty($value) ? $contactModel->_filter_birthday($value) : '');
                 break;
             case 'id':
                 break;
             default:
                 call_user_func(array($contact, 'set_' . $type), !empty($value) ? $value : '');
                 break;
         }
     }
     $formatted_name = $this->name_to_formatted_name($data['family_name'], $data['given_name']);
     //拼接后的全名为空,并且输入的全名不是空的,把全名拆分设置
     if (empty($formatted_name) and !empty($data['formatted_name'])) {
         $name = $this->formatted_name_to_name($data['formatted_name']);
         $contact->set_given_name($name['given_name']);
         $contact->set_family_name($name['family_name']);
     } else {
         $fn = $formatted_name;
     }
     if (!empty($fn)) {
         require_once Kohana::find_file('vendor', 'pinyin/c2p');
         $phonetic = getPinYin($fn, false, ' ');
         $tmp = explode(' ', $phonetic);
         $sort = '';
         if (is_array($tmp)) {
             foreach ($tmp as $t) {
                 $sort .= isset($t[0]) ? $t[0] : '';
             }
         }
         $t = ord($sort[0]);
//.........这里部分代码省略.........
开发者ID:momoim,项目名称:momo-api,代码行数:101,代码来源:group_contact.php


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