diff --git a/src/classes/entities/class-tainacan-log.php b/src/classes/entities/class-tainacan-log.php index 0499df61b..ab90eb919 100644 --- a/src/classes/entities/class-tainacan-log.php +++ b/src/classes/entities/class-tainacan-log.php @@ -27,6 +27,10 @@ class Log extends \Tainacan\Entity { $this->WP_Post = new \StdClass(); } + if( is_int($which) && $which == 0) { + $this->set_user_id(); + $this->set_blog_id(); + } } /** @@ -74,6 +78,15 @@ class Log extends \Tainacan\Entity { return $this->get_mapped_property('description'); } + /** + * Retorn the ID of blog + * + * @return integer + */ + function get_blog_id() { + return $this->get_mapped_property('blog_id'); + } + /** * Return User Id of who make the action * @@ -84,9 +97,9 @@ class Log extends \Tainacan\Entity { } /** - * Atribui titulo ao log + * Set log tittle * - * @param [type] $value + * @param string $value * @return void */ function set_title($value) { @@ -122,4 +135,26 @@ class Log extends \Tainacan\Entity { function set_description($value) { $this->set_mapped_property('description', $value); } + + /** + * user_id of log entry + * + * @param integer $value + * @return void + */ + protected function set_user_id($value = 0) { + if(0 == $value) $value = get_current_user_id(); + $this->set_mapped_property('user_id', $value); + } + + /** + * blog_id of log entry + * + * @param integer $value + * @return void + */ + protected function set_blog_id($value = 0) { + if(0 == $value) $value = get_current_blog_id(); + $this->set_mapped_property('blog_id', $value); + } } \ No newline at end of file diff --git a/src/classes/repositories/class-tainacan-logs.php b/src/classes/repositories/class-tainacan-logs.php index f66704865..5da85d658 100644 --- a/src/classes/repositories/class-tainacan-logs.php +++ b/src/classes/repositories/class-tainacan-logs.php @@ -6,6 +6,12 @@ if ( ! defined( 'ABSPATH' ) ) { exit; } +/** + * Implement a Logs system + * + * @author medialab + * + */ class Logs implements Repository { function __construct() { @@ -46,6 +52,10 @@ class Logs implements Repository { 'map' => 'post_author', 'validation' => '' ], + 'blog_id' => [ + 'map' => 'meta', + 'validation' => '' + ], ]; } @@ -54,7 +64,7 @@ class Logs implements Repository { 'name' => 'logs', 'singular_name' => 'logs', 'add_new' => 'Adicionar Novo', - 'add_new_item' =>'Adicionar Log', + 'add_new_item' => 'Adicionar Log', 'edit_item' => 'Editar', 'new_item' => 'Novo Log', 'view_item' => 'Visualizar', @@ -85,6 +95,14 @@ class Logs implements Repository { register_post_type(Entities\Log::POST_TYPE, $args); } + /** + * + * {@inheritDoc} + * @see \Tainacan\Repositories\Repository::insert() + * + * @param \Tainacan\Entities\Log $log + * + */ function insert($log) { // First iterate through the native post properties $map = $this->get_map(); @@ -100,10 +118,9 @@ class Logs implements Repository { // TODO verificar se salvou mesmo $id = wp_insert_post($log->WP_Post); - //$log->WP_Post->ID = $id; $log->WP_Post = get_post($id); - /* Now run through properties stored as postmeta TODO maybe a parent class function leave for future use + /* Now run through properties stored as postmeta TODO maybe a parent class function leave for future use */ foreach ($map as $prop => $mapped) { if ($mapped['map'] == 'meta') { update_post_meta($id, $prop, $log->get_mapped_property($prop)); @@ -114,7 +131,7 @@ class Logs implements Repository { foreach ($values as $value) add_post_meta($id, $prop, $value); } - }*/ + } // return a brand new object return new Entities\Log($log->WP_Post); diff --git a/tests/test-logs.php b/tests/test-logs.php index ec65c904a..960d1e82d 100644 --- a/tests/test-logs.php +++ b/tests/test-logs.php @@ -25,6 +25,9 @@ class Logs extends \WP_UnitTestCase { //setando os valores na classe do tainacan $log->set_title('blame someone'); $log->set_description('someone did that'); + + $user_id = get_current_user_id(); + $blog_id = get_current_blog_id(); //inserindo $log = $Tainacan_Logs->insert($log); @@ -34,6 +37,7 @@ class Logs extends \WP_UnitTestCase { $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() ); } - } \ No newline at end of file