Alter Metadata to Fields/Field (Big changes)

This commit is contained in:
Eduardo humberto 2018-01-31 12:47:59 -02:00
parent 095d192d6d
commit 722b5387d1
51 changed files with 524 additions and 524 deletions

View File

@ -3,36 +3,36 @@
The typical workflow when you create a Digital Repository with Tainacan is:
* Create a collection
* Configure which metadata (fields) item in this collections will have
* Configure which field (fields) item in this collections will have
* Configure the collection
* Configure which filters will be used when browsing the collection
* Upload item to the collection or import them from a source
## Collections
A collection is a group of items, that have the same set of metadata. Every item uploaded to your digital repository will be part of a collection. For instance, you could have a "paintings" collections, with metadata such as Title, Author, Country, Tecnique, etc and another collection for "films", with Title, Director, Country and Genre.
A collection is a group of items, that have the same set of field. Every item uploaded to your digital repository will be part of a collection. For instance, you could have a "paintings" collections, with field such as Title, Author, Country, Tecnique, etc and another collection for "films", with Title, Director, Country and Genre.
For each collection you can set a different set of metadata and they can share common taxonomies, which means you could browse for items in a specific Country, and get both paintings and films in your results.
For each collection you can set a different set of field and they can share common taxonomies, which means you could browse for items in a specific Country, and get both paintings and films in your results.
Collections can also have child collections, which will inherit parent's collection metadata and can add their own set of additional information.
Collections can also have child collections, which will inherit parent's collection field and can add their own set of additional information.
## Items
Items are the actual content of yout repository. The painting, the film, the book and so on. They belong to a collection and have all the metadata configured in the collection.
Items are the actual content of yout repository. The painting, the film, the book and so on. They belong to a collection and have all the field configured in the collection.
In WordPress, each item is a post and its post type represents its collection.
## Metadata
## Field
Every collection have a set of metadata. They are the description of the items of this collection.
Every collection have a set of field. They are the description of the items of this collection.
Each metadata has a set of settings. Is it required? Is it supposed to be unique (an ID number for example)? Does it accept multiple values? What is it Field Type? (see the complete list of metadata attributes).
Each field has a set of settings. Is it required? Is it supposed to be unique (an ID number for example)? Does it accept multiple values? What is it Field Type? (see the complete list of field attributes).
(Note: you can import/export presets of metadata)
(Note: you can import/export presets of field)
## Field Types
Field types are the objects that represent the types of metadata that can be used. Examples of Field Types are "Text", "Long text", "Date", "Multiple selection (checkbox)", "Relationship with another item", etc (see full list).
Field types are the objects that represent the types of field that can be used. Examples of Field Types are "Text", "Long text", "Date", "Multiple selection (checkbox)", "Relationship with another item", etc (see full list).
Each field type object have its own settings and web component that will be used to render the interface.
@ -40,13 +40,13 @@ Field Types can be created via plugins and extend the default set of types shipp
## Filters
For every collection, you may choose which metadata will be used to filter the results in a faceted search interface. These are the filters.
For every collection, you may choose which field will be used to filter the results in a faceted search interface. These are the filters.
Filters give the ability to the user to filter items in a collection using a Filter Type.
## Filter Types
Filter types are the different types of interface to filter items in a collections based on one specific Metadata. Examples of Filter Types are "text", "datepicker", "date range picker", "number range slider", etc.
Filter types are the different types of interface to filter items in a collections based on one specific Field. Examples of Filter Types are "text", "datepicker", "date range picker", "number range slider", etc.
Each Filter Type object have its own settings and web component that will be used to render the interface.

View File

@ -102,15 +102,15 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
 }
```
#### Metadata
#### Field
1. Route `wp-json/tainacan/v2/collection/(?P<collection_id>[\d]+)/metadata`
1. Route `wp-json/tainacan/v2/collection/(?P<collection_id>[\d]+)/field`
1.1. Endpoints supported:
1.1.1 POST (Create a metadata in collection and all your items)
1.1.1 POST (Create a field in collection and all your items)
In body of requisition pass a JSON with the attributes of metadata like:
In body of requisition pass a JSON with the attributes of field like:
```javascript
{
@ -130,24 +130,24 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
   }
```
1.1.2 GET (Fetch all collection metadata)
1.1.2 GET (Fetch all collection field)
2. Route `wp-json/tainacan/v2/item/(?P<item_id>[\d]+)/metadata`
2. Route `wp-json/tainacan/v2/item/(?P<item_id>[\d]+)/field`
2.1. Endpoints supported:
2.1.1 POST (Set a value of item metadata)
2.1.1 POST (Set a value of item field)
In body of requisition pass a JSON with value e and id of metadata like:
In body of requisition pass a JSON with value e and id of field like:
```javascript
{
    "metadata_id": "integer",
    "field_id": "integer",
    "values": "[any, type]"
 }
