Esempio n. 1
0
 /**
  * Set data per group.
  *
  * @param $fieldInfo
  * @param null $default
  */
 private function initRepeatFields($fieldInfo, $default = null)
 {
     $controls = array();
     $repeaterId = $fieldInfo->id;
     $entity = Entity::getEntity($this->entityId, $this->entityType, $repeaterId);
     $repeaters = Entity::getAllDataTranactionRepeater($this->entityId, $this->entityType, $repeaterId, $this->locale);
     $this->repeaterFieldData = Entity::getAllDataTranactionRepeaterFields($this->entityId, $this->entityType, $repeaterId, $this->locale);
     $post_data = @$default['value'];
     $this->defaultOrder = @$default['order'];
     $repeater_field = $this->field;
     $fieldOfRepeater = $repeater_field->getListFields();
     if (isset($post_data)) {
         unset($post_data['clone']);
         $this->deleteItems = $default['delete'];
         foreach ($post_data as $k => $control) {
             $listDefault = $post_data[$k];
             $controls[$k]['fields'] = $this->createListControlAfterPostData($k, $listDefault, $fieldOfRepeater);
             $controls[$k]['order'] = -1;
         }
     } else {
         if (count($repeaters)) {
             $i = 1;
             foreach ($repeaters as $repeater) {
                 $controls[$repeater->id]['fields'] = $this->createListControl($repeater, $fieldOfRepeater);
                 $controls[$repeater->id]['order'] = $i;
                 ++$i;
             }
         }
     }
     $this->groupFields = $controls;
     $this->repeaterHeaders = $this->createHeaderRepeater($fieldOfRepeater);
 }
Esempio n. 2
0
 public function init($_default = null)
 {
     // get data from db;
     $entity = Entity::getEntity($this->entityId, $this->entityType, $this->fieldId);
     $this->model = $entity->getFieldByLocale($this->locale);
     $files = Request::file();
     $this->file = @$files[$this->locale]['fields'][$this->fieldId]['value'];
     if (!isset($this->file)) {
         $this->value = $this->model->value;
         if (!$this->model->id) {
             $this->value = $this->getOption('default');
         }
     } else {
         $fileName = $this->entityId . '_' . $this->fieldId . '.' . $this->file->getClientOriginalExtension();
         $this->value = $fileName;
     }
 }
Esempio n. 3
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;
 }