當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Phone::setPerson方法代碼示例

本文整理匯總了PHP中Phone::setPerson方法的典型用法代碼示例。如果您正苦於以下問題:PHP Phone::setPerson方法的具體用法?PHP Phone::setPerson怎麽用?PHP Phone::setPerson使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Phone的用法示例。


在下文中一共展示了Phone::setPerson方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: findPerson

 /**
  * Try to find this person in the database.
  * If we cannot find them, create a new person record.
  *
  * @return Person
  */
 public static function findPerson($post)
 {
     $search = array();
     // Translates Open311 parameters into PersonList search parameters
     // open311 => personList
     $fields = array('first_name' => 'firstname', 'last_name' => 'lastname', 'email' => 'email', 'phone' => 'phoneNumber', 'device_id' => 'phoneDeviceId');
     foreach ($fields as $open311Field => $crmField) {
         if (!empty($post[$open311Field])) {
             $search[$crmField] = $post[$open311Field];
         }
     }
     // If the user provided any personal info, do a person search
     if (count($search)) {
         $table = new PersonTable();
         $list = $table->find($search);
         // When we find one and only one record, use the record we found
         if (count($list) == 1) {
             $person = $list->current();
         } else {
             $p = array();
             foreach ($fields as $key => $field) {
                 if (!empty($post[$key])) {
                     $p[$field] = $post[$key];
                 }
             }
             if (count($p)) {
                 $person = new Person();
                 try {
                     $person->handleUpdate($p);
                     $person->save();
                     if (!empty($post['email'])) {
                         $email = new Email();
                         $email->setPerson($person);
                         $email->setEmail($post['email']);
                         $email->save();
                     }
                     if (!empty($post['phone']) || !empty($post['device_id'])) {
                         $phone = new Phone();
                         $phone->setPerson($person);
                         if (!empty($post['phone'])) {
                             $phone->setNumber($post['phone']);
                         }
                         if (!empty($post['device_id'])) {
                             $phone->setDeviceId($post['device_id']);
                         }
                         $phone->save();
                     }
                 } catch (\Exception $e) {
                     unset($person);
                 }
             }
         }
     }
     return isset($person) ? $person : null;
 }
開發者ID:CodeForEindhoven,項目名稱:uReport,代碼行數:61,代碼來源:Open311Client.php


注:本文中的Phone::setPerson方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。