```
2.1.2 GET (Fetch all item metadata, with your values)
2.1.2 GET (Fetch all item field, with your values)
#### Taxonomies
@ -210,7 +210,7 @@ A REST API for Tainacan Plugin. This API uses the Wordpress REST API.
```javascript
{
  "collection_id": "int",
  "metadata_id": "int",
  "field_id": "int",
"filter_type": "string",
  "filter": {
    "name": "string",

View File

@ -31,13 +31,13 @@
<div class="el-upload__tip" slot="tip">imagens em formato jpg/png</div>
</el-upload>
</el-form-item>
<component v-for="(metadata, index) in metadataList" v-bind:key="index" :label="metadata.metadata.name"
:is="extractFieldType(metadata.metadata.field_type)"
:name="metadata.metadata.name"
:item_id="metadata.item.id"
:metadata_id="metadata.metadata.id"
:value="metadata.value"
:multiple="metadata.metadata.multiple"></component>
<component v-for="(field, index) in fieldList" v-bind:key="index" :label="field.field.name"
:is="extractFieldType(field.field.field_type)"
:name="field.field.name"
:item_id="field.item.id"
:field_id="field.field.id"
:value="field.value"
:multiple="field.field.multiple"></component>
<el-form-item>
<el-button type="primary" @click="onSubmit">Criar</el-button>
<el-button>Cancelar</el-button>
@ -86,14 +86,14 @@ export default {
...mapActions('item', [
'sendItem',
'updateItem',
'fetchMetadata',
'sendMetadata'
'fetchFields',
'sendField'
]),
...mapGetters('item',[
'getMetadata'
'getFields'
]),
onSubmit() {
this.getMetadata();
this.getFields();
let data = {item_id: this.itemId, title: this.form.title, description: this.form.description, status: this.form.status};
this.updateItem(data);
},
@ -103,8 +103,8 @@ export default {
}
},
computed: {
metadataList(){
return this.getMetadata();
fieldList(){
return this.getFields();
}
},
created(){
@ -123,8 +123,8 @@ export default {
// Fill this.form data with current data.
// TODO
loadingInstance.text = 'Carregando metadados...';
// Obtains Item Metadata
this.fetchMetadata(this.itemId).then(res => {
// Obtains Item Field
this.fetchFields(this.itemId).then(res => {
loadingInstance.close();
});

View File

@ -7,8 +7,8 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
private $collection;
private $collection_repository;
private $metadata;
private $metadata_repository;
private $field;
private $field_repository;
private $filter;
private $filter_repository;
@ -31,8 +31,8 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
$this->collection = new Entities\Collection();
$this->collection_repository = new Repositories\Collections();
$this->metadata = new Entities\Metadata();
$this->metadata_repository = new Repositories\Metadatas();
$this->field = new Entities\Field();
$this->field_repository = new Repositories\Fields();
$this->filter = new Entities\Filter();
$this->filter_repository = new Repositories\Filters();
@ -80,7 +80,7 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
$body = json_decode($request->get_body(), true);
$collection_id = $body['collection_id'];
$metadata_id = $body['metadata_id'];
$field_id = $body['field_id'];
$filter = $body['filter'];
$received_type = $body['filter_type'];
@ -107,7 +107,7 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
}
$this->filter->set_collection_id($collection_id);
$this->filter->set_metadata($metadata_id);
$this->filter->set_field($field_id);
$this->filter->set_filter_type($filter_type);
}

View File

@ -183,15 +183,15 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
$this->item->set_collection($collection);
$metadata = get_post_meta($collection->get_id());
$field = get_post_meta($collection->get_id());
if(!empty($metadata)) {
foreach ($metadata as $key => $value){
$new_metadata = new Entities\Metadata();
if(!empty($field)) {
foreach ($field as $key => $value){
$new_field = new Entities\Field();
try {
$set_ = 'set_' . $key;
$new_metadata->$set_( $value );
$new_field->$set_( $value );
} catch (\Error $exception){
// Do nothing
}
@ -199,7 +199,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
}
return $new_metadata;
return $new_field;
}
/**
@ -219,7 +219,7 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
}
try {
$metadata = $this->prepare_item_for_database( [ $item, $collection_id ] );
$field = $this->prepare_item_for_database( [ $item, $collection_id ] );
} catch (\Error $exception){
return new WP_REST_Response($exception->getMessage(), 400);
}
@ -227,10 +227,10 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
if($this->item->validate()) {
$item = $this->items_repository->insert($this->item );
$item_metadata = new Entities\Item_Metadata_Entity($item, $metadata );
$metadata_added = $this->item_metadata->insert( $item_metadata );
$item_metadata = new Entities\Item_Metadata_Entity($item, $field );
$field_added = $this->item_metadata->insert( $item_metadata );
return new WP_REST_Response($metadata_added->get_item()->__toArray(), 201 );
return new WP_REST_Response($field_added->get_item()->__toArray(), 201 );
}

View File

@ -4,15 +4,15 @@ use Tainacan\Entities;
use Tainacan\Repositories;
class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
private $metadata;
private $metadata_repository;
private $field;
private $field_repository;
private $item_metadata_repository;
private $item_repository;
private $collection_repository;
public function __construct() {
$this->namespace = 'tainacan/v2';
$this->rest_base = 'metadata';
$this->rest_base = 'field';
add_action('rest_api_init', array($this, 'register_routes'));
add_action('init', array(&$this, 'init_objects'), 11);
@ -22,24 +22,24 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
* Initialize objects after post_type register
*/
public function init_objects() {
$this->metadata = new Entities\Metadata();
$this->metadata_repository = new Repositories\Metadatas();
$this->field = new Entities\Field();
$this->metadata_repository = new Repositories\Fields();
$this->item_metadata_repository = new Repositories\Item_Metadata();
$this->item_repository = new Repositories\Items();
$this->collection_repository = new Repositories\Collections();
}
/**
* If POST on metadata/collection/<collection_id>, then
* a metadata will be created in matched collection and all your item will receive this metadata
* If POST on field/collection/<collection_id>, then
* a field will be created in matched collection and all your item will receive this field
*
* If POST on metadata/item/<item_id>, then a value will be added in a field and metadata passed
* If POST on field/item/<item_id>, then a value will be added in a field and field passed
* id body of requisition
*
* Both of GETs return the metadata of matched objects
* Both of GETs return the field of matched objects
*/
public function register_routes() {
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<metadata_id>[\d]+)',
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<field_id>[\d]+)',
array(
array(
'methods' => WP_REST_Server::DELETABLE,
@ -53,7 +53,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
)
)
);
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/' . $this->rest_base . '/(?P<metadata_id>[\d]+)',
register_rest_route($this->namespace, '/item/(?P<item_id>[\d]+)/' . $this->rest_base . '/(?P<field_id>[\d]+)',
array(
array(
'methods' => WP_REST_Server::EDITABLE,
@ -104,12 +104,12 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
foreach ($meta as $key => $value){
$set_ = 'set_' . $key;
$this->metadata->$set_($value);
$this->field->$set_($value);
}
$collection = new Entities\Collection($request[1]);
$this->metadata->set_collection($collection);
$this->field->set_collection($collection);
}
/**
@ -127,51 +127,51 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
return new WP_REST_Response($exception->getMessage(), 400);
}
if($this->metadata->validate()) {
$this->metadata_repository->insert( $this->metadata );
if($this->field->validate()) {
$this->metadata_repository->insert( $this->field );
$items = $this->item_repository->fetch([], $collection_id, 'WP_Query');
$metadata_added = '';
$field_added = '';
if($items->have_posts()){
while ($items->have_posts()){
$items->the_post();
$item = new Entities\Item($items->post);
$item_meta = new Entities\Item_Metadata_Entity($item, $this->metadata);
$item_meta = new Entities\Item_Metadata_Entity($item, $this->field);
$metadata_added = $this->item_metadata_repository->insert($item_meta);
$field_added = $this->item_metadata_repository->insert($item_meta);
}
return new WP_REST_Response($metadata_added->get_metadata()->__toArray(), 201);
return new WP_REST_Response($field_added->get_field()->__toArray(), 201);
}
else {
return new WP_REST_Response($this->metadata->__toArray(), 201);
return new WP_REST_Response($this->field->__toArray(), 201);
}
} else {
return new WP_REST_Response([
'error_message' => __('One or more values are invalid.', 'tainacan'),
'errors' => $this->metadata->get_errors(),
'metadata' => $this->metadata->__toArray(),
'errors' => $this->field->get_errors(),
'field' => $this->field->__toArray(),
], 400);
}
} elseif (!empty($request['item_id']) && !empty($request->get_body())){
$body = json_decode($request->get_body(), true);
$item_id = $request['item_id'];
$metadata_id = $body['metadata_id'];
$field_id = $body['field_id'];
$value = $body['values'];
$item = $this->item_repository->fetch($item_id);
$metadata = $this->metadata_repository->fetch($metadata_id);
$field = $this->metadata_repository->fetch($field_id);
$item_metadata = new Entities\Item_Metadata_Entity($item, $metadata);
$item_metadata = new Entities\Item_Metadata_Entity($item, $field);
$item_metadata->set_value($value);
if($item_metadata->validate()) {
$metadata_updated = $this->item_metadata_repository->insert( $item_metadata );
$field_updated = $this->item_metadata_repository->insert( $item_metadata );
return new WP_REST_Response( $metadata_updated->__toArray(), 201 );
return new WP_REST_Response( $field_updated->__toArray(), 201 );
} else {
return new WP_REST_Response([
'error_message' => __('One or more values are invalid.', 'tainacan'),
@ -208,20 +208,20 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
* @return array|WP_Error|WP_REST_Response
*/
public function prepare_item_for_response( $item, $request ) {
$metadata_as = [];
$field_as = [];
if($request['item_id']) {
foreach ( $item as $metadata ) {
$metadata_as[] = $metadata->__toArray();
foreach ( $item as $field ) {
$field_as[] = $field->__toArray();
}
} else if($request['collection_id']){
foreach ( $item as $metadata ) {
$metadata_as[] = $metadata->__toArray();
foreach ( $item as $field ) {
$field_as[] = $field->__toArray();
}
}
return $metadata_as;
return $field_as;
}
/**
@ -295,7 +295,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
$body = json_decode($request->get_body());
$collection_id = $request['collection_id'];
$metadata_id = $body['metadata_id'];
$field_id = $body['field_id'];
return new WP_REST_Response(['error' => 'Not Implemented.'], 400);
}
@ -336,19 +336,19 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
$body = json_decode( $request->get_body(), true );
$item_id = $request['item_id'];
$metadata_id = $request['metadata_id'];
$field_id = $request['field_id'];
$value = $body['values'];
$item = $this->item_repository->fetch( $item_id );
$metadata = $this->metadata_repository->fetch( $metadata_id );
$field = $this->metadata_repository->fetch( $field_id );
$item_metadata = new Entities\Item_Metadata_Entity( $item, $metadata );
$item_metadata = new Entities\Item_Metadata_Entity( $item, $field );
$item_metadata->set_value( $value );
if ( $item_metadata->validate() ) {
$metadata_updated = $this->item_metadata_repository->update( $item_metadata );
$field_updated = $this->item_metadata_repository->update( $item_metadata );
return new WP_REST_Response( $metadata_updated->__toArray(), 200 );
return new WP_REST_Response( $field_updated->__toArray(), 200 );
} else {
return new WP_REST_Response( [
'error_message' => __( 'One or more values are invalid.', 'tainacan' ),
@ -367,17 +367,17 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
if(!empty($body)){
$attributes = [];
$metadata_id = $request['metadata_id'];
$field_id = $request['field_id'];
foreach ($body['values'] as $att => $value){
$attributes[$att] = $value;
}
$metadata = $this->metadata_repository->fetch($metadata_id);
$field = $this->metadata_repository->fetch($field_id);
$updated_metadata = $this->metadata_repository->update($metadata, $attributes);
$updated_metadata = $this->metadata_repository->update($field, $attributes);
if(!($updated_metadata instanceof Entities\Metadata)){
if(!($updated_metadata instanceof Entities\Field)){
return new WP_REST_Response($updated_metadata, 400);
}
@ -394,7 +394,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_REST_Controller {
$up_metadata = $this->item_metadata_repository->update($item_meta);
}
return new WP_REST_Response($up_metadata->get_metadata()->__toArray(), 201);
return new WP_REST_Response($up_metadata->get_field()->__toArray(), 201);
}
return new WP_REST_Response($updated_metadata->__toArray(), 201);

View File

@ -49,7 +49,7 @@ class Capabilities {
"read"
]
],
"tainacan-metadata"=> [
"tainacan-field"=> [
"administrator"=> [
"delete_posts",
"delete_private_posts",

View File

@ -267,17 +267,17 @@ class Collection extends Entity {
}
/**
* Get collection metadata.
* Get collection field.
*
* Returns an array of \Entity\Metadata objects, representing all the metadata of the collection.
* Returns an array of \Entity\Field objects, representing all the field of the collection.
*
* @see \Tainacan\Repositories\Metadatas->fetch()
* @see \Tainacan\Repositories\Fields->fetch()
*
* @return [\Tainacan\Entities\Metadata] array
* @return [\Tainacan\Entities\Field] array
*/
function get_metadata() {
$Tainacan_Metadatas = new \Tainacan\Repositories\Metadatas();
return $Tainacan_Metadatas->fetch_by_collection( $this, [], 'OBJECT' );
function get_field() {
$Tainacan_Fields = new \Tainacan\Repositories\Fields();
return $Tainacan_Fields->fetch_by_collection( $this, [], 'OBJECT' );
}
/**

View File

@ -5,27 +5,27 @@ namespace Tainacan\Entities;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Represents the Entity Metadata
* Represents the Entity Field
*/
class Metadata extends Entity {
class Field extends Entity {
// Collection getter and setter declared here
use \Tainacan\Traits\Entity_Collection_Relation;
protected static $post_type = 'tainacan-metadata';
protected static $post_type = 'tainacan-field';
/**
* {@inheritDoc}
* @see \Tainacan\Entities\Entity::repository
* @var string
*/
protected $repository = 'Tainacan_Metadatas';
protected $repository = 'Tainacan_Fields';
public function __toString(){
return 'Hello, my name is '. $this->get_name();
}
/**
* Return the metadata name
* Return the field name
*
* @return string
*/
@ -34,7 +34,7 @@ class Metadata extends Entity {
}
/**
* Return the metadata order type
* Return the field order type
*
* @return string
*/
@ -52,7 +52,7 @@ class Metadata extends Entity {
}
/**
* Return the metadata description
* Return the field description
*
* @return string
*/
@ -61,7 +61,7 @@ class Metadata extends Entity {
}
/**
* Return if is a required metadata
* Return if is a required field
*
* @return boolean
*/
@ -70,7 +70,7 @@ class Metadata extends Entity {
}
/**
* Return if is a multiple metadata
* Return if is a multiple field
*
* @return boolean
*/
@ -88,7 +88,7 @@ class Metadata extends Entity {
}
/**
* Return if metadata is key
* Return if field is key
*
* @return boolean
*/
@ -115,7 +115,7 @@ class Metadata extends Entity {
}
/**
* Return the metadata default value
* Return the field default value
*
* @return string || integer
*/
@ -154,7 +154,7 @@ class Metadata extends Entity {
}
/**
* Set the metadata name
* Set the field name
*
* @param [string] $value
* @return void
@ -164,7 +164,7 @@ class Metadata extends Entity {
}
/**
* Set manually the order of the metadata
* Set manually the order of the field
*
* @param [string] $value
* @return void
@ -174,7 +174,7 @@ class Metadata extends Entity {
}
/**
* Set the metadata parent ID
* Set the field parent ID
*
* @param [integer] $value The ID from parent
* @return void
@ -184,7 +184,7 @@ class Metadata extends Entity {
}
/**
* Set metadata description
* Set field description
*
* @param [string] $value The text description
* @return void
@ -194,7 +194,7 @@ class Metadata extends Entity {
}
/**
* Allow the metadata be required
* Allow the field be required
*
* @param [boolean] $value
* @return void
@ -234,7 +234,7 @@ class Metadata extends Entity {
}
/**
* Set mask for the metadata
* Set mask for the field
*
* @param [string] $value
* @return void

View File

@ -51,13 +51,13 @@ class Filter extends Entity {
}
/**
* Return the metadata
* Return the field
*
* @return Metadata
* @return Field
*/
function get_metadata() {
$id = $this->get_mapped_property('metadata');
return new Metadata( $id );
function get_field() {
$id = $this->get_mapped_property('field');
return new Field( $id );
}
/**
@ -131,15 +131,15 @@ class Filter extends Entity {
}
/**
* Define the filter metadata
* Define the filter field
*
* @param \Tainacan\Entities\Metadata
* @param \Tainacan\Entities\Field
* @return void
*/
function set_metadata( $value ){
$id = ( $value instanceof Metadata ) ? $value->get_id() : $value;
$id = ( $value instanceof Field ) ? $value->get_id() : $value;
$this->set_mapped_property('metadata', $id);
$this->set_mapped_property('field', $id);
}
/**

View File

@ -5,7 +5,7 @@ namespace Tainacan\Entities;
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/**
* Represents the Item Metadata Entity
* Represents the Item Field Entity
*/
class Item_Metadata_Entity extends Entity {
protected static $post_type = false;
@ -16,20 +16,20 @@ class Item_Metadata_Entity extends Entity {
*/
protected $repository = 'Tainacan_Item_Metadata';
function __construct(Item $item, Metadata $metadata) {
function __construct(Item $item, Field $field) {
$this->set_item($item);
$this->set_metadata($metadata);
$this->set_field($field);
}
public function __toString(){
return 'Hello, I\'m the Item Metadata Entity';
return 'Hello, I\'m the Item Field Entity';
}
public function __toArray(){
$as_array['value'] = $this->get_value();
$as_array['item'] = $this->get_item()->__toArray();
$as_array['metadata'] = $this->get_metadata()->__toArray();
$as_array['field'] = $this->get_field()->__toArray();
return $as_array;
}
@ -45,7 +45,7 @@ class Item_Metadata_Entity extends Entity {
}
/**
* Define the metadata value
* Define the field value
*
* @param [integer | string] $value
* @return void
@ -55,13 +55,13 @@ class Item_Metadata_Entity extends Entity {
}
/**
* Define the metadata
* Define the field
*
* @param Metadata $metadata
* @param Field $field
* @return void
*/
function set_metadata(Metadata $metadata) {
$this->metadata = $metadata;
function set_field(Field $field) {
$this->field = $field;
}
/**
@ -74,16 +74,16 @@ class Item_Metadata_Entity extends Entity {
}
/**
* Return the metadata
* Return the field
*
* @return Metadata
* @return Field
*/
function get_metadata() {
return $this->metadata;
function get_field() {
return $this->field;
}
/**
* Return the metadata value
* Return the field value
*
* @return string | integer
*/
@ -96,30 +96,30 @@ class Item_Metadata_Entity extends Entity {
}
/**
* Return true if metadata is multiple, else return false
* Return true if field is multiple, else return false
*
* @return boolean
*/
function is_multiple() {
return $this->get_metadata()->is_multiple();
return $this->get_field()->is_multiple();
}
/**
* Return true if metadata is key
* Return true if field is key
*
* @return boolean
*/
function is_collection_key() {
return $this->get_metadata()->is_collection_key();
return $this->get_field()->is_collection_key();
}
/**
* Return true if metadata is required
* Return true if field is required
*
* @return boolean
*/
function is_required() {
return $this->get_metadata()->is_required();
return $this->get_field()->is_required();
}
/**
@ -129,11 +129,11 @@ class Item_Metadata_Entity extends Entity {
*/
function validate() {
$value = $this->get_value();
$metadata = $this->get_metadata();
$field = $this->get_field();
$item = $this->get_item();
if (empty($value) && $this->is_required()) {
$this->add_error('required', $metadata->get_name() . ' is required');
$this->add_error('required', $field->get_name() . ' is required');
return false;
}
@ -154,19 +154,19 @@ class Item_Metadata_Entity extends Entity {
}
if ($this->is_required() && !$one_filled) {
$this->add_error('required', $metadata->get_name() . ' is required');
$this->add_error('required', $field->get_name() . ' is required');
return false;
}
if (!$valid) {
$this->add_error('invalid', $metadata->get_name() . ' is invalid');
$this->add_error('invalid', $field->get_name() . ' is invalid');
return false;
}
$this->set_as_valid();
return true;
} else {
$this->add_error('invalid', $metadata->get_name() . ' is invalid');
$this->add_error('invalid', $field->get_name() . ' is invalid');
return false;
}
} else {
@ -177,14 +177,14 @@ class Item_Metadata_Entity extends Entity {
$test = $Tainacan_Items->fetch([
'meta_query' => [
[
'key' => $this->metadata->get_id(),
'key' => $this->field->get_id(),
'value' => $value
],
]
], $item->get_collection());
if ($test->have_posts()) {
$this->add_error('key_exists', $metadata->get_name() . ' is a collection key and there is another item with the same value');
$this->add_error('key_exists', $field->get_name() . ' is a collection key and there is another item with the same value');
return false;
}
}

View File

@ -165,20 +165,20 @@ class Item extends Entity {
}
/**
* Return a Metadata or a List of Metadata
* Return a Field or a List of Field
*
* @return array || Metadata
* @return array || Field
*/
function get_metadata() {
global $Tainacan_Metadatas;
function get_field() {
global $Tainacan_Fields;
if (isset($this->metadata))
return $this->metadata;
if (isset($this->field))
return $this->field;
$collection = $this->get_collection();
$all_metadata = [];
if ($collection) {
$meta_list = $Tainacan_Metadatas->fetch_by_collection( $collection, [], 'OBJECT' );
$meta_list = $Tainacan_Fields->fetch_by_collection( $collection, [], 'OBJECT' );
foreach ($meta_list as $meta) {
$all_metadata[$meta->get_id()] = new Item_Metadata_Entity($this, $meta);
@ -188,20 +188,20 @@ class Item extends Entity {
}
/**
* Define the Metadata
* Define the Field
*
* @param Metadata $new_metadata
* @param Field $new_metadata
* @param [string || integer || array] $value
* @return void
*/
function add_metadata(Metadata $new_metadata, $value) {
function add_metadata(Field $new_metadata, $value) {
//TODO Multiple metadata must receive an array as value
//TODO Multiple field must receive an array as value
$item_metadata = new Item_Metadata_Entity($this, $new_metadata);
$item_metadata->set_value($value);
$current_meta = $this->get_metadata();
$current_meta = $this->get_field();
$current_meta[$new_metadata->get_id()] = $item_metadata;
$this->set_metadata($current_meta);
@ -210,11 +210,11 @@ class Item extends Entity {
/**
* Aux function for @method add_metadata
*
* @param array $metadata
* @param array $field
* @return void
*/
function set_metadata(Array $metadata) {
$this->metadata = $metadata;
function set_metadata(Array $field) {
$this->field = $field;
}
/**

View File

@ -33,7 +33,7 @@
item_id: {
type: Number
},
metadata_id: {
field_id: {
type: Number
},
value: {
@ -54,7 +54,7 @@
const array_values = JSON.parse( this.value );
if ( array_values.length > 0 ){
this.checked = array_values;
this.$store.dispatch('item/setSingleMetadata', { item_id: this.item_id, metadata_id: this.metadata_id, values: array_values });
this.$store.dispatch('item/setSingleMetadata', { item_id: this.item_id, field_id: this.field_id, values: array_values });
}
},
sendValue ( event ){
@ -64,7 +64,7 @@
}else{
this.checked.push( event.target.value );
}
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, metadata_id: this.metadata_id, values: this.checked });
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, field_id: this.field_id, values: this.checked });
},
isChecked ( value ){
let index = this.checked.indexOf( value );

View File

@ -23,10 +23,10 @@ class Checkbox extends Field_Type {
public function render( $itemMetadata ){
$options = ( isset( $this->options['options'] ) ) ? $this->options['options'] : '';
return '<tainacan-checkbox options="'.$options.'"
metadata_id ="'.$itemMetadata->get_metadata()->get_id().'"
field_id ="'.$itemMetadata->get_field()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_metadata()->get_name().'"></tainacan-checkbox>';
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-checkbox>';
}
/**
@ -37,7 +37,7 @@ class Checkbox extends Field_Type {
<tr>
<td>
<label><?php echo __('Options','tainacan'); ?></label><br/>
<small><?php echo __('Insert the options, separate by lines for the metadata value','tainacan'); ?></small>
<small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small>
</td>
<td>
<textarea name="field_type_checkbox[options]"><?php echo ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; ?></textarea>

View File

@ -22,7 +22,7 @@
props: {
name: { type: String },
item_id: { type: Number },
metadata_id: { type: Number },
field_id: { type: Number },
value: { type: [ String,Number ] },
errorsMsg: { type: [ String,Number ] },
},
@ -36,7 +36,7 @@
},
methods: {
changeValue(){
this.$emit('input', { item_id: this.item_id, metadata_id: this.metadata_id, values: event.target.value } );
this.$emit('input', { item_id: this.item_id, field_id: this.field_id, values: event.target.value } );
},
getValue(){
try{

View File

@ -22,10 +22,10 @@ class Date extends Field_Type {
*/
public function render( $itemMetadata ){
return '<tainacan-date metadata_id ="'.$itemMetadata->get_metadata()->get_id().'"
return '<tainacan-date field_id ="'.$itemMetadata->get_field()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_metadata()->get_name().'"></tainacan-date>';
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-date>';
}
/**

View File

@ -19,8 +19,8 @@ abstract class Field_Type {
}
public function register_field_type(){
global $Tainacan_Metadatas;
$Tainacan_Metadatas->register_field_type( $this );
global $Tainacan_Fields;
$Tainacan_Fields->register_field_type( $this );
}
public function validate($value) {

View File

@ -13,13 +13,13 @@
props: {
name: { type: String },
item_id: { type: Number },
metadata_id: { type: Number },
field_id: { type: Number },
value: { type: [ String,Number ] },
errorsMsg: { type: [ String,Number ] },
},
methods: {
changeValue( event ){
this.$emit('changeValue', { item_id: this.item_id, metadata_id: this.metadata_id, values: event.target.value } );
this.$emit('changeValue', { item_id: this.item_id, field_id: this.field_id, values: event.target.value } );
},
getValue(){
try{

View File

@ -22,10 +22,10 @@ class Numeric extends Field_Type {
public function render( $itemMetadata ){
return '<tainacan-numeric
metadata_id ="'.$itemMetadata->get_metadata()->get_id().'"
field_id ="'.$itemMetadata->get_field()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_metadata()->get_name().'"></tainacan-numeric>';
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-numeric>';
}
/**

View File

@ -22,7 +22,7 @@ class Radio extends Field_Type {
public function render( $itemMetadata ){
$options = ( isset( $this->options['options'] ) ) ? $this->options['options'] : '';
return '<tainacan-radio options="'.$options.'" name="'.$itemMetadata->get_metadata()->get_name().'"></tainacan-radio>';
return '<tainacan-radio options="'.$options.'" name="'.$itemMetadata->get_field()->get_name().'"></tainacan-radio>';
}
/**
@ -33,7 +33,7 @@ class Radio extends Field_Type {
<tr>
<td>
<label><?php echo __('Options','tainacan'); ?></label><br/>
<small><?php echo __('Insert the options, separate by lines for the metadata value','tainacan'); ?></small>
<small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small>
</td>
<td>
<textarea name="field_type_radio[options]"><?php echo ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; ?></textarea>

View File

@ -34,7 +34,7 @@
item_id: {
type: Number
},
metadata_id: {
field_id: {
type: Number
},
value: {
@ -51,22 +51,22 @@
},
manageValue : {
get(){
let metadata = this.$store.getters['item/getMetadata'].find(metadata => metadata.metadata_id === this.metadata_id );
if( metadata ){
return metadata.values;
let field = this.$store.getters['item/getMetadata'].find(field => field.field_id === this.field_id );
if( field ){
return field.values;
}else if( this.value ){
return JSON.parse( this.value );
}
},
set( value ){
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, metadata_id: this.metadata_id, values: value });
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, field_id: this.field_id, values: value });
}
}
},
methods: {
setInitValueOnStore(){
if ( this.value ){
this.$store.dispatch('item/setSingleMetadata', { item_id: this.item_id, metadata_id: this.metadata_id, values: JSON.parse( this.value ) });
this.$store.dispatch('item/setSingleMetadata', { item_id: this.item_id, field_id: this.field_id, values: JSON.parse( this.value ) });
}
}
}

View File

@ -23,7 +23,7 @@ class Relationship extends Field_Type {
*/
public function render( $itemMetadata ){
return '<tainacan-relationship name="'.$itemMetadata->get_metadata()->get_name().'"></tainacan-relationship>';
return '<tainacan-relationship name="'.$itemMetadata->get_field()->get_name().'"></tainacan-relationship>';
}
/**
@ -43,8 +43,8 @@ class Relationship extends Field_Type {
<?php if( $this->options['collection_id'] ): ?>
<tr>
<td>
<label><?php echo __('Metadata for search','tainacan'); ?></label><br/>
<small><?php echo __('Selected metadata to help in the search','tainacan'); ?></small>
<label><?php echo __('Field for search','tainacan'); ?></label><br/>
<small><?php echo __('Selected field to help in the search','tainacan'); ?></small>
</td>
<td>
<?php Helpers\HtmlHelpers::metadata_checkbox_list(
@ -67,7 +67,7 @@ class Relationship extends Field_Type {
<?php if( isset( $this->options['collection_id'] ) ): ?>
<?php
//filter only related metadata
//filter only related field
$args = array( 'meta_query' => array ( array(
'key' => 'field_type',
'value' => 'Tainacan\Field_Types\Relationship',
@ -77,7 +77,7 @@ class Relationship extends Field_Type {
<tr>
<td>
<label><?php echo __('Inverse','tainacan'); ?></label><br/>
<small><?php echo __('Select the relationship inverse for this metadata','tainacan'); ?></small>
<small><?php echo __('Select the relationship inverse for this field','tainacan'); ?></small>
</td>
<td>
<?php Helpers\HtmlHelpers::metadata_dropdown(

View File

@ -34,7 +34,7 @@
item_id: {
type: Number
},
metadata_id: {
field_id: {
type: Number
},
value: {
@ -51,22 +51,22 @@
},
manageValue : {
get(){
let metadata = this.$store.getters['item/getMetadata'].find(metadata => metadata.metadata_id === this.metadata_id );
if( metadata ){
return metadata.values;
let field = this.$store.getters['item/getMetadata'].find(field => field.field_id === this.field_id );
if( field ){
return field.values;
}else if( this.value ){
return JSON.parse( this.value );
}
},
set( value ){
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, metadata_id: this.metadata_id, values: value });
this.$store.dispatch('item/sendMetadata', { item_id: this.item_id, field_id: this.field_id, values: value });
}
}
},
methods: {
setInitValueOnStore(){
if ( this.value ){
this.$store.dispatch('item/updateMetadata', { item_id: this.item_id, metadata_id: this.metadata_id, values: JSON.parse( this.value ) });
this.$store.dispatch('item/updateMetadata', { item_id: this.item_id, field_id: this.field_id, values: JSON.parse( this.value ) });
}
}
}

View File

@ -23,10 +23,10 @@ class Selectbox extends Field_Type {
public function render( $itemMetadata ){
$options = ( isset( $this->options['options'] ) ) ? $this->options['options'] : '';
return '<tainacan-selectbox options="'.$options.'"
metadata_id ="'.$itemMetadata->get_metadata()->get_id().'"
field_id ="'.$itemMetadata->get_field()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_metadata()->get_name().'"></tainacan-selectbox>';
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-selectbox>';
}
/**
@ -37,7 +37,7 @@ class Selectbox extends Field_Type {
<tr>
<td>
<label><?php echo __('Options','tainacan'); ?></label><br/>
<small><?php echo __('Insert the options, separate by lines for the metadata value','tainacan'); ?></small>
<small><?php echo __('Insert the options, separate by lines for the field value','tainacan'); ?></small>
</td>
<td>
<textarea name="field_type_selectbox[options]"><?php echo ( isset( $this->options['options'] ) ) ? $this->options['options'] : ''; ?></textarea>

View File

@ -20,7 +20,7 @@
name: { type: String },
required: { type: Boolean },
item_id: { type: Number },
metadata_id: { type: Number },
field_id: { type: Number },
value: { },
message: { type: [ String,Number ] },
multiple: { type: String }
@ -40,8 +40,8 @@
},
methods: {
changeValue(){
this.$emit('changeValues', { item_id: this.item_id, metadata_id: this.metadata_id, values: this.inputs } );
eventBus.$emit('input', { item_id: this.item_id, metadata_id: this.metadata_id, values: this.inputs, instance: this } );
this.$emit('changeValues', { item_id: this.item_id, field_id: this.field_id, values: this.inputs } );
eventBus.$emit('input', { item_id: this.item_id, field_id: this.field_id, values: this.inputs, instance: this } );
},
getValue(){
if (this.value instanceof Array) {

View File

@ -21,10 +21,10 @@ class Text extends Field_Type {
*/
public function render( $itemMetadata ){
return '<tainacan-text metadata_id ="'.$itemMetadata->get_metadata()->get_id().'"
return '<tainacan-text field_id ="'.$itemMetadata->get_field()->get_id().'"
item_id="'.$itemMetadata->get_item()->get_id().'"
value=\''.json_encode( $itemMetadata->get_value() ).'\'
name="'.$itemMetadata->get_metadata()->get_name().'"></tainacan-text>';
name="'.$itemMetadata->get_field()->get_name().'"></tainacan-text>';
}
/**

View File

@ -21,7 +21,7 @@ class Textarea extends Field_Type {
*/
public function render( $itemMetadata ){
return '<tainacan-textarea name="'.$itemMetadata->get_metadata()->get_name().'"></tainacan-textarea>';
return '<tainacan-textarea name="'.$itemMetadata->get_field()->get_name().'"></tainacan-textarea>';
}
/**

View File

@ -9,7 +9,7 @@ abstract class Filter_Type {
private $supported_types = [];
public $options;
abstract function render( $metadata );
abstract function render( $field );
public function get_supported_types(){
return $this->supported_types;

View File

@ -14,7 +14,7 @@ class List_Filter extends Filter_Type {
}
/**
* @param $metadata
* @param $field
* @return string
*/

View File

@ -14,7 +14,7 @@ class Range extends Filter_Type {
}
/**
* @param $metadata
* @param $field
* @return string
*/
public function render( $filter ){

View File

@ -141,7 +141,7 @@ class Collections extends Repository {
* Properties yet to be implemented
*
* Moderators (a property attached to the collection or to the user?)
* geo metadata?
* geo field?
*
*
*

View File

@ -7,10 +7,10 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
use \Respect\Validation\Validator as v;
/**
* Class Metadatas
* Class Fields
*/
class Metadatas extends Repository {
public $entities_type = '\Tainacan\Entities\Metadata';
class Fields extends Repository {
public $entities_type = '\Tainacan\Entities\Field';
protected $default_metadata = 'default';
public $field_types = [];
@ -21,7 +21,7 @@ class Metadatas extends Repository {
'map' => 'post_title',
'title' => __('Name', 'tainacan'),
'type' => 'string',
'description'=> __('Name of the metadata', 'tainacan'),
'description'=> __('Name of the field', 'tainacan'),
'on_error' => __('The name should be a text value and not empty', 'tainacan'),
'validation' => v::stringType()->notEmpty(),
],
@ -29,7 +29,7 @@ class Metadatas extends Repository {
'map' => 'menu_order',
'title' => __('Order', 'tainacan'),
'type' => 'string',
'description'=> __('Metadata order. Field used if collections are manually ordered', 'tainacan'),
'description'=> __('Field order. Field used if collections are manually ordered', 'tainacan'),
'on_error' => __('The menu order should be a numeric value', 'tainacan'),
//'validation' => v::numeric(),
],
@ -37,7 +37,7 @@ class Metadatas extends Repository {
'map' => 'parent',
'title' => __('Parent', 'tainacan'),
'type' => 'integer',
'description'=> __('Parent metadata', 'tainacan'),
'description'=> __('Parent field', 'tainacan'),
//'on_error' => __('The Parent should be numeric value', 'tainacan'),
//'validation' => v::numeric(),
],
@ -45,7 +45,7 @@ class Metadatas extends Repository {
'map' => 'post_content',
'title' => __('Description', 'tainacan'),
'type' => 'string',
'description'=> __('The metadata description', 'tainacan'),
'description'=> __('The field description', 'tainacan'),
'default' => '',
//'on_error' => __('The description should be a text value', 'tainacan'),
//'validation' => v::stringType()->notEmpty(),
@ -54,16 +54,16 @@ class Metadatas extends Repository {
'map' => 'meta',
'title' => __('Type', 'tainacan'),
'type' => 'string',
'description'=> __('The metadata type', 'tainacan'),
'on_error' => __('Metadata type is empty', 'tainacan'),
'description'=> __('The field type', 'tainacan'),
'on_error' => __('Field type is empty', 'tainacan'),
'validation' => v::stringType()->notEmpty(),
],
'required' => [
'map' => 'meta',
'title' => __('Required', 'tainacan'),
'type' => 'string',
'description'=> __('The metadata is required', 'tainacan'),
'on_error' => __('Metadata required field is invalid', 'tainacan'),
'description'=> __('The field is required', 'tainacan'),
'on_error' => __('Field required field is invalid', 'tainacan'),
'validation' => v::stringType()->in(['yes', 'no']), // yes or no
'default' => 'no'
],
@ -71,7 +71,7 @@ class Metadatas extends Repository {
'map' => 'meta',
'title' => __('Collection key', 'tainacan'),
'type' => 'string',
'description'=> __('Metadata value should not be repeated', 'tainacan'),
'description'=> __('Field value should not be repeated', 'tainacan'),
'on_error' => __('Collection key is invalid', 'tainacan'),
'validation' => v::stringType()->in(['yes', 'no']), // yes or no
'default' => 'no'
@ -80,7 +80,7 @@ class Metadatas extends Repository {
'map' => 'meta',
'title' => __('Multiple', 'tainacan'),
'type' => 'string',
'description'=> __('Allow multiple fields for the metadata', 'tainacan'),
'description'=> __('Allow multiple fields for the field', 'tainacan'),
'on_error' => __('Multiple fields is invalid', 'tainacan'),
'validation' => v::stringType()->in(['yes', 'no']), // yes or no. It cant be multiple if its collection_key
'default' => 'no'
@ -98,7 +98,7 @@ class Metadatas extends Repository {
'map' => 'meta',
'title' => __('Privacy', 'tainacan'),
'type' => 'string',
'description'=> __('The metadata should be omitted in item view', 'tainacan'),
'description'=> __('The field should be omitted in item view', 'tainacan'),
'on_error' => __('Privacy is invalid', 'tainacan'),
'validation' => v::stringType()->in(['yes', 'no']), // yes or no. It cant be multiple if its collection_key
'default' => 'no'
@ -107,7 +107,7 @@ class Metadatas extends Repository {
'map' => 'meta',
'title' => __('Mask', 'tainacan'),
'type' => 'string',
'description'=> __('The mask to be used in the metadata', 'tainacan'),
'description'=> __('The mask to be used in the field', 'tainacan'),
//'on_error' => __('Mask is invalid', 'tainacan'),
//'validation' => ''
],
@ -115,7 +115,7 @@ class Metadatas extends Repository {
'map' => 'meta',
'title' => __('Default value', 'tainacan'),
'type' => 'string',
'description'=> __('The value default fot the metadata', 'tainacan'),
'description'=> __('The value default fot the field', 'tainacan'),
],
'field_type_options' => [ // not showed in form
'map' => 'meta',
@ -136,18 +136,18 @@ class Metadatas extends Repository {
public function register_post_type() {
$labels = array(
'name' => __('Metadata', 'tainacan'),
'singular_name' => __('Metadata', 'tainacan'),
'name' => __('Field', 'tainacan'),
'singular_name' => __('Field', 'tainacan'),
'add_new' => __('Add new', 'tainacan'),
'add_new_item' => __('Add new Metadata', 'tainacan'),
'edit_item' => __('Edit Metadata', 'tainacan'),
'new_item' => __('New Metadata', 'tainacan'),
'view_item' => __('View Metadata', 'tainacan'),
'search_items' => __('Search Metadata', 'tainacan'),
'not_found' => __('No Metadata found ', 'tainacan'),
'not_found_in_trash' => __('No Metadata found in trash', 'tainacan'),
'parent_item_colon' => __('Parent Metadata:', 'tainacan'),
'menu_name' => __('Metadata', 'tainacan')
'add_new_item' => __('Add new Field', 'tainacan'),
'edit_item' => __('Edit Field', 'tainacan'),
'new_item' => __('New Field', 'tainacan'),
'view_item' => __('View Field', 'tainacan'),
'search_items' => __('Search Field', 'tainacan'),
'not_found' => __('No Field found ', 'tainacan'),
'not_found_in_trash' => __('No Field found in trash', 'tainacan'),
'parent_item_colon' => __('Parent Field:', 'tainacan'),
'menu_name' => __('Fields', 'tainacan')
);
$args = array(
@ -167,18 +167,18 @@ class Metadatas extends Repository {
'can_export' => true,
'rewrite' => true,
'map_meta_cap' => true,
'capability_type' => Entities\Metadata::get_post_type(),
'capability_type' => Entities\Field::get_post_type(),
'supports' => [
'title',
'editor',
'page-attributes'
]
);
register_post_type(Entities\Metadata::get_post_type(), $args);
register_post_type(Entities\Field::get_post_type(), $args);
}
/**
* constant used in default metadata in attribute collection_id
* constant used in default field in attribute collection_id
*
* @return string the value of constant
*/
@ -219,14 +219,14 @@ class Metadatas extends Repository {
/**
* fetch metadata based on ID or WP_Query args
* fetch field based on ID or WP_Query args
*
* metadata are stored as posts. Check WP_Query docs
* field are stored as posts. Check WP_Query docs
* to learn all args accepted in the $args parameter (@see https://developer.wordpress.org/reference/classes/wp_query/)
* You can also use a mapped property, such as name and description, as an argument and it will be mapped to the
* appropriate WP_Query argument
*
* @param array $args WP_Query args || int $args the metadata id
* @param array $args WP_Query args || int $args the field id
* @param string $output The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
* @return \WP_Query|Array an instance of wp query OR array of entities;
*/
@ -235,7 +235,7 @@ class Metadatas extends Repository {
if( is_numeric($args) ){
$existing_post = get_post($args);
if ($existing_post instanceof \WP_Post) {
return new Entities\Metadata($existing_post);
return new Entities\Field($existing_post);
} else {
return [];
}
@ -246,7 +246,7 @@ class Metadatas extends Repository {
'post_status' => 'publish'
], $args);
$args['post_type'] = Entities\Metadata::get_post_type();
$args['post_type'] = Entities\Field::get_post_type();
$wp_query = new \WP_Query($args);
return $this->fetch_output($wp_query, $output);
@ -254,12 +254,12 @@ class Metadatas extends Repository {
}
/**
* fetch metadata by collection, searches all metadata available
* fetch field by collection, searches all field available
*
* @param Entities\Collection $collection
* @param array $args
* @param string $output The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
* @return Array Entities\Metadata
* @return Array Entities\Field
*/
public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null){
$collection_id = $collection->get_id();
@ -270,7 +270,7 @@ class Metadatas extends Repository {
//insert the actual collection
$parents[] = $collection_id;
//search for default metadata
//search for default field
$parents[] = $this->get_default_metadata_attribute();
$meta_query = array(

View File

@ -62,11 +62,11 @@ class Filters extends Repository {
'description'=> __('Filter color', 'tainacan'),
'validation' => ''
],
'metadata' => [
'field' => [
'map' => 'meta',
'title' => __('Metadata', 'tainacan'),
'title' => __('Field', 'tainacan'),
'type' => 'integer',
'description'=> __('Filter metadata', 'tainacan'),
'description'=> __('Filter field', 'tainacan'),
'validation' => ''
],
]);
@ -116,30 +116,30 @@ class Filters extends Repository {
/**
* @param Entities\Metadata $metadata
* @param Entities\Field $field
* @return int
*
public function insert($metadata) {
public function insert($field) {
// First iterate through the native post properties
$map = $this->get_map();
foreach ($map as $prop => $mapped) {
if ($mapped['map'] != 'meta' && $mapped['map'] != 'meta_multi') {
$metadata->WP_Post->{$mapped['map']} = $metadata->get_mapped_property($prop);
$field->WP_Post->{$mapped['map']} = $field->get_mapped_property($prop);
}
}
// save post and get its ID
$metadata->WP_Post->post_type = Entities\Filter::get_post_type();
$metadata->WP_Post->post_status = 'publish';
$id = wp_insert_post($metadata->WP_Post);
$metadata->WP_Post = get_post($id);
$field->WP_Post->post_type = Entities\Filter::get_post_type();
$field->WP_Post->post_status = 'publish';
$id = wp_insert_post($field->WP_Post);
$field->WP_Post = get_post($id);
// Now run through properties stored as postmeta
foreach ($map as $prop => $mapped) {
if ($mapped['map'] == 'meta') {
update_post_meta($id, $prop, $metadata->get_mapped_property($prop));
update_post_meta($id, $prop, $field->get_mapped_property($prop));
} elseif ($mapped['map'] == 'meta_multi') {
$values = $metadata->get_mapped_property($prop);
$values = $field->get_mapped_property($prop);
delete_post_meta($id, $prop);
@ -152,7 +152,7 @@ class Filters extends Repository {
}
// return a brand new object
return new Entities\Filter($metadata->WP_Post);
return new Entities\Filter($field->WP_Post);
}*/
/**
@ -241,7 +241,7 @@ class Filters extends Repository {
/**
* fetch only supported filters for the type specified
*
* @param ( string || array ) $types Primitve types of metadata ( float, string, int)
* @param ( string || array ) $types Primitve types of field ( float, string, int)
* @return array Filters supported by the primitive types passed in $types
*/
public function fetch_supported_filter_types($types){

View File

@ -12,15 +12,15 @@ class Item_Metadata extends Repository {
$unique = !$item_metadata->is_multiple();
if ($unique) {
add_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), wp_slash( $item_metadata->get_value() ) );
add_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $item_metadata->get_value() ) );
} else {
delete_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id());
delete_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id());
if (is_array($item_metadata->get_value())){
$values = $item_metadata->get_value();
foreach ($values as $value){
add_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), wp_slash( $value ));
add_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $value ));
}
}
}
@ -28,22 +28,22 @@ class Item_Metadata extends Repository {
do_action('tainacan-insert', $item_metadata);
do_action('tainacan-insert-Item_Metadata_Entity', $item_metadata);
return new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_metadata());
return new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_field());
}
public function update($item_metadata, $new_values = null){
$unique = !$item_metadata->is_multiple();
if ($unique) {
update_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), wp_slash( $item_metadata->get_value() ) );
update_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $item_metadata->get_value() ) );
} else {
delete_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id());
delete_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id());
if (is_array($item_metadata->get_value())){
$values = $item_metadata->get_value();
foreach ($values as $value){
update_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), wp_slash( $value ));
update_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash( $value ));
}
}
}
@ -51,11 +51,11 @@ class Item_Metadata extends Repository {
do_action('tainacan-update', $item_metadata);
do_action('tainacan-update-Item_Metadata_Entity', $item_metadata);
return new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_metadata());
return new Entities\Item_Metadata_Entity($item_metadata->get_item(), $item_metadata->get_field());
}
/**
* Delete Item Metadata
* Delete Item Field
*
* @param $item_metadata
*
@ -66,22 +66,22 @@ class Item_Metadata extends Repository {
// $values = $item_metadata->get_value();
//
// foreach ($values as $value){
// delete_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), wp_slash($value));
// delete_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash($value));
// }
// } else {
// delete_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), wp_slash($item_metadata->get_value()));
// delete_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), wp_slash($item_metadata->get_value()));
// }
}
/**
* Fetch Item Metadata objects related to an Item
* Fetch Item Field objects related to an Item
*
* @param Entities\Item $object
* @return array
*/
public function fetch($object, $output = null ){
if($object instanceof Entities\Item){
global $Tainacan_Items, $Tainacan_Metadatas;
global $Tainacan_Items, $Tainacan_Fields;
$collection = $object->get_collection();
@ -89,7 +89,7 @@ class Item_Metadata extends Repository {
return [];
}
$meta_list = $Tainacan_Metadatas->fetch_by_collection($collection, [], 'OBJECT' );
$meta_list = $Tainacan_Fields->fetch_by_collection($collection, [], 'OBJECT' );
$return = [];
@ -106,7 +106,7 @@ class Item_Metadata extends Repository {
}
/**
* Get the value for a Item metadata.
* Get the value for a Item field.
*
* @param Entities\Item_Metadata_Entity $item_metadata
* @return mixed
@ -114,7 +114,7 @@ class Item_Metadata extends Repository {
public function get_value(Entities\Item_Metadata_Entity $item_metadata) {
$unique = ! $item_metadata->is_multiple();
return get_post_meta($item_metadata->item->get_id(), $item_metadata->metadata->get_id(), $unique);
return get_post_meta($item_metadata->item->get_id(), $item_metadata->field->get_id(), $unique);
}
public function register_post_type() { }

View File

@ -71,7 +71,7 @@ class Items extends Repository {
'description' => __('The collection thumbnail URL')
],
//'collection' => 'relation...',
// metadata .. metadata...
// field .. field...
]);
}
@ -106,7 +106,7 @@ class Items extends Repository {
public function insert($item) {
global $Tainacan_Metadatas;
global $Tainacan_Fields;
$map = $this->get_map();
@ -150,11 +150,11 @@ class Items extends Repository {
}
}
// save metadata
$metadata = $item->get_metadata();
// save field
$field = $item->get_field();
global $Tainacan_Item_Metadata;
foreach ($metadata as $meta) {
foreach ($field as $meta) {
$Tainacan_Item_Metadata->insert($meta);
}

View File

@ -351,8 +351,8 @@ abstract class Repository {
}
}
else {
global $Tainacan_Collections,$Tainacan_Metadatas, $Tainacan_Item_Metadata,$Tainacan_Filters,$Tainacan_Taxonomies,$Tainacan_Terms,$Tainacan_Logs;
$tnc_globals = [$Tainacan_Collections,$Tainacan_Metadatas, $Tainacan_Item_Metadata,$Tainacan_Filters,$Tainacan_Taxonomies,$Tainacan_Terms,$Tainacan_Logs];
global $Tainacan_Collections,$Tainacan_Fields, $Tainacan_Item_Metadata,$Tainacan_Filters,$Tainacan_Taxonomies,$Tainacan_Terms,$Tainacan_Logs;
$tnc_globals = [$Tainacan_Collections,$Tainacan_Fields, $Tainacan_Item_Metadata,$Tainacan_Filters,$Tainacan_Taxonomies,$Tainacan_Terms,$Tainacan_Logs];
foreach ($tnc_globals as $tnc_repository)
{
$entity_post_type = $tnc_repository->entities_type::get_post_type();

View File

@ -72,18 +72,18 @@ $Tainacan_Collections = new \Tainacan\Repositories\Collections();
global $Tainacan_Item_Metadata;
$Tainacan_Item_Metadata = new \Tainacan\Repositories\Item_Metadata();
global $Tainacan_Metadatas;
$Tainacan_Metadatas = new \Tainacan\Repositories\Metadatas();
global $Tainacan_Fields;
$Tainacan_Fields = new \Tainacan\Repositories\Fields();
//register field types
$Tainacan_Metadatas->register_field_type('Tainacan\Field_Types\Text');
$Tainacan_Metadatas->register_field_type('Tainacan\Field_Types\Textarea');
$Tainacan_Metadatas->register_field_type('Tainacan\Field_Types\Date');
$Tainacan_Metadatas->register_field_type('Tainacan\Field_Types\Numeric');
$Tainacan_Metadatas->register_field_type('Tainacan\Field_Types\Selectbox');
$Tainacan_Metadatas->register_field_type('Tainacan\Field_Types\Relationship');
$Tainacan_Metadatas->register_field_type('Tainacan\Field_Types\Radio');
$Tainacan_Metadatas->register_field_type('Tainacan\Field_Types\Checkbox');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Text');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Textarea');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Date');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Numeric');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Selectbox');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Relationship');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Radio');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Checkbox');
global $Tainacan_Filters;
$Tainacan_Filters = new \Tainacan\Repositories\Filters();

View File

@ -17,9 +17,9 @@ class DevInterface {
add_filter('post_type_link', array(&$this, 'permalink_filter'), 10, 3);
global $Tainacan_Collections, $Tainacan_Filters, $Tainacan_Logs, $Tainacan_Metadatas, $Tainacan_Taxonomies;
global $Tainacan_Collections, $Tainacan_Filters, $Tainacan_Logs, $Tainacan_Fields, $Tainacan_Taxonomies;
$repositories = [$Tainacan_Collections, $Tainacan_Filters, $Tainacan_Logs, $Tainacan_Metadatas, $Tainacan_Taxonomies];
$repositories = [$Tainacan_Collections, $Tainacan_Filters, $Tainacan_Logs, $Tainacan_Fields, $Tainacan_Taxonomies];
foreach ($repositories as $repo) {
$cpt = $repo->entities_type::get_post_type();
@ -76,7 +76,7 @@ class DevInterface {
/**
* Run through all post types attributes and add metaboxes for them.
*
* Also run through all collections metadata and add metaboxes for its items post type
* Also run through all collections field and add metaboxes for its items post type
*
* @return void
*/
@ -101,8 +101,8 @@ class DevInterface {
foreach ($collections as $col) {
add_meta_box(
$col->get_db_identifier() . '_metadata',
__('Metadata', 'tainacan'),
$col->get_db_identifier() . '_field',
__('Field', 'tainacan'),
array(&$this, 'metadata_metabox'),
$col->get_db_identifier(), //post type
'normal'
@ -111,7 +111,7 @@ class DevInterface {
add_meta_box(
$col->get_db_identifier() . '_metadata_js',
__('Metadata Components', 'tainacan'),
__('Field Components', 'tainacan'),
array(&$this, 'metadata_components_metabox'),
$col->get_db_identifier(), //post type
'normal'
@ -134,9 +134,9 @@ class DevInterface {
global $Tainacan_Logs;
$this->properties_metabox($Tainacan_Logs);
}
function properties_metabox_Metadatas() {
global $Tainacan_Metadatas;
$this->properties_metabox($Tainacan_Metadatas);
function properties_metabox_Fields() {
global $Tainacan_Fields;
$this->properties_metabox($Tainacan_Fields);
}
function properties_metabox_Taxonomies() {
global $Tainacan_Taxonomies;
@ -230,7 +230,7 @@ class DevInterface {
if (!$entity->get_collection_id())
$entity->set_collection($current_collection);
$metadata = $Tainacan_Item_Metadata->fetch($entity, 'OBJECT');
$field = $Tainacan_Item_Metadata->fetch($entity, 'OBJECT');
wp_nonce_field( 'save_metadata_'.$typenow, $typenow.'_metadata_noncename' );
@ -243,14 +243,14 @@ class DevInterface {
<thead>
<tr>
<th class="left"><?php _e('Metadata', 'tainacan'); ?></th>
<th class="left"><?php _e('Field', 'tainacan'); ?></th>
<th><?php _e('Value', 'tainacan'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($metadata as $item_meta): ?>
<?php foreach ($field as $item_meta): ?>
<?php
$value = $item_meta->get_value();
@ -258,11 +258,11 @@ class DevInterface {
?>
<tr>
<td>
<label><?php echo $item_meta->get_metadata()->get_name(); ?></label><br/>
<small><?php echo $item_meta->get_metadata()->get_description(); ?></small>
<label><?php echo $item_meta->get_field()->get_name(); ?></label><br/>
<small><?php echo $item_meta->get_field()->get_description(); ?></small>
</td>
<td>
<textarea name="tnc_metadata_<?php echo $item_meta->get_metadata()->get_id(); ?>"><?php echo htmlspecialchars($value); ?></textarea>
<textarea name="tnc_metadata_<?php echo $item_meta->get_field()->get_id(); ?>"><?php echo htmlspecialchars($value); ?></textarea>
</td>
</tr>
@ -300,7 +300,7 @@ class DevInterface {
if (!$entity->get_collection_id())
$entity->set_collection($current_collection);
$metadata = $Tainacan_Item_Metadata->fetch($entity, 'OBJECT');
$field = $Tainacan_Item_Metadata->fetch($entity, 'OBJECT');
wp_nonce_field( 'save_metadata_'.$typenow, $typenow.'_metadata_noncename' );
@ -313,14 +313,14 @@ class DevInterface {
<thead>
<tr>
<th class="left"><?php _e('Metadata', 'tainacan'); ?></th>
<th class="left"><?php _e('Field', 'tainacan'); ?></th>
<th><?php _e('Value', 'tainacan'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($metadata as $item_meta): ?>
<?php foreach ($field as $item_meta): ?>
<?php
$value = $item_meta->get_value();
@ -328,12 +328,12 @@ class DevInterface {
?>
<tr>
<td>
<label><?php echo $item_meta->get_metadata()->get_name(); ?></label><br/>
<small><?php echo $item_meta->get_metadata()->get_description(); ?></small>
<label><?php echo $item_meta->get_field()->get_name(); ?></label><br/>
<small><?php echo $item_meta->get_field()->get_description(); ?></small>
</td>
<td>
<?php //echo '<tainacan-text name="'.$item_meta->get_metadata()->get_name().'"></tainacan-text>'; ?>
<?php echo $item_meta->get_metadata()->get_field_type_object()->render( $item_meta ); ?>
<?php //echo '<tainacan-text name="'.$item_meta->get_field()->get_name().'"></tainacan-text>'; ?>
<?php echo $item_meta->get_field()->get_field_type_object()->render( $item_meta ); ?>
</td>
</tr>
@ -350,7 +350,7 @@ class DevInterface {
function field_type_dropdown($id,$selected) {
global $Tainacan_Metadatas;
global $Tainacan_Fields;
$class = ( class_exists( $selected ) ) ? new $selected() : '';
@ -358,7 +358,7 @@ class DevInterface {
$selected = str_replace('Tainacan\Field_Types\\','', get_class( $class ) );
}
$field_types = $Tainacan_Metadatas->fetch_field_types('NAME');
$field_types = $Tainacan_Fields->fetch_field_types('NAME');
?>
<select name="tnc_prop_field_type">
<?php foreach ($field_types as $field_type): ?>
@ -447,7 +447,7 @@ class DevInterface {
// TODO: there should ve a method in the repository to find this out
// or I could try to initialize an entity and find out what type it is
global $Tainacan_Collections, $Tainacan_Items, $Tainacan_Metadatas, $Tainacan_Item_Metadata;
global $Tainacan_Collections, $Tainacan_Items, $Tainacan_Fields, $Tainacan_Item_Metadata;
$collections = $Tainacan_Collections->fetch([], 'OBJECT');
$cpts = [];
foreach($collections as $col) {
@ -465,7 +465,7 @@ class DevInterface {
}
$metalist = $Tainacan_Metadatas->fetch_by_collection($cpts[$post_type], [], 'OBJECT');
$metalist = $Tainacan_Fields->fetch_by_collection($cpts[$post_type], [], 'OBJECT');
foreach ($metalist as $meta) {
$item_meta = new \Tainacan\Entities\Item_Metadata_Entity($entity, $meta);

View File

@ -43,21 +43,21 @@ use Tainacan\Entities;
}
/**
* generates select field for all publish metadata for a single collection
* generates select field for all publish field for a single collection
*
* @param Entities\Collection | integer $collection The collection id or the collection object
* @param string $selected The collection id for the selected option
* @param string $name_field (optional) default 'tnc_prop_collections_id'
* @param array $args (optional) filter the metadata list
* @param array $args (optional) filter the field list
*/
public static function metadata_dropdown( $collection , $selected, $name_field = 'tnc_prop_metadata_id', $args = []){
global $Tainacan_Metadatas;
public static function metadata_dropdown( $collection , $selected, $name_field = 'tnc_prop_field_id', $args = []){
global $Tainacan_Fields;
$collection = ( is_numeric( $collection ) ) ? new Entities\Collection( $collection ) : $collection;
$metadata = $Tainacan_Metadatas->fetch_by_collection( $collection, $args, 'OBJECT');
$field = $Tainacan_Fields->fetch_by_collection( $collection, $args, 'OBJECT');
?>
<select name="<?php echo $name_field ?>">
<option value=""><?php echo __('Select an option','tainacan') ?>...</option>
<?php foreach ($metadata as $col): ?>
<?php foreach ($field as $col): ?>
<option value="<?php echo $col->get_id(); ?>" <?php selected($col->get_id(), $selected) ?>><?php echo $col->get_name(); ?></option>
<?php endforeach; ?>
</select>
@ -66,21 +66,21 @@ use Tainacan\Entities;
/**
* generates checkboxes fields for all publish metadata for a single collection
* generates checkboxes fields for all publish field for a single collection
*
* @param Entities\Collection | integer $collection The collection id or the collection object
* @param string(json) $selected string(json) | array json with an array or array of ids to be checked
* @param string $name_field (optional) default 'tnc_prop_tnc_metadata_ids[]' the checkbox field name
* @param array $args (optional) filter the metadata list
* @param string $name_field (optional) default 'tnc_prop_tnc_field_ids[]' the checkbox field name
* @param array $args (optional) filter the field list
*/
public static function metadata_checkbox_list( $collection , $selected,$name_field = 'tnc_prop_tnc_metadata_ids[]', $args = []) {
global $Tainacan_Metadatas;
public static function metadata_checkbox_list( $collection , $selected,$name_field = 'tnc_prop_tnc_field_ids[]', $args = []) {
global $Tainacan_Fields;
$collection = ( is_numeric( $collection ) ) ? new Entities\Collection( $collection ) : $collection;
$metadata = $Tainacan_Metadatas->fetch_by_collection( $collection, $args, 'OBJECT');
$field = $Tainacan_Fields->fetch_by_collection( $collection, $args, 'OBJECT');
$selected = ( is_array( $selected) ) ? $selected : json_decode($selected);
$selected = ( $selected ) ? $selected : [];
?>
<?php foreach ($metadata as $col): ?>
<?php foreach ($field as $col): ?>
<input type="checkbox" name="<?php echo $name_field ?>" value="<?php echo $col->get_id(); ?>" <?php checked(in_array($col->get_id(), $selected)); ?> style="width: 15px;">
<?php echo $col->get_name(); ?>
<br/>

View File

@ -29,8 +29,8 @@ export const eventBus = new Vue({
eventElement.errorsMsg = JSON.stringify( [] );
eventElement.value = response.value;
}, error => {
const metadata = this.errors.find(error => error.metadata_id === event.detail[0].metadata_id );
eventElement.errorsMsg = JSON.stringify( metadata.error );
const field = this.errors.find(error => error.field_id === event.detail[0].field_id );
eventElement.errorsMsg = JSON.stringify( field.error );
eventElement.value = event.detail[0].values;
});
}
@ -40,22 +40,22 @@ export const eventBus = new Vue({
updateValue(data){
if ( data.item_id ){
const promisse = this.$store.dispatch('item/updateMetadata',
{ item_id: data.item_id, metadata_id: data.metadata_id, values: data.values });
{ item_id: data.item_id, field_id: data.field_id, values: data.values });
promisse.then( response => {
data.instance.message = JSON.stringify( [] );
data.instance.value = response.value;
}, error => {
const metadata = this.errors.find(error => error.metadata_id === data.metadata_id );
eventElement.errorsMsg = JSON.stringify( metadata.error );
const field = this.errors.find(error => error.field_id === data.field_id );
eventElement.errorsMsg = JSON.stringify( field.error );
eventElement.value = data.values;
});
}
},
setValues(){
const metadata = this.$store.getters['item/getMetadata'];
if( metadata ){
for(let singleMetadata of metadata){
const eventElement = this.getComponentById( singleMetadata.metadata_id );
const field = this.$store.getters['item/getMetadata'];
if( field ){
for(let singleMetadata of field){
const eventElement = this.getComponentById( singleMetadata.field_id );
eventElement.value = singleMetadata.values;
}
}
@ -78,12 +78,12 @@ export const eventBus = new Vue({
}
return components;
},
getComponentById( metadata_id ){
getComponentById( field_id ){
for( let component of this.componentsTag ){
const eventElements = document.getElementsByTagName( component );
if( eventElements ) {
for (let eventElement of eventElements){
if( eventElement.metadata_id === metadata_id ){
if( eventElement.field_id === field_id ){
return eventElement;
}
}

View File

@ -1,37 +1,37 @@
import axios from '../../../axios/axios';
// Actions related to Item's metadata
export const sendMetadata = ( { commit }, { item_id, metadata_id, values }) => {
// Actions related to Item's field
export const sendField = ( { commit }, { item_id, field_id, values }) => {
return new Promise( (resolve, reject) => {
axios.post('/item/'+item_id+'/metadata/'+metadata_id, {
axios.post('/item/'+item_id+'/field/'+field_id, {
values: values
})
.then( res => {
console.log( 'success',res.data );
commit('setSingleMetadata', { item_id: item_id, metadata_id: metadata_id, values: values });
commit('removeError', { metadata_id: metadata_id });
commit('setSingleMetadata', { item_id: item_id, field_id: field_id, values: values });
commit('removeError', { field_id: field_id });
resolve( res.data );
})
.catch(error => {
console.log( 'error',error );
commit('setSingleMetadata', { item_id: item_id, metadata_id: metadata_id, values: values });
commit('setError', { item_id: item_id, metadata_id: metadata_id, value: values, error: error.response.data.errors });
commit('setSingleMetadata', { item_id: item_id, field_id: field_id, values: values });
commit('setError', { item_id: item_id, field_id: field_id, value: values, error: error.response.data.errors });
reject( error);
});
});
};
export const updateMetadata = ({ commit }, { item_id, metadata_id, values }) => {
export const updateMetadata = ({ commit }, { item_id, field_id, values }) => {
return new Promise((resolve, reject) => {
console.log(metadata_id);
axios.patch(`/item/${item_id}/metadata/${metadata_id}`, {
console.log(field_id);
axios.patch(`/item/${item_id}/field/${field_id}`, {
values: values
})
.then( res => {
console.log(res);
let metadata = res.data;
commit('setSingleMetadata', metadata);
let field = res.data;
commit('setSingleField', field);
})
.catch( error => {
console.log('error', error);
@ -39,12 +39,12 @@ export const updateMetadata = ({ commit }, { item_id, metadata_id, values }) =>
});
};
export const fetchMetadata = ({ commit }, item_id) => {
export const fetchFields = ({ commit }, item_id) => {
return new Promise((resolve, reject) => {
axios.get('/item/'+item_id+'/metadata')
axios.get('/item/'+item_id+'/field')
.then(res => {
let items = res.data;
commit('setMetadata', items);
commit('setFields', items);
resolve( res.data );
})
.catch(error => {
@ -93,6 +93,6 @@ export const sendItem = ( { commit }, { collection_id, title, description, statu
};
export const updateItem = ({ commit }, { item_id, metadata_id, values }) => {
export const updateItem = ({ commit }, { item_id, field_id, values }) => {
commit('setSingleItem', { item_id: item_id, title: title, description: description, status: status });
};

View File

@ -1,6 +1,6 @@
export const getMetadata = state => {
return state.metadata;
export const getFields = state => {
return state.fields;
}
export const getItem = state => {

View File

@ -4,7 +4,7 @@ import * as mutations from './mutations';
const state = {
item: [],
metadata: [],
fields: [],
error: []
};

View File

@ -4,42 +4,42 @@ export const setItem = ( state, item ) => {
state.item = item;
}
export const setMetadata = ( state, metadata) => {
state.metadata = metadata;
export const setFields = ( state, field) => {
state.fields = field;
}
export const setSingleMetadata = ( state, metadata) => {
let index = state.metadata.findIndex(itemMetadata => itemMetadata.metadata_id === metadata.metadata_id);
export const setSingleField = ( state, field) => {
let index = state.fields.findIndex(itemMetadata => itemMetadata.field_id === field.field_id);
if ( index >= 0){
//state.metadata[index] = metadata;
Vue.set( state.metadata, index, metadata );
//state.field[index] = field;
Vue.set( state.fields, index, field );
}else{
state.metadata.push( metadata );
state.fields.push( field );
}
}
export const setSingleItem = ( state, item) => {
let index = state.item.findIndex(itemItem => itemItem.item_id === item.item_id);
if ( index >= 0){
//state.metadata[index] = metadata;
//state.field[index] = field;
Vue.set( state.item, index, item );
}else{
state.item.push( item );
}
}
export const setError = ( state, metadata ) => {
let index = state.error.findIndex(itemMetadata => itemMetadata.metadata_id === metadata.metadata_id);
export const setError = ( state, field ) => {
let index = state.error.findIndex(itemMetadata => itemMetadata.field_id === field.field_id);
if ( index >= 0){
//state.error[index] = metadata;
Vue.set( state.error, index, metadata );
//state.error[index] = field;
Vue.set( state.error, index, field );
}else{
state.error.push( metadata );
state.error.push( field );
}
};
export const removeError = ( state, metadata ) => {
let index = state.error.findIndex(itemMetadata => itemMetadata.metadata_id === metadata.metadata_id);
export const removeError = ( state, field ) => {
let index = state.error.findIndex(itemMetadata => itemMetadata.field_id === field.field_id);
if ( index >= 0){
state.error.splice( index, 1);
}

View File

@ -18,8 +18,8 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
true
);
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'Metadata filtered',
'description' => 'Is filtered',
@ -33,7 +33,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
$request_body = json_encode(
array(
'collection_id' => $collection->get_id(),
'metadata_id' => $metadata->get_id(),
'field_id' => $field->get_id(),
'filter_type' => 'range',
'filter' => [
'name' => 'Filter name',
@ -64,10 +64,10 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
true
);
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'Metadata filtered',
'name' => 'Field filtered',
'description' => 'Is filtered',
)
);
@ -80,7 +80,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'name' => 'filtro',
'collection' => $collection,
'description' => 'descricao',
'metadata' => $metadata,
'field' => $field,
'filter_type' => $filter_type,
),
true
@ -134,10 +134,10 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
true
);
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'Metadata filtered',
'name' => 'Field filtered',
'description' => 'Is filtered',
'collection_id' => $collection->get_id()
)
@ -151,7 +151,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'name' => 'filtro',
'collection' => $collection,
'description' => 'descricao',
'metadata' => $metadata,
'field' => $field,
'filter_type' => $filter_type,
),
true
@ -185,17 +185,17 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
true
);
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'Metadata filtered',
'name' => 'Field filtered',
'description' => 'Is filtered',
'collection_id' => $collection->get_id()
)
);
$metadata2 = $this->tainacan_entity_factory->create_entity(
'metadata',
$field2 = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'Other filtered',
'description' => 'Is filtered',
@ -211,7 +211,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'name' => 'filtro',
'collection' => $collection,
'description' => 'descricao',
'metadata' => $metadata,
'field' => $field,
'filter_type' => $filter_type,
'status' => 'publish'
),
@ -224,7 +224,7 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_UnitApiTestCase {
'name' => 'filtro2',
'collection' => $collection,
'description' => 'descricao',
'metadata' => $metadata2,
'field' => $field2,
'filter_type' => $filter_type,
'status' => 'publish'
),

View File

@ -24,7 +24,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$field = $this->tainacan_field_factory->create_field('text', '', true);
$metadata = json_encode(
$field = json_encode(
array(
'name' => 'Moeda',
'description' => 'Descreve campo moeda.',
@ -34,15 +34,15 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$request = new \WP_REST_Request(
'POST',
$this->namespace . '/collection/' . $collection->get_id() . '/metadata'
$this->namespace . '/collection/' . $collection->get_id() . '/field'
);
$request->set_body($metadata);
$request->set_body($field);
$response = $this->server->dispatch($request);
$metadata_added = $response->get_data();
$this->assertTrue(is_array($metadata_added) && array_key_exists('name', $metadata_added), sprintf('cannot create metadata, response: %s', print_r($metadata_added, true)));
$this->assertEquals('Moeda', $metadata_added['name']);
$field_added = $response->get_data();
$this->assertTrue(is_array($field_added) && array_key_exists('name', $field_added), sprintf('cannot create field, response: %s', print_r($field_added, true)));
$this->assertEquals('Moeda', $field_added['name']);
}
@ -71,8 +71,8 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$field = $this->tainacan_field_factory->create_field('text', '', true);
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'Data',
'description' => 'Descreve valor do campo data.',
@ -83,42 +83,42 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
true
);
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $metadata);
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $field);
$item_metadata->set_value('12/12/2017');
$item_metadata->validate();
$Tainacan_Item_Metadata->insert($item_metadata);
#################### Get metadata of collection ######################
#################### Get field of collection ######################
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/collection/' . $collection->get_id() . '/metadata'
$this->namespace . '/collection/' . $collection->get_id() . '/field'
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$metadata = $data[0];
$field = $data[0];
$this->assertEquals('Data', $metadata['name']);
$this->assertEquals('Data', $field['name']);
################### Get metadata of item with value #######################
################### Get field of item with value #######################
$request = new \WP_REST_Request(
'GET',
$this->namespace . '/item/' . $item->get_id() . '/metadata'
$this->namespace . '/item/' . $item->get_id() . '/field'
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertTrue(is_array($data) && array_key_exists(0, $data), sprintf('cannot read metadata, response: %s', print_r($data, true)));
$this->assertTrue(is_array($data) && array_key_exists(0, $data), sprintf('cannot read field, response: %s', print_r($data, true)));
$item_metadata = $data[0];
$metadata = $item_metadata['metadata'];
$field = $item_metadata['field'];
$this->assertEquals('Data', $metadata['name']);
$this->assertEquals('Data', $field['name']);
$this->assertEquals('12/12/2017', $item_metadata['value']);
}
@ -144,8 +144,8 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$field = $this->tainacan_field_factory->create_field('text', '', true);
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'Data',
'description' => 'Descreve o dado do campo data.',
@ -164,7 +164,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$request = new \WP_REST_Request(
'PATCH',
$this->namespace . '/item/' . $item->get_id() . '/metadata/' . $metadata->get_id()
$this->namespace . '/item/' . $item->get_id() . '/field/' . $field->get_id()
);
$request->set_body($meta_values);
@ -172,16 +172,16 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$item_metadata_updated = $response->get_data();
$metadata_updated = $item_metadata_updated['metadata'];
$field_updated = $item_metadata_updated['field'];
$this->assertEquals($metadata->get_id(), $metadata_updated['id']);
$this->assertEquals($field->get_id(), $field_updated['id']);
$metav = get_post_meta($item->get_id(), $metadata_updated['id'], true);
$metav = get_post_meta($item->get_id(), $field_updated['id'], true);
$this->assertEquals('19/01/2018', $metav);
#### UPDATE METADATA IN COLLECTION ####
#### UPDATE FIELD IN COLLECTION ####
$values = json_encode([
'values' => [
@ -192,7 +192,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$request = new \WP_REST_Request(
'PATCH',
$this->namespace . '/collection/' . $collection->get_id() . '/metadata/' . $metadata->get_id()
$this->namespace . '/collection/' . $collection->get_id() . '/field/' . $field->get_id()
);
$request->set_body($values);
@ -201,7 +201,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$data = $response->get_data();
$this->assertEquals($metadata->get_id(), $data['id']);
$this->assertEquals($field->get_id(), $data['id']);
$this->assertEquals('Dia/Mês/Ano', $data['name']);
// Mantém-se o valor antigo no item

View File

@ -3,21 +3,21 @@
namespace Tainacan\Tests;
use Tainacan\Field_Types;
/**
* Class Metadata
* Class Field
*
* @package Test_Tainacan
*/
/**
* Metadata test case.
* Field test case.
*/
class Metadata extends TAINACAN_UnitTestCase {
class Fields extends TAINACAN_UnitTestCase {
/**
* Test insert a regular metadata with type
* Test insert a regular field with type
*/
function test_add() {
global $Tainacan_Metadatas;
global $Tainacan_Fields;
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
@ -29,8 +29,8 @@ class Metadata extends TAINACAN_UnitTestCase {
$type = $this->tainacan_field_factory->create_field('text');
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado',
'description' => 'descricao',
@ -40,7 +40,7 @@ class Metadata extends TAINACAN_UnitTestCase {
true
);
$test = $Tainacan_Metadatas->fetch($metadata->get_id());
$test = $Tainacan_Fields->fetch($field->get_id());
$this->assertEquals($test->get_name(), 'metadado');
$this->assertEquals($test->get_description(), 'descricao');
@ -48,10 +48,10 @@ class Metadata extends TAINACAN_UnitTestCase {
}
/**
* Test insert a regular metadata with type
* Test insert a regular field with type
*/
function test_add_type(){
global $Tainacan_Metadatas;
global $Tainacan_Fields;
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
@ -63,8 +63,8 @@ class Metadata extends TAINACAN_UnitTestCase {
$type = $this->tainacan_field_factory->create_field('text');
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado',
'description' => 'descricao',
@ -74,7 +74,7 @@ class Metadata extends TAINACAN_UnitTestCase {
true
);
$test = $Tainacan_Metadatas->fetch($metadata->get_id());
$test = $Tainacan_Fields->fetch($field->get_id());
$this->assertEquals($test->get_name(), 'metadado');
$this->assertEquals($test->get_collection_id(), $collection->get_id());
@ -83,18 +83,18 @@ class Metadata extends TAINACAN_UnitTestCase {
}
/**
* test if parent metadata are visible for children collection
* test if parent field are visible for children collection
*/
function test_hierarchy_metadata(){
global $Tainacan_Metadatas;
global $Tainacan_Fields;
$type = $this->tainacan_field_factory->create_field('text');
$this->tainacan_entity_factory->create_entity(
'metadata',
'field',
array(
'name' => 'metadata default',
'collection_id' => $Tainacan_Metadatas->get_default_metadata_attribute(),
'name' => 'field default',
'collection_id' => $Tainacan_Fields->get_default_metadata_attribute(),
'field_type' => $type,
'status' => 'publish'
),
@ -110,9 +110,9 @@ class Metadata extends TAINACAN_UnitTestCase {
);
$this->tainacan_entity_factory->create_entity(
'metadata',
'field',
array(
'name' => 'metadata grandfather',
'name' => 'field grandfather',
'collection_id' => $collection_grandfather->get_id(),
'field_type' => $type,
'status' => 'publish'
@ -130,9 +130,9 @@ class Metadata extends TAINACAN_UnitTestCase {
);
$this->tainacan_entity_factory->create_entity(
'metadata',
'field',
array(
'name' => 'metadata father',
'name' => 'field father',
'collection_id' => $collection_father->get_id(),
'field_type' => $type,
'status' => 'publish'
@ -153,9 +153,9 @@ class Metadata extends TAINACAN_UnitTestCase {
$this->assertEquals( $collection_father->get_id(), $collection_son->get_parent() );
$this->tainacan_entity_factory->create_entity(
'metadata',
'field',
array(
'name' => 'metadata son',
'name' => 'field son',
'collection_id' => $collection_son->get_id(),
'field_type' => $type,
'status' => 'publish'
@ -163,7 +163,7 @@ class Metadata extends TAINACAN_UnitTestCase {
true
);
$retrieve_metadata = $Tainacan_Metadatas->fetch_by_collection( $collection_son, [], 'OBJECT' );
$retrieve_metadata = $Tainacan_Fields->fetch_by_collection( $collection_son, [], 'OBJECT' );
$this->assertEquals( 4, sizeof( $retrieve_metadata ) );
}
@ -171,17 +171,17 @@ class Metadata extends TAINACAN_UnitTestCase {
* test if the defaults types are registered
*/
function test_metadata_field_type(){
global $Tainacan_Metadatas;
$this->assertEquals( 8, sizeof( $Tainacan_Metadatas->fetch_field_types() ) );
global $Tainacan_Fields;
$this->assertEquals( 8, sizeof( $Tainacan_Fields->fetch_field_types() ) );
}
/**
* test if the defaults types are registered
*/
function test_metadata_field_type_insert(){
global $Tainacan_Metadatas;
global $Tainacan_Fields;
$class = new RandomType;
$this->assertEquals( 9, sizeof( $Tainacan_Metadatas->fetch_field_types() ) );
$this->assertEquals( 9, sizeof( $Tainacan_Fields->fetch_field_types() ) );
}
}
@ -195,9 +195,9 @@ class RandomType extends Field_Types\Field_Type {
}
/**
* @param $metadata
* @param $field
* @return string
*/
public function render( $metadata ){}
public function render( $field ){}
}

View File

@ -56,8 +56,8 @@ class Filters extends TAINACAN_UnitTestCase {
$type = $this->tainacan_field_factory->create_field('text');
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado',
'collection_id' => $collection->get_id(),
@ -75,7 +75,7 @@ class Filters extends TAINACAN_UnitTestCase {
'name' => 'filtro',
'collection' => $collection,
'description' => 'descricao',
'metadata' => $metadata,
'field' => $field,
'filter_type' => $filter_list_type
),
true
@ -90,7 +90,7 @@ class Filters extends TAINACAN_UnitTestCase {
$this->assertEquals( 'filtro', $test->get_name() );
$this->assertEquals( $collection->get_id(), $test->get_collection_id() );
$this->assertEquals( $metadata->get_id(), $test->get_metadata()->get_id() );
$this->assertEquals( $field->get_id(), $test->get_field()->get_id() );
$objClass = get_class( $filter_list_type );
$storedObjClass = get_class( $test->get_filter_type_object() );
$this->assertEquals($objClass , $storedObjClass );

View File

@ -18,7 +18,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
*/
function test_add() {
global $Tainacan_Metadatas, $Tainacan_Item_Metadata;
global $Tainacan_Fields, $Tainacan_Item_Metadata;
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
@ -31,8 +31,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
$type = $this->tainacan_field_factory->create_field('text');
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado',
'description' => 'descricao',
@ -42,7 +42,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true
);
$test = $Tainacan_Metadatas->fetch($metadata->get_id());
$test = $Tainacan_Fields->fetch($field->get_id());
$i = $this->tainacan_entity_factory->create_entity(
'item',
@ -70,7 +70,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
* Teste da insercao de um metadado simples com o tipo
*/
function teste_required(){
global $Tainacan_Metadatas, $Tainacan_Item_Metadata;
global $Tainacan_Fields, $Tainacan_Item_Metadata;
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
@ -83,8 +83,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
$type = $this->tainacan_field_factory->create_field('text');
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado',
'description' => 'descricao',
@ -95,7 +95,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true
);
$test = $Tainacan_Metadatas->fetch($metadata->get_id());
$test = $Tainacan_Fields->fetch($field->get_id());
$i = $this->tainacan_entity_factory->create_entity(
'item',
@ -125,7 +125,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
}
function teste_collection_key(){
global $Tainacan_Metadatas, $Tainacan_Item_Metadata;
global $Tainacan_Fields, $Tainacan_Item_Metadata;
$collection = $this->tainacan_entity_factory->create_entity(
'collection',
@ -138,8 +138,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
$type = $this->tainacan_field_factory->create_field('text');
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado',
'description' => 'descricao',
@ -150,7 +150,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true
);
$test = $Tainacan_Metadatas->fetch($metadata->get_id());
$test = $Tainacan_Fields->fetch($field->get_id());
$i = $this->tainacan_entity_factory->create_entity(
'item',
@ -199,7 +199,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
$type = $this->tainacan_field_factory->create_field('text');
$this->tainacan_entity_factory->create_entity(
'metadata',
'field',
array(
'name' => 'metadado',
'description' => 'descricao',
@ -210,7 +210,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true
);
//$test = $Tainacan_Metadatas->fetch($metadata->get_id());
//$test = $Tainacan_Fields->fetch($field->get_id());
$i = $this->tainacan_entity_factory->create_entity(
'item',
@ -226,7 +226,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
$this->assertTrue(is_array($item_metadatas));
$this->assertEquals(1, sizeof($item_metadatas));
$this->assertEquals('metadado', $item_metadatas[0]->get_metadata()->get_name());
$this->assertEquals('metadado', $item_metadatas[0]->get_field()->get_name());
}
}

View File

@ -94,8 +94,8 @@ class Items extends TAINACAN_UnitTestCase {
true
);
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado',
'status' => 'publish',
@ -105,8 +105,8 @@ class Items extends TAINACAN_UnitTestCase {
true
);
$metadata2 = $this->tainacan_entity_factory->create_entity(
'metadata',
$field2 = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado2',
'status' => 'publish',
@ -116,8 +116,8 @@ class Items extends TAINACAN_UnitTestCase {
true
);
$metadata3 = $this->tainacan_entity_factory->create_entity(
'metadata',
$field3 = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado3',
'status' => 'publish',
@ -135,7 +135,7 @@ class Items extends TAINACAN_UnitTestCase {
'title' => 'orange',
'collection' => $collection,
'add_metadata' => [
[$metadata, 'value_1']
[$field, 'value_1']
],
'status' => 'publish'
),
@ -143,11 +143,11 @@ class Items extends TAINACAN_UnitTestCase {
);
$item = $Tainacan_Items->fetch($i->get_id());
$meta_test = $item->get_metadata();
$meta_test = $item->get_field();
$this->assertTrue( isset($meta_test[$metadata->get_id()]) );
$this->assertTrue( $meta_test[$metadata->get_id()] instanceof Entities\Item_Metadata_Entity );
$this->assertEquals( 'value_1', $meta_test[$metadata->get_id()]->get_value());
$this->assertTrue( isset($meta_test[$field->get_id()]) );
$this->assertTrue( $meta_test[$field->get_id()] instanceof Entities\Item_Metadata_Entity );
$this->assertEquals( 'value_1', $meta_test[$field->get_id()]->get_value());
$this->tainacan_entity_factory->create_entity(
'item',
@ -155,8 +155,8 @@ class Items extends TAINACAN_UnitTestCase {
'title' => 'apple',
'collection' => $collection2,
'add_metadata' => [
[$metadata2, 'value_2'],
[$metadata3, 'value_2']
[$field2, 'value_2'],
[$field3, 'value_2']
],
'status' => 'publish'
),
@ -169,9 +169,9 @@ class Items extends TAINACAN_UnitTestCase {
'title' => 'lemon',
'collection' => $collection2,
'add_metadata' => [
[$metadata2, 'value_2'],
[$metadata2, 'value_3'],
[$metadata3, 'value_3']
[$field2, 'value_2'],
[$field2, 'value_3'],
[$field3, 'value_3']
],
'status' => 'publish'
),
@ -184,8 +184,8 @@ class Items extends TAINACAN_UnitTestCase {
'title' => 'pineapple',
'collection' => $collection2,
'add_metadata' => [
[$metadata2, 'value_3'],
[$metadata3, 'value_6']
[$field2, 'value_3'],
[$field3, 'value_6']
],
'status' => 'publish'
),
@ -234,7 +234,7 @@ class Items extends TAINACAN_UnitTestCase {
$test_query = $Tainacan_Items->fetch([
'meta_query' => [
[
'key' => $metadata2->get_id(),
'key' => $field2->get_id(),
'value' => 'value_2'
]
]
@ -245,7 +245,7 @@ class Items extends TAINACAN_UnitTestCase {
$test_query = $Tainacan_Items->fetch([
'meta_query' => [
[
'key' => $metadata2->get_id(),
'key' => $field2->get_id(),
'value' => 'value_3'
]
]
@ -256,7 +256,7 @@ class Items extends TAINACAN_UnitTestCase {
$test_query = $Tainacan_Items->fetch([
'meta_query' => [
[
'key' => $metadata3->get_id(),
'key' => $field3->get_id(),
'value' => 'value_2',
'compare' => '>'
]

View File

@ -47,8 +47,8 @@ class Objects extends TAINACAN_UnitTestCase {
true
);
$metadata = $this->tainacan_entity_factory->create_entity(
'metadata',
$field = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado',
'status' => 'publish',
@ -58,8 +58,8 @@ class Objects extends TAINACAN_UnitTestCase {
true
);
$metadata2 = $this->tainacan_entity_factory->create_entity(
'metadata',
$field2 = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado2',
'status' => 'publish',
@ -69,8 +69,8 @@ class Objects extends TAINACAN_UnitTestCase {
true
);
$metadata3 = $this->tainacan_entity_factory->create_entity(
'metadata',
$field3 = $this->tainacan_entity_factory->create_entity(
'field',
array(
'name' => 'metadado3',
'status' => 'publish',
@ -88,7 +88,7 @@ class Objects extends TAINACAN_UnitTestCase {
'title' => 'orange',
'collection' => $collection,
'add_metadata' => [
[$metadata, 'value_1']
[$field, 'value_1']
]
),
true
@ -97,19 +97,19 @@ class Objects extends TAINACAN_UnitTestCase {
$entity = Repository::get_entity_by_post($test);
$this->assertEquals($i->get_db_identifier(), $entity->get_db_identifier());
$test = get_post($metadata->get_id());
$test = get_post($field->get_id());
$entity = Repository::get_entity_by_post($test);
$this->assertEquals($metadata->get_db_identifier(), $entity->get_db_identifier());
$this->assertEquals($field->get_db_identifier(), $entity->get_db_identifier());
$test = get_post($metadata2->get_id());
$test = get_post($field2->get_id());
$entity = Repository::get_entity_by_post($test);
$this->assertEquals($metadata2->get_db_identifier(), $entity->get_db_identifier());
$this->assertEquals($field2->get_db_identifier(), $entity->get_db_identifier());
$metadatas = $i->get_metadata();
//var_dump($metadatas);
$item_metadata = array_pop($metadatas);
$test = get_post($item_metadata->get_metadata()->get_id());
$fields = $i->get_field();
//var_dump($fields);
$item_metadata = array_pop($fields);
$test = get_post($item_metadata->get_field()->get_id());
$entity = Repository::get_entity_by_post($test);
$this->assertEquals($item_metadata->get_metadata()->get_db_identifier(), $entity->get_db_identifier());
$this->assertEquals($item_metadata->get_field()->get_db_identifier(), $entity->get_db_identifier());
}
}