add authors names and dates of the modifies on export csv #360

This commit is contained in:
vnmedeiros 2020-04-07 22:37:41 -03:00
parent 2f969447f0
commit 4acb58014a
2 changed files with 34 additions and 5 deletions

View File

@ -255,11 +255,7 @@ class REST_Items_Controller extends REST_Controller {
}
// \error_log("DEBUG-1:");
// \error_log(\json_encode($item_arr));
$item_arr = apply_filters('tainacan-api-items-prepare-for-response', $item_arr, $item, $request);
// \error_log("DEBUG-2:");
// \error_log(\json_encode($item_arr));
return $item_arr;
}

View File

@ -50,8 +50,9 @@ class CSV extends Exporter {
$line[] = implode( $this->get_option('multivalued_delimiter'), $rel );
else
$line[] = $rel;
} else
} else {
$line[] = $meta->get_value_as_string();
}
}
@ -66,6 +67,14 @@ class CSV extends Exporter {
$line[] = $this->get_attachments_cell($item);
$line[] = $item->get_comment_status();
$line[] = $item->get_author_name();
$line[] = $item->get_creation_date();
$line[] = $this->get_author_name_last_modification($item->get_id());
$line[] = $item->get_modification_date();
$line_string = $this->str_putcsv($line, $this->get_option('delimiter'), $this->get_option('enclosure'));
@ -99,6 +108,26 @@ class CSV extends Exporter {
return implode( $this->get_option('multivalued_delimiter'), $attachments_urls );
}
function get_author_name_last_modification($item_id) {
$logs = \Tainacan\Repositories\Logs::get_instance()->fetch([
'item_id'=>$item_id,
'paged'=>1,
'posts_per_page'=>1
]);
$response;
if($logs->have_posts()){
while ($logs->have_posts()){
$logs->the_post();
$log = new Entities\Log($logs->post);
$response = $log->get_user_name();
}
wp_reset_postdata();
}
return $response;
}
public function output_header() {
$mapper = $this->get_current_mapper();
@ -136,6 +165,10 @@ class CSV extends Exporter {
$line[] = 'special_document';
$line[] = 'special_attachments';
$line[] = 'special_comment_status';
$line[] = 'author_name';
$line[] = 'creation_date';
$line[] = 'user_last_modified';
$line[] = 'modification_date';
$line_string = $this->str_putcsv($line, $this->get_option('delimiter'), $this->get_option('enclosure'));