@@ -821,7 +825,9 @@
:active.sync="isFilterModalActive"
:width="736"
animation="slide-menu"
- trap-focus>
+ trap-focus
+ aria-modal
+ aria-role="dialog">
+
+
+
@@ -798,7 +796,9 @@
:active.sync="isFilterModalActive"
:width="736"
animation="slide-menu"
- trap-focus>
+ trap-focus
+ aria-modal
+ aria-role="dialog">
__( 'Exporter', 'tainacan'),
// Labels (used mainly on Aria Labels and Inputs)
- 'label' => __( 'label', 'tainacan' ),
+ 'label' => __( 'Label', 'tainacan' ),
'label_clean' => __( 'Clear', 'tainacan' ),
+ 'label_none' => __( 'None', 'tainacan' ),
'label_clear_filters' => __( 'Clear filters', 'tainacan' ),
'label_and' => __( 'and', 'tainacan' ),
'label_selected' => __( 'Selected', 'tainacan' ),
@@ -532,7 +533,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_no_terms_created_on_taxonomy' => __( 'No term was created for this taxonomy.', 'tainacan' ),
'info_no_terms_found' => __( 'No term was found here', 'tainacan' ),
'info_no_more_terms_found' => __( 'No more terms found', 'tainacan' ),
- 'info_no_item_created' => __( 'No item was created in this collection.', 'tainacan' ),
+ 'info_no_item_created' => __( 'No item was created so far.', 'tainacan' ),
'info_no_page_found' => __( 'No page was found with this name.', 'tainacan' ),
'info_no_user_found' => __( 'No user was found with this name.', 'tainacan' ),
'info_no_item_found_filter' => __( 'No item was found here with these filters.', 'tainacan' ),
@@ -582,7 +583,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_warning_taxonomy_not_saved' => __( 'Are you sure? The taxonomy is not saved, changes will be lost.', 'tainacan' ),
'info_warning_terms_not_saved' => __( 'Are you sure? There are terms not saved, changes will be lost.', 'tainacan' ),
'info_warning_orphan_terms' => __( 'Are you sure? This term is parent of other terms. These will be converted to root terms.', 'tainacan' ),
- 'info_no_activities' => __( 'No activities', 'tainacan' ),
+ 'info_no_activities' => __( 'No activities yet.', 'tainacan' ),
'info_logs_before' => __( 'Before', 'tainacan' ),
'info_logs_after' => __( 'After', 'tainacan' ),
'info_there_is_no_metadatum' => __( 'There is no metadata here yet.', 'tainacan' ),
@@ -649,7 +650,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_process_status_cancelled' => __('Cancelled', 'tainacan'),
'info_process_status_paused' => __('Paused', 'tainacan'),
'info_process_status_running' => __('Running', 'tainacan'),
- 'info_warning_process_cancelled' => __( 'Are you sure? This process will be cancelled', 'tainacan' ),
+ 'info_warning_process_cancelled' => __( 'Are you sure? This process will be cancelled', 'tainacan' ),
'info_empty' => __( 'empty', 'tainacan' ),
'info_url_copied' => __( 'URL link copied', 'tainacan' ),
'info_other_options' => __( 'Other options: ', 'tainacan'),
@@ -664,31 +665,7 @@ return apply_filters( 'tainacan-admin-i18n', [
'info_expose_only_displayed_metadata' => __( 'By checking this option, only metatada that are displayed on the current list will be exposed', 'tainacan' ),
'info_initial_value' => __( 'Initial value', 'tainacan' ),
'info_final_value' => __( 'Final value', 'tainacan' ),
- 'info_show_interval_on_tag' => __( 'Show interval on tag', 'tainacan' ),
-
- // Tainacan Metadatum Types
- 'tainacan-text' => __( 'Text', 'tainacan' ),
- 'tainacan-textarea' => __( 'Text area', 'tainacan' ),
- 'tainacan-date' => __( 'Date', 'tainacan' ),
- 'tainacan-numeric' => __( 'Numeric', 'tainacan' ),
- 'tainacan-selectbox' => __( 'Select box', 'tainacan' ),
- 'tainacan-relationship' => __( 'Relationship', 'tainacan' ),
- 'tainacan-taxonomy' => __( 'Taxonomy', 'tainacan' ),
- 'tainacan-compound' => __( 'Compound', 'tainacan' ),
-
- // Tainacan Filter Types
- 'tainacan-filter-custom-interval' => __( 'Custom Interval', 'tainacan' ),
- 'tainacan-filter-numeric' => __( 'Numeric', 'tainacan' ),
- 'tainacan-filter-date' => __( 'Date', 'tainacan' ),
- 'tainacan-filter-selectbox' => __( 'Select Box', 'tainacan' ),
- 'tainacan-filter-autocomplete' => __( 'Autocomplete', 'tainacan' ),
- 'tainacan-filter-taginput' => __( 'Tag Input', 'tainacan' ),
- 'tainacan-filter-checkbox' => __( 'Check Box', 'tainacan' ),
- 'tainacan-filter-taxonomy-taginput' => __( 'Taxonomy Tag Input', 'tainacan' ),
- 'tainacan-filter-taxonomy-checkbox' => __( 'Taxonomy Check Box', 'tainacan' ),
- 'tainacan-filter-taxonomy-selectbox' => __( 'Taxonomy Select Box', 'tainacan' ),
- 'tainacan-filter-numeric-interval' => __( 'Numeric Interval', 'tainacan' ),
- 'tainacan-filter-numeric-list-interval' => __( 'Numeric Interval List', 'tainacan' ),
+ 'info_show_interval_on_tag' => __( 'Show applied interval on tags', 'tainacan' ),
// Datepicker months
'datepicker_month_january' => __( 'January', 'tainacan' ),
diff --git a/src/api/class-tainacan-rest-controller.php b/src/api/class-tainacan-rest-controller.php
index fb9087b5d..093065052 100644
--- a/src/api/class-tainacan-rest-controller.php
+++ b/src/api/class-tainacan-rest-controller.php
@@ -66,7 +66,7 @@ class REST_Controller extends \WP_REST_Controller {
'name' => 'title',
'title' => 'title',
'id' => 'p',
- 'authorid' => 'author_id',
+ 'authorid' => 'author',
'authorname' => 'author_name',
'search' => 's',
'searchterm' => 'search',
@@ -165,6 +165,7 @@ class REST_Controller extends \WP_REST_Controller {
$terms = get_terms([
'taxonomy' => $tax_query['taxonomy'],
'fields' => 'ids',
+ 'hide_empty' => isset($args['hide_empty']) ? $args['hide_empty'] : true,
'search' => $tax_query['terms']
]);
@@ -179,6 +180,7 @@ class REST_Controller extends \WP_REST_Controller {
$terms = get_terms([
'taxonomy' => $tax_query['taxonomy'],
'fields' => 'ids',
+ 'hide_empty' => isset($args['hide_empty']) ? $args['hide_empty'] : true,
'search' => $tax_query['terms']
]);
if ($terms) {
@@ -270,11 +272,11 @@ class REST_Controller extends \WP_REST_Controller {
*/
public function get_fetch_only_param(){
return [
- 'fetch_only' => [
+ 'fetch_only' => array(
'type' => 'string/array',
'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.', 'tainacan' ),
//TODO: explicar o fetch only meta.. cabe aqui?
- ]
+ )
];
}
@@ -286,11 +288,22 @@ class REST_Controller extends \WP_REST_Controller {
* @return array|void
*/
public function get_wp_query_params(){
+
$query_params['id'] = array(
'description' => __("Limit result to objects with specific id.", 'tainacan'),
'type' => 'integer',
);
+ $query_params['context'] = array(
+ 'type' => 'string',
+ 'default' => 'view',
+ 'description' => 'The context in which the request is made.',
+ 'enum' => array(
+ 'view',
+ 'edit'
+ ),
+ );
+
$query_params['search'] = array(
'description' => __( 'Limit results to those matching a string.', 'tainacan' ),
'type' => 'string',
@@ -329,7 +342,7 @@ class REST_Controller extends \WP_REST_Controller {
'description' => __( 'Order sort attribute ascending or descending.', 'tainacan' ),
'type' => 'string/array',
'default' => 'desc',
- 'enum' => array( 'asc', 'desc' ),
+ 'enum' => array( 'asc', 'desc', 'ASC', 'DESC' ),
);
$query_params['orderby'] = array(
@@ -387,8 +400,26 @@ class REST_Controller extends \WP_REST_Controller {
),
'metacompare' => array(
'type' => 'string',
- 'description' => __('Operator to test the meta_value. Possible values are =, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, NOT EXISTS, REGEXP, NOT REGEXP or RLIKE.'),
+ 'description' => __('Operator to test the metavalue'),
'default' => '=',
+ 'enum' => array(
+ '=',
+ '!=',
+ '>',
+ '>=',
+ '<',
+ '<=',
+ 'LIKE',
+ 'NOT LIKE',
+ 'IN',
+ 'NOT IN',
+ 'BETWEEN',
+ 'NOT BETWEEN',
+ 'NOT EXISTS',
+ 'REGEXP',
+ 'NOT REGEXP',
+ 'RLIKE'
+ )
),
'metaquery' => array(
'description' => __('Limits result set to items that have specific custom metadata'),
@@ -406,8 +437,24 @@ class REST_Controller extends \WP_REST_Controller {
),
'compare' => array(
'type' => 'string',
- 'description' => __('Operator to test. Possible values are =, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, EXISTS and NOT EXISTS.'),
- 'default' => '='
+ 'description' => __('Operator to test.'),
+ 'default' => '=',
+ 'enum' => array(
+ '=',
+ '!=',
+ '>',
+ '>=',
+ '<',
+ '<=',
+ 'LIKE',
+ 'NOT LIKE',
+ 'IN',
+ 'NOT IN',
+ 'BETWEEN',
+ 'NOT BETWEEN',
+ 'EXISTS',
+ 'NOT EXISTS'
+ )
),
'relation' => array(
'type' => 'string',
@@ -457,8 +504,24 @@ class REST_Controller extends \WP_REST_Controller {
),
'compare' => array(
'type' => 'string',
- 'description' => __('Operator to test. Possible values are =, !=, >, >=, <, <=, LIKE, NOT LIKE, IN, NOT IN, BETWEEN, NOT BETWEEN, EXISTS and NOT EXISTS.'),
- 'default' => '='
+ 'description' => __('Operator to test.'),
+ 'default' => '=',
+ 'enum' => array(
+ '=',
+ '!=',
+ '>',
+ '>=',
+ '<',
+ '<=',
+ 'LIKE',
+ 'NOT LIKE',
+ 'IN',
+ 'NOT IN',
+ 'BETWEEN',
+ 'NOT BETWEEN',
+ 'EXISTS',
+ 'NOT EXISTS'
+ )
),
'dayofweek' => array('type' => 'array'),
'inclusive' => array(
@@ -488,7 +551,14 @@ class REST_Controller extends \WP_REST_Controller {
),
'metadatum' => array(
'type' => 'string',
- 'description' => __('Select taxonomy term by. Possible values are term_id, name, slug or term_taxonomy_id. Default value is term_id.')
+ 'default' => 'term_id',
+ 'description' => __('Select taxonomy term by'),
+ 'enum' => array(
+ 'term_id',
+ 'name',
+ 'slug',
+ 'term_taxonomy_id'
+ )
),
'terms' => array(
'type' => 'int/string/array',
@@ -496,13 +566,24 @@ class REST_Controller extends \WP_REST_Controller {
),
'operator' => array(
'type' => 'string',
- 'description' => __('Operator to test. Possible values are IN, NOT IN, AND, EXISTS and NOT EXISTS'),
- 'default' => 'IN'
+ 'description' => __('Operator to test.'),
+ 'default' => 'IN',
+ 'enum' => array(
+ 'IN',
+ 'NOT IN',
+ 'AND',
+ 'EXISTS',
+ 'NOT EXISTS'
+ )
),
'relation' => array(
'type' => 'string',
- 'description' => __('The logical relationship between each inner taxonomy array when there is more than one. Possible values are AND, OR. Do not use with a single inner taxonomy array.'),
- 'default' => 'AND'
+ 'description' => __('The logical relationship between each inner taxonomy array when there is more than one. Do not use with a single inner taxonomy array.'),
+ 'default' => 'AND',
+ 'enum' => array(
+ 'AND',
+ 'OR'
+ )
),
),
'type' => 'array'
diff --git a/src/api/endpoints/class-tainacan-rest-background-processes-controller.php b/src/api/endpoints/class-tainacan-rest-background-processes-controller.php
index 917f6257d..8e0f2264b 100644
--- a/src/api/endpoints/class-tainacan-rest-background-processes-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-background-processes-controller.php
@@ -42,38 +42,48 @@ class REST_Background_Processes_Controller extends REST_Controller {
],
'all_users' => [
'type' => 'bool',
- 'description' => __( 'Whether to return processes from all users (if current user is admin). Default false.', 'tainacan' ),
+ 'description' => __( 'Whether to return processes from all users (if current user is admin).', 'tainacan' ),
+ 'default' => false,
],
'status' => [
'type' => 'string',
- 'description' => __( '"open" returns only processes currently running. "closed" returns only finished or aborted. "all" returns all. Default "all"', 'tainacan' ),
+ 'description' => __( '"open" returns only processes currently running. "closed" returns only finished or aborted. "all" returns all.', 'tainacan' ),
+ 'default' => 'all',
+ 'enum' => array(
+ 'open',
+ 'closed',
+ 'all'
+ )
],
'perpage' => [
'type' => 'integer',
- 'description' => __( 'Number of processes to return per page. Default 10', 'tainacan' ),
+ 'description' => __( 'Number of processes to return per page', 'tainacan' ),
+ 'default' => 10,
],
'paged' => [
'type' => 'integer',
- 'description' => __( 'Page to retrieve. Default 1', 'tainacan' ),
+ 'description' => __( 'Page to retrieve', 'tainacan' ),
+ 'default' => 1
],
'recent' => [
'type' => 'bool',
'description' => __( 'Returns only processes created or updated recently', 'tainacan' ),
+ 'default' => false
],
],
),
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P
[0-9]+)', array(
-
+
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'bg_processes_permissions_check'),
),
-
+
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P[0-9]+)', array(
-
+
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array($this, 'update_item'),
@@ -82,27 +92,31 @@ class REST_Background_Processes_Controller extends REST_Controller {
'status' => [
'type' => 'string',
'description' => __( '"open" or "closed" ', 'tainacan' ),
+ 'enum' => array(
+ 'open',
+ 'closed'
+ )
]
],
),
-
+
));
register_rest_route($this->namespace, '/' . $this->rest_base . '/(?P[0-9]+)', array(
-
+
array(
'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'bg_processes_permissions_check'),
-
+
),
-
+
));
}
-
+
/**
*
* @param \WP_REST_Request $request
@@ -141,7 +155,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$user_q = $wpdb->prepare("AND user_id = %d", $request['user_id']);
}
- if ( isset($user_q['all_users']) && $user_q['all_users'] ) {
+ if ( isset($request['all_users']) && $request['all_users'] ) {
$user_q = "";
}
}
@@ -154,7 +168,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$status_q = "AND done = 1";
}
}
-
+
$recent_q = '';
if ( isset($request['recent']) && $request['recent'] !== false ) {
$recent_q = "AND (processed_last >= NOW() - INTERVAL 10 MINUTE OR queued_on >= NOW() - INTERVAL 10 MINUTE)";
@@ -180,7 +194,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$rest_response->header('X-WP-Total', (int) $total_items);
$rest_response->header('X-WP-TotalPages', (int) $max_pages);
-
+
return $rest_response;
}
@@ -314,9 +328,9 @@ class REST_Background_Processes_Controller extends REST_Controller {
public function get_log_url($id, $action, $type = '') {
$suffix = $type ? '-' . $type : '';
-
+
$filename = 'bg-' . $action . '-' . $id . $suffix . '.log';
-
+
$upload_url = wp_upload_dir();
if (!file_exists( $upload_url['basedir'] . '/tainacan/' . $filename )) {
@@ -325,7 +339,7 @@ class REST_Background_Processes_Controller extends REST_Controller {
$upload_url = trailingslashit( $upload_url['baseurl'] );
$logs_url = $upload_url . 'tainacan/' . $filename;
-
+
return $logs_url;
}
diff --git a/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php b/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php
index a86b58b44..3ce91d330 100644
--- a/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-bulkedit-controller.php
@@ -456,9 +456,6 @@ class REST_Bulkedit_Controller extends REST_Controller {
* @return array|void
*/
public function get_create_params($object_name = null) {
- $query_params['context']['default'] = 'view';
-
- array_merge($query_params, parent::get_wp_query_params());
$query_params['title'] = array(
'description' => __('Limits the result set to items with a specific title'),
@@ -478,7 +475,11 @@ class REST_Bulkedit_Controller extends REST_Controller {
'description' => __( 'Whether to use the current query to select posts', 'tainacan' ),
];
- $query_params = array_merge($query_params, parent::get_meta_queries_params());
+ $query_params = array_merge(
+ $query_params,
+ parent::get_wp_query_params(),
+ parent::get_meta_queries_params()
+ );
return $query_params;
}
diff --git a/src/api/endpoints/class-tainacan-rest-collections-controller.php b/src/api/endpoints/class-tainacan-rest-collections-controller.php
index f2a7279d1..a591deb8c 100644
--- a/src/api/endpoints/class-tainacan-rest-collections-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-collections-controller.php
@@ -43,7 +43,7 @@ class REST_Collections_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
- 'args' => $this->get_wp_query_params(),
+ 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
),
array(
'methods' => \WP_REST_Server::CREATABLE,
@@ -58,7 +58,7 @@ class REST_Collections_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'),
- 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
+ 'args' => $this->get_wp_query_params(),
),
array(
@@ -73,8 +73,8 @@ class REST_Collections_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array(
'permanently' => array(
- 'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'),
- 'default' => 'false'
+ 'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
+ 'default' => '0',
),
)
),
@@ -476,12 +476,6 @@ class REST_Collections_Controller extends REST_Controller {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
- $endpoint_args['context'] = array(
- 'type' => 'string',
- 'default' => 'view',
- 'items' => array( 'view, edit' )
- );
-
$endpoint_args['name'] = array(
'description' => __('Limits the result set to collections with a specific name'),
'type' => 'string',
diff --git a/src/api/endpoints/class-tainacan-rest-export-controller.php b/src/api/endpoints/class-tainacan-rest-export-controller.php
deleted file mode 100644
index 3bf2e237f..000000000
--- a/src/api/endpoints/class-tainacan-rest-export-controller.php
+++ /dev/null
@@ -1,336 +0,0 @@
-rest_base = 'export';
- parent::__construct();
- add_action('init', array(&$this, 'init_objects'), 11);
- }
-
- /**
- * Initialize objects after post_type register
- *
- * @throws \Exception
- */
- public function init_objects() {
- $this->metadatum_repository = Repositories\Metadata::get_instance();
- $this->item_metadata_repository = Repositories\Item_Metadata::get_instance();
- $this->items_repository = Repositories\Items::get_instance();
- $this->collection_repository = Repositories\Collections::get_instance();
- }
-
- /**
- * If POST on metadatum/collection/, then
- * a metadatum will be created in matched collection and all your item will receive this metadatum
- *
- * If POST on metadatum/item/, then a value will be added in a metadatum and metadatum passed
- * id body of requisition
- *
- * Both of GETs return the metadatum of matched objects
- *
- * @throws \Exception
- */
- public function register_routes() {
- register_rest_route($this->namespace, '/' . $this->rest_base. '/collection/(?P[\d]+)',
- array(
- array(
- 'methods' => \WP_REST_Server::READABLE,
- 'callback' => array($this, 'get_items'),
- 'permission_callback' => array($this, 'get_items_permissions_check'),
- 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
- ),
- )
- );
- register_rest_route($this->namespace, '/' . $this->rest_base. '/item/(?P[\d]+)',
- array(
- array(
- 'methods' => \WP_REST_Server::READABLE,
- 'callback' => array($this, 'get_item'),
- 'permission_callback' => array($this, 'get_item_permissions_check'),
- 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
- ),
- )
- );
- register_rest_route($this->namespace, '/' . $this->rest_base,
- array(
- array(
- 'methods' => \WP_REST_Server::READABLE,
- 'callback' => array($this, 'get_items'),
- 'permission_callback' => array($this, 'get_items_permissions_check'),
- 'args' => $this->get_wp_query_params(),
- )
- )
- );
- }
-
- /**
- * @param \WP_REST_Request $request
- *
- * @return \WP_Error|\WP_REST_Response
- */
- public function get_item( $request ) { }
-
- /**
- * @param \WP_REST_Request $request
- *
- * @return bool|\WP_Error
- * @throws \Exception
- */
- public function get_item_permissions_check( $request ) {
- if(isset($request['collection_id'])) {
- $collection = $this->collection_repository->fetch($request['collection_id']);
- if($collection instanceof Entities\Collection) {
- if (! $collection->can_read()) {
- return false;
- }
- return true;
- }
- } elseif(isset($request['item_id'])) {
- $item = $this->items_repository->fetch($request['item_id']);
- if($item instanceof Entities\Item) {
- if (! $item->can_read()) {
- return false;
- }
- return true;
- }
- } else { // Exporting all
- $dummy = new Entities\Collection();
- return current_user_can($dummy->get_capabilities()->read); // Need to check Colletion by collection
- }
- return false;
- }
-
- /**
- * @param \Tainacan\Entities\Item $item
- * @param \WP_REST_Request $request
- *
- * @return array|\WP_Error|\WP_REST_Response
- */
- public function prepare_item_for_response( $item, $request ) {
- $items_metadata = $item->get_metadata();
-
- $prepared_item = [];
-
- foreach ($items_metadata as $item_metadata){
- $prepared_item[] = $item_metadata->_toArray();
- }
-
- return $prepared_item;
- }
-
- /**
- *
- * @param \WP_REST_Request $request
- * @param \WP_Query|Entities\Item $query
- * @param array $args
- * @return \WP_Error|number
- */
- public function export($request, $query, $args) {
-
- $type = \Tainacan\Exposers_Handler::request_has_type($request);
- $path = wp_upload_dir();
- $path = $path['path'];
- $filename = $path.date('YmdHis').'-tainacan-export.'.$type->get_extension();
- $pid = -1;
-
- $log = \Tainacan\Entities\Log::create(
- __('Export Process', 'tainacan'),
- __('Exporting Data', 'tainacan').'\nArgs: '.print_r($args, true),
- ['file' => $filename],
- [],
- 'processing'
- );
-
- $body = json_decode( $request->get_body(), true );
- $background = ! (isset($body['export-background']) && $body['export-background'] == false);
- if( $background ) {
- $pid = pcntl_fork();
- } else {
- $pid = true;
- }
- if ($pid === -1) {
- $error = new \WP_Error('could not fork');
- $log = \Tainacan\Entities\Log::create(
- __('Export Process Error', 'tainacan'),
- __('Exporting Error', 'tainacan').'\\nArgs: '.print_r($args, true).'\\nError: could not fork',
- $error,
- [],
- 'error'
- );
- remove_filter( 'rest_request_after_callbacks', [\Tainacan\Exposers_Handler::get_instance(), 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
- remove_filter( 'tainacan-rest-response', [\Tainacan\Exposers_Handler::get_instance(), 'rest_response'], 10, 2 ); // exposer types
- return $log;
- } elseif ($pid) { // we are the parent or run at foreground
- try {
- ignore_user_abort(true);
- set_time_limit(0);
- ini_set("memory_limit", "256M");
-
- if($background) { // wait for child to respond and exit and reconnect database if is forked
- $status = null;
- pcntl_wait($status);
- global $wpdb;
- $wpdb->db_connect();
- }
-
- $response = [];
- if(isset($request['collection_id'])) { // One Colletion
- $collection_id = $request['collection_id'];
- $items = $query;
- if ($items->have_posts()) {
- while ( $items->have_posts() ) { //TODO write line by line
- $items->the_post();
-
- $item = new Entities\Item($items->post);
-
- $prepared_item = $this->prepare_item_for_response($item, $request);
-
- array_push($response, $prepared_item);
- }
- wp_reset_postdata();
- }
- } elseif (isset($request['item_id'])) { // One Item
-
- $item = new Entities\Item($request['item_id']);
- if($item->get_id() > 0) {
- $prepared_item = $this->prepare_item_for_response($item, $request);
-
- $response = [$prepared_item];
- }
- } else { // Export All
- $collections = $query;
- $collection_controller = new REST_Collections_Controller();
- if ($collections->have_posts()) {
- while ($collections->have_posts()) {
- $collections->the_post();
- $collection_id = $collections->post->ID;
- $collection = \Tainacan\Repositories\Repository::get_entity_by_post($collections->post);
-
- $prepared_collection = $collection_controller->prepare_item_for_response($collection, $request);
-
- $prepared_items = [];
-
- $items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
- if ($items->have_posts()) {
- while ( $items->have_posts() ) { //TODO write line by line
- $items->the_post();
-
- $item = new Entities\Item($items->post);
-
- $prepared_item = $this->prepare_item_for_response($item, $request);
-
- array_push($prepared_items, $prepared_item);
- }
- wp_reset_postdata();
- }
-
- $prepared_collection['items'] = $prepared_items;
- array_push($prepared_collection, $response);
- }
- wp_reset_postdata();
- }
- }
-
- $rest_response = new \WP_REST_Response(apply_filters('tainacan-rest-response', $response, $request));
- $data = $rest_response->get_data();
- file_put_contents($filename, is_string($data) ? $data : print_r($data, true));
-
- if($background) {
- $log->set_status('publish');
- $logs = \Tainacan\Repositories\Logs::get_instance();
- $logs->update($log);
- exit(1);
- } else {
- return $rest_response->get_data();
- }
- } catch (\Exception $e) {
- if($background) {
- exit(1);
- } else {
- throw $e;
- }
- }
- } else { // we are the child
-
- remove_filter( 'rest_request_after_callbacks', [\Tainacan\Exposers_Handler::get_instance(), 'rest_request_after_callbacks'], 10, 3 ); //exposer mapping
- remove_filter( 'tainacan-rest-response', [\Tainacan\Exposers_Handler::get_instance(), 'rest_response'], 10, 2 ); // exposer types
- return $log;
- }
-
- }
-
- /**
- * @param \WP_REST_Request $request
- *
- * @return \WP_Error|\WP_REST_Response
- */
- public function get_items( $request ) {
- $args = $this->prepare_filters($request); // TODO default args
- $rest_response = new \WP_REST_Response([], 200); // TODO error, empty response
-
- if(isset($request['collection_id'])) { // One Colletion
- $collection_id = $request['collection_id'];
- $items = $this->items_repository->fetch($args, $collection_id, 'WP_Query');
-
- $response = $this->export($request, $items, $args);
-
- $total_items = $items->found_posts;
- $ret = $response instanceof Entity ? $response->__toArray() : $response;
- $rest_response = new \WP_REST_Response($ret, 200);
-
- $rest_response->header('X-WP-Total', (int) $total_items);
- } elseif (isset($request['item_id'])) { // One Item
-
- $item = new Entities\Item($request['item_id']);
- if($item->get_id() > 0) {
- $response = $this->export($request, $item, $args);
-
- $total_items = 1;
- $max_pages = 1;
-
- $rest_response = new \WP_REST_Response($response->__toArray(), 200);
-
- $rest_response->header('X-WP-Total', 1);
- $rest_response->header('X-WP-TotalPages', 1);
- }
- } else { // Export All
- $Tainacan_Collection = \Tainacan\Repositories\Collections::get_instance();
- $collections = $Tainacan_Collection->fetch(['post_status' => 'publish'], 'WP_Query');
-
- $response = $this->export($request, $collections, $args);
- $total_items = $collections->found_posts;
- $ret = $response instanceof Entity ? $response->__toArray() : $response;
- $rest_response = new \WP_REST_Response($ret, 200);
-
- $rest_response->header('X-WP-Total', (int) $total_items);
- }
-
- return $rest_response;
- }
-
- /**
- * @param \WP_REST_Request $request
- *
- * @return bool|\WP_Error
- * @throws \Exception
- */
- public function get_items_permissions_check( $request ) {
- return $this->get_item_permissions_check($request);
- }
-
-}
-
-?>
diff --git a/src/api/endpoints/class-tainacan-rest-filter-types-controller.php b/src/api/endpoints/class-tainacan-rest-filter-types-controller.php
index c0fb0fffc..65f2826ca 100644
--- a/src/api/endpoints/class-tainacan-rest-filter-types-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-filter-types-controller.php
@@ -59,7 +59,6 @@ class REST_Filter_Types_Controller extends REST_Controller {
$filter_type = new $name();
$filter_arr = $filter_type->_toArray();
- $filter_arr['name'] = $item;
return $filter_arr;
}
diff --git a/src/api/endpoints/class-tainacan-rest-filters-controller.php b/src/api/endpoints/class-tainacan-rest-filters-controller.php
index ffc42f9ec..8d4239d95 100644
--- a/src/api/endpoints/class-tainacan-rest-filters-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-filters-controller.php
@@ -83,8 +83,8 @@ class REST_Filters_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array(
'permanently' => array(
- 'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'),
- 'default' => 'false'
+ 'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
+ 'default' => '0'
),
)
),
@@ -122,13 +122,11 @@ class REST_Filters_Controller extends REST_Controller {
if(empty($received_type)){
throw new \InvalidArgumentException('The type can\'t be empty');
} elseif(!strrchr($received_type, '_')){
- $received_type = ucfirst(strtolower($received_type));
+ $type = ucfirst(strtolower($received_type));
} else {
- $received_type = ucwords(strtolower($received_type), '_');
+ $type = ucwords(strtolower($received_type), '_\\');
}
- $type = "Tainacan\Filter_Types\\$received_type";
-
$filter_type = new $type();
foreach ($filter as $attribute => $value){
@@ -467,11 +465,10 @@ class REST_Filters_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
- $endpoint_args['context'] = array(
- 'type' => 'string',
- 'default' => 'view',
- 'items' => array( 'view, edit' )
- );
+ $endpoint_args = array_merge(
+ $endpoint_args,
+ parent::get_wp_query_params()
+ );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->filter_repository->get_map();
@@ -496,16 +493,17 @@ class REST_Filters_Controller extends REST_Controller {
* @return array|void
*/
public function get_wp_query_params() {
- $query_params['context']['default'] = 'view';
-
- $query_params = array_merge($query_params, parent::get_wp_query_params());
$query_params['name'] = array(
'description' => __('Limits the result set to filters with a specific name'),
'type' => 'string',
);
- $query_params = array_merge($query_params, parent::get_meta_queries_params());
+ $query_params = array_merge(
+ $query_params,
+ parent::get_wp_query_params(),
+ parent::get_meta_queries_params()
+ );
return $query_params;
}
diff --git a/src/api/endpoints/class-tainacan-rest-importers-controller.php b/src/api/endpoints/class-tainacan-rest-importers-controller.php
index 2897bf72d..51dddbd92 100644
--- a/src/api/endpoints/class-tainacan-rest-importers-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-importers-controller.php
@@ -267,7 +267,7 @@ class REST_Importers_Controller extends REST_Controller {
if ( method_exists($importer, 'get_source_special_fields') ) {
$response['source_special_fields'] = $importer->get_source_special_fields();
}
-
+ $Tainacan_Importer_Handler->save_importer_instance($importer);
return new \WP_REST_Response( $response, 200 );
}
diff --git a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php
index ea9b3dc6d..30cdef1f6 100644
--- a/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-item-metadata-controller.php
@@ -56,7 +56,7 @@ class REST_Item_Metadata_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
- 'args' => $this->get_wp_query_params(),
+ 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
)
)
);
@@ -268,7 +268,12 @@ class REST_Item_Metadata_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
- if ($method === \WP_REST_Server::EDITABLE) {
+ if($method === \WP_REST_Server::READABLE) {
+ $endpoint_args = array_merge(
+ $endpoint_args,
+ $this->get_wp_query_params()
+ );
+ } elseif ($method === \WP_REST_Server::EDITABLE) {
$endpoint_args['values'] = [
'type' => 'array/string/object/integer',
'items' => [
@@ -290,7 +295,15 @@ class REST_Item_Metadata_Controller extends REST_Controller {
* @return array
*/
public function get_wp_query_params() {
- $query_params['context']['default'] = 'view';
+ $query_params['context'] = array(
+ 'type' => 'string',
+ 'default' => 'view',
+ 'description' => 'The context in which the request is made.',
+ 'enum' => array(
+ 'view',
+ 'edit'
+ ),
+ );
return $query_params;
}
diff --git a/src/api/endpoints/class-tainacan-rest-items-controller.php b/src/api/endpoints/class-tainacan-rest-items-controller.php
index 9d06a0cfa..fb07f33ec 100644
--- a/src/api/endpoints/class-tainacan-rest-items-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-items-controller.php
@@ -80,8 +80,8 @@ class REST_Items_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array(
'permanently' => array(
- 'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection', 'tainacan'),
- 'default' => 'false'
+ 'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection', 'tainacan'),
+ 'default' => '0'
),
)
),
@@ -757,15 +757,18 @@ class REST_Items_Controller extends REST_Controller {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
- $endpoint_args['fetch_only'] = array(
- 'type' => 'string/array',
- 'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.' ),
- );
-
$endpoint_args['context'] = array(
- 'type' => 'string',
- 'default' => 'view',
- 'items' => array( 'view, edit' )
+ 'type' => 'string',
+ 'default' => 'view',
+ 'description' => 'The context in which the request is made.',
+ 'enum' => array(
+ 'view',
+ 'edit'
+ ),
+ );
+ $endpoint_args = array_merge(
+ $endpoint_args,
+ parent::get_fetch_only_param()
);
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->items_repository->get_map();
@@ -791,16 +794,16 @@ class REST_Items_Controller extends REST_Controller {
* @return array|void
*/
public function get_wp_query_params() {
- $query_params['context']['default'] = 'view';
-
- array_merge($query_params, parent::get_wp_query_params());
-
$query_params['title'] = array(
'description' => __('Limits the result set to items with a specific title'),
'type' => 'string',
);
- $query_params = array_merge($query_params, parent::get_meta_queries_params());
+ $query_params = array_merge(
+ $query_params,
+ parent::get_wp_query_params(),
+ parent::get_meta_queries_params()
+ );
return $query_params;
}
diff --git a/src/api/endpoints/class-tainacan-rest-logs-controller.php b/src/api/endpoints/class-tainacan-rest-logs-controller.php
index 920b4258a..c64aebcbb 100644
--- a/src/api/endpoints/class-tainacan-rest-logs-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-logs-controller.php
@@ -38,7 +38,17 @@ class REST_Logs_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'),
- 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
+ 'args' => array(
+ 'context' => array(
+ 'type' => 'string',
+ 'default' => 'view',
+ 'description' => 'The context in which the request is made.',
+ 'enum' => array(
+ 'view',
+ 'edit'
+ )
+ ),
+ ),
),
'schema' => [$this, 'get_schema']
)
@@ -351,11 +361,10 @@ class REST_Logs_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
- $endpoint_args['context'] = array(
- 'type' => 'string',
- 'default' => 'view',
- 'items' => array( 'view' )
- );
+ $endpoint_args = array_merge(
+ $endpoint_args,
+ parent::get_wp_query_params()
+ );
}
return $endpoint_args;
diff --git a/src/api/endpoints/class-tainacan-rest-metadata-controller.php b/src/api/endpoints/class-tainacan-rest-metadata-controller.php
index 513da9fab..046e81ae3 100644
--- a/src/api/endpoints/class-tainacan-rest-metadata-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-metadata-controller.php
@@ -44,24 +44,33 @@ class REST_Metadata_Controller extends REST_Controller {
public function register_routes() {
register_rest_route($this->namespace, '/collection/(?P[\d]+)/' . $this->rest_base . '/(?P[\d]+)',
array(
+ array(
+ 'methods' => \WP_REST_Server::READABLE,
+ 'callback' => array($this, 'get_item'),
+ 'permission_callback' => array($this, 'get_item_permissions_check'),
+ 'args' => array(
+ 'context' => array(
+ 'type' => 'string',
+ 'default' => 'view',
+ 'description' => 'The context in which the request is made.',
+ 'enum' => array(
+ 'view',
+ 'edit'
+ )
+ ),
+ ),
+ ),
array(
'methods' => \WP_REST_Server::EDITABLE,
'callback' => array($this, 'update_item'),
'permission_callback' => array($this, 'update_item_permissions_check'),
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
),
- // ENDPOINT X. THIS ENDPOINT DO THE SAME THING OF ENDPOINT Z. I hope in a brief future it function changes.
array(
'methods' => \WP_REST_Server::DELETABLE,
'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'delete_item_permissions_check'),
),
- array(
- 'methods' => \WP_REST_Server::READABLE,
- 'callback' => array($this, 'get_item'),
- 'permission_callback' => array($this, 'get_item_permissions_check'),
- 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE),
- ),
'schema' => [$this, 'get_schema']
)
);
@@ -84,28 +93,38 @@ class REST_Metadata_Controller extends REST_Controller {
);
register_rest_route($this->namespace, '/' . $this->rest_base,
array(
- array(
- 'methods' => \WP_REST_Server::CREATABLE,
- 'callback' => array($this, 'create_item'),
- 'permission_callback' => array($this, 'create_item_permissions_check'),
- 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
- ),
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'args' => $this->get_wp_query_params(),
),
+ array(
+ 'methods' => \WP_REST_Server::CREATABLE,
+ 'callback' => array($this, 'create_item'),
+ 'permission_callback' => array($this, 'create_item_permissions_check'),
+ 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::CREATABLE),
+ ),
'schema' => [$this, 'get_schema'],
)
);
register_rest_route($this->namespace, '/'. $this->rest_base . '/(?P[\d]+)',
array(
- // ENDPOINT Z.
array(
- 'methods' => \WP_REST_Server::DELETABLE,
- 'callback' => array($this, 'delete_item'),
- 'permission_callback' => array($this, 'delete_item_permissions_check')
+ 'methods' => \WP_REST_Server::READABLE,
+ 'callback' => array($this, 'get_item'),
+ 'permission' => array($this, 'get_item_permissions_check'),
+ 'args' => array(
+ 'context' => array(
+ 'type' => 'string',
+ 'default' => 'view',
+ 'description' => 'The context in which the request is made.',
+ 'enum' => array(
+ 'view',
+ 'edit'
+ )
+ ),
+ ),
),
array(
'methods' => \WP_REST_Server::EDITABLE,
@@ -114,10 +133,9 @@ class REST_Metadata_Controller extends REST_Controller {
'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::EDITABLE)
),
array(
- 'methods' => \WP_REST_Server::READABLE,
- 'callback' => array($this, 'get_item'),
- 'permission' => array($this, 'get_item_permissions_check'),
- 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
+ 'methods' => \WP_REST_Server::DELETABLE,
+ 'callback' => array($this, 'delete_item'),
+ 'permission_callback' => array($this, 'delete_item_permissions_check')
),
'schema' => [$this, 'get_schema'],
)
@@ -564,11 +582,10 @@ class REST_Metadata_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
- $endpoint_args['context'] = array(
- 'type' => 'string',
- 'default' => 'view',
- 'items' => array( 'view, edit' )
- );
+ $endpoint_args = array_merge(
+ $endpoint_args,
+ parent::get_wp_query_params()
+ );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->metadatum_repository->get_map();
diff --git a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php
index a1f71856e..7004eb5da 100644
--- a/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-taxonomies-controller.php
@@ -54,7 +54,21 @@ class REST_Taxonomies_Controller extends REST_Controller {
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_item'),
'permission_callback' => array($this, 'get_item_permissions_check'),
- 'args' => $this->get_endpoint_args_for_item_schema(\WP_REST_Server::READABLE)
+ 'args' => array(
+ 'context' => array(
+ 'type' => 'string',
+ 'default' => 'view',
+ 'description' => 'The context in which the request is made.',
+ 'enum' => array(
+ 'view',
+ 'edit'
+ )
+ ),
+ 'fetch_only' => array(
+ 'type' => 'string/array',
+ 'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.', 'tainacan' ),
+ )
+ )
),
array(
'methods' => \WP_REST_Server::DELETABLE,
@@ -62,8 +76,8 @@ class REST_Taxonomies_Controller extends REST_Controller {
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => array(
'permanently' => array(
- 'description' => __('To delete permanently, you can pass \'permanently\' as true. By default this will only trash collection'),
- 'default' => 'false',
+ 'description' => __('To delete permanently, you can pass \'permanently\' as 1. By default this will only trash collection'),
+ 'default' => '0',
),
)
),
@@ -452,16 +466,11 @@ class REST_Taxonomies_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
- $endpoint_args['fetch_only'] = array(
- 'type' => 'string/array',
- 'description' => __( 'Fetch only specific attribute. The specifics attributes are the same in schema.' ),
- );
-
- $endpoint_args['context'] = array(
- 'type' => 'string',
- 'default' => 'view',
- 'items' => array( 'view, edit' )
- );
+ $endpoint_args = array_merge(
+ $endpoint_args,
+ parent::get_wp_query_params(),
+ parent::get_fetch_only_param()
+ );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->taxonomy_repository->get_map();
diff --git a/src/api/endpoints/class-tainacan-rest-terms-controller.php b/src/api/endpoints/class-tainacan-rest-terms-controller.php
index cf74853d6..e1debad91 100644
--- a/src/api/endpoints/class-tainacan-rest-terms-controller.php
+++ b/src/api/endpoints/class-tainacan-rest-terms-controller.php
@@ -56,8 +56,9 @@ class REST_Terms_Controller extends REST_Controller {
'callback' => array($this, 'delete_item'),
'permission_callback' => array($this, 'delete_item_permissions_check'),
'args' => [
- 'info' => [
- 'description' => __('Delete term permanently.')
+ 'permanently' => [
+ 'description' => __('Delete term permanently.'),
+ 'default' => '1'
]
]
),
@@ -420,11 +421,10 @@ class REST_Terms_Controller extends REST_Controller {
public function get_endpoint_args_for_item_schema( $method = null ) {
$endpoint_args = [];
if($method === \WP_REST_Server::READABLE) {
- $endpoint_args['context'] = array(
- 'type' => 'string',
- 'default' => 'view',
- 'items' => array( 'view, edit' )
- );
+ $endpoint_args = array_merge(
+ $endpoint_args,
+ parent::get_wp_query_params()
+ );
} elseif ($method === \WP_REST_Server::CREATABLE || $method === \WP_REST_Server::EDITABLE) {
$map = $this->terms_repository->get_map();
diff --git a/src/api/tainacan-rest-creator.php b/src/api/tainacan-rest-creator.php
index 973df1004..f6fb740c1 100644
--- a/src/api/tainacan-rest-creator.php
+++ b/src/api/tainacan-rest-creator.php
@@ -19,10 +19,9 @@ $rest_background_processes_controller = new \Tainacan\API\EndPoints\REST_Back
$rest_bulkedit_controller = new \Tainacan\API\EndPoints\REST_Bulkedit_Controller();
$rest_exposers_controller = new \Tainacan\API\EndPoints\REST_Exposers_Controller();
$rest_roles_controller = new \Tainacan\API\EndPoints\REST_Roles_Controller();
-new \Tainacan\API\EndPoints\REST_Export_Controller();
new \Tainacan\API\EndPoints\REST_Metadatum_Mappers_Controller();
$rest_facets_controller = new \Tainacan\API\EndPoints\REST_Facets_Controller();
$rest_oaipmh_expose_controller = new \Tainacan\API\EndPoints\REST_Oaipmh_Expose_Controller();
// Add here other endpoints imports
-?>
\ No newline at end of file
+?>
diff --git a/src/classes/class-tainacan-elastic-press.php b/src/classes/class-tainacan-elastic-press.php
index a2ff3d3f2..a68b326d1 100644
--- a/src/classes/class-tainacan-elastic-press.php
+++ b/src/classes/class-tainacan-elastic-press.php
@@ -584,7 +584,7 @@ class Elastic_Press {
}
if($search != '') {
- $formatted_args['query']['bool']['must'][] = ["wildcard"=>["$field.name.raw" => "*$search*"]];
+ $formatted_args['query']['bool']['must'][] = ["wildcard"=>["$field.name.sortable" => "*$search*"]];
}
} else {
$aggs[$id] = [
@@ -613,7 +613,7 @@ class Elastic_Press {
$field_relationship_label = "$field_relationship_label[0].$field_relationship_label[1].relationship_label";
//$formatted_args['query']['bool']['must'][] = ["wildcard"=>["$field" => "*$search*"]];
$formatted_args['query']['bool']['must'][] = ["bool"=>["should"=>[
- ["wildcard"=>["$field"=>"*$search*"]],
+ ["wildcard"=>["$id.value.sortable"=>"*$search*"]],
["wildcard"=>["$field_relationship_label"=>"*$search*"]] //pega nome do metadado é melhor!
]]];
}
diff --git a/src/classes/class-tainacan-private-files.php b/src/classes/class-tainacan-private-files.php
index 56da2f3cf..bca6421cb 100644
--- a/src/classes/class-tainacan-private-files.php
+++ b/src/classes/class-tainacan-private-files.php
@@ -8,9 +8,11 @@ use Tainacan\Entities;
* Class withe helpful methods to handle media in Tainacan
*/
class Private_Files {
-
+
private static $instance = null;
+ public $dir_separator;
+
public static function get_instance() {
if(!isset(self::$instance)) {
self::$instance = new self();
@@ -18,26 +20,31 @@ class Private_Files {
return self::$instance;
}
-
+
protected function __construct() {
+
+ // Once upon a time I thought I had to worry about Windows and use DIRECTORY_SEPARATOR
+ // but this only gave me frustration and bugs.
+ $this->dir_separator = '/';
+
add_filter('wp_handle_upload_prefilter', [$this, 'pre_upload']);
add_filter('wp_handle_sideload_prefilter', [$this, 'pre_upload']);
add_filter('wp_handle_upload', [$this, 'post_upload']);
-
+
add_action('tainacan-pre-insert-attachment', [$this, 'pre_tainacan_upload'], 10, 3);
add_action('tainacan-post-insert-attachment', [$this, 'post_tainacan_upload'], 10, 3);
-
+
add_action('template_redirect', [$this, 'template_redirect']);
add_filter('image_get_intermediate_size', [$this, 'image_get_intermediate_size'], 10, 3);
add_filter('wp_get_attachment_url', [$this, 'wp_get_attachment_url'], 10, 2);
-
+
add_action('tainacan-insert', [$this, 'update_item_and_collection']);
-
+
add_action('tainacan-bulk-edit-set-status', [$this, 'bulk_edit'], 10, 4);
-
-
+
+
}
-
+
function pre_tainacan_upload($blob, $filename, $post_id) {
if (is_numeric($post_id)) {
global $TAINACAN_UPLOADING_ATTACHMENT_TO_POST;
@@ -45,33 +52,33 @@ class Private_Files {
add_filter('upload_dir', [$this, 'change_upload_dir']);
}
}
-
+
function post_tainacan_upload($attach_id, $attach_data, $post_id) {
remove_filter('upload_dir', [$this, 'change_upload_dir']);
}
-
+
/**
- * Adds a filter to the upload_dir hook when uploading a new file
- *
+ * Adds a filter to the upload_dir hook when uploading a new file
+ *
*/
function pre_upload($file){
add_filter('upload_dir', [$this, 'change_upload_dir']);
return $file;
}
-
+
/**
- * Removes a filter to the upload_dir hook after uploading a new file
- *
+ * Removes a filter to the upload_dir hook after uploading a new file
+ *
*/
function post_upload($fileinfo){
remove_filter('upload_dir', [$this, 'change_upload_dir']);
return $fileinfo;
}
-
+
/**
- * Gets the base directory inside the uploads folder where
- * attachments and documents for items will be uploaded
- *
+ * Gets the base directory inside the uploads folder where
+ * attachments and documents for items will be uploaded
+ *
* @return string The folder name
*/
function get_items_uploads_folder() {
@@ -80,11 +87,11 @@ class Private_Files {
}
return 'tainacan-items';
}
-
+
/**
* Gets the directory prefix to be added to folders holding
- * attachments and documents for private items or collections
- *
+ * attachments and documents for private items or collections
+ *
* @return string The folder prefix
*/
function get_private_folder_prefix() {
@@ -93,140 +100,140 @@ class Private_Files {
}
return '_x_';
}
-
+
/**
- * Change the upload directory for items attachments and documents
+ * Change the upload directory for items attachments and documents
*
- * It replaces the default WordPress strucutre, which is YYYY/MM/file
- * with a path containing the collection id and the item id inside the @see get_items_uploads_folder():
+ * It replaces the default WordPress strucutre, which is YYYY/MM/file
+ * with a path containing the collection id and the item id inside the @see get_items_uploads_folder():
* ex: * tainacan-items/$collection_id/$item_id
*
- * It also add a prefix in the folder name of private items or collections:
+ * It also add a prefix in the folder name of private items or collections:
* tainacan-items/$collection_id/_x_$item_id ($item_id is a private item)
- *
+ *
*/
function change_upload_dir($path) {
$post_id = false;
-
+
// regular ajax uploads via Admin Panel will send post_id
if ( isset($_REQUEST['post_id']) && $_REQUEST['post_id'] ) {
$post_id = $_REQUEST['post_id'];
}
-
+
// API requests to media endpoint will send post
if ( false === $post_id && isset($_REQUEST['post']) && is_numeric($_REQUEST['post']) ) {
$post_id = $_REQUEST['post'];
}
-
- // tainacan internals, scripts and tests, will set this global
+
+ // tainacan internals, scripts and tests, will set this global
if (false === $post_id) {
global $TAINACAN_UPLOADING_ATTACHMENT_TO_POST;
if ( isset($TAINACAN_UPLOADING_ATTACHMENT_TO_POST) && is_numeric($TAINACAN_UPLOADING_ATTACHMENT_TO_POST) ) {
$post_id = $TAINACAN_UPLOADING_ATTACHMENT_TO_POST;
}
}
-
+
if (false === $post_id) {
return $path;
}
-
+
$theme_helper = \Tainacan\Theme_Helper::get_instance();
-
+
$post = get_post($post_id);
-
+
if ( !$theme_helper->is_post_an_item($post) ) {
return $path;
}
-
+
$item = \Tainacan\Repositories\Items::get_instance()->fetch( (int) $post_id );
-
+
if ($item instanceof \Tainacan\Entities\Item) {
-
+
$tainacan_basepath = $this->get_items_uploads_folder();
$col_id_url = $item->get_collection_id();
$col_id = $item->get_collection_id();
$item_id_url = $item->get_id();
$item_id = $item->get_id();
-
+
$col_status = get_post_status_object($item->get_collection()->get_status());
$item_status = get_post_status_object($item->get_status());
-
+
if ( ! $col_status->public ) {
$col_id = $this->get_private_folder_prefix() . $col_id;
}
if ( ! $item_status->public ) {
$item_id = $this->get_private_folder_prefix() . $item_id;
}
-
+
$path['path'] = str_replace($path['subdir'], '', $path['path']); //remove default subdir (year/month)
- $path['url'] = str_replace($path['subdir'], '/' . $tainacan_basepath . '/' . $col_id_url . '/' . $item_id_url, $path['url']);
- $path['path'] .= DIRECTORY_SEPARATOR . $tainacan_basepath . DIRECTORY_SEPARATOR . $col_id . '/' . $item_id;
- $path['subdir'] = DIRECTORY_SEPARATOR . $tainacan_basepath . DIRECTORY_SEPARATOR . $col_id . '/' . $item_id;
-
+ $path['url'] = str_replace($path['subdir'], '/' . $tainacan_basepath . '/' . $col_id_url . '/' . $item_id_url, $path['url']);
+ $path['path'] .= $this->dir_separator . $tainacan_basepath . $this->dir_separator . $col_id . $this->dir_separator . $item_id;
+ $path['subdir'] = $this->dir_separator . $tainacan_basepath . $this->dir_separator . $col_id . $this->dir_separator . $item_id;
+
}
-
+
return $path;
-
+
}
-
+
/**
- * Handles 404 returns looking for attachments inside the tainacan items uploads folder
+ * Handles 404 returns looking for attachments inside the tainacan items uploads folder
*
- * When looking for a file that does not exists, it checks for relative prefixed folders.
+ * When looking for a file that does not exists, it checks for relative prefixed folders.
* If it finds the file, it then checks to see if current user have permission to see this file, based on
* the permission he/she have to read the related item.
- *
+ *
*/
function template_redirect() {
-
+
if (is_404()) {
-
+
$upload_dir = wp_get_upload_dir();
$base_upload_url = preg_replace('/^https?:\/\//', '', $upload_dir['baseurl']);
-
+
$requested_uri = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
-
+
if ( strpos($requested_uri, $base_upload_url) === false ) {
- // Not uploads
+ // Not uploads
return;
}
-
+
$requested_uri = str_replace('/' . $this->get_private_folder_prefix(), '/', $requested_uri);
-
- $file_path = \str_replace( '/', DIRECTORY_SEPARATOR, str_replace($base_upload_url, '', $requested_uri) );
-
+
+ $file_path = \str_replace( '/', $this->dir_separator, str_replace($base_upload_url, '', $requested_uri) );
+
$file = $upload_dir['basedir'] . $file_path;
-
+
$existing_file = false;
-
- $file_dirs = explode(DIRECTORY_SEPARATOR, $file);
+
+ $file_dirs = explode($this->dir_separator, $file);
$file_dirs_size = sizeof($file_dirs);
-
+
$item_id = $file_dirs[$file_dirs_size-2];
$collection_id = $file_dirs[$file_dirs_size-3];
-
- // private item
- $prefixed_file = str_replace( DIRECTORY_SEPARATOR . $item_id . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $item_id . DIRECTORY_SEPARATOR, $file);
-
+
+ // private item
+ $prefixed_file = str_replace( $this->dir_separator . $item_id . $this->dir_separator, $this->dir_separator . $this->get_private_folder_prefix() . $item_id . $this->dir_separator, $file);
+
if ( \file_exists( $prefixed_file ) ) {
$existing_file = $prefixed_file;
}
- // private collection
- $prefixed_collection = str_replace( DIRECTORY_SEPARATOR . $collection_id . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $collection_id . DIRECTORY_SEPARATOR, $file);
+ // private collection
+ $prefixed_collection = str_replace( $this->dir_separator . $collection_id . $this->dir_separator, $this->dir_separator . $this->get_private_folder_prefix() . $collection_id . $this->dir_separator, $file);
if ( !$existing_file && \file_exists( $prefixed_collection ) ) {
$existing_file = $prefixed_collection;
}
- // private both
- $prefixed_both = str_replace( DIRECTORY_SEPARATOR . $collection_id . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $collection_id . DIRECTORY_SEPARATOR, $prefixed_file);
+ // private both
+ $prefixed_both = str_replace( $this->dir_separator . $collection_id . $this->dir_separator, $this->dir_separator . $this->get_private_folder_prefix() . $collection_id . $this->dir_separator, $prefixed_file);
if ( !$existing_file && \file_exists( $prefixed_both ) ) {
$existing_file = $prefixed_both;
}
-
+
if ($existing_file) {
-
+
$item = \Tainacan\Repositories\Items::get_instance()->fetch( (int) $item_id, (int) $collection_id );
$mime_type = \Tainacan\Media::get_instance()->get_mime_content_type($existing_file);
-
+
if ($item instanceof \Tainacan\Entities\Item && $item->can_read()) {
//header('Content-Description: File Transfer');
//header('Content-Type: application/octet-stream');
@@ -237,137 +244,137 @@ class Private_Files {
// header('Pragma: public');
// header('Content-Length: ' . filesize($file));
\readfile($existing_file);
-
+
die;
}
-
+
}
-
-
-
+
+
+
}
-
+
}
-
+
/**
- * Filters the image_get_intermediate_size hook to strip out the
+ * Filters the image_get_intermediate_size hook to strip out the
* private uploads folder prefix from the attachments URLs
*/
function image_get_intermediate_size($data, $post_id, $size) {
-
- $data['path'] = str_replace(DIRECTORY_SEPARATOR . $this->get_private_folder_prefix(), DIRECTORY_SEPARATOR, $data['path']);
+
+ $data['path'] = str_replace($this->dir_separator . $this->get_private_folder_prefix(), $this->dir_separator, $data['path']);
$data['url'] = str_replace('/' . $this->get_private_folder_prefix(), '/', $data['url']);
-
+
return $data;
-
+
}
-
+
/**
- * Filters the wp_get_attachment_url hook to strip out the
+ * Filters the wp_get_attachment_url hook to strip out the
* private uploads folder prefix from the attachments URLs
*/
function wp_get_attachment_url($url, $post_id) {
$url = str_replace('/' . $this->get_private_folder_prefix(), '/', $url);
return $url;
}
-
+
/**
- * When an item or collection is saved, it checks if the satus was changed and
- * if the items upload directory mus be renamed to add or remove the
- * private folder prefix
+ * When an item or collection is saved, it checks if the satus was changed and
+ * if the items upload directory mus be renamed to add or remove the
+ * private folder prefix
*/
function update_item_and_collection($obj) {
-
- $folder = DIRECTORY_SEPARATOR;
- $check_folder = DIRECTORY_SEPARATOR;
+
+ $folder = $this->dir_separator;
+ $check_folder = $this->dir_separator;
$check = false;
-
+
if ( $obj instanceof \Tainacan\Entities\Collection ) {
-
+
$status_obj = get_post_status_object($obj->get_status());
-
+
$folder .= $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check_folder .= ! $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
-
+
$check = true;
-
+
}
-
+
if ( $obj instanceof \Tainacan\Entities\Item ) {
-
+
$collection = $obj->get_collection();
$col_status_object = get_post_status_object($collection->get_status());
-
- $folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . DIRECTORY_SEPARATOR;
- $check_folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . DIRECTORY_SEPARATOR;
-
- $folder .= DIRECTORY_SEPARATOR;
- $check_folder .= DIRECTORY_SEPARATOR;
-
+
+ $folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . $this->dir_separator;
+ $check_folder .= $col_status_object->public ? $collection->get_id() : $this->get_private_folder_prefix() . $collection->get_id() . $this->dir_separator;
+
+ $folder .= $this->dir_separator;
+ $check_folder .= $this->dir_separator;
+
$status_obj = get_post_status_object($obj->get_status());
-
+
$folder .= $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
$check_folder .= ! $status_obj->public ? $obj->get_id() : $this->get_private_folder_prefix() . $obj->get_id();
-
+
$check = true;
-
+
}
-
+
if ($check) {
-
+
$upload_dir = wp_get_upload_dir();
$base_dir = $upload_dir['basedir'];
- $full_path = $base_dir . DIRECTORY_SEPARATOR . $this->get_items_uploads_folder() . $folder;
- $full_path_check = $base_dir . DIRECTORY_SEPARATOR . $this->get_items_uploads_folder() . $check_folder;
-
+ $full_path = $base_dir . $this->dir_separator . $this->get_items_uploads_folder() . $folder;
+ $full_path_check = $base_dir . $this->dir_separator . $this->get_items_uploads_folder() . $check_folder;
+
if (\file_exists($full_path_check)) {
rename($full_path_check, $full_path);
do_action('tainacan-upload-folder-renamed', $full_path_check, $full_path);
}
-
+
}
-
-
+
+
}
-
+
/**
- * Rename all folders from items after a bulk edit operation move their statuses
+ * Rename all folders from items after a bulk edit operation move their statuses
*
* TODO: In the upcoming bulk edit refactor this must be handled as there are performance issues
- *
+ *
*/
function bulk_edit($status, $group, $select_query, $query) {
global $wpdb;
-
+
$ids = $wpdb->get_col($select_query);
-
+
$status_obj = get_post_status_object($status);
$prefix = $status_obj->public ? $this->get_private_folder_prefix() : '';
-
+
$upload_dir = wp_get_upload_dir();
$base_dir = $upload_dir['basedir'];
- $full_path = $base_dir . DIRECTORY_SEPARATOR . $this->get_items_uploads_folder() . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . $prefix;
-
+ $full_path = $base_dir . $this->dir_separator . $this->get_items_uploads_folder() . $this->dir_separator . '*' . $this->dir_separator . $prefix;
+
foreach ($ids as $id) {
$folder = $full_path . $id;
$found = glob($folder);
-
+
if (sizeof($found) == 1 && isset($found[0])) {
-
+
if ($status_obj->public) {
- $target = str_replace(DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $id, DIRECTORY_SEPARATOR . $id, $found[0]);
+ $target = str_replace($this->dir_separator . $this->get_private_folder_prefix() . $id, $this->dir_separator . $id, $found[0]);
} else {
- $target = str_replace(DIRECTORY_SEPARATOR . $id, DIRECTORY_SEPARATOR . $this->get_private_folder_prefix() . $id, $found[0]);
+ $target = str_replace($this->dir_separator . $id, $this->dir_separator . $this->get_private_folder_prefix() . $id, $found[0]);
}
-
+
rename($found[0], $target);
do_action('tainacan-upload-folder-renamed', $found[0], $target);
-
+
}
if (\file_exists($folder)) {
-
+
}
}
}
-
-}
\ No newline at end of file
+
+}
diff --git a/src/classes/entities/class-tainacan-entity.php b/src/classes/entities/class-tainacan-entity.php
index 9940d8be7..d21c5dce0 100644
--- a/src/classes/entities/class-tainacan-entity.php
+++ b/src/classes/entities/class-tainacan-entity.php
@@ -366,7 +366,7 @@ class Entity {
$attributes = [];
foreach($map as $prop => $content) {
- $attributes[$prop] = $this->get_mapped_property($prop);
+ $attributes[$prop] = $this->get($prop);
}
$hook_prefix = self::get_post_type();
diff --git a/src/classes/entities/class-tainacan-filter.php b/src/classes/entities/class-tainacan-filter.php
index ada699f51..f1e84e2d1 100644
--- a/src/classes/entities/class-tainacan-filter.php
+++ b/src/classes/entities/class-tainacan-filter.php
@@ -152,7 +152,7 @@ class Filter extends Entity {
}
$object_type = new $class_name();
- $object_type->set_options( $this->get_filter_type_options() );
+ $object_type->set_options( $this->get_mapped_property('filter_type_options') );
return $object_type;
}
@@ -171,6 +171,10 @@ class Filter extends Entity {
* @return array Configurations for the filter type object
*/
function get_filter_type_options(){
+ $object = $this->get_filter_type_object();
+ if ($object) {
+ return $object->get_options(); // merge with dedault filter type options
+ }
return $this->get_mapped_property('filter_type_options');
}
diff --git a/src/classes/entities/class-tainacan-item-metadata-entity.php b/src/classes/entities/class-tainacan-item-metadata-entity.php
index 25b58923f..603452b16 100644
--- a/src/classes/entities/class-tainacan-item-metadata-entity.php
+++ b/src/classes/entities/class-tainacan-item-metadata-entity.php
@@ -444,25 +444,29 @@ class Item_Metadata_Entity extends Entity {
}
if ($this->is_required() && !$one_filled) {
- $this->add_error('required', $metadatum->get_name() . ' is required');
+ // translators: %s = metadatum name. ex: Title is required
+ $this->add_error( 'required', sprintf( __('%s is required', 'tainacan'), $metadatum->get_name() ) );
return false;
}
if (!$valid) {
- $this->add_error('invalid', $metadatum->get_name() . ' is invalid');
+ // translators: %s = metadatum name. ex: Title is invalid
+ $this->add_error( 'invalid', sprintf( __('%s is invalid', 'tainacan'), $metadatum->get_name() ) );
return false;
}
$this->set_as_valid();
return true;
} else {
- $this->add_error('invalid', $metadatum->get_name() . ' is invalid');
+ // translators: %s = metadatum name. ex: Title is invalid
+ $this->add_error( 'invalid', sprintf( __('%s is invalid', 'tainacan'), $metadatum->get_name() ) );
return false;
}
} else {
if( is_array($value) ){
- $this->add_error('not_multiple', $metadatum->get_name() . ' do not accept array as value');
+ // translators: %s = metadatum name. ex: Title accepts only one single value and not a list of values
+ $this->add_error( 'not_multiple', sprintf( __('%s accepts only one single value and not a list of values', 'tainacan'), $metadatum->get_name() ) );
return false;
}
@@ -476,11 +480,12 @@ class Item_Metadata_Entity extends Entity {
'value' => $value
],
],
- 'post__not_in' => [$item->get_id()]
+ 'post__not_in' => [$item->get_id()]
], $item->get_collection());
if ($test->have_posts()) {
- $this->add_error('key_exists', $metadatum->get_name() . ' is a collection key and there is another item with the same value');
+ // translators: %s = metadatum name. ex: Register ID is a collection key and there is another item with the same value
+ $this->add_error( 'key_exists', sprintf( __('%s is a collection key and there is another item with the same value', 'tainacan'), $metadatum->get_name() ) );
return false;
}
}
diff --git a/src/classes/entities/class-tainacan-log.php b/src/classes/entities/class-tainacan-log.php
index 9059b878e..f63d4c6a7 100644
--- a/src/classes/entities/class-tainacan-log.php
+++ b/src/classes/entities/class-tainacan-log.php
@@ -120,6 +120,14 @@ class Log extends Entity {
return $this->get_mapped_property( 'date' );
}
+ /**
+ * Return the log slug
+ *
+ * @return mixed|null
+ */
+ function get_slug() {
+ return $this->get_mapped_property( 'slug' );
+ }
/**
* Return the Log description
@@ -150,7 +158,7 @@ class Log extends Entity {
public function get_old_value() {
return $this->get_mapped_property( 'old_value' );
}
-
+
/**
* Get new value of log entry object
*
@@ -208,7 +216,7 @@ class Log extends Entity {
public function set_old_value( $value ) {
$this->set_mapped_property( 'old_value', $value );
}
-
+
/**
* Set new value of log entry
*
@@ -226,19 +234,19 @@ class Log extends Entity {
public function get_log_diffs(){
return $this->get_mapped_property('log_diffs');
}
-
+
public function get_object_type() {
- $this->get_mapped_property('object_type');
+ return $this->get_mapped_property('object_type');
}
-
+
public function set_object_type($value) {
$this->set_mapped_property('object_type', $value);
}
-
+
public function get_object_id() {
- $this->get_mapped_property('object_id');
+ return $this->get_mapped_property('object_id');
}
-
+
public function set_object_id($value) {
$this->set_mapped_property('object_id', $value);
}
@@ -256,11 +264,11 @@ class Log extends Entity {
public function get_item_id(){
return $this->get_mapped_property('item_id');
}
-
+
public function get_action() {
- $this->get_mapped_property('action');
+ return $this->get_mapped_property('action');
}
-
+
public function set_action($value) {
$this->set_mapped_property('action', $value);
}
@@ -274,4 +282,4 @@ class Log extends Entity {
return $repository->approve( $this );
}
-}
\ No newline at end of file
+}
diff --git a/src/classes/entities/class-tainacan-metadatum.php b/src/classes/entities/class-tainacan-metadatum.php
index 70e965372..5a57dc165 100644
--- a/src/classes/entities/class-tainacan-metadatum.php
+++ b/src/classes/entities/class-tainacan-metadatum.php
@@ -178,7 +178,7 @@ class Metadatum extends Entity {
}
$object_type = new $class_name();
- $object_type->set_options( $this->get_metadata_type_options() );
+ $object_type->set_options( $this->get_mapped_property('metadata_type_options') );
return $object_type;
}
@@ -197,7 +197,11 @@ class Metadatum extends Entity {
* @return array Configurations for the metadatum type object
*/
function get_metadata_type_options(){
- return $this->get_mapped_property('metadata_type_options');
+ $object = $this->get_metadata_type_object();
+ if ($object) {
+ return $object->get_options(); // merge with dedault metadata type options
+ }
+ return $this->get_mapped_property('metadata_type_options');
}
/**
diff --git a/src/classes/entities/class-tainacan-taxonomy.php b/src/classes/entities/class-tainacan-taxonomy.php
index 9155981f5..3139f7d40 100644
--- a/src/classes/entities/class-tainacan-taxonomy.php
+++ b/src/classes/entities/class-tainacan-taxonomy.php
@@ -80,7 +80,8 @@ class Taxonomy extends Entity {
'show_admin_column' => false,
'rewrite' => [
'slug' => $this->get_slug()
- ],
+ ],
+ 'update_count_callback' => '_update_generic_term_count'
);
if (taxonomy_exists($this->get_db_identifier())){
diff --git a/src/classes/filter-types/autocomplete/Autocomplete.vue b/src/classes/filter-types/autocomplete/Autocomplete.vue
index e7087955b..11d99df6f 100644
--- a/src/classes/filter-types/autocomplete/Autocomplete.vue
+++ b/src/classes/filter-types/autocomplete/Autocomplete.vue
@@ -54,11 +54,11 @@
},
watch: {
'query.metaquery'() {
- this.selectedValues();
+ this.updateSelectedValues();
},
},
mounted() {
- this.selectedValues();
+ this.updateSelectedValues();
},
methods: {
onSelect(option){
@@ -74,7 +74,7 @@
collection_id: this.collectionId,
value: this.selected
});
- this.selectedValues();
+ this.updateSelectedValues();
},
search: _.debounce( function(query) {
@@ -111,7 +111,7 @@
});
}
}, 500),
- selectedValues(){
+ updateSelectedValues(){
if (!this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ))
return false;
@@ -121,9 +121,12 @@
let metadata = this.query.metaquery[ index ];
if (this.metadatumType === 'Tainacan\\Metadata_Types\\Relationship') {
-
- axios.get('/items/' + metadata.value + '?fetch_only=title,thumbnail')
+
+ let endpoint = '/items/' + metadata.value + '?fetch_only=title,thumbnail';
+
+ axios.get(endpoint)
.then( res => {
+
let item = res.data;
this.label = item.title;
this.selected = item.title;
@@ -136,11 +139,11 @@
} else {
this.label = metadata.value;
this.selected = metadata.value;
-
this.$emit( 'sendValuesToTags', { label: this.label, value: this.selected });
}
} else {
- return false;
+ this.label = '';
+ this.selected = '';
}
}
}
diff --git a/src/classes/filter-types/autocomplete/class-tainacan-autocomplete.php b/src/classes/filter-types/autocomplete/class-tainacan-autocomplete.php
index b5d249c00..13db2a442 100644
--- a/src/classes/filter-types/autocomplete/class-tainacan-autocomplete.php
+++ b/src/classes/filter-types/autocomplete/class-tainacan-autocomplete.php
@@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Autocomplete extends Filter_Type {
function __construct(){
- $this->set_name('Autocomplete');
+ $this->set_name( __('Autocomplete', 'tainacan') );
$this->set_supported_types(['string','long_string','item']);
$this->set_component('tainacan-filter-autocomplete');
$this->set_use_max_options(false);
diff --git a/src/classes/filter-types/checkbox/Checkbox.vue b/src/classes/filter-types/checkbox/Checkbox.vue
index 94a725cee..64b2c6583 100644
--- a/src/classes/filter-types/checkbox/Checkbox.vue
+++ b/src/classes/filter-types/checkbox/Checkbox.vue
@@ -70,7 +70,7 @@
this.loadOptions();
},
methods: {
- loadOptions(skipSelected) {
+ loadOptions() {
let promise = null;
// Cancels previous Request
@@ -82,27 +82,18 @@
else
promise = this.getValuesPlainText( this.metadatumId, null, this.isRepositoryLevel, [], 0, this.filter.max_options, false, '1' );
- if (skipSelected != undefined && skipSelected == true) {
- promise.request
- .then(() => {
- if (this.options.length > this.filter.max_options)
- this.options.splice(this.filter.max_options);
- }).catch((error) => {
- this.$console.error(error);
- });
- } else {
- promise.request
- .then(() => {
- this.selectedValues();
- })
- .catch( (error) => {
- if (isCancel(error)) {
- this.$console.log('Request canceled: ' + error.message);
- this.selectedValues();
- } else
- this.$console.error( error );
- });
- }
+ promise.request
+ .then(() => {
+ this.updateSelectedValues();
+ })
+ .catch( (error) => {
+ if (isCancel(error)) {
+ this.$console.log('Request canceled: ' + error.message);
+ this.updateSelectedValues();
+ } else
+ this.$console.error( error );
+ });
+
// Search Request Token for cancelling
this.getOptionsValuesCancel = promise.source;
},
@@ -115,7 +106,7 @@
value: this.selected
});
},
- selectedValues() {
+ updateSelectedValues() {
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false;
diff --git a/src/classes/filter-types/checkbox/class-tainacan-checkbox.php b/src/classes/filter-types/checkbox/class-tainacan-checkbox.php
index c5acf4a58..ebad4f1d4 100644
--- a/src/classes/filter-types/checkbox/class-tainacan-checkbox.php
+++ b/src/classes/filter-types/checkbox/class-tainacan-checkbox.php
@@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Checkbox extends Filter_Type {
function __construct(){
- $this->set_name('Checkbox List');
+ $this->set_name( __('Checkbox List', 'tainacan') );
$this->set_supported_types(['string','long_string','item']);
$this->set_component('tainacan-filter-checkbox');
$this->set_preview_template('
diff --git a/src/classes/filter-types/custom-interval/CustomInterval.vue b/src/classes/filter-types/custom-interval/CustomInterval.vue
deleted file mode 100644
index 6c9362943..000000000
--- a/src/classes/filter-types/custom-interval/CustomInterval.vue
+++ /dev/null
@@ -1,269 +0,0 @@
-
-
-
-
-
-
{{ $i18n.get('label_until') }}
-
-
-
-
-
-
-
{{ $i18n.get('label_until') }}
-
-
-
-
-
-
-
-
diff --git a/src/classes/filter-types/custom-interval/class-tainacan-custom-interval.php b/src/classes/filter-types/custom-interval/class-tainacan-custom-interval.php
deleted file mode 100644
index 7efb4e78c..000000000
--- a/src/classes/filter-types/custom-interval/class-tainacan-custom-interval.php
+++ /dev/null
@@ -1,74 +0,0 @@
-set_name('Custom Interval');
- $this->set_supported_types(['float','date']);
- $this->set_component('tainacan-filter-custom-interval');
- $this->set_use_max_options(false);
- $this->set_preview_template('
-
- ');
- }
-
- /**
- * @param $filter
- * @return string
- * @internal param $metadatum
- */
- public function render( $filter ){
- $type = ( $filter->get_metadatum()->get_metadata_type() === 'Tainacan\Metadata_Types\Date' ) ? 'date' : 'numeric';
- return '';
- }
-}
\ No newline at end of file
diff --git a/src/classes/filter-types/date-interval/DateInterval.vue b/src/classes/filter-types/date-interval/DateInterval.vue
new file mode 100644
index 000000000..d6fa88c37
--- /dev/null
+++ b/src/classes/filter-types/date-interval/DateInterval.vue
@@ -0,0 +1,181 @@
+
+
+
+
{{ $i18n.get('label_until') }}
+
+
+
+
+
+
+
diff --git a/src/classes/filter-types/date-interval/class-tainacan-date-interval.php b/src/classes/filter-types/date-interval/class-tainacan-date-interval.php
new file mode 100644
index 000000000..d9d8716ca
--- /dev/null
+++ b/src/classes/filter-types/date-interval/class-tainacan-date-interval.php
@@ -0,0 +1,55 @@
+set_name( __('Date Interval', 'tainacan') );
+ $this->set_supported_types(['date']);
+ $this->set_component('tainacan-filter-date-interval');
+ $this->set_use_max_options(false);
+ $this->set_preview_template('
+
+ ');
+ }
+
+ /**
+ * @param $filter
+ * @return string
+ * @internal param $metadatum
+ */
+ public function render( $filter ){
+ return '';
+ }
+}
\ No newline at end of file
diff --git a/src/classes/filter-types/date/Date.vue b/src/classes/filter-types/date/Date.vue
index 0f46413f6..464c08029 100644
--- a/src/classes/filter-types/date/Date.vue
+++ b/src/classes/filter-types/date/Date.vue
@@ -78,6 +78,7 @@
:date-parser="(date) => dateParser(date)"
size="is-small"
icon="calendar-today"
+ :years-range="[-200, 50]"
:day-names="[
$i18n.get('datepicker_short_sunday'),
$i18n.get('datepicker_short_monday'),
@@ -121,7 +122,7 @@
filterTypeMixin
],
mounted() {
- this.selectedValues();
+ this.updateSelectedValues();
},
data(){
return {
@@ -131,7 +132,7 @@
},
watch: {
'query.metaquery'() {
- this.selectedValues();
+ this.updateSelectedValues();
}
},
computed: {
@@ -151,7 +152,7 @@
}
},
methods: {
- selectedValues(){
+ updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false;
diff --git a/src/classes/filter-types/date/class-tainacan-date.php b/src/classes/filter-types/date/class-tainacan-date.php
index 9b0bfe773..eec010199 100644
--- a/src/classes/filter-types/date/class-tainacan-date.php
+++ b/src/classes/filter-types/date/class-tainacan-date.php
@@ -10,7 +10,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Date extends Filter_Type {
function __construct(){
- $this->set_name('Date');
+ $this->set_name( __('Date', 'tainacan') );
$this->set_supported_types(['date']);
$this->set_component('tainacan-filter-date');
// $this->set_form_component('tainacan-filter-form-date');
diff --git a/src/classes/filter-types/filter-type/class-tainacan-filter-type.php b/src/classes/filter-types/filter-type/class-tainacan-filter-type.php
index b3a24a46e..b4a5b48a4 100644
--- a/src/classes/filter-types/filter-type/class-tainacan-filter-type.php
+++ b/src/classes/filter-types/filter-type/class-tainacan-filter-type.php
@@ -228,4 +228,8 @@ abstract class Filter_Type {
public function set_form_component($form_component){
$this->form_component = $form_component;
}
+
+ public function get_filter_type() {
+ return str_replace( 'Tainacan\Filter_Types\\', '', get_class($this) );
+ }
}
\ No newline at end of file
diff --git a/src/classes/filter-types/filter-types-mixin.js b/src/classes/filter-types/filter-types-mixin.js
index 58d037746..a452caf21 100644
--- a/src/classes/filter-types/filter-types-mixin.js
+++ b/src/classes/filter-types/filter-types-mixin.js
@@ -22,7 +22,7 @@ export const filterTypeMixin = {
this.collectionId = this.filter.collection_id ? this.filter.collection_id : this.collectionId;
this.metadatumId = this.filter.metadatum.metadatum_id ? this.filter.metadatum.metadatum_id : this.metadatumId;
this.filterTypeOptions = this.filter.filter_type_options ? this.filter.filter_type_options : this.filterTypeOptions;
- this.metadatumType = this.filter.metadatum.metadata_type_object.className ? this.filter.metadatum.metadata_type_object.className : this.metadatumType;
+ this.metadatumType = this.filter.metadatum.metadata_type_object && this.filter.metadatum.metadata_type_object.className ? this.filter.metadatum.metadata_type_object.className : this.metadatumType;
}
};
diff --git a/src/classes/filter-types/numeric-interval/NumericInterval.vue b/src/classes/filter-types/numeric-interval/NumericInterval.vue
index d0f8527a1..96721f059 100644
--- a/src/classes/filter-types/numeric-interval/NumericInterval.vue
+++ b/src/classes/filter-types/numeric-interval/NumericInterval.vue
@@ -3,7 +3,7 @@
@@ -11,7 +11,7 @@
@@ -24,29 +24,45 @@
mixins: [ filterTypeMixin ],
data(){
return {
- valueInit: 0,
- valueEnd: 10,
- isValid: false,
- withError: false
+ valueInit: null,
+ valueEnd: null
}
},
mounted() {
- this.selectedValues();
+ this.updateSelectedValues();
+ },
+ watch: {
+ 'query.metaquery'() {
+ this.updateSelectedValues();
+ }
},
methods: {
// only validate if the first value is higher than first
- validate_values: _.debounce( function (){
- if ( parseFloat( this.valueInit ) > parseFloat( this.valueEnd )) {
- //this.valueEnd = parseFloat( this.valueInit ) + 1;
- //this.withError = true;
-
+ validadeValues: _.debounce( function () {
+ if (this.valueInit == null || this.valueEnd == null)
+ return
+
+ if (this.valueInit.constructor == Number)
+ this.valueInit = this.valueInit.valueOf();
+
+ if (this.valueEnd.constructor == Number)
+ this.valueEnd = this.valueEnd.valueOf();
+
+ this.valueInit = parseFloat(this.valueInit);
+ this.valueEnd = parseFloat(this.valueEnd);
+
+ if (isNaN(this.valueInit) || isNaN(this.valueEnd))
+ return
+
+ if (this.valueInit > this.valueEnd) {
+ this.showErrorMessage();
return;
}
- //this.withError = false;
+
this.emit();
}, 600),
// message for error
- error_message(){
+ showErrorMessage(){
this.$buefy.toast.open({
duration: 3000,
message: this.$i18n.get('info_error_first_value_greater'),
@@ -61,7 +77,6 @@
this.$emit('input', {
type: type,
- //filter: 'range',
compare: 'BETWEEN',
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
@@ -71,7 +86,7 @@
if (values[0] != undefined && values[1] != undefined)
this.$emit('sendValuesToTags', { label: values[0] + ' - ' + values[1], value: values });
},
- selectedValues(){
+ updateSelectedValues(){
if ( !this.query || !this.query.metaquery || !Array.isArray( this.query.metaquery ) )
return false;
@@ -79,15 +94,16 @@
if ( index >= 0 ){
let metaquery = this.query.metaquery[ index ];
if ( metaquery.value && metaquery.value.length > 1 ) {
- this.valueInit = metaquery.value[0];
- this.valueEnd = metaquery.value[1];
+ this.valueInit = new Number(metaquery.value[0]);
+ this.valueEnd = new Number(metaquery.value[1]);
}
if (metaquery.value[0] != undefined && metaquery.value[1] != undefined)
- this.$emit('sendValuesToTags', { label: this.valueInit + ' - ' + this.valueEnd, value: metaquery.values });
+ this.$emit('sendValuesToTags', { label: this.valueInit + ' - ' + this.valueEnd, value: metaquery.value });
} else {
- return false;
+ this.valueInit = null;
+ this.valueEnd = null;
}
},
}
diff --git a/src/classes/filter-types/numeric-interval/class-tainacan-numeric-interval.php b/src/classes/filter-types/numeric-interval/class-tainacan-numeric-interval.php
index e0f39751e..ff17a4c9e 100644
--- a/src/classes/filter-types/numeric-interval/class-tainacan-numeric-interval.php
+++ b/src/classes/filter-types/numeric-interval/class-tainacan-numeric-interval.php
@@ -10,7 +10,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class Numeric_Interval extends Filter_Type {
function __construct(){
- $this->set_name('Numeric Interval');
+ $this->set_name( __('Numeric Interval', 'tainacan') );
$this->set_supported_types(['float']);
$this->set_component('tainacan-filter-numeric-interval');
$this->set_form_component('tainacan-filter-form-numeric-interval');
diff --git a/src/classes/filter-types/numeric-list-interval/FormNumericListInterval.vue b/src/classes/filter-types/numeric-list-interval/FormNumericListInterval.vue
index 49944ce89..1cc6bb8bf 100644
--- a/src/classes/filter-types/numeric-list-interval/FormNumericListInterval.vue
+++ b/src/classes/filter-types/numeric-list-interval/FormNumericListInterval.vue
@@ -1,85 +1,87 @@
-
-
-
-
-
-
- {{ $i18n.get('info_show_interval_on_tag') }}
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+ {{ $i18n.get('info_show_interval_on_tag') }}
+
+
+
+
+
+
+
+
+
+
+
@@ -212,7 +203,7 @@
}
.datepicker {
- @media screen and (min-width: 1024px) {
+ @media screen and (min-width: 768px) {
.datepicker-header {
@@ -220,20 +211,19 @@
max-width: 165px !important;
}
.pagination .pagination-list .control {
- width: 74px !important;
+ width: 77px !important;
.select {
- min-width: 100% !important;
+ min-width: 100% !important;
select {
padding-left: 1px !important;
font-size: 0.75rem !important;
height: 24px !important;
min-width: 100% !important;
-
- &:not(.is-loading)::after {
- margin-top: -13px !important;
- }
+ }
+ &:not(.is-loading)::after {
+ margin-top: -13px !important;
}
}
}
diff --git a/src/classes/filter-types/taxonomy/Checkbox.vue b/src/classes/filter-types/taxonomy/Checkbox.vue
index 324e48724..432794f97 100644
--- a/src/classes/filter-types/taxonomy/Checkbox.vue
+++ b/src/classes/filter-types/taxonomy/Checkbox.vue
@@ -60,7 +60,7 @@
options: [],
selected: [],
taxonomy: '',
- taxonomy_id: Number
+ taxonomyId: ''
}
},
watch: {
@@ -80,6 +80,16 @@
this.loadOptions();
}
},
+ created() {
+ if (this.filter.metadatum &&
+ this.filter.metadatum.metadata_type_object &&
+ this.filter.metadatum.metadata_type_object.options &&
+ this.filter.metadatum.metadata_type_object.options.taxonomy &&
+ this.filter.metadatum.metadata_type_object.options.taxonomy_id) {
+ this.taxonomyId = this.filter.metadatum.metadata_type_object.options.taxonomy_id;
+ this.taxonomy = this.filter.metadatum.metadata_type_object.options.taxonomy;
+ }
+ },
mounted(){
this.loadOptions();
},
@@ -87,7 +97,7 @@
...mapGetters('search', [
'getFacets'
]),
- loadOptions(skipSelected) {
+ loadOptions() {
if (!this.isUsingElasticSearch) {
let promise = null;
const source = CancelToken.source();
@@ -123,7 +133,7 @@
});
promise.request
.then((res) => {
- this.prepareOptionsForTaxonomy(res.data.values ? res.data.values : res.data, skipSelected);
+ this.prepareOptionsForTaxonomy(res.data.values ? res.data.values : res.data);
this.isLoadingOptions = false;
})
.catch( error => {
@@ -143,14 +153,14 @@
for (const facet in this.facetsFromItemSearch) {
if (facet == this.filter.id) {
if (Array.isArray(this.facetsFromItemSearch[facet]))
- this.prepareOptionsForTaxonomy(this.facetsFromItemSearch[facet], skipSelected);
+ this.prepareOptionsForTaxonomy(this.facetsFromItemSearch[facet]);
else
- this.prepareOptionsForTaxonomy(Object.values(this.facetsFromItemSearch[facet]), skipSelected);
+ this.prepareOptionsForTaxonomy(Object.values(this.facetsFromItemSearch[facet]));
}
}
}
},
- selectedValues(){
+ updateSelectedValues(){
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false;
@@ -164,7 +174,6 @@
return false;
}
-
let onlyLabels = [];
for (let selected of this.selected) {
@@ -240,7 +249,7 @@
props: {
parent: parent,
filter: this.filter,
- taxonomy_id: this.taxonomy_id,
+ taxonomy_id: this.taxonomyId,
selected: this.selected,
metadatumId: this.metadatumId,
taxonomy: this.taxonomy,
@@ -257,12 +266,7 @@
trapFocus: true
});
},
- prepareOptionsForTaxonomy(items, skipSelected) {
-
- if (items[0] != undefined) {
- this.taxonomy = items[0].taxonomy;
- this.taxonomy_id = items[0].taxonomy_id;
- }
+ prepareOptionsForTaxonomy(items) {
this.options = [];
this.options = items.slice(); // copy array.
@@ -287,9 +291,7 @@
}
}
}
- if (skipSelected == undefined || skipSelected == false) {
- this.selectedValues();
- }
+ this.updateSelectedValues();
},
updatesIsLoading(isLoadingOptions) {
this.isLoadingOptions = isLoadingOptions;
diff --git a/src/classes/filter-types/taxonomy/Taginput.vue b/src/classes/filter-types/taxonomy/Taginput.vue
index 4ea365056..848f28021 100644
--- a/src/classes/filter-types/taxonomy/Taginput.vue
+++ b/src/classes/filter-types/taxonomy/Taginput.vue
@@ -15,6 +15,7 @@
:aria-labelledby="'filter-label-id-' + filter.id"
:class="{'has-selected': selected != undefined && selected != []}"
@typing="search"
+ @input="onSelect"
:placeholder="$i18n.get('info_type_to_add_terms')">
@@ -42,25 +43,31 @@
export default {
mixins: [ filterTypeMixin, dynamicFilterTypeMixin ],
- created(){
- let endpoint = '/collection/' + this.collectionId + '/metadata/' + this.metadatumId;
-
- if (this.isRepositoryLevel || this.collectionId == 'default'){
- endpoint = '/metadata/' + this.metadatumId;
+ created() {
+ if (this.filter.metadatum &&
+ this.filter.metadatum.metadata_type_object &&
+ this.filter.metadatum.metadata_type_object.options &&
+ this.filter.metadatum.metadata_type_object.options.taxonomy &&
+ this.filter.metadatum.metadata_type_object.options.taxonomy_id) {
+ this.taxonomyId = this.filter.metadatum.metadata_type_object.options.taxonomy_id;
+ this.taxonomy = this.filter.metadatum.metadata_type_object.options.taxonomy;
+ }
+ },
+ watch: {
+ 'query.taxquery'() {
+ this.updateSelectedValues();
}
-
- axios.get(endpoint)
- .then( res => {
- let metadatum = res.data;
- this.selectedValues( metadatum.metadata_type_options.taxonomy_id );
- });
+ },
+ mounted() {
+ this.updateSelectedValues();
},
data(){
return {
results:'',
selected:[],
options: [],
- taxonomy: ''
+ taxonomy: '',
+ taxonomyId: ''
}
},
methods: {
@@ -76,15 +83,13 @@
let endpoint = this.isRepositoryLevel ? '/facets/' + this.metadatumId : '/collection/'+ this.collectionId +'/facets/' + this.metadatumId;
endpoint += '?order=asc&' + qs.stringify(query_items);
+
let valuesToIgnore = [];
- for(let val of this.selected){
+ for(let val of this.selected)
valuesToIgnore.push( val.value );
- }
-
+
return axios.get(endpoint).then( res => {
for (let term of res.data.values) {
-
- this.taxonomy = term.taxonomy;
if (valuesToIgnore != undefined && valuesToIgnore.length > 0) {
let indexToIgnore = valuesToIgnore.findIndex(value => value == term.value);
@@ -114,52 +119,54 @@
this.$console.log(error);
});
}, 500),
- selectedValues( taxonomyId ){
+ updateSelectedValues(){
if ( !this.query || !this.query.taxquery || !Array.isArray( this.query.taxquery ) )
return false;
- this.taxonomy = 'tnc_tax_' + taxonomyId;
+ let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == this.taxonomy);
- let index = this.query.taxquery.findIndex(newMetadatum => newMetadatum.taxonomy == this.taxonomy );
- if ( index >= 0){
+ if (index >= 0) {
let metadata = this.query.taxquery[ index ];
+ this.selected = [];
- for ( let id of metadata.terms ){
- this.getTerm( taxonomyId, id );
+ if (metadata.terms && metadata.terms.length) {
+ this.getTerms(metadata)
+ .then(() => {
+ this.$emit( 'sendValuesToTags', {
+ label: this.selected.map((option) => option.label),
+ value: this.selected.map((option) => option.value),
+ taxonomy: this.taxonomy
+ });
+ });
}
} else {
- return false;
+ this.selected = [];
}
},
onSelect() {
- let values = [];
- let labels = [];
- if( this.selected.length > 0 ){
- for(let val of this.selected){
- values.push( val.value );
- labels.push( val.label );
- }
- }
this.$emit('input', {
filter: 'taginput',
compare: 'IN',
taxonomy: this.taxonomy,
metadatum_id: this.metadatumId,
collection_id: this.collectionId,
- terms: values
+ terms: this.selected.map((option) => option.value)
});
-
- this.$emit('sendValuesToTags', { label: labels, taxonomy: this.taxonomy, value: values });
},
- getTerm( taxonomy, id ){
- //getting a specific value from api, does not need be in fecat api
- return axios.get('/taxonomy/' + taxonomy + '/terms/' + id + '?order=asc' )
+ getTerms(metadata) {
+
+ let params = {
+ 'include': metadata.terms,
+ 'order': 'asc'
+ };
+
+ return axios.get('/taxonomy/' + this.taxonomyId + '/terms/?' + qs.stringify(params) )
.then( res => {
- this.selected.push({ label: res.data.name, value: res.data.id });
+ this.selected = res.data.map(term => { return { label: term.name, value: term.id } });
})
.catch(error => {
this.$console.log(error);
- });
+ })
}
}
}
diff --git a/src/classes/filter-types/taxonomy/class-tainacan-taxonomycheckbox.php b/src/classes/filter-types/taxonomy/class-tainacan-taxonomycheckbox.php
index 580d1bc3e..b327ca54a 100644
--- a/src/classes/filter-types/taxonomy/class-tainacan-taxonomycheckbox.php
+++ b/src/classes/filter-types/taxonomy/class-tainacan-taxonomycheckbox.php
@@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class TaxonomyCheckbox extends Filter_Type {
function __construct(){
- $this->set_name('Taxonomy Checkbox List');
+ $this->set_name( __('Taxonomy Checkbox List', 'tainacan') );
$this->set_supported_types(['term']);
$this->set_component('tainacan-filter-taxonomy-checkbox');
$this->set_preview_template('
diff --git a/src/classes/filter-types/taxonomy/class-tainacan-taxonomytaginput.php b/src/classes/filter-types/taxonomy/class-tainacan-taxonomytaginput.php
index aba6e8eef..0be31c430 100644
--- a/src/classes/filter-types/taxonomy/class-tainacan-taxonomytaginput.php
+++ b/src/classes/filter-types/taxonomy/class-tainacan-taxonomytaginput.php
@@ -9,7 +9,7 @@ defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
class TaxonomyTaginput extends Filter_Type {
function __construct(){
- $this->set_name('Taxonomy Tag Input');
+ $this->set_name( __('Taxonomy Tag Input', 'tainacan') );
$this->set_supported_types(['term']);
$this->set_component('tainacan-filter-taxonomy-taginput');
$this->set_use_max_options(false);
diff --git a/src/classes/metadata-types/core-title/class-tainacan-core-title.php b/src/classes/metadata-types/core-title/class-tainacan-core-title.php
index e28e72edd..e0c2ba997 100644
--- a/src/classes/metadata-types/core-title/class-tainacan-core-title.php
+++ b/src/classes/metadata-types/core-title/class-tainacan-core-title.php
@@ -19,7 +19,7 @@ class Core_Title extends Metadata_Type {
$this->set_core(true);
$this->set_related_mapped_prop('title');
$this->set_component('tainacan-text');
- $this->set_name( __('Core Description', 'tainacan') );
+ $this->set_name( __('Core Title', 'tainacan') );
$this->set_description( __('The "Core Title" is a compulsory metadata automatically created for all collections by default. It is the main metadatum of the item and where the basic research tools will do their searches.', 'tainacan') );
}
diff --git a/src/classes/metadata-types/relationship/class-tainacan-relationship.php b/src/classes/metadata-types/relationship/class-tainacan-relationship.php
index 83b87b1b9..698d5d88a 100644
--- a/src/classes/metadata-types/relationship/class-tainacan-relationship.php
+++ b/src/classes/metadata-types/relationship/class-tainacan-relationship.php
@@ -148,8 +148,8 @@ class Relationship extends Metadata_Type {
}
- } catch (Exception $e) {
- // item not found
+ } catch (\Exception $e) {
+ // item not found
}
}
@@ -164,7 +164,7 @@ class Relationship extends Metadata_Type {
$return .= $this->get_item_html($item);
}
- } catch (Exception $e) {
+ } catch (\Exception $e) {
// item not found
}
diff --git a/src/classes/metadata-types/tainacan-form-item.vue b/src/classes/metadata-types/tainacan-form-item.vue
index d39c4937f..2500b6dd0 100644
--- a/src/classes/metadata-types/tainacan-form-item.vue
+++ b/src/classes/metadata-types/tainacan-form-item.vue
@@ -28,7 +28,7 @@
v-if="metadatum.metadatum.required == 'yes'"
class="required-metadatum-asterisk"
:class="metadatumTypeMessage">*
-
({{ $i18n.get(metadatum.metadatum.metadata_type_object.component) }})
+
({{ metadatum.metadatum.metadata_type_object.name }})
@@ -46,7 +46,7 @@
0 && this.inputs[0].value){
- let terms = [];
+ if (this.inputs.length > 0 && this.inputs[0].value) {
+ let terms = this.inputs.map(term => term.value)
+
+ if (this.metadatum.value instanceof Array){
+ let equal = [];
- for(let term of this.inputs){
- terms.push(term.value);
- }
-
- if(this.metadatum.value instanceof Array){
- let eq = [];
-
- for(let meta of terms){
- let found = this.metadatum.value.find((element) => {
- return meta == element.id;
- });
-
- if(found){
- eq.push(found);
- }
+ for (let meta of terms) {
+ let foundIndex = this.metadatum.value.findIndex(element => meta == element.id);
+ if (foundIndex >= 0)
+ equal.push(this.metadatum.value[foundIndex]);
}
- if(eq.length == terms.length && this.metadatum.value.length <= eq.length){
+ if (equal.length == terms.length && this.metadatum.value.length <= equal.length)
return;
- }
- }
- } else if(this.metadatum.value.constructor.name == 'Object'){
- if(this.metadatum.value.id == this.inputs){
+ }
+ } else if (this.metadatum.value.constructor.name == 'Object') {
+
+ if (this.metadatum.value.id == this.inputs)
return;
- }
- } else if(this.metadatum.value instanceof Array){
- let eq = [];
+
+ } else if (this.metadatum.value instanceof Array) {
+ let equal = [];
- for(let meta of this.inputs){
- let found = this.metadatum.value.find((element) => {
- return meta == element.id;
- });
+ for (let meta of this.inputs) {
+ let foundIndex = this.metadatum.value.findIndex(element => meta == element.id);
- if(found){
- eq.push(found);
- }
+ if (foundIndex >= 0)
+ equal.push(this.metadatum.value[foundIndex]);
}
- if(eq.length == this.inputs.length && this.metadatum.value.length <= eq.length){
+ if (equal.length == this.inputs.length && this.metadatum.value.length <= equal.length)
return;
- }
}
eventBus.$emit('input', { item_id: this.metadatum.item.id, metadatum_id: this.metadatum.metadatum.id, values: this.inputs } );
@@ -198,9 +180,9 @@
if (this.metadatum.value instanceof Array) {
this.inputs = this.metadatum.value.slice(0);
- if (this.inputs.length === 0){
+ if (this.inputs.length === 0)
this.inputs.push('');
- }
+
} else {
this.metadatum.value == null || this.metadatum.value == undefined ? this.inputs.push('') : this.inputs.push(this.metadatum.value);
}
@@ -213,11 +195,11 @@
this.inputs.splice(index, 1);
this.changeValue();
},
- isTextInputComponent( component ){
+ isTextInputComponent(component){
let array = ['tainacan-relationship','tainacan-taxonomy'];
return !( array.indexOf( component ) >= 0 );
},
- setMetadatumTypeMessage( message ){
+ setMetadatumTypeMessage(message){
this.metadatumTypeMessage = message;
}
}
diff --git a/src/classes/metadata-types/taxonomy/FormTaxonomy.vue b/src/classes/metadata-types/taxonomy/FormTaxonomy.vue
index 2266c0ec2..6f166e211 100644
--- a/src/classes/metadata-types/taxonomy/FormTaxonomy.vue
+++ b/src/classes/metadata-types/taxonomy/FormTaxonomy.vue
@@ -85,10 +85,8 @@