adding all collection properties

This commit is contained in:
Leo Germani 2017-11-28 18:49:20 -02:00
parent d318bd0d42
commit bec743c80a
4 changed files with 139 additions and 21 deletions

View File

@ -40,7 +40,6 @@ class Collection extends Entity {
[ [
'name' => $this->get_name(), 'name' => $this->get_name(),
'description' => $this->get_description(), 'description' => $this->get_description(),
'items_per_page' => $this->get_itens_per_page(),
], ],
JSON_NUMERIC_CHECK, JSON_NUMERIC_CHECK,
JSON_UNESCAPED_UNICODE JSON_UNESCAPED_UNICODE
@ -152,14 +151,41 @@ class Collection extends Entity {
function get_description() { function get_description() {
return $this->get_mapped_property('description'); return $this->get_mapped_property('description');
} }
/** /**
* Get collection items per page option * Get collection default order
* *
* @return integer * @return string
*/ */
function get_itens_per_page() { function get_default_order() {
return $this->get_mapped_property('itens_per_page'); return $this->get_mapped_property('default_order');
}
/**
* Get collection default orderby
*
* @return string
*/
function get_default_orderby() {
return $this->get_mapped_property('default_orderby');
}
/**
* Get collection columns option
*
* @return string
*/
function get_columns() {
return $this->get_mapped_property('columns');
}
/**
* Get collection default_view_mode option
*
* @return string
*/
function get_default_view_mode() {
return $this->get_mapped_property('default_view_mode');
} }
/** /**
@ -242,14 +268,45 @@ class Collection extends Entity {
function set_description($value) { function set_description($value) {
$this->set_mapped_property('description', $value); $this->set_mapped_property('description', $value);
} }
/** /**
* Set collection itens per page option * Set collection default order option
* *
* @param [integer] $value * @param [string] $value
* @return void * @return void
*/ */
function set_itens_per_page($value) { function set_default_order($value) {
$this->set_mapped_property('itens_per_page', $value); $this->set_mapped_property('default_order', $value);
} }
/**
* Set collection default_orderby option
*
* @param [string] $value
* @return void
*/
function set_default_orderby($value) {
$this->set_mapped_property('default_orderby', $value);
}
/**
* Set collection columns option
*
* @param [string] $value
* @return void
*/
function set_columns($value) {
$this->set_mapped_property('columns', $value);
}
/**
* Set collection default_view_mode option
*
* @param [string] $value
* @return void
*/
function set_default_view_mode($value) {
$this->set_mapped_property('default_view_mode', $value);
}
} }

View File

@ -13,33 +13,89 @@ class Collections extends Repository {
return [ return [
'id' => [ 'id' => [
'map' => 'ID', 'map' => 'ID',
'name' => __('ID', 'tainacan'),
'description'=> __('Unique identifier', 'tainacan'),
//'validation' => v::numeric(), //'validation' => v::numeric(),
], ],
'name' => [ 'name' => [
'map' => 'post_title', 'map' => 'post_title',
'name' => __('Name', 'tainacan'),
'description'=> __('Name of the collection', 'tainacan'),
'validation' => v::stringType(), 'validation' => v::stringType(),
], ],
'order' => [ 'order' => [
'map' => 'menu_order', 'map' => 'menu_order',
'name' => __('Order', 'tainacan'),
'description'=> __('Collection order. Field used if collections are manually ordered', 'tainacan'),
//'validation' => v::stringType(), //'validation' => v::stringType(),
], ],
'parent' => [ 'parent' => [
'map' => 'parent', 'map' => 'parent',
'name' => __('Parent Collection', 'tainacan'),
'description'=> __('Parent collection ID', 'tainacan'),
//'validation' => v::stringType(), //'validation' => v::stringType(),
], ],
'description' => [ 'description' => [
'map' => 'post_content', 'map' => 'post_content',
'name' => __('Description', 'tainacan'),
'description'=> __('Collection description', 'tainacan'),
//'validation' => v::stringType(), //'validation' => v::stringType(),
], ],
'slug' => [ 'slug' => [
'map' => 'post_name', 'map' => 'post_name',
'name' => __('Slug', 'tainacan'),
'description'=> __('A unique and santized string representation of the collection, used to build the collection URL', 'tainacan'),
//'validation' => v::stringType(), //'validation' => v::stringType(),
], ],
'itens_per_page' => [
'default_orderby' => [
'map' => 'meta', 'map' => 'meta',
'default' => 10, 'name' => __('Default Order field', 'tainacan'),
'validation' => v::intVal()->positive(), 'description'=> __('Default property items in this collections will be ordered by', 'tainacan'),
'default' => 'name',
//'validation' => v::stringType(),
], ],
'default_order' => [
'map' => 'meta',
'name' => __('Default order', 'tainacan'),
'description'=> __('Default order for items in this collection. ASC or DESC', 'tainacan'),
'default' => 'ASC',
'validation' => v::stringType()->in(['ASC', 'DESC']),
],
'columns' => [
'map' => 'meta',
'name' => __('Columns', 'tainacan'),
'description'=> __('List of collections property that will be displayed in the table view', 'tainacan'),
//'validation' => v::stringType(),
],
'default_view_mode' => [
'map' => 'meta',
'name' => __('Default view mode', 'tainacan'),
'description'=> __('Collection default visualization mode', 'tainacan'),
//'validation' => v::stringType(),
],
/*
Isnt it just post status private?
'privacy' => [
'map' => 'meta',
'name' => __('Privacy', 'tainacan'),
'description'=> __('Collection privacy, defines wether a collection is visible to the public or not', 'tainacan'),
//'validation' => v::stringType(),
],
*/
/**
* Properties yet to be implemented
*
* Moderators (a property attached to the collection or to the user?)
* geo metadata?
*
*
*
*/
]; ];
} }

