/** * Handle the event. * * @param PodcastWasPurchased $event */ public function handle(PageWasReplicated $event) { $entity = new Entity(); $entities = $entity->getFieldsByEntity($event->pageId); foreach ($entities as $item) { $item->duplicate($event->replicateId); } }
/** * 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); }
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; } }
/** * Initial fields of each group and assign to GroupFields array. * * @param $group * @param null $default */ private function initGroup($group, $default = null) { $groupId = $group->id; $groupName = $group->name; $fields = $group->getListFields(); $fieldData = $this->getFieldPostData($default); $controls = array(); if ($fields->count()) { $this->fieldInDB = EntityModel::getAllDataFields($this->entityId, $this->type); $controls['name'] = $groupName; foreach ($fields as $field) { $fieldValue = @$fieldData['fields'][$field->id]; $fieldControl = null; $dbData = $this->getFieldDataInDB($field->id, $this->locale); switch ($field->type) { case 'text': $fieldControl = new Text($field, $this->entityId, $this->locale, $dbData); break; case 'number': $fieldControl = new Number($field, $this->entityId, $this->locale, $dbData); break; case 'textarea': $fieldControl = new Textarea($field, $this->entityId, $this->locale, $dbData); break; case 'wysiwyg': $fieldControl = new Wysiwyg($field, $this->entityId, $this->locale, $dbData); break; case 'file': $fieldControl = new File($field, $this->entityId, $this->locale, $dbData); break; case 'image': $fieldControl = new Image($field, $this->entityId, $this->locale, $dbData); break; case 'repeater': $fieldControl = new Repeater($field, $this->entityId, $this->locale, $dbData); break; } // assign entity type class to field to use for save data; $fieldControl->setEntityType($this->type); $fieldControl->init($fieldValue); $controls['fields'][$field->id] = $fieldControl; $this->fieldValues[$field->name] = $fieldControl->getDisplayValue(); } $this->groupFields[$groupId] = $controls; } }
/** * 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; }