getIntance TO get_instance

This commit is contained in:
andre2ar 2018-04-11 11:18:55 -03:00
parent 8a9aabb823
commit 9e0f467db7
56 changed files with 325 additions and 231 deletions

View File

@ -24,7 +24,7 @@ This layer is based on a Repository pattern. Each entity Tainacan deals with hav
Repositories are the classes that comunicate with the database and know where everything is stored and how to find things. It is a singleton class, so it have only one instance available to be used by any part of the application. Repositories are the classes that comunicate with the database and know where everything is stored and how to find things. It is a singleton class, so it have only one instance available to be used by any part of the application.
```PHP ```PHP
$fields_repo = Tainacan\Repositories\Fields::getInstance(); $fields_repo = Tainacan\Repositories\Fields::get_instance();
``` ```
Entities classes are the representation of the individual of each repository. Entities classes are the representation of the individual of each repository.
@ -46,7 +46,7 @@ Tainacan will automatically map the values of the attributes to and from where t
When you want to fetch entities from the database, this abstraction layer steps aside and let you use all the power and flexibility of `WP_Query`, which you know and love. For example: When you want to fetch entities from the database, this abstraction layer steps aside and let you use all the power and flexibility of `WP_Query`, which you know and love. For example:
```PHP ```PHP
Repositories\Fields::getInstance()->fetch('s=test'); Repositories\Fields::get_instance()->fetch('s=test');
``` ```
The `fetch` method from the repositories accept exactly the same arguments accepted by `WP_Query` and uses it internally. In fact, you could use `WP_Query` directly if you prefer, but using the repository class gives you some advantages. You dont have to know the name of the post type, you can also fetch by some mapped attribute calling it directly, withour having to use `meta_query` (or even know wether a property is stored as a post attribute or post_meta). See more details in the Fetch section below. The `fetch` method from the repositories accept exactly the same arguments accepted by `WP_Query` and uses it internally. In fact, you could use `WP_Query` directly if you prefer, but using the repository class gives you some advantages. You dont have to know the name of the post type, you can also fetch by some mapped attribute calling it directly, withour having to use `meta_query` (or even know wether a property is stored as a post attribute or post_meta). See more details in the Fetch section below.
@ -68,7 +68,7 @@ $collection = new Tainacan\Entities\Collection($collection_id);
This will have the same effect as calling the `fetch` method from the repository passing an integer as argument. THe repository will assume it is the collection ID. This will have the same effect as calling the `fetch` method from the repository passing an integer as argument. THe repository will assume it is the collection ID.
```PHP ```PHP
$collection = Tainacan\Repositories\Collections::getInstance()->fetch($collection_id); $collection = Tainacan\Repositories\Collections::get_instance()->fetch($collection_id);
``` ```
### Fethcing many individuals ### Fethcing many individuals
@ -80,8 +80,8 @@ To fetch collections (or any other entity) based on a query search, you may call
Examples: Examples:
```PHP ```PHP
$repo = Tainacan\Repositories\Collections::getInstance(); $repo = Tainacan\Repositories\Collections::get_instance();
$items_repo = Tainacan\Repositories\Collections::getInstance(); $items_repo = Tainacan\Repositories\Collections::get_instance();
$collections = $repo->fetch(); // get all public collections (or any private collections current user can view. It works exactly the same way WP_Query) $collections = $repo->fetch(); // get all public collections (or any private collections current user can view. It works exactly the same way WP_Query)
@ -106,7 +106,7 @@ $items = $items_repo->fetch([
Note that you can use the mapped attribute names to build your query, but it is just fine if you want to use the native WordPress names. The same can be achievied with attributes stored as post_meta: Note that you can use the mapped attribute names to build your query, but it is just fine if you want to use the native WordPress names. The same can be achievied with attributes stored as post_meta:
```PHP ```PHP
$repo = Tainacan\Repositories\Fields::getInstance(); $repo = Tainacan\Repositories\Fields::get_instance();
$fields = $repo->fetch([ $fields = $repo->fetch([
'required' => 'yes' 'required' => 'yes'
@ -143,7 +143,7 @@ However, before insertion, you must validate the entity, calling the `validate()
So this is a typical routine for creating an entity: So this is a typical routine for creating an entity:
```PHP ```PHP
$collectionsRepo = \Tainacan\Repositories\Collections::getInstance(); $collectionsRepo = \Tainacan\Repositories\Collections::get_instance();
$collection = new \Tainacan\Entities\Collection(); $collection = new \Tainacan\Entities\Collection();
$collection->set_name('New Collection'); $collection->set_name('New Collection');
@ -187,7 +187,7 @@ $itemMetadada = new \Tainacan\Entities\ItemMetadataEntity($item, $field);
$itemMetadata->set_value('Red'); $itemMetadata->set_value('Red');
if ($itemMetadata->validate()) { if ($itemMetadata->validate()) {
$ItemMetadataRepo = \Tainacan\Repositories\ItemMetadata::getInstance(); $ItemMetadataRepo = \Tainacan\Repositories\ItemMetadata::get_instance();
$ItemMetadata = $ItemMetadataRepo->insert($ItemMetadata); $ItemMetadata = $ItemMetadataRepo->insert($ItemMetadata);
} else { } else {
$errors = $ItemMetadata->get_errors(); $errors = $ItemMetadata->get_errors();
@ -313,7 +313,7 @@ $item->can_edit();
So now you know how to check the permision when a user wants to update an item. Here is the complete code: So now you know how to check the permision when a user wants to update an item. Here is the complete code:
```PHP ```PHP
$collectionsRepo = \Tainacan\Repositories\Collections::getInstance(); $collectionsRepo = \Tainacan\Repositories\Collections::get_instance();
$collection = new \Tainacan\Entities\Collection(23); $collection = new \Tainacan\Entities\Collection(23);
if ($collection->can_edit()) { if ($collection->can_edit()) {

View File

@ -8,7 +8,7 @@ class Admin {
private $menu_slug = 'tainacan_admin'; private $menu_slug = 'tainacan_admin';
private static $instance = null; private static $instance = null;
public static function getInstance() { public static function get_instance() {
if ( ! isset( self::$instance ) ) { if ( ! isset( self::$instance ) ) {
self::$instance = new self(); self::$instance = new self();
} }
@ -110,11 +110,11 @@ class Admin {
function get_admin_js_localization_params() { function get_admin_js_localization_params() {
global $TAINACAN_BASE_URL; global $TAINACAN_BASE_URL;
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$tainacan_admin_i18n = require( 'tainacan-admin-i18n.php' ); $tainacan_admin_i18n = require( 'tainacan-admin-i18n.php' );

View File

@ -28,7 +28,7 @@ class TAINACAN_REST_Collections_Controller extends TAINACAN_REST_Controller {
* Initialize objects after post_type register * Initialize objects after post_type register
*/ */
public function init_objects() { public function init_objects() {
$this->collections_repository = Repositories\Collections::getInstance(); $this->collections_repository = Repositories\Collections::get_instance();
$this->collection = new Entities\Collection(); $this->collection = new Entities\Collection();
} }

View File

@ -80,7 +80,7 @@ class TAINACAN_REST_Field_Types_Controller extends TAINACAN_REST_Controller {
* @return WP_Error|WP_REST_Response * @return WP_Error|WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$field_types = $Tainacan_Fields->fetch_field_types('NAME'); $field_types = $Tainacan_Fields->fetch_field_types('NAME');

View File

@ -23,10 +23,10 @@ class TAINACAN_REST_Fields_Controller extends TAINACAN_REST_Controller {
* @throws Exception * @throws Exception
*/ */
public function init_objects() { public function init_objects() {
$this->field_repository = Repositories\Fields::getInstance(); $this->field_repository = Repositories\Fields::get_instance();
$this->item_metadata_repository = Repositories\Item_Metadata::getInstance(); $this->item_metadata_repository = Repositories\Item_Metadata::get_instance();
$this->item_repository = Repositories\Items::getInstance(); $this->item_repository = Repositories\Items::get_instance();
$this->collection_repository = Repositories\Collections::getInstance(); $this->collection_repository = Repositories\Collections::get_instance();
} }
/** /**

View File

@ -65,7 +65,7 @@ class TAINACAN_REST_Filter_Types_Controller extends TAINACAN_REST_Controller {
* @return WP_Error|WP_REST_Response * @return WP_Error|WP_REST_Response
*/ */
public function get_items( $request ) { public function get_items( $request ) {
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$filter_types = $Tainacan_Filters->fetch_filter_types('NAME'); $filter_types = $Tainacan_Filters->fetch_filter_types('NAME');

View File

@ -28,11 +28,11 @@ class TAINACAN_REST_Filters_Controller extends TAINACAN_REST_Controller {
*/ */
public function init_objects() { public function init_objects() {
$this->collection = new Entities\Collection(); $this->collection = new Entities\Collection();
$this->collection_repository = Repositories\Collections::getInstance(); $this->collection_repository = Repositories\Collections::get_instance();
$this->field_repository = Repositories\Fields::getInstance(); $this->field_repository = Repositories\Fields::get_instance();
$this->filter_repository = Repositories\Filters::getInstance(); $this->filter_repository = Repositories\Filters::get_instance();
} }
public function register_routes() { public function register_routes() {

View File

@ -23,10 +23,10 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_REST_Controller {
*/ */
public function init_objects() { public function init_objects() {
$this->field = new Entities\Field(); $this->field = new Entities\Field();
$this->field_repository = Repositories\Fields::getInstance(); $this->field_repository = Repositories\Fields::get_instance();
$this->item_metadata_repository = Repositories\Item_Metadata::getInstance(); $this->item_metadata_repository = Repositories\Item_Metadata::get_instance();
$this->item_repository = Repositories\Items::getInstance(); $this->item_repository = Repositories\Items::get_instance();
$this->collection_repository = Repositories\Collections::getInstance(); $this->collection_repository = Repositories\Collections::get_instance();
} }
/** /**

View File

@ -30,10 +30,10 @@ class TAINACAN_REST_Items_Controller extends TAINACAN_REST_Controller {
* Initialize objects after post_type register * Initialize objects after post_type register
*/ */
public function init_objects() { public function init_objects() {
$this->items_repository = Repositories\Items::getInstance(); $this->items_repository = Repositories\Items::get_instance();
$this->item = new Entities\Item(); $this->item = new Entities\Item();
$this->item_metadata = Repositories\Item_Metadata::getInstance(); $this->item_metadata = Repositories\Item_Metadata::get_instance();
$this->collections_repository = Repositories\Collections::getInstance(); $this->collections_repository = Repositories\Collections::get_instance();
} }
/** /**

View File

@ -20,7 +20,7 @@ class TAINACAN_REST_Logs_Controller extends TAINACAN_REST_Controller {
} }
public function init_objects(){ public function init_objects(){
$this->logs_repository = Repositories\Logs::getInstance(); $this->logs_repository = Repositories\Logs::get_instance();
$this->log = new Entities\Log(); $this->log = new Entities\Log();
} }

View File

@ -23,7 +23,7 @@ class TAINACAN_REST_Taxonomies_Controller extends TAINACAN_REST_Controller {
*/ */
public function init_objects() { public function init_objects() {
$this->taxonomy = new Entities\Taxonomy(); $this->taxonomy = new Entities\Taxonomy();
$this->taxonomy_repository = Repositories\Taxonomies::getInstance(); $this->taxonomy_repository = Repositories\Taxonomies::get_instance();
} }
public function register_routes() { public function register_routes() {

View File

@ -25,9 +25,9 @@ class TAINACAN_REST_Terms_Controller extends TAINACAN_REST_Controller {
*/ */
public function init_objects() { public function init_objects() {
$this->term = new Entities\Term(); $this->term = new Entities\Term();
$this->terms_repository = Repositories\Terms::getInstance(); $this->terms_repository = Repositories\Terms::get_instance();
$this->taxonomy = new Entities\Taxonomy(); $this->taxonomy = new Entities\Taxonomy();
$this->taxonomy_repository = Repositories\Taxonomies::getInstance(); $this->taxonomy_repository = Repositories\Taxonomies::get_instance();
} }
public function register_routes() { public function register_routes() {

View File

@ -272,7 +272,7 @@ class Capabilities {
]; ];
private static $instance = null; private static $instance = null;
public static function getInstance() public static function get_instance()
{ {
if(!isset(self::$instance)) if(!isset(self::$instance))
{ {
@ -392,7 +392,7 @@ class Capabilities {
} }
} }
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collections = $Tainacan_Collections->fetch([], 'OBJECT'); $collections = $Tainacan_Collections->fetch([], 'OBJECT');
foreach ($collections as $collection) { foreach ($collections as $collection) {
$this->set_items_capabilities($collection, $defaults_caps); $this->set_items_capabilities($collection, $defaults_caps);

View File

@ -373,7 +373,7 @@ class Collection extends Entity {
* @throws \Exception * @throws \Exception
*/ */
function get_fields() { function get_fields() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
return $Tainacan_Fields->fetch_by_collection( $this, [], 'OBJECT' ); return $Tainacan_Fields->fetch_by_collection( $this, [], 'OBJECT' );
} }

View File

@ -128,7 +128,7 @@ class Entity {
public function get_repository() public function get_repository()
{ {
$namespace = '\Tainacan\Repositories\\'.$this->repository; $namespace = '\Tainacan\Repositories\\'.$this->repository;
$repository = $namespace::getInstance(); $repository = $namespace::get_instance();
return $repository; return $repository;
} }

View File

@ -256,7 +256,7 @@ class Item_Metadata_Entity extends Entity {
if (isset($this->value)) if (isset($this->value))
return $this->value; return $this->value;
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
return $Tainacan_Item_Metadata->get_value($this); return $Tainacan_Item_Metadata->get_value($this);
} }
@ -362,7 +362,7 @@ class Item_Metadata_Entity extends Entity {
} }
if ($this->is_collection_key()) { if ($this->is_collection_key()) {
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$test = $Tainacan_Items->fetch([ $test = $Tainacan_Items->fetch([
'meta_query' => [ 'meta_query' => [

View File

@ -335,7 +335,7 @@ class Item extends Entity {
* @return array Array of ItemMetadata objects * @return array Array of ItemMetadata objects
*/ */
function get_fields() { function get_fields() {
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
return $Tainacan_Item_Metadata->fetch( $this, 'OBJECT' ); return $Tainacan_Item_Metadata->fetch( $this, 'OBJECT' );

View File

@ -264,7 +264,7 @@ class Log extends Entity {
throw new \Exception( 'msn or new_value is need to log' ); throw new \Exception( 'msn or new_value is need to log' );
} }
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
if ( $log->validate() ) { if ( $log->validate() ) {
return $Tainacan_Logs->insert( $log ); return $Tainacan_Logs->insert( $log );

View File

@ -69,7 +69,7 @@ class Category extends Field_Type {
if (empty($this->get_option('taxonomy_id'))) if (empty($this->get_option('taxonomy_id')))
return ['taxonomy_id' => __('Please select a category', 'tainacan')]; return ['taxonomy_id' => __('Please select a category', 'tainacan')];
$Tainacan_Fields = Fields::getInstance(); $Tainacan_Fields = Fields::get_instance();
$category_fields = $Tainacan_Fields->fetch([ $category_fields = $Tainacan_Fields->fetch([
'collection_id' => $field->get_collection_id(), 'collection_id' => $field->get_collection_id(),

View File

@ -14,7 +14,7 @@ class Collections extends Repository {
private static $instance = null; private static $instance = null;
public static function getInstance() { public static function get_instance() {
if ( ! isset( self::$instance ) ) { if ( ! isset( self::$instance ) ) {
self::$instance = new self(); self::$instance = new self();
} }
@ -221,7 +221,7 @@ class Collections extends Repository {
* @see \Tainacan\Repositories\Repository::insert() * @see \Tainacan\Repositories\Repository::insert()
*/ */
public function insert( $collection ) { public function insert( $collection ) {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$this->pre_update_moderators( $collection ); $this->pre_update_moderators( $collection );
$new_collection = parent::insert( $collection ); $new_collection = parent::insert( $collection );

View File

@ -22,7 +22,7 @@ class Fields extends Repository {
private static $instance = null; private static $instance = null;
public static function getInstance() public static function get_instance()
{ {
if(!isset(self::$instance)) if(!isset(self::$instance))
{ {
@ -419,7 +419,7 @@ class Fields extends Repository {
* @see \Tainacan\Repositories\Repository::insert() * @see \Tainacan\Repositories\Repository::insert()
*/ */
public function insert($field){ public function insert($field){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$this->pre_update_category_field($field); $this->pre_update_category_field($field);
$new_field = parent::insert($field); $new_field = parent::insert($field);
@ -629,7 +629,7 @@ class Fields extends Repository {
// handle core titles // handle core titles
if( strpos( $field->get_field_type(), 'Core') !== false ){ if( strpos( $field->get_field_type(), 'Core') !== false ){
$collection = new Entities\Collection( $collection_id ); $collection = new Entities\Collection( $collection_id );
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$items = $Tainacan_Items->fetch( [], $collection, 'OBJECT'); $items = $Tainacan_Items->fetch( [], $collection, 'OBJECT');
$return = []; $return = [];

View File

@ -12,7 +12,7 @@ class Filters extends Repository {
private static $instance = null; private static $instance = null;
public static function getInstance() public static function get_instance()
{ {
if(!isset(self::$instance)) if(!isset(self::$instance))
{ {

View File

@ -16,7 +16,7 @@ class Item_Metadata extends Repository {
private static $instance = null; private static $instance = null;
public static function getInstance() public static function get_instance()
{ {
if(!isset(self::$instance)) if(!isset(self::$instance))
{ {
@ -120,7 +120,7 @@ class Item_Metadata extends Repository {
$value = $item_metadata->get_value(); $value = $item_metadata->get_value();
$item->$set_method( is_array( $value ) ? $value[0] : $value ); $item->$set_method( is_array( $value ) ? $value[0] : $value );
if ($item->validate_core_fields()) { if ($item->validate_core_fields()) {
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Items->insert($item); $Tainacan_Items->insert($item);
} else { } else {
throw new \Exception('Item metadata should be validated beforehand'); throw new \Exception('Item metadata should be validated beforehand');
@ -178,7 +178,7 @@ class Item_Metadata extends Repository {
*/ */
public function fetch($object, $output = null ){ public function fetch($object, $output = null ){
if($object instanceof Entities\Item){ if($object instanceof Entities\Item){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection = $object->get_collection(); $collection = $object->get_collection();

View File

@ -12,7 +12,7 @@ class Items extends Repository {
private static $instance = null; private static $instance = null;
public static function getInstance() public static function get_instance()
{ {
if(!isset(self::$instance)) if(!isset(self::$instance))
{ {
@ -142,8 +142,8 @@ class Items extends Repository {
*/ */
public function register_post_type() { public function register_post_type() {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$collections = $Tainacan_Collections->fetch( [], 'OBJECT' ); $collections = $Tainacan_Collections->fetch( [], 'OBJECT' );
$taxonomies = $Tainacan_Taxonomies->fetch( ['status' => ['auto-draft', 'draft', 'publish', 'private']], 'OBJECT' ); $taxonomies = $Tainacan_Taxonomies->fetch( ['status' => ['auto-draft', 'draft', 'publish', 'private']], 'OBJECT' );
@ -247,7 +247,7 @@ class Items extends Repository {
*/ */
public function fetch( $args = [], $collections = [], $output = null ) { public function fetch( $args = [], $collections = [], $output = null ) {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
if ( is_numeric( $args ) ) { if ( is_numeric( $args ) ) {
$existing_post = get_post( $args ); $existing_post = get_post( $args );

View File

@ -17,7 +17,7 @@ class Logs extends Repository {
public $entities_type = '\Tainacan\Entities\Log'; public $entities_type = '\Tainacan\Entities\Log';
private static $instance = null; private static $instance = null;
public static function getInstance() { public static function get_instance() {
if ( ! isset( self::$instance ) ) { if ( ! isset( self::$instance ) ) {
self::$instance = new self(); self::$instance = new self();
} }

View File

@ -342,7 +342,7 @@ abstract class Repository {
* @return array[] * @return array[]
*/ */
public static function get_collections_db_identifier() { public static function get_collections_db_identifier() {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collections = $Tainacan_Collections->fetch( [], 'OBJECT' ); $collections = $Tainacan_Collections->fetch( [], 'OBJECT' );
$cpts = []; $cpts = [];
foreach ( $collections as $col ) { foreach ( $collections as $col ) {
@ -393,15 +393,15 @@ abstract class Repository {
} else { } else {
throw new \Exception( 'Collection object not found for this post' ); throw new \Exception( 'Collection object not found for this post' );
} }
} elseif ($post_type === \Tainacan\Repositories\Item_Metadata::getInstance()->entities_type::get_post_type()){ } elseif ($post_type === \Tainacan\Repositories\Item_Metadata::get_instance()->entities_type::get_post_type()){
return new Entities\Item_Metadata_Entity(null, null); return new Entities\Item_Metadata_Entity(null, null);
} else { } else {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_Terms = \Tainacan\Repositories\Terms::getInstance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
$tnc_globals = [ $tnc_globals = [
$Tainacan_Collections, $Tainacan_Collections,
@ -435,17 +435,17 @@ abstract class Repository {
// its is a collection Item? // its is a collection Item?
if ( $prefix == Entities\Collection::$db_identifier_prefix ) { if ( $prefix == Entities\Collection::$db_identifier_prefix ) {
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
return $Tainacan_Items; return $Tainacan_Items;
} else { } else {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_Terms = \Tainacan\Repositories\Terms::getInstance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$tnc_globals = [ $tnc_globals = [
$Tainacan_Collections, $Tainacan_Collections,

View File

@ -15,7 +15,7 @@ class Taxonomies extends Repository {
private static $instance = null; private static $instance = null;
public static function getInstance() public static function get_instance()
{ {
if(!isset(self::$instance)) if(!isset(self::$instance))
{ {

View File

@ -15,7 +15,7 @@ class Terms extends Repository {
private static $instance = null; private static $instance = null;
public static function getInstance() public static function get_instance()
{ {
if(!isset(self::$instance)) if(!isset(self::$instance))
{ {
@ -168,7 +168,7 @@ class Terms extends Repository {
*/ */
public function fetch( $args = [], $taxonomies = []){ public function fetch( $args = [], $taxonomies = []){
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
if (is_numeric($taxonomies)){ if (is_numeric($taxonomies)){
$taxonomies = $Tainacan_Taxonomies->fetch( $taxonomies ); $taxonomies = $Tainacan_Taxonomies->fetch( $taxonomies );

View File

@ -74,11 +74,11 @@ function tainacan_autoload($class_name){
} }
} }
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
//register field types //register field types
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Text'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Text');
@ -90,7 +90,7 @@ $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Relationship');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Category'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Category');
$Tainacan_Fields->register_field_type('Tainacan\Field_Types\Compound'); $Tainacan_Fields->register_field_type('Tainacan\Field_Types\Compound');
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
//register filter type //register filter type
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Custom_Interval'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\Custom_Interval');
@ -102,12 +102,12 @@ $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\CategoryTaginput'
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\CategoryCheckbox'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\CategoryCheckbox');
$Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\CategorySelectbox'); $Tainacan_Filters->register_filter_type('Tainacan\Filter_Types\CategorySelectbox');
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Terms = \Tainacan\Repositories\Terms::getInstance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
?> ?>

View File

@ -31,7 +31,7 @@ trait Entity_Collection_Relation {
return $this->collection; return $this->collection;
if (is_numeric($this->get_collection_id())) { if (is_numeric($this->get_collection_id())) {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$this->collection = $Tainacan_Collections->fetch($this->get_collection_id()); $this->collection = $Tainacan_Collections->fetch($this->get_collection_id());
return $this->collection; return $this->collection;

View File

@ -16,7 +16,7 @@ trait Entity_Collections_Relation {
return $this->collections; return $this->collections;
if (is_array($this->get_collections_ids()) && !empty($this->get_collections_ids())) { if (is_array($this->get_collections_ids()) && !empty($this->get_collections_ids())) {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$this->collections = []; $this->collections = [];

View File

@ -11,7 +11,7 @@ class DevInterface {
private static $instance = null; private static $instance = null;
public static function getInstance() public static function get_instance()
{ {
if(!isset(self::$instance)) if(!isset(self::$instance))
{ {
@ -29,11 +29,11 @@ class DevInterface {
add_filter('post_type_link', array(&$this, 'permalink_filter'), 10, 3); add_filter('post_type_link', array(&$this, 'permalink_filter'), 10, 3);
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$repositories = [$Tainacan_Collections, $Tainacan_Filters, $Tainacan_Logs, $Tainacan_Fields, $Tainacan_Taxonomies]; $repositories = [$Tainacan_Collections, $Tainacan_Filters, $Tainacan_Logs, $Tainacan_Fields, $Tainacan_Taxonomies];
@ -54,7 +54,7 @@ class DevInterface {
'components' => $components 'components' => $components
]; ];
$tainacan_settings = \Tainacan\Admin::getInstance()->get_admin_js_localization_params(); $tainacan_settings = \Tainacan\Admin::get_instance()->get_admin_js_localization_params();
$settings = array_merge($settings, $tainacan_settings); $settings = array_merge($settings, $tainacan_settings);
@ -114,7 +114,7 @@ class DevInterface {
} }
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collections = $Tainacan_Collections->fetch([], 'OBJECT'); $collections = $Tainacan_Collections->fetch([], 'OBJECT');
foreach ($collections as $col) { foreach ($collections as $col) {
@ -133,23 +133,23 @@ class DevInterface {
} }
function properties_metabox_Collections() { function properties_metabox_Collections() {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$this->properties_metabox($Tainacan_Collections); $this->properties_metabox($Tainacan_Collections);
} }
function properties_metabox_Filters() { function properties_metabox_Filters() {
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$this->properties_metabox($Tainacan_Filters); $this->properties_metabox($Tainacan_Filters);
} }
function properties_metabox_Logs() { function properties_metabox_Logs() {
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$this->properties_metabox($Tainacan_Logs); $this->properties_metabox($Tainacan_Logs);
} }
function properties_metabox_Fields() { function properties_metabox_Fields() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$this->properties_metabox($Tainacan_Fields); $this->properties_metabox($Tainacan_Fields);
} }
function properties_metabox_Taxonomies() { function properties_metabox_Taxonomies() {
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$this->properties_metabox($Tainacan_Taxonomies); $this->properties_metabox($Tainacan_Taxonomies);
} }
@ -227,8 +227,8 @@ class DevInterface {
function metadata_metabox() { function metadata_metabox() {
global $typenow, $post; global $typenow, $post;
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collections = $Tainacan_Collections->fetch([], 'OBJECT'); $collections = $Tainacan_Collections->fetch([], 'OBJECT');
@ -299,8 +299,8 @@ class DevInterface {
function metadata_components_metabox() { function metadata_components_metabox() {
global $typenow, $post; global $typenow, $post;
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collections = $Tainacan_Collections->fetch([], 'OBJECT'); $collections = $Tainacan_Collections->fetch([], 'OBJECT');
@ -372,7 +372,7 @@ class DevInterface {
function field_type_dropdown($id,$selected) { function field_type_dropdown($id,$selected) {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$class = ( class_exists( $selected ) ) ? new $selected() : ''; $class = ( class_exists( $selected ) ) ? new $selected() : '';
@ -399,7 +399,7 @@ class DevInterface {
function filter_type_dropdown($id,$selected) { function filter_type_dropdown($id,$selected) {
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$class = ( class_exists( $selected ) ) ? new $selected() : ''; $class = ( class_exists( $selected ) ) ? new $selected() : '';
@ -430,7 +430,7 @@ class DevInterface {
} }
function collections_checkbox_list($selected) { function collections_checkbox_list($selected) {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collections = $Tainacan_Collections->fetch([], 'OBJECT'); $collections = $Tainacan_Collections->fetch([], 'OBJECT');
$selected = json_decode($selected); $selected = json_decode($selected);
?> ?>
@ -505,10 +505,10 @@ class DevInterface {
// TODO: there should ve a method in the repository to find this out // TODO: there should ve a method in the repository to find this out
// or I could try to initialize an entity and find out what type it is // or I could try to initialize an entity and find out what type it is
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collections = $Tainacan_Collections->fetch([], 'OBJECT'); $collections = $Tainacan_Collections->fetch([], 'OBJECT');
$cpts = []; $cpts = [];

View File

@ -12,7 +12,7 @@ use Tainacan\Entities;
* @param string $name_field (optional) default 'tnc_prop_collections_id' * @param string $name_field (optional) default 'tnc_prop_collections_id'
*/ */
public static function collections_dropdown($selected, $name_field = 'tnc_prop_collection_id'){ public static function collections_dropdown($selected, $name_field = 'tnc_prop_collection_id'){
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collections = $Tainacan_Collections->fetch([], 'OBJECT'); $collections = $Tainacan_Collections->fetch([], 'OBJECT');
?> ?>
<select name="<?php echo $name_field ?>"> <select name="<?php echo $name_field ?>">
@ -30,7 +30,7 @@ use Tainacan\Entities;
* @param string $name_field (optional) default 'tnc_prop_collections_ids[]' * @param string $name_field (optional) default 'tnc_prop_collections_ids[]'
*/ */
public static function collections_checkbox_list($selected,$name_field = 'tnc_prop_collections_ids[]') { public static function collections_checkbox_list($selected,$name_field = 'tnc_prop_collections_ids[]') {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collections = $Tainacan_Collections->fetch([], 'OBJECT'); $collections = $Tainacan_Collections->fetch([], 'OBJECT');
$selected = json_decode($selected); $selected = json_decode($selected);
?> ?>
@ -51,7 +51,7 @@ use Tainacan\Entities;
* @param array $args (optional) filter the field list * @param array $args (optional) filter the field list
*/ */
public static function metadata_dropdown( $collection , $selected, $name_field = 'tnc_prop_field_id', $args = []){ public static function metadata_dropdown( $collection , $selected, $name_field = 'tnc_prop_field_id', $args = []){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection = ( is_numeric( $collection ) ) ? new Entities\Collection( $collection ) : $collection; $collection = ( is_numeric( $collection ) ) ? new Entities\Collection( $collection ) : $collection;
$field = $Tainacan_Fields->fetch_by_collection( $collection, $args, 'OBJECT'); $field = $Tainacan_Fields->fetch_by_collection( $collection, $args, 'OBJECT');
?> ?>
@ -74,7 +74,7 @@ use Tainacan\Entities;
* @param array $args (optional) filter the field list * @param array $args (optional) filter the field list
*/ */
public static function metadata_checkbox_list( $collection , $selected,$name_field = 'tnc_prop_tnc_field_ids[]', $args = []) { public static function metadata_checkbox_list( $collection , $selected,$name_field = 'tnc_prop_tnc_field_ids[]', $args = []) {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection = ( is_numeric( $collection ) ) ? new Entities\Collection( $collection ) : $collection; $collection = ( is_numeric( $collection ) ) ? new Entities\Collection( $collection ) : $collection;
$field = $Tainacan_Fields->fetch_by_collection( $collection, $args, 'OBJECT'); $field = $Tainacan_Fields->fetch_by_collection( $collection, $args, 'OBJECT');
$selected = ( is_array( $selected) ) ? $selected : json_decode($selected); $selected = ( is_array( $selected) ) ? $selected : json_decode($selected);

View File

@ -343,9 +343,9 @@ abstract class Importer {
* @return Tainacan\Entities\Item Item inserted * @return Tainacan\Entities\Item Item inserted
*/ */
public function insert( $index, $processed_item ){ public function insert( $index, $processed_item ){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$isUpdate = ( is_array( $this->processed_items ) && isset( $this->processed_items[ $index ] ) ) $isUpdate = ( is_array( $this->processed_items ) && isset( $this->processed_items[ $index ] ) )
? $this->processed_items[ $index ] : 0; ? $this->processed_items[ $index ] : 0;
@ -424,15 +424,15 @@ abstract class Importer {
$new_collection = new Entities\Collection(); $new_collection = new Entities\Collection();
$new_collection->set_name('New Imported Collection'); $new_collection->set_name('New Imported Collection');
$new_collection->set_status('publish'); $new_collection->set_status('publish');
$new_collection->validade(); $new_collection->validate();
$new_collection = \Tainacan\Repositories\Collections::get_instance()->insert($new_collection); $new_collection = Tainacan\Repositories\Collections::get_instance()->insert($new_collection);
$this->set_collection($new_collection); $this->set_collection($new_collection);
if (!method_exists($this, 'create_fields_and_mapping')) { if (!method_exists($this, 'create_fields_and_mapping')) {
throw new Exception('Importers with import_structure_and_mapping true must implement create_fields_and_mapping method'); throw new Exception('Importers with import_structure_and_mapping true must implement create_fields_and_mapping method');
} }
$this->create_fields_and_mapping(); $this->create_fields_and_mapping();
} }

View File

@ -11,11 +11,13 @@ namespace Tainacan\Importer;
class Old_Tainacan extends Importer class Old_Tainacan extends Importer
{ {
public function __construct() { public function __construct($import_structure_and_mapping = false) {
parent::__construct(); parent::__construct();
$this->remove_import_method('file'); $this->remove_import_method('file');
$this->add_import_method('url'); $this->add_import_method('url');
$this->import_structure_and_mapping = $import_structure_and_mapping;
} }
/** /**
@ -26,7 +28,6 @@ class Old_Tainacan extends Importer
*/ */
public function get_fields() public function get_fields()
{ {
// TODO: Implement get_fields() method.
$file = new \SplFileObject( $this->tmp_file, 'r' ); $file = new \SplFileObject( $this->tmp_file, 'r' );
$json = json_decode($file->fread($file->getSize()), true); $json = json_decode($file->fread($file->getSize()), true);
@ -65,10 +66,36 @@ class Old_Tainacan extends Importer
return $processedItem; return $processedItem;
} }
function create_fields_and_mapping() {
$file = new \SplFileObject( $this->tmp_file, 'r' );
$json = json_decode($file->fread($file->getSize()), true);
print ".";
/*$fields_repository = \Tainacan\Repositories\Fields::get_instance();
$newField = new \Tainacan\Entities\Field();
$newField->set_name = 'New Field';
$newField->set_field_type = 'Tainacan\Field_Types\Text';
$newField->set_collection($this->collection);
$newField->validate(); // there is no user input here, so we can be sure it will validate.
$newField = $fields_repository->insert($newField);
$source_fields = $this->get_fields();
$this->set_mapping([
$newField->get_id() => $source_fields[0]
]);*/
}
/** /**
* Method implemented by the child importer class to return the number of items to be imported * Method implemented by the child importer class to return the number of items to be imported
* @return int * @return int
*/ */
public function get_total_items_from_source() public function get_total_items_from_source()
{ {
$file = new \SplFileObject( $this->tmp_file, 'r' ); $file = new \SplFileObject( $this->tmp_file, 'r' );

View File

@ -20,7 +20,7 @@ require_once(API_DIR . 'tainacan-rest-creator.php');
require_once('dev-interface/class-tainacan-dev-interface.php'); require_once('dev-interface/class-tainacan-dev-interface.php');
if ( tnc_enable_dev_wp_interface() ) { if ( tnc_enable_dev_wp_interface() ) {
$Tainacan_Dev_interface = \Tainacan\DevInterface\DevInterface::getInstance(); $Tainacan_Dev_interface = \Tainacan\DevInterface\DevInterface::get_instance();
} }
@ -28,12 +28,12 @@ function tnc_enable_dev_wp_interface() {
return defined('TNC_ENABLE_DEV_WP_INTERFACE') && true === TNC_ENABLE_DEV_WP_INTERFACE ? true : false; return defined('TNC_ENABLE_DEV_WP_INTERFACE') && true === TNC_ENABLE_DEV_WP_INTERFACE ? true : false;
} }
$Tainacan_Capabilities = \Tainacan\Capabilities::getInstance(); $Tainacan_Capabilities = \Tainacan\Capabilities::get_instance();
register_activation_hook( __FILE__, array( $Tainacan_Capabilities, 'init' ) ); register_activation_hook( __FILE__, array( $Tainacan_Capabilities, 'init' ) );
// TODO move it somewhere else? // TODO move it somewhere else?
require_once('admin/class-tainacan-admin.php'); require_once('admin/class-tainacan-admin.php');
$Tainacan_Admin = \Tainacan\Admin::getInstance(); $Tainacan_Admin = \Tainacan\Admin::get_instance();
require_once('theme-helper/class-tainacan-theme-helper.php'); require_once('theme-helper/class-tainacan-theme-helper.php');
require_once('theme-helper/template-tags.php'); require_once('theme-helper/template-tags.php');

View File

@ -32,7 +32,7 @@ class Entity_Factory {
public function create_entity($type, $args = [], $is_validated_and_in_db = false, $publish = false){ public function create_entity($type, $args = [], $is_validated_and_in_db = false, $publish = false){
ini_set('display_errors', 1); ini_set('display_errors', 1);
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
try { try {
if(empty($type)){ if(empty($type)){
@ -55,7 +55,7 @@ class Entity_Factory {
} }
$this->entity = new $this->entity_type(); $this->entity = new $this->entity_type();
$this->repository = $this->repository_type::getInstance(); $this->repository = $this->repository_type::get_instance();
if($publish) { if($publish) {
$this->entity->set_status('publish'); $this->entity->set_status('publish');

View File

@ -6,7 +6,7 @@ class Item_Metadata_Factory {
private $item_metadata; private $item_metadata;
public function create_item_metadata(\Tainacan\Entities\Item $item, \Tainacan\Entities\Field $field, $value = ''){ public function create_item_metadata(\Tainacan\Entities\Item $item, \Tainacan\Entities\Field $field, $value = ''){
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $field); $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $field);
if (!empty($value)) if (!empty($value))

View File

@ -15,7 +15,7 @@ class TAINACAN_REST_Field_Types_Controller extends TAINACAN_UnitApiTestCase {
$data = $ftype_response->get_data(); $data = $ftype_response->get_data();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$field_types = $Tainacan_Fields->fetch_field_types('NAME'); $field_types = $Tainacan_Fields->fetch_field_types('NAME');

View File

@ -15,7 +15,7 @@ class TAINACAN_REST_Filter_Types_Controller extends TAINACAN_UnitApiTestCase {
$data = $ftype_response->get_data(); $data = $ftype_response->get_data();
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$filter_types = $Tainacan_Filters->fetch_filter_types('NAME'); $filter_types = $Tainacan_Filters->fetch_filter_types('NAME');

View File

@ -93,7 +93,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals(200, $response->get_status()); $this->assertEquals(200, $response->get_status());
$data = $response->get_data(); $data = $response->get_data();
$this->assertEquals( 'pending', $data['status'] ); $this->assertEquals( 'pending', $data['status'] );
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$query = $Tainacan_Logs->fetch(['post_status' => 'pending']); $query = $Tainacan_Logs->fetch(['post_status' => 'pending']);
$log = false; $log = false;
@ -153,7 +153,7 @@ class TAINACAN_REST_Item_Metadata_Controller extends TAINACAN_UnitApiTestCase {
$this->assertEquals(200, $response->get_status()); $this->assertEquals(200, $response->get_status());
$data = $response->get_data(); $data = $response->get_data();
$this->assertEquals( 'pending', $data['status'] ); $this->assertEquals( 'pending', $data['status'] );
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$query = $Tainacan_Logs->fetch(['post_status' => 'pending']); $query = $Tainacan_Logs->fetch(['post_status' => 'pending']);
$log = false; $log = false;

View File

@ -143,7 +143,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
} }
public function test_get_item_and_collection_metadata(){ public function test_get_item_and_collection_metadata(){
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -405,7 +405,7 @@ class TAINACAN_REST_Metadata_Controller extends TAINACAN_UnitApiTestCase {
} }
public function test_fetch_all_field_values(){ public function test_fetch_all_field_values(){
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',

View File

@ -18,9 +18,9 @@ class CategoryFieldTypes extends TAINACAN_UnitTestCase {
function test_category_field_types() { function test_category_field_types() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -135,8 +135,8 @@ class CategoryFieldTypes extends TAINACAN_UnitTestCase {
} }
function test_relate_taxonomy() { function test_relate_taxonomy() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -207,9 +207,9 @@ class CategoryFieldTypes extends TAINACAN_UnitTestCase {
} }
function test_values_and_html() { function test_values_and_html() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_ItemMetadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_ItemMetadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',

View File

@ -66,7 +66,7 @@ class Collections extends TAINACAN_UnitTestCase {
$collection_test->add_moderator_id($current_user_id); $collection_test->add_moderator_id($current_user_id);
$collection_test->validate(); $collection_test->validate();
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collection_test = $Tainacan_Collections->insert($collection_test); $collection_test = $Tainacan_Collections->insert($collection_test);
@ -146,7 +146,7 @@ class Collections extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$this->assertEquals('Tainacan\Entities\Collection', get_class($x)); $this->assertEquals('Tainacan\Entities\Collection', get_class($x));
@ -210,7 +210,7 @@ class Collections extends TAINACAN_UnitTestCase {
$this->assertEquals($x->get_slug(), $y->get_slug()); $this->assertEquals($x->get_slug(), $y->get_slug());
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$x->set_status('publish'); $x->set_status('publish');
$x->validate(); $x->validate();
$x = $Tainacan_Collections->insert($x); $x = $Tainacan_Collections->insert($x);
@ -233,7 +233,7 @@ class Collections extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$collection = $Tainacan_Collections->fetch($x->get_id()); $collection = $Tainacan_Collections->fetch($x->get_id());
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
@ -247,7 +247,7 @@ class Collections extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$item = $Tainacan_Items->fetch( $i->get_id() ); $item = $Tainacan_Items->fetch( $i->get_id() );
$this->assertEquals($item->get_title(), 'item test'); $this->assertEquals($item->get_title(), 'item test');
@ -281,7 +281,7 @@ class Collections extends TAINACAN_UnitTestCase {
} }
function test_hooks() { function test_hooks() {
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$this->assertTrue(has_action('init', array($Tainacan_Collections, 'register_post_type')) !== false, 'Collections Init is not registred!'); $this->assertTrue(has_action('init', array($Tainacan_Collections, 'register_post_type')) !== false, 'Collections Init is not registred!');
} }

View File

@ -18,9 +18,9 @@ class CompoundFieldTypes extends TAINACAN_UnitTestCase {
function test_compound_field_types() { function test_compound_field_types() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -117,9 +117,9 @@ class CompoundFieldTypes extends TAINACAN_UnitTestCase {
function test_multiple_compound_field_types() { function test_multiple_compound_field_types() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',

View File

@ -18,8 +18,8 @@ class CoreFieldTypes extends TAINACAN_UnitTestCase {
function test_core_field_types() { function test_core_field_types() {
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',

View File

@ -17,7 +17,7 @@ class DefaultCapabilities extends TAINACAN_UnitTestCase {
function test_capabilities_present() { function test_capabilities_present() {
$Tainacan_Capabilities = \Tainacan\Capabilities::getInstance(); $Tainacan_Capabilities = \Tainacan\Capabilities::get_instance();
$c = new \Tainacan\Entities\Collection(); $c = new \Tainacan\Entities\Collection();
$caps = $c->get_capabilities(); $caps = $c->get_capabilities();

View File

@ -18,7 +18,7 @@ class Fields extends TAINACAN_UnitTestCase {
* Test insert a regular field with type * Test insert a regular field with type
*/ */
function test_add() { function test_add() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -52,7 +52,7 @@ class Fields extends TAINACAN_UnitTestCase {
* Test insert a regular field with type * Test insert a regular field with type
*/ */
function test_add_type(){ function test_add_type(){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -85,7 +85,7 @@ class Fields extends TAINACAN_UnitTestCase {
* test if parent field are visible for children collection * test if parent field are visible for children collection
*/ */
function test_hierarchy_metadata(){ function test_hierarchy_metadata(){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$this->tainacan_entity_factory->create_entity( $this->tainacan_entity_factory->create_entity(
'field', 'field',
@ -170,7 +170,7 @@ class Fields extends TAINACAN_UnitTestCase {
* test remove core fields * test remove core fields
*/ */
function test_core_fields(){ function test_core_fields(){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection_grandfather = $this->tainacan_entity_factory->create_entity( $collection_grandfather = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -193,7 +193,7 @@ class Fields extends TAINACAN_UnitTestCase {
* test if the defaults types are registered * test if the defaults types are registered
*/ */
function test_metadata_field_type(){ function test_metadata_field_type(){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$this->assertEquals( 8, sizeof( $Tainacan_Fields->fetch_field_types() ) ); $this->assertEquals( 8, sizeof( $Tainacan_Fields->fetch_field_types() ) );
} }
@ -202,8 +202,8 @@ class Fields extends TAINACAN_UnitTestCase {
* *
*/ */
function test_ordenation_fields(){ function test_ordenation_fields(){
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -322,7 +322,7 @@ class Fields extends TAINACAN_UnitTestCase {
$this->assertEquals($x->get_slug(), $y->get_slug()); $this->assertEquals($x->get_slug(), $y->get_slug());
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$x->set_status('publish'); $x->set_status('publish');
$x->validate(); $x->validate();
$x = $Tainacan_Fields->insert($x); $x = $Tainacan_Fields->insert($x);
@ -335,7 +335,7 @@ class Fields extends TAINACAN_UnitTestCase {
} }
function test_validation_of_field_types() { function test_validation_of_field_types() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',

View File

@ -15,7 +15,7 @@ class Filters extends TAINACAN_UnitTestCase {
function teste_add(){ function teste_add(){
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -43,7 +43,7 @@ class Filters extends TAINACAN_UnitTestCase {
} }
function test_add_with_metadata_and_type(){ function test_add_with_metadata_and_type(){
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -96,7 +96,7 @@ class Filters extends TAINACAN_UnitTestCase {
} }
function test_get_filters_type(){ function test_get_filters_type(){
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$all_filter_types = $Tainacan_Filters->fetch_filter_types(); $all_filter_types = $Tainacan_Filters->fetch_filter_types();
$this->assertEquals( 8, count( $all_filter_types ) ); $this->assertEquals( 8, count( $all_filter_types ) );
@ -109,7 +109,7 @@ class Filters extends TAINACAN_UnitTestCase {
* @group filter * @group filter
*/ */
function test_validate_supported_filters(){ function test_validate_supported_filters(){
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',

View File

@ -27,13 +27,31 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$id = $old_tainacan_importer->get_id(); $id = $old_tainacan_importer->get_id();
$_SESSION['tainacan_importer'][$id]->set_collection( $collection ); $_SESSION['tainacan_importer'][$id]->set_collection( $collection );
$this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() ); $this->assertEquals( $collection->get_id(), $_SESSION['tainacan_importer'][$id]->collection->get_id() );
/*$_SESSION['tainacan_importer'][$id]->fetch_from_remote( 'http://localhost/wp-json/tainacan/v1/collections/860/items' );
$_SESSION['tainacan_importer'][$id]->process_item(2);*/
} }
public function test_automapping_old_tainacan()
{
$Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$old_tainacan = new Importer\Old_Tainacan(true);
$id = $old_tainacan->get_id();
$_SESSION['tainacan_importer'][$id]->set_items_per_step(2);
if(!copy('./tests/attachment/json_old_tainacan_base.txt', './tests/attachment/json_old_tainacan.txt'))
{
return false;
}
$_SESSION['tainacan_importer'][$id]->set_file( './tests/attachment/json_old_tainacan.txt' );
$_SESSION['tainacan_importer'][$id]->run();
}
public function test_file_old_tainacan () { public function test_file_old_tainacan () {
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$old_tainacan = new Importer\Old_Tainacan(); $old_tainacan = new Importer\Old_Tainacan();
$id = $old_tainacan->get_id(); $id = $old_tainacan->get_id();
@ -100,7 +118,6 @@ class ImporterTests extends TAINACAN_UnitTestCase {
$items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' ); $items = $Tainacan_Items->fetch( [], $collection, 'OBJECT' );
$this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) ); $this->assertEquals( $_SESSION['tainacan_importer'][$id]->get_total_items(), count( $items ) );
} }
/** /**
* @group importer * @group importer
@ -130,8 +147,8 @@ class ImporterTests extends TAINACAN_UnitTestCase {
* @group importer * @group importer
*/ */
public function test_file_csv () { public function test_file_csv () {
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$csv_importer = new Importer\CSV(); $csv_importer = new Importer\CSV();
$id = $csv_importer->get_id(); $id = $csv_importer->get_id();

View File

@ -18,8 +18,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
*/ */
function test_add() { function test_add() {
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -53,7 +53,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$item = $Tainacan_Items->fetch($i->get_id()); $item = $Tainacan_Items->fetch($i->get_id());
@ -71,8 +71,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
* Teste da insercao de um metadado simples com o tipo * Teste da insercao de um metadado simples com o tipo
*/ */
function teste_required(){ function teste_required(){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -107,7 +107,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$item = $Tainacan_Items->fetch($i->get_id()); $item = $Tainacan_Items->fetch($i->get_id());
$item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $test); $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($item, $test);
@ -125,8 +125,8 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
} }
function teste_collection_key(){ function teste_collection_key(){
$Tainacan_Fields = \Tainacan\Repositories\Fields::getInstance(); $Tainacan_Fields = \Tainacan\Repositories\Fields::get_instance();
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',
@ -162,7 +162,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$item = $Tainacan_Items->fetch($i->get_id()); $item = $Tainacan_Items->fetch($i->get_id());
@ -183,7 +183,7 @@ class Item_Metadata extends TAINACAN_UnitTestCase {
} }
function teste_fetch(){ function teste_fetch(){
$Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::getInstance(); $Tainacan_Item_Metadata = \Tainacan\Repositories\Item_Metadata::get_instance();
$collection = $this->tainacan_entity_factory->create_entity( $collection = $this->tainacan_entity_factory->create_entity(
'collection', 'collection',

View File

@ -125,7 +125,7 @@ class Items extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
'item', 'item',

View File

@ -17,6 +17,11 @@ use Tainacan\Entities\Log;
class Logs extends TAINACAN_UnitTestCase { class Logs extends TAINACAN_UnitTestCase {
/**
* Teste da insercao de um log simples apenas se criar o dado bruto
*/
function test_add() {
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
/** /**
* Teste da insercao de um log simples apenas se criar o dado bruto * Teste da insercao de um log simples apenas se criar o dado bruto
*/ */
@ -24,21 +29,64 @@ class Logs extends TAINACAN_UnitTestCase {
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance();
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance();
$log = $this->tainacan_entity_factory->create_entity( $log = $this->tainacan_entity_factory->create_entity(
'log', 'log',
array( array(
'title' => 'blame someone', 'title' => 'blame someone',
'description' => 'someone did that' 'description' => 'someone did that'
), ),
true true
); );
$user_id = get_current_user_id();
$blog_id = get_current_blog_id();
$user_id = get_current_user_id(); //retorna a taxonomia
$blog_id = get_current_blog_id(); $test = $Tainacan_Logs->fetch($log->get_id());
//retorna a taxonomia
$test = $Tainacan_Logs->fetch( $log->get_id() );
$this->assertEquals( 'blame someone', $test->get_title() );
$this->assertEquals( 'someone did that', $test->get_description() );
$this->assertEquals( $user_id, $test->get_user_id() );
$this->assertEquals( $blog_id, $test->get_blog_id() );
$value = $this->tainacan_entity_factory->create_entity(
'collection',
array(
'name' => 'testeLogs',
'description' => 'adasdasdsa123',
'default_order' => 'DESC'
),
true
);
$Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$value->set_name('new_testeLogs');
$value->validate();
$new_value = $Tainacan_Collections->insert($value);
$create_log = Log::create('teste create', 'testing a log creation function', $new_value, $value);
$this->assertEquals( 'teste create', $create_log->get_title() );
$this->assertEquals( 'testing a log creation function', $create_log->get_description() );
$this->assertEquals( $new_value, $create_log->get_value() );
$this->assertEquals( $value, $create_log->get_old_value() );
$testDB = $Tainacan_Logs->fetch($create_log->get_id());
$this->assertEquals( 'teste create', $testDB->get_title() );
$this->assertEquals( 'testing a log creation function', $testDB->get_description() );
$this->assertEquals( $new_value, $testDB->get_value() );
$this->assertEquals( $value, $testDB->get_old_value() );
$last_log = $Tainacan_Logs->fetch_last();
$this->assertTrue(is_object($last_log));
$collection = $last_log->get_value();
$this->assertEquals($collection->get_name(), 'new_testeLogs');
$this->assertEquals($collection->get_description(), 'adasdasdsa123');
$this->assertEquals($collection->get_default_order(), 'DESC');
}
$this->assertEquals( 'blame someone', $test->get_title() ); $this->assertEquals( 'blame someone', $test->get_title() );
$this->assertEquals( 'someone did that', $test->get_description() ); $this->assertEquals( 'someone did that', $test->get_description() );
$this->assertEquals( $user_id, $test->get_user_id() ); $this->assertEquals( $user_id, $test->get_user_id() );
@ -83,29 +131,31 @@ class Logs extends TAINACAN_UnitTestCase {
$this->assertEquals( 'DESC', $collection->get_default_order() ); $this->assertEquals( 'DESC', $collection->get_default_order() );
} }
public function test_log_diff(){
$Tainacan_Logs = \Tainacan\Repositories\Logs::get_instance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::get_instance();
public function test_log_diff() { public function test_log_diff() {
$Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance(); $Tainacan_Logs = \Tainacan\Repositories\Logs::getInstance();
$Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance(); $Tainacan_Filters = \Tainacan\Repositories\Filters::getInstance();
$filter = $this->tainacan_entity_factory->create_entity( $filter = $this->tainacan_entity_factory->create_entity(
'filter', 'filter',
array( array(
'name' => 'No name', 'name' => 'No name'
), ),
true true
); );
// Modify filter name // Modify filter name
$filter->set_name( 'With name' ); $filter->set_name('With name');
$Tainacan_Filters->update( $filter ); $Tainacan_Filters->update($filter);
$log = $Tainacan_Logs->fetch_last(); $log = $Tainacan_Logs->fetch_last();
$diff = $log->diff(); $diff = $log->diff();
$this->assertEquals( 'With name', "{$diff['name']['new'][0]} {$diff['name']['new'][1]}" ); $this->assertEquals('With name', $diff['name']['new']);
$this->assertEquals( 'No name', $diff['name']['old'] ); $this->assertEquals('No name', $diff['name']['old']);
$this->assertEquals( 'With', $diff['name']['diff_with_index'][0] ); }
}
} }

View File

@ -78,7 +78,7 @@ class Objects extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$i = $this->tainacan_entity_factory->create_entity( $i = $this->tainacan_entity_factory->create_entity(
'item', 'item',
@ -125,7 +125,7 @@ class Objects extends TAINACAN_UnitTestCase {
$collection->set_name(''); $collection->set_name('');
$this->assertEquals('', $collection->get_name()); $this->assertEquals('', $collection->get_name());
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$this->assertTrue($collection->validate()); $this->assertTrue($collection->validate());
$newCol = $Tainacan_Collections->insert($collection); $newCol = $Tainacan_Collections->insert($collection);
$this->assertEquals('', $newCol->get_name()); $this->assertEquals('', $newCol->get_name());

View File

@ -52,7 +52,7 @@ class PrivateObjects extends TAINACAN_UnitTestCase {
true true
); );
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$items = $Tainacan_Items->fetch([], $collection); $items = $Tainacan_Items->fetch([], $collection);
@ -135,8 +135,8 @@ class PrivateObjects extends TAINACAN_UnitTestCase {
$new_contributor_user = $this->factory()->user->create(array( 'role' => 'contributor' )); $new_contributor_user = $this->factory()->user->create(array( 'role' => 'contributor' ));
wp_set_current_user($new_contributor_user); wp_set_current_user($new_contributor_user);
$Tainacan_Items = \Tainacan\Repositories\Items::getInstance(); $Tainacan_Items = \Tainacan\Repositories\Items::get_instance();
$Tainacan_Collections = \Tainacan\Repositories\Collections::getInstance(); $Tainacan_Collections = \Tainacan\Repositories\Collections::get_instance();
$items = $Tainacan_Items->fetch([], $collection); $items = $Tainacan_Items->fetch([], $collection);
$this->assertEquals(2, $items->found_posts, 'items of a public collections should be visible'); $this->assertEquals(2, $items->found_posts, 'items of a public collections should be visible');

View File

@ -18,7 +18,7 @@ class Taxonomies extends TAINACAN_UnitTestCase {
* Teste da insercao de uma taxonomia simples * Teste da insercao de uma taxonomia simples
*/ */
function test_add() { function test_add() {
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$taxonomy = $this->tainacan_entity_factory->create_entity( $taxonomy = $this->tainacan_entity_factory->create_entity(
'taxonomy', 'taxonomy',
@ -40,8 +40,8 @@ class Taxonomies extends TAINACAN_UnitTestCase {
} }
function test_add_term_taxonomy(){ function test_add_term_taxonomy(){
$Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::getInstance(); $Tainacan_Taxonomies = \Tainacan\Repositories\Taxonomies::get_instance();
$Tainacan_Terms = \Tainacan\Repositories\Terms::getInstance(); $Tainacan_Terms = \Tainacan\Repositories\Terms::get_instance();
$taxonomy = $this->tainacan_entity_factory->create_entity( $taxonomy = $this->tainacan_entity_factory->create_entity(
'taxonomy', 'taxonomy',