View File

@ -22,7 +22,7 @@ class Collections extends \WP_UnitTestCase {
$x->set_name('teste'); $x->set_name('teste');
$x->set_description('adasdasdsa'); $x->set_description('adasdasdsa');
$x->set_itens_per_page(23); $x->set_default_order('DESC');
global $Tainacan_Collections; global $Tainacan_Collections;
$col = $Tainacan_Collections->insert($x); $col = $Tainacan_Collections->insert($x);
@ -35,7 +35,7 @@ class Collections extends \WP_UnitTestCase {
$this->assertEquals($test->get_name(), 'teste'); $this->assertEquals($test->get_name(), 'teste');
$this->assertEquals($test->get_description(), 'adasdasdsa'); $this->assertEquals($test->get_description(), 'adasdasdsa');
$this->assertEquals($test->get_itens_per_page(), 23); $this->assertEquals($test->get_default_order(), 'DESC');
} }
@ -47,7 +47,7 @@ class Collections extends \WP_UnitTestCase {
$x->set_name('teste'); $x->set_name('teste');
$x->set_description('adasdasdsa'); $x->set_description('adasdasdsa');
$x->set_itens_per_page(23); $x->set_default_order('DESC');
global $Tainacan_Collections; global $Tainacan_Collections;
$col = $Tainacan_Collections->insert($x); $col = $Tainacan_Collections->insert($x);
@ -79,12 +79,17 @@ class Collections extends \WP_UnitTestCase {
$x->set_name('teste'); $x->set_name('teste');
$x->set_description('adasdasdsa'); $x->set_description('adasdasdsa');
$x->set_itens_per_page('blah'); $x->set_default_order(13);
$this->assertFalse($x->validate()); $this->assertFalse($x->validate());
$this->assertTrue(sizeof($x->get_errors()) > 0); $this->assertTrue(sizeof($x->get_errors()) > 0);
$x->set_itens_per_page(15); $x->set_default_order('ASDASD');
$this->assertFalse($x->validate());
$this->assertTrue(sizeof($x->get_errors()) > 0);
$x->set_default_order('DESC');
$this->assertTrue($x->validate()); $this->assertTrue($x->validate());
$this->assertTrue(empty($x->get_errors())); $this->assertTrue(empty($x->get_errors()));

View File

@ -45,7 +45,7 @@ class Logs extends \WP_UnitTestCase {
$value = new Collection(); $value = new Collection();
$value->set_name('testeLogs'); $value->set_name('testeLogs');
$value->set_description('adasdasdsa123'); $value->set_description('adasdasdsa123');
$value->set_itens_per_page(23); $value->set_default_order('DESC');
global $Tainacan_Collections; global $Tainacan_Collections;
$value = $Tainacan_Collections->insert($value); $value = $Tainacan_Collections->insert($value);
@ -72,6 +72,6 @@ class Logs extends \WP_UnitTestCase {
$this->assertEquals($collection->get_name(), 'new_testeLogs'); $this->assertEquals($collection->get_name(), 'new_testeLogs');
$this->assertEquals($collection->get_description(), 'adasdasdsa123'); $this->assertEquals($collection->get_description(), 'adasdasdsa123');
$this->assertEquals($collection->get_itens_per_page(), 23); $this->assertEquals($collection->get_default_order(), 'DESC');
} }
} }