Exemple #1
0
 /**
  * Save field data to database.
  *
  * @return bool
  */
 public function save()
 {
     $bResult = false;
     try {
         if (!empty($this->deleteItems)) {
             $items = explode(',', $this->deleteItems);
             RepeaterTranslation::destroy($items);
         }
         if (count($this->groupFields)) {
             foreach ($this->groupFields as $groupId => $group) {
                 $fields = $group['fields'];
                 $order = $this->defaultOrder[$groupId];
                 $translate_id = 0;
                 foreach ($fields as $field) {
                     if ($translate_id) {
                         $field->setTranslateId($translate_id);
                     }
                     $field->save();
                     $translate_id = $field->getTranslateId();
                 }
                 // update order
                 $translate = RepeaterTranslation::find($translate_id);
                 $translate->order = $order;
                 $translate->save();
             }
         }
         $bResult = true;
     } catch (\Exception $e) {
         //exception handling
     }
     return $bResult;
 }
Exemple #2
0
 /**
  * Save repeat data for field of repeater.
  */
 public function saveRepeaterField()
 {
     $repeaterId = $this->repeaterId;
     $repeaterTranslate = RepeaterTranslation::firstOrNew(array('id' => $this->translationId));
     if (!$repeaterTranslate->id) {
         $entity = Entity::getEntity($this->entityId, $this->entityType, $repeaterId);
         if (!$entity->id) {
             $entity->entity_id = $this->entityId;
             $entity->entity_type = $this->entityType;
             $entity->field_id = $repeaterId;
             $entity->save();
         }
         $repeaterTranslate->entity_repeater_id = $entity->id;
         $repeaterTranslate->locale = $this->locale;
         $repeaterTranslate->save();
     }
     $this->model->translation_id = $repeaterTranslate->id;
     $this->model->field_id = $this->fieldId;
     $this->model->value = $this->getValue();
     $this->model->save();
     // assign translate_id to same group;
     $this->translationId = $this->model->translation_id;
 }