/** * [createNewInstanceField description] * @param [type] $instance [description] * @param [type] $field [description] * @return [type] [description] */ public function createNewInstanceField($instance, $fieldInput) { $field = $this->Field->newInstance(); $field->collection_instance_id = $instance->id; $field->page_version_id = $instance->page_version_id; $field->type = $fieldInput['type']; $field->key = $fieldInput['key']; $field->human_name = $fieldInput['human_name']; $field->json_value = array_get($fieldInput, 'json_value', '{}'); $field->content_requested = array_get($fieldInput, 'content_requested', false) == 1; $field->save(); return $field; }
/** * Create page field given input * * @param array $input * @internal param Field $field * @return PageField */ protected function newPageField($pageVersionId, $key, $type, $humanName) { $field = $this->Field->newInstance(); $field->page_version_id = $pageVersionId; $field->type = $type; $field->human_name = $humanName; $field->key = $key; $field->collection_instance_id = null; $field->json_value = '{}'; $field->save(); return $field; }
/** * Create a new field instance * * @param array $tag * @return DvsField */ protected function createFieldInstance($tag) { $field = $this->DvsField->newInstance(); $field->collection_instance_id = null; $field->page_version_id = $this->pageVersionId; $field->type = $tag['type']; $field->human_name = $tag['humanName']; $field->key = $tag['key']; $field->json_value = $tag['defaults'] ?: '{}'; $field->content_requested = false; $field->save(); return $field; }
/** * Creates a field for this instance * * @param [type] $instance * @param [type] $collectionField * @param [type] $pageVersionId * @return [type] */ protected function createFieldsForInstance($instance, $collectionFields, $pageVersionId) { $fields = []; foreach ($collectionFields as $collectionField) { $field = $this->Field->newInstance(); $field->collection_instance_id = $instance->id; $field->page_version_id = $pageVersionId; $field->type = $collectionField['type']; $field->human_name = $collectionField['humanName']; $field->key = $collectionField['key']; $field->json_value = '{}'; $field->content_requested = 0; $field->save(); $fields[] = $field; $instance->fields->add($field); } return $fields; }
/** * Find all pristine page fields that match this * key * * @param string $key * @return Collection */ public function findPristinePageFields($key) { return $this->Field->newInstance()->where('key', '=', $key)->where('created_at', '=', \DB::raw('updated_at'))->get(); }
/** * Remove instance from database * * @param integer $id * @return bool */ public function removeInstance($id) { $instance = $this->CollectionInstance->find($id); $this->Field->where('collection_instance_id', $id)->forceDelete(); return $instance ? $instance->delete() : false; }
/** * Creates collection fields object from a collection * instance that we pulled from the database (those will * have fields associated with them too) * * @param CollectionInstance $instance * @return CollectionFields */ public function createFromCollectionInstance($instance) { $fields = $this->Field->where('collection_instance_id', '=', $instance->id)->where('page_version_id', '=', $instance->page_version_id)->get(); return new CollectionFields($fields); }
public function test_it_finds_trashed_field_by_id_and_scope() { \DvsField::find(1)->delete(); $output = $this->FieldsRepository->findTrashedFieldByIdAndScope(1, 'page'); assertEquals(1, $output->id); }