Example #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)];
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CustomerRecord::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->joinWith('addresses');
     $dataProvider->sort->attributes['country'] = ['asc' => ['address.country' => SORT_ASC], 'desc' => ['address.country' => SORT_DESC]];
     $query->joinWith('emails');
     $dataProvider->sort->attributes['email'] = ['asc' => ['email.address' => SORT_ASC], 'desc' => ['email.address' => SORT_DESC]];
     /*
             $query->joinWith('phones');
             $dataProvider->sort->attributes['phone'] = [
                 'asc' => ['phone.number' => SORT_ASC],
                 'desc' => ['phone.number' => SORT_DESC],
             ];
     */
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['customer.id' => $this->id, 'birth_date' => $this->birth_date, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'notes', $this->notes]);
     // $query->andWhere(['like', 'address.country', $this->country]);
     return $dataProvider;
 }
 /**
  * Finds the CustomerRecord model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CustomerRecord the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CustomerRecord::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Example #5
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']);
 }