Merge branch 'develop' of https://github.com/tainacan/tainacan into develop

This commit is contained in:
vnmedeiros 2018-10-05 12:36:04 -03:00
commit 8980ffacf7
16 changed files with 341 additions and 1899 deletions

View File

@ -1,70 +0,0 @@
# Collections
## Collection Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-collections.php -->
### `protected function __construct()`
Collections constructor.
### `public function get_map()`
{@inheritDoc}
### `public function get_cpt_labels()`
Get the labels for the custom post type of this repository
**Returns:** `array` — Labels in the format expected by register_post_type()
### `public function insert( $collection )`
{@inheritDoc}
**Parameters:**
* `$collection` — \Tainacan\Entities\Collection
**Returns:** \Tainacan\Entities\Collection
### `public function delete( $args )`
**Parameters:**
* `(` — $args — is a array like [post_id, [is_permanently => bool]] )
**Returns:** mixed|Collection
### `public function fetch( $args = [], $output = null )`
fetch collection based on ID or WP_Query args
Collections 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
**Parameters:**
* `$args` — array — WP_Query args || int $args the collection id
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `\WP_Query|Array` — an instance of wp query OR array of entities;
### `public function map_meta_cap( $caps, $cap, $user_id, $args )`
Filter to handle special permissions
<!-- END DOC-COMMENT -->
## Collection Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-collection.php -->
### `function validate()`
Validate Collection
**Returns:** bool
<!-- END DOC-COMMENT -->

View File

