Exemplo n.º 1
0
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     // Default name
     if ($this->name == "") {
         $this->name = BookingEx::EXTRA_FIELD_PREFIX . $this->id;
         $this->update();
     }
     $ids = Booking::find()->select(['id'])->where(['tour_id' => $this->tour_id])->column();
     // Insert default values
     foreach ($ids as $booking_id) {
         $fieldValue = new TourFieldValue();
         $fieldValue->booking_id = $booking_id;
         $fieldValue->field_id = $this->id;
         $fieldValue->value = $this->default_value;
         try {
             $fieldValue->insert();
         } catch (Exception $e) {
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Save basic model and extra field values
  * @param bool|true $runValidation
  * @return bool
  */
 public function save($runValidation = true)
 {
     if ($this->primaryModel->isNewRecord) {
         $ok = $this->primaryModel->insert($runValidation) !== false;
         if (!$ok) {
             return false;
         }
         $this->id = $this->primaryModel->id;
         foreach ($this as $key => $value) {
             if (!StringHelper::startsWith($key, $this->extra_field_prefix)) {
                 continue;
             }
             $field_id = substr($key, strlen($this->extra_field_prefix));
             $fieldValue = new TourFieldValue();
             $fieldValue->field_id = $field_id;
             $fieldValue->booking_id = $this->primaryModel->id;
             $fieldValue->value = $value;
             $fieldValue->insert($runValidation);
         }
     } else {
         $ok = $this->primaryModel->update($runValidation) !== false;
         if (!$ok) {
             return false;
         }
         foreach ($this->primaryModel->fieldValues as $fieldValue) {
             $ok = $fieldValue->update($runValidation) !== false;
             if (!$ok) {
                 return false;
             }
         }
     }
     return true;
 }