Esempio n. 1
0
 private function store(Customer $customer)
 {
     $customer_record = new CustomerRecord();
     $customer_record->name = $customer->name;
     $customer_record->birth_date = $customer->birth_date->format('Y-m-d');
     $customer_record->notes = $customer->notes;
     $customer_record->save();
     foreach ($customer->phones as $phone) {
         $phone_record = new PhoneRecord();
         $phone_record->number = $phone->number;
         $phone_record->customer_id = $customer_record->id;
         $phone_record->save();
     }
 }
 private function getRecordsByPhoneNumber($number)
 {
     $phone_record = PhoneRecord::findOne(['number' => $number]);
     if (!$phone_record) {
         return [];
     }
     $customer_record = CustomerRecord::findOne($phone_record->customer_id);
     if (!$customer_record) {
         return [];
     }
     return [$this->makeCustomer($customer_record, $phone_record)];
 }
Esempio n. 3
0
 public function getPhones()
 {
     return $this->hasMany(PhoneRecord::className(), ['customer_id' => 'id']);
 }
Esempio n. 4
0
 /**
  * @param CustomerRecord $customer
  * @param PhoneRecord $phone
  * @param array $post
  * @return bool
  */
 private function load(CustomerRecord $customer, PhoneRecord $phone, array $post)
 {
     return $customer->load($post) && $phone->load($post) && $customer->validate() && $phone->validate(['numerical']);
 }