@ -1,516 +0,0 @@
# Metadata
## Metadatum Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-metadata.php -->
### `class Metadata extends Repository`
Class Metadata
### `protected function __construct()`
Register specific hooks for metadatum repository
### `public function get_cpt_labels()`
Get the labels for the custom post type of this repository
**Returns:** `array` — Labels in the format expected by register_post_type()
### `public function get_default_metadata_attribute()`
constant used in default metadatum in attribute collection_id
**Returns:** `string` — the value of constant
### `public function register_field_type( $class_name )`
register metadatum types class on array of types
**Parameters:**
* `string` — $class_name — | object The class name or the instance
### `public function unregister_field_type( $class_name )`
register metadatum types class on array of types
**Parameters:**
* `string` — $class_name — | object The class name or the instance
### `public function fetch( $args, $output = null )`
fetch metadatum based on ID or WP_Query args
metadatum 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
**Parameters:**
* `$args` — array — WP_Query args || int $args the metadatum id
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `Entities\Metadatum|\WP_Query|Array` — an instance of wp query OR array of entities;
### `public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null)`
fetch metadatum by collection, searches all metadatum available
**Parameters:**
* `$collection` — Entities\Collection
* `$args` — array — WP_Query args plus disabled_fields
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `array` — Entities\Metadatum
### `public function order_result( $result, Entities\Collection $collection, $include_disabled = false )`
Ordinate the result from fetch response if $collection has an ordination, metadata not ordinated appear on the end of the list
**Parameters:**
* `Response` — $result — from method fetch
* `$collection` — Entities\Collection
* `$include_disabled` — bool — Wether to include disabled metadata in the results or not
**Returns:** `array` — or WP_Query ordinate
### `public function insert($metadatum)`
{@inheritDoc}
**Parameters:**
* `$metadatum` — \Tainacan\Entities\Metadatum
**Returns:** \Tainacan\Entities\Metadatum
### `public function update($object, $new_values = null)`
**Returns:** mixed|string|Entities\Entity
### `public function fetch_field_types( $output = 'CLASS')`
fetch all registered metadatum type classes
Possible outputs are: CLASS (default) - returns the Class name of of metadatum types registered NAME - return an Array of the names of metadatum types registered
**Parameters:**
* `string` — $output — CLASS | NAME
**Returns:** `array` — of Entities\Metadatum_Types\Metadatum_Type classes path name
### `public function register_core_fields( Entities\Collection $collection )`
**Parameters:**
* `$collection` — Entities\Collection
**Returns:** bool
### `public function disable_delete_core_fields( $before, $post )`
block user from remove core metadata
**Parameters:**
* `wordpress` — $before — pass a null value
* `the` — $post — post which is moving to trash
**Returns:** null/bool
### `public function force_delete_core_fields( $before, $post, $force_delete )`
block user from remove core metadata ( if use wp_delete_post)
**Parameters:**
* `wordpress` — $before — pass a null value
* `the` — $post — post which is deleting
* `a` — $force_delete — boolean that force the deleting
**Returns:** `null` — /bool
### `public function get_core_fields( Entities\Collection $collection )`
returns all core items from a specific collection
**Parameters:**
* `$collection` — Entities\Collection
**Returns:** Array|\WP_Query
### `public function insert_array_field( $data )`
create a metadatum entity and insert by an associative array ( attribute => value )
**Parameters:**
* `$data` — Array — the array of attributes to insert a metadatum
**Returns:** `int` — the metadatum id inserted
### `public function fetch_all_field_values($collection_id, $metadatum_id)`
Fetch all values of a metadatum from a collection in all it collection items
**Returns:** array|null|object
### `private function pre_update_taxonomy_field($metadatum)`
Stores the value of the taxonomy_id option to use on update_taxonomy_field method.
### `private function update_taxonomy_field($metadatum)`
Triggers hooks when saving a Taxonomy Metadatum, indicating wich taxonomy was added or removed from a collection.
This is used by Taxonomies repository to update the collections_ids property of the taxonomy as a metadatum type taxonomy is inserted or removed
**Parameters:**
* `$metadatum` — [type] — [description]
**Returns:** `[type]` — [description]
<!-- END DOC-COMMENT -->
## Metadatum Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-metadatum.php -->
### `class Metadatum extends Entity`
Represents the Entity Metadatum
### `protected $repository = 'Metadata'`
{@inheritDoc}
### `function get_name()`
Return the metadatum name
**Returns:** string
### `function get_slug()`
Get metadatum slug
**Returns:** string
### `function get_order()`
Return the metadatum order type
**Returns:** string
### `function get_parent()`
Return the parent ID
**Returns:** string
### `function get_description()`
Return the metadatum description
**Returns:** string
### `function get_required()`
Return if is a required metadatum
**Returns:** boolean
### `function get_multiple()`
Return if is a multiple metadatum
**Returns:** boolean
### `function get_cardinality()`
Return the cardinality
**Returns:** string
### `function get_collection_key()`
Return if metadatum is key
**Returns:** boolean
### `function get_mask()`
Return the mask
**Returns:** string
### `function get_default_value()`
Return the metadatum default value
**Returns:** `string` — || integer
### `function get_field_type_object()`
Return the an object child of \Tainacan\Metadatum_Types\Metadatum_Type with options
**Returns:** `\Tainacan\Metadatum_Types\Metadatum_Type` — The metadatum type class with filled options
### `function get_field_type()`
Return the class name for the metadatum type
**Returns:** `string` — The
### `function get_field_type_options()`
Return the actual options for the current metadatum type
**Returns:** `array` — Configurations for the metadatum type object
### `function set_name($value)`
Set the metadatum name
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function get_accept_suggestion()`
Return true if this metadatum allow community suggestions, false otherwise
**Returns:** bool
### `function set_slug($value)`
Set the metadatum slug
If you dont set the metadatum slug, it will be set automatically based on the name and following WordPress default behavior of creating slugs for posts.
If you set the slug for an existing one, WordPress will append a number at the end of in order to make it unique (e.g slug-1, slug-2)
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_order($value)`
Set manually the order of the metadatum
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_parent($value)`
Set the metadatum parent ID
**Parameters:**
* `$value` — [integer] — The ID from parent
**Returns:** void
### `function set_description($value)`
Set metadatum description
**Parameters:**
* `$value` — [string] — The text description
**Returns:** void
### `function set_required( $value )`
Allow the metadatum be required
**Parameters:**
* `$value` — [boolean]
**Returns:** void
### `function set_multiple( $value )`
Allow multiple metadata
**Parameters:**
* `$value` — [boolean]
**Returns:** void
### `function set_cardinality( $value )`
The number of possible metadata
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_collection_key( $value )`
Define if the value is key on the collection
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_mask( $value )`
Set mask for the metadatum
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_privacy( $value )`
Set privacy
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_default_value( $value )`
Set default value
**Parameters:**
* `||` — [string — integer] $value
**Returns:** void
### `public function set_field_type( $value )`
set the metadatum type class name
**Parameters:**
* `|` — string — \Tainacan\Metadatum_Types\Metadatum_Type $value The name of the class or the instance
### `function set_accept_suggestion( $value )`
Set if this metadatum allow community suggestions
**Parameters:**
* `$value` — bool
### `function set_field_type_options( $value )`
Set Metadatum type options
**Parameters:**
* `||` — [string — integer] $value
**Returns:** void
### `public function get_enabled_for_collection()`
Transient property used to store the status of the metadatum for a particular collection
Used by the API to tell front end when a metadatum is disabled
### `function is_multiple()`
Return true if is multiple, else return false
**Returns:** boolean
### `function is_collection_key()`
Return true if is collection key, else return false
**Returns:** boolean
### `function is_required()`
Return true if is required, else return false
**Returns:** boolean
### `public function validate()`
{@inheritdoc }
Also validates the metadatum, calling the validate_options callback of the Metadatum Type
**Returns:** `bool` — valid or not
<!-- END DOC-COMMENT -->

View File

@ -1,239 +0,0 @@
# Filters
## Filter Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-filters.php -->
### `public function delete($args)`
**Parameters:**
* `$args` — array
**Returns:** Entities\Filter
### `public function fetch($args = [], $output = null)`
fetch filter based on ID or WP_Query args
Filters 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
**Parameters:**
* `$args` — array — WP_Query args || int $args the filter id
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `\WP_Query|Array` — an instance of wp query OR array of entities;
### `public function register_filter_type( $class_name )`
register metadatum types class on array of types
**Parameters:**
* `string` — $class_name — | object The class name or the instance
### `public function deregister_filter_type( $class_name )`
register metadatum types class on array of types
**Parameters:**
* `string` — $class_name — | object The class name or the instance
### `public function fetch_filter_types( $output = 'CLASS')`
fetch all registered filter type classes
Possible outputs are: CLASS (default) - returns the Class name of of filter types registered NAME - return an Array of the names of filter types registered
**Parameters:**
* `string` — $output — CLASS | NAME
**Returns:** `array` — of Entities\Filter_Types\Filter_Type classes path name
### `public function fetch_supported_filter_types($types)`
fetch only supported filters for the type specified
**Parameters:**
* `string` — ( — || array ) $types Primitve types of metadatum ( float, string, int)
**Returns:** `array` — Filters supported by the primitive types passed in $types
### `public function fetch_by_collection(Entities\Collection $collection, $args = [], $output = null)`
fetch filters by collection, searches all filters available
**Parameters:**
* `$collection` — Entities\Collection
* `$args` — array — WP_Query args plus disabled_fields
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `Array` — Entities\Metadatum
### `public function order_result( $result, Entities\Collection $collection )`
Ordinate the result from fetch response if $collection has an ordination, filters not ordinated appear on the end of the list
**Parameters:**
* `Response` — $result — from method fetch
* `$collection` — Entities\Collection
**Returns:** `array` — or WP_Query ordinate
<!-- END DOC-COMMENT -->
## Filter Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-filter.php -->
### `class Filter extends Entity`
Represents the entity Filter
### `protected $repository = 'Filters'`
{@inheritDoc}
### `public function _toArray()`
**Returns:** array
### `function get_name()`
Return the filter name
**Returns:** string
### `function get_description()`
**Returns:** mixed|null
### `function get_order()`
Return the filter order type
**Returns:** string
### `function get_color()`
Return the filter color
**Returns:** string
### `function get_field()`
Return the metadatum
**Returns:** Metadatum
### `function get_filter_type_object()`
Return the an object child of \Tainacan\Filter_Types\Filter_Type with options
**Returns:** `\Tainacan\Filter_Types\Filter_Type` — The filter type class with filled options
### `function get_filter_type()`
Return the class name for the filter type
**Returns:** `string` — The
### `function get_filter_options()`
Return the actual options for the current filter type
**Returns:** `array` — Configurations for the filter type object
### `function set_name($value)`
Define the filter name
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_order($value)`
Define the filter order type
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_description($value)`
Define the filter description
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_color( $value )`
Define the filter color
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_field( $value )`
Define the filter metadatum
**Returns:** void
### `public function set_filter_type($value)`
Save the filter type class name
**Parameters:**
* `|` — string — \Tainacan\Filter_Types\Filter_Type $value The name of the class or the instance
### `public function validate()`
{@inheritdoc }
Also validates the metadatum, calling the validate_options callback of the Metadatum Type
**Returns:** `bool` — valid or not
<!-- END DOC-COMMENT -->

View File

@ -1,216 +0,0 @@
# Item Metadata
## Item Metadata Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-item-metadata.php -->
### `if ( $item_metadata->get_field()->get_parent() > 0 && is_null($item_metadata->get_meta_id()) )`
When we are adding a metadatum that is child of another, this means it is inside a compound metadatum
In that case, if the Item_Metadata object is not set with a meta_id, it means we want to create a new one and not update an existing. This is the case of a multiple compound metadatum.
### `public function delete($item_metadata)`
**Returns:** mixed|void
### `public function add_compound_value(Entities\Item_Metadata_Entity $item_metadata, $meta_id)`
**Returns:** `null|ind` — the meta id of the created compound metadata
### `public function fetch($object, $output = null )`
Fetch Item Metadatum objects related to an Item
**Parameters:**
* `$object` — Entities\Item
**Returns:** array
### `public function get_value(Entities\Item_Metadata_Entity $item_metadata)`
Get the value for a Item metadatum.
**Parameters:**
* `$item_metadata` — Entities\Item_Metadata_Entity
**Returns:** mixed
### `private function extract_compound_value(array $ids, Entities\Item $item, $compund_meta_id)`
Transforms the array saved as meta_value with the IDs of post_meta saved as a value for compound metadata and converts it into an array of Item Metadatada Entitites
**Parameters:**
* `$ids` — array — The array of post_meta ids
* `$item` — Entities\Item — The item this post_meta is related to
* `$compund_meta_id` — int — the meta_id of the parent compound metadata
**Returns:** `array` — An array of Item_Metadata_Entity objects
### `public function update( $object, $new_values = null )`
**Returns:** mixed
### `public function suggest($item_metadata)`
Suggest a value to be inserted as a item Metadatum value, return a pending log
**Parameters:**
* `$item_metadata` — Entities\Item_Metadata_Entity
**Returns:** Entities\Log
<!-- END DOC-COMMENT -->
## Item Metadata Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-item-metadata-entity.php -->
### `class Item_Metadata_Entity extends Entity`
Represents the Item Metadatum Entity
### `protected $repository = 'Item_Metadata'`
{@inheritDoc}
### `function __construct(Item $item, Metadatum $metadatum, $meta_id = null, $parent_meta_id = null)`
**Parameters:**
* `$item` — Item — Item Entity
* `$metadatum` — Metadatum — Metadatum Entity
* `$meta_id` — int — ID for a specific meta row
### `function set_item(Item $item)`
Define the item
**Parameters:**
* `$item` — Item
**Returns:** void
### `function set_value($value)`
Define the metadatum value
**Parameters:**
* `|` — [integer — string] $value
**Returns:** void
### `function set_field(Metadatum $metadatum)`
Define the metadatum
**Parameters:**
* `$metadatum` — Metadatum
**Returns:** void
### `function set_meta_id($meta_id)`
Set the specific meta ID for this metadata.
When this value is set, get_value() will use it to fetch the value from the post_meta table, instead of considering the item and metadatum IDs
**Parameters:**
* `$meta_id` — int — the ID of a specifica post_meta row
### `function set_parent_meta_id($parent_meta_id)`
Set parent_meta_id. Used when a item_metadata is inside a compound Metadatum
When you have a multiple compound metadatum, this indicates of which instace of the value this item_metadata is attached to
**Parameters:**
* `$parent_meta_id` — [type] — [description]
### `function get_item()`
Return the item
**Returns:** Item
### `function get_field()`
Return the metadatum
**Returns:** Metadatum
### `function get_meta_id()`
Return the meta_id
**Returns:** Metadatum
### `function get_parent_meta_id()`
Return the meta_id
**Returns:** Metadatum
### `function get_value()`
Return the metadatum value
**Returns:** `string` — | integer
### `function is_multiple()`
Return true if metadatum is multiple, else return false
**Returns:** boolean
### `function is_collection_key()`
Return true if metadatum is key
**Returns:** boolean
### `function is_required()`
Return true if metadatum is required
**Returns:** boolean
### `function validate()`
Validate attributes
**Returns:** boolean
<!-- END DOC-COMMENT -->

View File

@ -1,263 +0,0 @@
# Items
## Items Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-items.php -->
### `public function get_cpt_labels()`
Get generic labels for the custom post types created for each collection
**Returns:** `array` — Labels in the format expected by register_post_type()
### `public function register_post_type()`
Register each Item post_type {@inheritDoc}
### `public function fetch( $args = [], $collections = [], $output = null )`
fetch items based on ID or WP_Query args
Items 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
The second paramater specifies from which collections item should be fetched. You can pass the Collection ID or object, or an Array of IDs or collection objects
**Parameters:**
* `$args` — array — WP_Query args || int $args the item id
* `$collections` — array — Array Entities\Collection || Array int collections IDs || int collection id || Entities\Collection collection object
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `\WP_Query|Array` — an instance of wp query OR array of entities;
### `if ( ! isset( $args['post_status'] ) )`
If no specific status is defined in the query, WordPress will fetch public items and private items for users withe the correct permission.
If a collection is private, it must have the same behavior, despite its items are public or not.
### `public function fetch_ids( $args = [], $collections = [] )`
fetch items IDs based on WP_Query args
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
The second paramater specifies from which collections item should be fetched. You can pass the Collection ID or object, or an Array of IDs or collection objects
**Parameters:**
* `$args` — array — WP_Query args || int $args the item id
* `$collections` — array — Array Entities\Collection || Array int collections IDs || int collection id || Entities\Collection collection object
**Returns:** `Array` — array of IDs;
### `public function delete( $args )`
**Parameters:**
* `(` — $args — is a array like [post_id, [is_permanently => bool]] )
**Returns:** mixed|Entities\Item
### `public function title_in_posts_where( $where, $wp_query )`
allow wp query filter post by array of titles
**Returns:** string
### `public function content_in_posts_where( $where, $wp_query )`
allow wp query filter post by array of content
**Returns:** string
<!-- END DOC-COMMENT -->
## Item Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-item.php -->
### `class Item extends Entity`
Represents the Entity Item
### `protected $repository = 'Items'`
{@inheritDoc}
### `function __construct( $which = 0 )`
{@inheritDoc}
### `function set_terms( $value )`
### `function get_terms()`
**Returns:** mixed|null
### `function get_attachments()`
**Returns:** array
### `function get_author_name()`
**Returns:** string
### `function get_featured_image()`
**Returns:** false|string
### `function set_featured_img_id( $id )`
### `function get_featured_img_id()`
**Returns:** int|string
### `function get_modification_date()`
**Returns:** mixed|null
### `function get_creation_date()`
**Returns:** mixed|null
### `function get_author_id()`
**Returns:** mixed|null
### `function get_url()`
**Returns:** mixed|null
### `function get_id()`
Return the item ID
**Returns:** integer
### `function get_title()`
Return the item title
**Returns:** string
### `function get_order()`
Return the item order type
**Returns:** string
### `function get_parent()`
Return the parent ID
**Returns:** integer
### `function get_description()`
Return the item description
**Returns:** string
### `public function get_db_identifier()`
{@inheritDoc}
### `public function get_capabilities()`
Use especial Item capabilities {@inheritDoc}
### `function set_title( $value )`
Define the title
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_order( $value )`
Define the order type
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_parent( $value )`
Define the parent ID
**Parameters:**
* `$value` — [integer]
**Returns:** void
### `function set_description( $value )`
Define the description
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function get_fields()`
Return a List of ItemMetadata objects
It will return all metadata associeated with the collection this item is part of.
If the item already has a value for any of the metadata, it will be available.
**Returns:** `array` — Array of ItemMetadata objects
### `protected function set_cap()`
set meta cap object
### `function validate()`
{@inheritDoc}
### `public function validate_core_fields()`
{@inheritDoc}
<!-- END DOC-COMMENT -->

View File

@ -1,237 +0,0 @@
# Logs
## Logs Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-logs.php -->
### `class Logs extends Repository`
Implement a Logs system
### `public function register_post_type()`
{@inheritDoc}
### `public function fetch($args = [], $output = null)`
fetch logs based on ID or WP_Query args
Logs 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
**Parameters:**
* `$args` — array — WP_Query args || int $args the log id
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `\WP_Query|Array` — an instance of wp query OR array of entities;
### `public function insert_log($new_value, $value = null)`
Insert a log when a new entity is inserted
**Parameters:**
* `$new_value` — Entity
* `$value` — Entity
**Returns:** `Entities\Log` — new created log
### `public function approve($log)`
**Parameters:**
* `$log` — Entities\Log
**Returns:** `Entities\Entity|boolean` — return insert/update valeu or false
### `$value = $log->get_value()`
<!-- END DOC-COMMENT -->
## Log Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-log.php -->
### `class Log extends Entity`
Represents entity Log
### `protected $repository = 'Logs'`
{@inheritDoc}
### `function get_title()`
Return the Log title
**Returns:** string
### `function get_order()`
Return the log order type
**Returns:** string
### `function get_parent()`
Retun the parent ID
**Returns:** integer
### `function get_description()`
Return the Log description
**Returns:** string
### `function get_blog_id()`
Return the ID of blog
**Returns:** integer
### `function get_user_id()`
Return User Id of who make the action
**Returns:** `int` — User Id of logged action
### `public function get_value()`
Get value of log entry
**Parameters:**
* `$value` — mixed
**Returns:** void
### `public function get_old_value()`
Get old value of log entry object
**Parameters:**
* `$value` — mixed
**Returns:** void
### `function set_title($value)`
Set log tittle
**Parameters:**
* `$value` — string
**Returns:** void
### `function set_order($value)`
Define the order type
**Parameters:**
* `$value` — [string]
**Returns:** void
### `function set_parent($value)`
Define the parent ID
**Parameters:**
* `$value` — [integer]
**Returns:** void
### `function set_description($value)`
Define the Log description
**Parameters:**
* `$value` — [string]
**Returns:** void
### `protected function set_user_id($value = 0)`
Define the user ID of log entry
**Parameters:**
* `$value` — [integer]
**Returns:** void
### `protected function set_blog_id($value = 0)`
Define the blog ID of log entry
**Parameters:**
* `$value` — [integer]
**Returns:** void
### `protected function set_value($value = null)`
Define the value of log entry
**Parameters:**
* `$value` — [mixed]
**Returns:** void
### `protected function set_old_value($value = null)`
Set old value of log entry
**Parameters:**
* `$value` — [mixed]
**Returns:** void
### `public static function create($msn = false, $desc = '', $new_value = null, $old_value = null, $status = 'publish')`
**Parameters:**
* `$msn` — boolean|string
* `$desc` — string
* `$new_value` — mixed
* `$old_value` — mixed
* `$status` — string — 'publish', 'private' or 'pending'
**Returns:** \Tainacan\Entities\Log
### `public function approve()`
{@inheritDoc}
<!-- END DOC-COMMENT -->

View File

@ -1,143 +0,0 @@
# Taxonomies
## Taxonomies Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-taxonomies.php -->
### `class Taxonomies extends Repository`
Class Tainacan_Taxonomies
### `public function get_cpt_labels()`
Get the labels for the custom post type of this repository
**Returns:** `array` — Labels in the format expected by register_post_type()
### `public function insert($taxonomy)`
**Parameters:**
* `$taxonomy` — Entities\Taxonomy
**Returns:** Entities\Entity
### `public function fetch( $args = [], $output = null )`
fetch taxonomies based on ID or WP_Query args
Taxonomies 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
**Parameters:**
* `$args` — array — WP_Query args | int $args the taxonomy id
* `$output` — string — The desired output format (@see \Tainacan\Repositories\Repository::fetch_output() for possible values)
**Returns:** `\WP_Query|Array` — an instance of wp query OR array of entities;
<!-- END DOC-COMMENT -->
## Taxonomy Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-taxonomy.php -->
### `class Taxonomy extends Entity`
Represents the Entity Taxonomy
### `protected static $post_type = 'tainacan-taxonomy'`
{@inheritDoc}
### `protected static $capability_type = ['tainacan-taxonomy', 'tainacan-taxonomies']`
{@inheritDoc}
### `protected $repository = 'Taxonomies'`
{@inheritDoc}
### `function register_taxonomy()`
Register the taxonomy
**Returns:** bool
### `function get_name()`
Return the name
**Returns:** string
### `function get_description()`
Return the description
**Returns:** string
### `function get_allow_insert()`
Return true if allow insert or false if not allow insert
**Returns:** boolean
### `function get_slug()`
Return the slug
**Returns:** string
### `function get_db_identifier()`
Return the DB ID
**Returns:** bool|string
### `function set_name($value)`
Define the name of taxonomy
**Parameters:**
* `$value` — [string]
### `function set_slug($value)`
Define the slug
**Parameters:**
* `$value` — [string]
### `function set_description($value)`
Define the description
**Parameters:**
* `$value` — [string]
### `function set_allow_insert($value)`
Define if allow insert or not
**Parameters:**
* `$value` — [boolean]
### `function validate()`
Validate Taxonomy
**Returns:** bool
<!-- END DOC-COMMENT -->

View File

@ -1,142 +0,0 @@
# Terms
## Terms Repository
<!-- BEGIN DOC-COMMENT H3 src/classes/repositories/class-tainacan-terms.php -->
### `class Terms extends Repository`
Class Tainacan_Terms
### `public function insert($term)`
**Parameters:**
* `$term` — Entities\Entity
**Returns:** Entities\Entity|Entities\Term
### `public function fetch( $args = [], $taxonomies = [])`
fetch terms based on ID or get terms args
Terms are stored as WordPress regular terms. Check (@see https://developer.wordpress.org/reference/functions/get_terms/) get_terms() docs to learn all args accepted in the $args parameter
The second paramater specifies from which taxonomies terms should be fetched. You can pass the Taxonomy ID or object, or an Array of IDs or taxonomies objects
**Parameters:**
* `$args` — array — WP_Query args || int $args the term id
* `$taxonomies` — array — Array Entities\Taxonomy || Array int terms IDs || int collection id || Entities\Taxonomy taxonomy object
**Returns:** `array` — of Entities\Term objects || Entities\Term
<!-- END DOC-COMMENT -->
## Term Entity
<!-- BEGIN DOC-COMMENT H3 src/classes/entities/class-tainacan-term.php -->
### `class Term extends Entity`
Represents the Entity Term
### `protected $repository = 'Terms'`
{@inheritDoc}
### `function __construct($which = 0, $taxonomy = false )`
Term constructor.
**Parameters:**
* `$which` — int
* `$taxonomy` — string
### `function get_id()`
Return the unique identifier
**Returns:** integer
### `function get_name()`
Return the name
**Returns:** string
### `function get_parent()`
Return the parent ID
**Returns:** integer
### `function get_description()`
Return the description
**Returns:** string
### `function get_user()`
Return the user ID
**Returns:** integer
### `function get_taxonomy()`
Return the taxonomy
**Returns:** integer
### `function set_name($value)`
Define the name
**Parameters:**
* `$value` — [string]
### `function set_parent($value)`
Define the parent ID
**Parameters:**
* `$value` — [integer]
### `function set_description($value)`
Define the description
**Parameters:**
* `$value` — [string]
### `function set_user($value)`
Define the user associated
**Parameters:**
* `$value` — [integer]
### `function set_taxonomy($value)`
Define the taxonomy associated
**Parameters:**
* `$value` — [integer]
<!-- END DOC-COMMENT -->

View File

@ -4,16 +4,6 @@ This page shows how the internal API works and how to create and fetch all kinds
Its important that you first get familiar with the [key concepts](key-concepts.md) of tainacan.
This page gives an overview of the API. Detailed documentation and reference on each entity can be found below:
* [Collections Reference](class-reference-collections.md)
* [Items Reference](class-reference-items.md)
* [Item Metadata Reference](class-reference-item-metadata.md)
* [Metadata Reference](class-reference-metadata.md)
* [Filters Reference](class-reference-filters.md)
* [Taxonomies Reference](class-reference-taxonomies.md)
* [Terms Reference](class-reference-terms.md)
* [Logs Reference](class-reference-logs.md)
## Overview

View File

@ -3,7 +3,7 @@
/**
* @see \Tainacan\Admin_Hooks->register()
*/
function register_admin_hook( $context, $callback, $position = 'end-left' ) {
function tainacan_register_admin_hook( $context, $callback, $position = 'end-left' ) {
$admin_hooks = \Tainacan\Admin_Hooks::get_instance();
return $admin_hooks->register( $context, $callback, $position );
}

View File

@ -1,8 +1,8 @@
<template>
<div class="tainacan-modal-content">
<header class="tainacan-modal-title">
<h2 v-if="isFilter">{{ this.$i18n.get('filter') }} <em>{{ filter.name }}</em></h2>
<h2 v-else>{{ this.$i18n.get('metadatum') }} <em>{{ metadatum.name }}</em></h2>
<h2 v-if="isFilter">{{ $i18n.get('filter') }} <em>{{ filter.name }}</em></h2>
<h2 v-else>{{ $i18n.get('metadatum') }} <em>{{ metadatum.name }}</em></h2>
<hr>
</header>
<div class="tainacan-form">
@ -22,7 +22,6 @@
<b-tabs
v-if="!isSearching"
size="is-small"
expanded
animated
@input="fetchSelectedLabels()"
v-model="activeTab">
@ -147,13 +146,14 @@
grouped
group-multiline>
<div
v-for="(term, index) in (selected instanceof Array ? selected : [this.selected])"
v-for="(term, index) in (selected instanceof Array ? selected : [selected])"
:key="index"
class="control">
<b-tag
v-if="selected instanceof Array ? true : selected != ''"
attached
closable
@close="selected.splice(index, 1)">
@close="selected instanceof Array ? selected.splice(index, 1) : selected = ''">
{{ isTaxonomy ? selectedTagsName[term] : term }}
</b-tag>
</div>

View File

@ -36,6 +36,15 @@ class REST_Bulkedit_Controller extends REST_Controller {
'args' => $this->get_create_params()
),
)
);
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'bulk_edit_permissions_check'),
),
)
);
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)/add',
array(
@ -158,6 +167,15 @@ class REST_Bulkedit_Controller extends REST_Controller {
],
),
)
);
register_rest_route($this->namespace, '/collection/(?P<collection_id>[\d]+)/' . $this->rest_base . '/(?P<group_id>[0-9a-f]+)/sequence/(?P<sequence_index>[\d]+)',
array(
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item_in_sequence'),
'permission_callback' => array($this, 'bulk_edit_permissions_check'),
),
)
);
}
@ -181,6 +199,9 @@ class REST_Bulkedit_Controller extends REST_Controller {
if (isset($body['items_ids']) && is_array($body['items_ids']) && !empty($body['items_ids'])) {
$args['items_ids'] = $body['items_ids'];
if (isset($body['options'])) {
$args['options'] = $body['options'];
}
} elseif ( isset($body['use_query']) && $body['use_query'] ) {
unset($body['use_query']['paged']);
@ -205,14 +226,10 @@ class REST_Bulkedit_Controller extends REST_Controller {
$bulk = new \Tainacan\Bulk_Edit($args);
$response = [
'id' => $bulk->get_id()
];
$response = $this->prepare_item_for_response($bulk, $request);
$rest_response = new \WP_REST_Response($response, 200);
$rest_response->header('X-WP-Total', $bulk->count_posts());
return $rest_response;
}
@ -265,6 +282,40 @@ class REST_Bulkedit_Controller extends REST_Controller {
}
public function get_item($request) {
$group_id = $request['group_id'];
$args = ['id' => $group_id];
$bulk = new \Tainacan\Bulk_Edit($args);
$return = $this->prepare_item_for_response($bulk, $request);
if (0 === $return['items_count']) {
return new \WP_REST_Response([
'error_message' => __('Group not found', 'tainacan'),
], 404);
}
return new \WP_REST_Response($return, 200);
}
function prepare_item_for_response($bulk_object, $request) {
$count = $bulk_object->count_posts();
$options = $bulk_object->get_options();
$return = [
'id' => $bulk_object->get_id(),
'items_count' => $count,
'options' => $options
];
return $return;
}
public function trash_items($request) {
$group_id = $request['group_id'];
@ -377,6 +428,25 @@ class REST_Bulkedit_Controller extends REST_Controller {
}
}
public function get_item_in_sequence($request) {
$group_id = $request['group_id'];
$index = $request['sequence_index'];
$args = ['id' => $group_id];
$bulk = new \Tainacan\Bulk_Edit($args);
$item_id = $bulk->get_item_id_by_index( (int) $index );
if ( !$item_id ) {
return new \WP_REST_Response([
'error_message' => __('Item not found.', 'tainacan'),
], 404);
} else {
return new \WP_REST_Response($item_id, 200);
}
}
/**

View File

@ -42,6 +42,7 @@ class Bulk_Edit {
* @type int $collection_id The items collection ID. Required if initializing using a query search
* @type array $query The query paramaters used to fetch items that will be part of this bulk edit group
* @type array $items_ids an array containing the IDs of items that will be part of this bulk edit group
* @type array $options an array containing additional options for this bulk edit group (currently used to store sorting information)
* @type string $id The ID of the Bulk edit group.
*
* }
@ -87,7 +88,10 @@ class Bulk_Edit {
$wpdb->query( "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) {$items_query->request}" );
return;
$bulk_params = [
'orderby' => isset($params['query']['orderby']) ? $params['query']['orderby'] : 'post_date',
'order' => isset($params['query']['order']) ? $params['query']['order'] : 'DESC'
];
} elseif (isset($params['items_ids']) && is_array($params['items_ids'])) {
$items_ids = array_filter($params['items_ids'], 'is_integer');
@ -100,10 +104,23 @@ class Bulk_Edit {
$wpdb->query( "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) VALUES $insert_q" );
return;
$bulk_params = [
'orderby' => isset($params['options']['orderby']) ? $params['options']['orderby'] : 'post_date',
'order' => isset($params['options']['order']) ? $params['options']['order'] : 'DESC'
];
}
/**
* This is stored to be used by the get_sequence_item_by_index() method, which is used
* by the sequence edit routine.
*
* For everything else, the order does not matter...
*/
$this->save_options($bulk_params);
return;
}
/**
@ -126,16 +143,64 @@ class Bulk_Edit {
return $this->id;
}
// return the number of items selected in the current bulk group
/**
* return the number of items selected in the current bulk group
* @return int number of items in the group
*/
public function count_posts() {
global $wpdb;
$id = $this->get_id();
if (!empty($id)) {
return $wpdb->get_var( $wpdb->prepare("SELECT COUNT(post_id) FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $this->meta_key, $id) );
return (int) $wpdb->get_var( $wpdb->prepare("SELECT COUNT(post_id) FROM $wpdb->postmeta WHERE meta_key = %s AND meta_value = %s", $this->meta_key, $id) );
}
return 0;
}
/**
* Gets the id of the item in a given position inside the group
*
* @param int $index THe position of the index to search for. From 1 to the length of the group
* @return int|bool Returns the ID of the item or false if the index is out of range
*/
public function get_item_id_by_index($index) {
if (!is_int($index)) {
throw new InvalidArgumentException('get_item_id_by_index function only accepts integers. Input was: '.$index);
}
$options = $this->get_options();
$query = [
'meta_query' => [
[
'key' => $this->meta_key,
'value' => $this->get_id()
]
],
'fields' => 'ids',
'post_type' => \Tainacan\Repositories\Repository::get_collections_db_identifiers(),
'posts_per_page' => 1,
'paged' => $index,
'orderby' => $options['orderby'],
'order' => $options['order']
];
$object = new \WP_Query($query);
if ( $object->have_posts() && isset($object->posts) && is_array($object->posts) && isset($object->posts[0]) && is_integer($object->posts[0]) ) {
return $object->posts[0];
}
return false;
}
public function save_options($value) {
update_option('tainacan_bulk_' . $this->get_id(), $value);
}
public function get_options() {
return get_option('tainacan_bulk_' . $this->get_id());
}
private function _build_select($fields) {
global $wpdb;

View File

@ -1,5 +1,5 @@
=== Tainacan ===
Contributors: andrebenedito, fabianobn, jacsonp, leogermani, weryques, wetah
Contributors: andrebenedito, daltonmartins, fabianobn, jacsonp, leogermani, weryques, wetah
Tags: museums, libraries, archives, GLAM, collections, repository
Requires at least: 4.8
Tested up to: 4.9.8

View File

@ -181,7 +181,6 @@
id="tainacan-slide-container">
<swiper-slide
:ref="'thumb-' + item.id"
@click="slideIndex = index;"
:key="index"
v-for="(item, index) of slideItems"
class="tainacan-slide-item"
@ -268,6 +267,7 @@ export default {
slideIndex: 0,
minPage: 1,
maxPage: 1,
readjustedSlideIndex: 0,
preloadedItem: {},
swiperOption: {
mousewheel: true,
@ -321,7 +321,7 @@ export default {
items: {
handler () {
if (this.items.length > 0) {
let updatedSlideIndex = this.slideIndex != undefined ? JSON.parse(JSON.stringify(this.slideIndex)) : 0;
let updatedSlideIndex = this.slideIndex != undefined ? (this.slideIndex + 0) : 0;
// Loops through new items list. Depending on direction, goes from start or end of list.
for (let newItem of ((this.goingRight) ? this.items : JSON.parse(JSON.stringify(this.items)).reverse())) {
@ -352,26 +352,20 @@ export default {
}
}
if (this.$refs.mySwiper != undefined && this.$refs.mySwiper.swiper != undefined)
this.$refs.mySwiper.swiper.update();
// When changes where made in the array, updates slider position
this.$nextTick(() => {
if (this.goingRight == undefined && updatedSlideIndex == 0) {
this.slideIndex = -1; // Used to force reload of index when page has not loaded slideItems yet
} else {
if (this.$refs.mySwiper != undefined && this.$refs.mySwiper.swiper != undefined) {
// if (updatedSlideIndex != undefined && this.$refs.mySwiper.swiper.slides[updatedSlideIndex] != undefined)
// this.$refs.mySwiper.swiper.slides[updatedSlideIndex].click();
this.$refs.mySwiper.swiper.activeIndex = this.slideIndex;
this.slideIndex = updatedSlideIndex;
// console.log("Após: " + this.slideIndex + " " + this.$refs.mySwiper.swiper.activeIndex);
}
}
if (this.slideIndex != undefined && this.$refs.mySwiper.swiper.slides[this.slideIndex] != undefined)
this.$refs.mySwiper.swiper.slides[this.slideIndex].click();
this.$refs.mySwiper.swiper.activeIndex == this.slideIndex;
this.$refs.mySwiper.swiper.slideTo(this.slideIndex, 0, false);
this.$refs.mySwiper.swiper.update();
});
}
},
immediate: true
@ -393,8 +387,17 @@ export default {
this.loadCurrentItem();
// Handles requesting new page of items, either to left or right
this.$nextTick(() => {
if (this.slideItems.length > 0) {
if (this.$refs.mySwiper != undefined && this.$refs.mySwiper.swiper != undefined) {
if (this.slideIndex != this.$refs.mySwiper.swiper.activeIndex) {
if (this.slideIndex != undefined && this.$refs.mySwiper.swiper.slides[this.slideIndex] != undefined)
this.$refs.mySwiper.swiper.slides[this.slideIndex].click();
this.readjustedSlideIndex = this.slideIndex;
this.$refs.mySwiper.swiper.activeIndex = this.slideIndex + 0;
// console.log("Index: " + this.slideIndex, this.$refs.mySwiper.swiper.activeIndex, this.readjustedSlideIndex)
} else if (this.slideItems.length > 0) {
if (this.$refs.mySwiper.swiper.activeIndex == this.slideItems.length - 1 && this.page < this.totalPages)
oldVal == undefined ? this.$eventBusSearch.setPage(this.page + 1) : this.$eventBusSearch.setPage(this.maxPage + 1);
else if (this.$refs.mySwiper.swiper.activeIndex == 0 && this.page > 1 && this.slideItems.length < this.totalItems) {
@ -405,7 +408,7 @@ export default {
// Handles pausing auto play when reaches the end of the list.
if (this.$refs.mySwiper.swiper.activeIndex == this.slideItems.length - 1 && this.page == this.totalPages)
this.isPlaying = false;
});
}
}
},
immediate: true
@ -450,8 +453,20 @@ export default {
}, 500);
},
onSlideChange() {
// console.log(this.slideIndex, this.$refs.mySwiper.swiper.activeIndex, this.readjustedSlideIndex)
if (this.$refs.mySwiper.swiper != undefined)
this.slideIndex = this.$refs.mySwiper.swiper.activeIndex;
this.$nextTick(() => {
if (this.readjustedSlideIndex != undefined) {
this.slideIndex = this.readjustedSlideIndex;
// if (this.slideIndex != undefined && this.$refs.mySwiper.swiper.slides[this.slideIndex] != undefined)
// this.$refs.mySwiper.swiper.slides[this.slideIndex].click();
this.$refs.mySwiper.swiper.activeIndex = this.slideIndex + 0;
this.readjustedSlideIndex = undefined;
}
});
},
nextSlide() {
if (this.$refs.mySwiper.swiper != undefined)

View File

@ -89,10 +89,12 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
for ($i = 1; $i<=40; $i++) {
$title = 'testeItem ' . str_pad($i, 2, "0", STR_PAD_LEFT);
$item = $this->tainacan_entity_factory->create_entity(
'item',
array(
'title' => 'testeItem ' . $i,
'title' => $title,
'collection' => $collection,
'status' => 'publish'
),
@ -103,7 +105,7 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
$this->tainacan_item_metadata_factory->create_item_metadata($item, $metadatum, $i % 2 == 0 ? 'even' : 'odd');
$this->tainacan_item_metadata_factory->create_item_metadata($item, $category, ['good', 'bad']);
$this->tainacan_item_metadata_factory->create_item_metadata($item, $collection->get_core_title_metadatum(), 'testeItem ' . $i);
$this->tainacan_item_metadata_factory->create_item_metadata($item, $collection->get_core_title_metadatum(), $title);
}
@ -912,7 +914,7 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
$this->assertTrue(is_string($data['id']));
$this->assertEquals(17, $response->headers['X-WP-Total']);
$this->assertEquals(17, $data['items_count']);
}
@ -960,7 +962,7 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
$this->assertTrue(is_string($data['id']));
$this->assertEquals(20, $response->headers['X-WP-Total']);
$this->assertEquals(20, $data['items_count']);
}
@ -1303,5 +1305,131 @@ class BulkEdit extends TAINACAN_UnitApiTestCase {
}
/**
* @group sequence
*/
function test_get_item_in_sequence() {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$query = [
'posts_per_page' => 22,
'orderby' => 'title'
];
$bulk = new \Tainacan\Bulk_Edit([
'query' => $query,
'collection_id' => $this->collection->get_id()
]);
$item_id = $bulk->get_item_id_by_index(7);
$item = $Tainacan_Items->fetch($item_id);
$this->assertEquals('testeItem 34', $item->get_title());
$item_id = $bulk->get_item_id_by_index(15);
$item = $Tainacan_Items->fetch($item_id);
$this->assertEquals('testeItem 26', $item->get_title());
$query = [
'posts_per_page' => 22,
'orderby' => 'title',
'order' => 'ASC'
];
$bulk = new \Tainacan\Bulk_Edit([
'query' => $query,
'collection_id' => $this->collection->get_id()
]);
$item_id = $bulk->get_item_id_by_index(19);
$item = $Tainacan_Items->fetch($item_id);
$this->assertEquals('testeItem 19', $item->get_title());
$item_id = $bulk->get_item_id_by_index(30);
$this->assertFalse($item_id);
}
/**
* @group sequence
*/
function test_api_get_item_in_sequence() {
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$query = [
'posts_per_page' => 22,
'orderby' => 'title',
'order' => 'ASC'
];
$bulk = new \Tainacan\Bulk_Edit([
'query' => $query,
'collection_id' => $this->collection->get_id()
]);
$request = new \WP_REST_Request(
'GET', $this->api_baseroute . '/' . $bulk->get_id() . '/sequence/7'
);
$response = $this->server->dispatch($request);
$id = $response->get_data();
$item = $Tainacan_Items->fetch($id);
$this->assertEquals('testeItem 07', $item->get_title());
}
function test_api_get_group() {
$query = [
'posts_per_page' => 22,
'orderby' => 'title',
'order' => 'ASC'
];
$bulk = new \Tainacan\Bulk_Edit([
'query' => $query,
'collection_id' => $this->collection->get_id()
]);
$request = new \WP_REST_Request(
'GET', $this->api_baseroute . '/' . $bulk->get_id()
);
$response = $this->server->dispatch($request);
$data = $response->get_data();
$this->assertEquals($bulk->get_id(), $data['id']);
$this->assertEquals($bulk->get_options()['order'], $data['options']['order']);
$this->assertEquals($bulk->get_options()['orderby'], $data['options']['orderby']);
$this->assertEquals($bulk->count_posts(), $data['items_count']);
$request = new \WP_REST_Request(
'GET', $this->api_baseroute . '/fefefe23232'
);
$response = $this->server->dispatch($request);
$this->assertEquals(404, $response->get_status());
}
}