Commit 623d15d1 authored by Fabrice Gangler's avatar Fabrice Gangler 🎨
Browse files

FEAT(export users): add taxonomies data

parent 9d25f8e4
Pipeline #27618 passed with stage
in 4 minutes and 7 seconds
......@@ -402,7 +402,7 @@ class UsersController extends AppController
];
$csvData = '';
foreach ($this->paginate($users) as $user) {
$lastUserUpdate = $user->modified;
$lastUserUpdate = $user->modified; // Cake\I18n\Time object
// Provider
$providedForSoftwareUrl = '';
......@@ -414,10 +414,10 @@ class UsersController extends AppController
}
foreach ($user->providerforsoftwares as $providedSoftware) {
if ($lastUserUpdate < $providedSoftware->created) {
$lastUserUpdate = $providedSoftware->created;
$lastUserUpdate = $providedSoftware->created; // Cake\I18n\Time object
}
if (empty($lastProvidedForSoftware) || $lastProvidedForSoftware < $providedSoftware->created) {
$lastProvidedForSoftware = $providedSoftware->created;
$lastProvidedForSoftware = $providedSoftware->created; // Cake\I18n\Time object
}
$providedForSoftwares[] = [
'created' => $providedSoftware->created,
......@@ -438,10 +438,10 @@ class UsersController extends AppController
}
foreach ($user->reviews as $review) {
if ($lastUserUpdate < $review->created) {
$lastUserUpdate = $review->created;
$lastUserUpdate = $review->created; // Cake\I18n\Time object
}
if (empty($lastReview) || $lastReview < $review->created) {
$lastReview = $review->created;
$lastReview = $review->created; // Cake\I18n\Time object
}
$review_url = '';
$review_url .= 'https://comptoir-du-libre.org/fr/softwares/';
......@@ -449,7 +449,7 @@ class UsersController extends AppController
$reviews[] = [
'review_id' => $review->id,
'review_url' => $review_url,
'review_created' => $review->created,
'review_created' => $review->created, // Cake\I18n\Time object
'software' => $review->software->softwarename,
'software_id' => $review->software->id,
'software_url' => 'https://comptoir-du-libre.org/fr/softwares/'.$review->software->id,
......@@ -467,24 +467,44 @@ class UsersController extends AppController
}
foreach ($user->usedsoftwares as $usedsoftware) {
if ($lastUserUpdate < $usedsoftware->created) {
$lastUserUpdate = $usedsoftware->created;
$lastUserUpdate = $usedsoftware->created; // Cake\I18n\Time object
}
if (empty($lastUsedSoftware) || $lastUsedSoftware < $usedsoftware->created) {
$lastUsedSoftware = $usedsoftware->created;
$lastUsedSoftware = $usedsoftware->created; // Cake\I18n\Time object
}
$usedSoftwares[] = [
'created' => $usedsoftware->created,
'created' => $usedsoftware->created, // Cake\I18n\Time object
'software' => $usedsoftware->software->softwarename,
'software_id' => $usedsoftware->software->id,
'software_url' => 'https://comptoir-du-libre.org/fr/softwares/'.$usedsoftware->software->id,
];
}
// Taxonomies
$softwareDeclaredInTaxonomy = $this->getSofwareMappingForUser($user);
$taxonomiesSoftware = [];
$lastTaxonomiesSoftware = '';
$taxonomiesSoftwareUrl = '';
$taxonomiesSoftwareNumber = count($softwareDeclaredInTaxonomy);
if ($taxonomiesSoftwareNumber > 0) {
foreach ($softwareDeclaredInTaxonomy as $softwareName => $item) {
$updateDate = $item['modified'];
$softwareId = $item['softwareId'];
$taxonomiesSoftware[$softwareId] = $item;
if ($lastUserUpdate < $updateDate) {
$lastUserUpdate = $updateDate; // Cake\I18n\Time object
}
if (empty($lastTaxonomiesSoftware) || $lastTaxonomiesSoftware < $updateDate) {
$lastTaxonomiesSoftware = $updateDate; // Cake\I18n\Time object
}
}
}
// JSON data
$item = [
'id' => $user->id,
'created' => $user->created,
'modified' => $lastUserUpdate,
'created' => $user->created, // Cake\I18n\Time object
'modified' => $lastUserUpdate, // Cake\I18n\Time object
'url' => 'https://comptoir-du-libre.org/fr/users/'. $user->id,
'name' => $user->username,
'user_type' => $user->user_type->cd,
......@@ -493,19 +513,25 @@ class UsersController extends AppController
],
'reviews' => [
'number' => $reviewNumber,
'last' => $lastReview,
'last' => $lastReview, // Cake\I18n\Time object
'url' => $reviewUrl,
'software' => $reviews,
],
'usingSoftware' => [
'number' => $usedSoftwareNumber,
'last' => $lastUsedSoftware,
'last' => $lastUsedSoftware, // Cake\I18n\Time object
'url' => $usedSoftwareUrl,
'software' => $usedSoftwares,
],
'taxonomies' => [
'number' => $taxonomiesSoftwareNumber,
'last' => $lastTaxonomiesSoftware, // Cake\I18n\Time object
'url' => $taxonomiesSoftwareUrl,
'software' => $taxonomiesSoftware,
],
'providingSoftware' => [
'number' => $providedForSoftwareNumber,
'last' => $lastProvidedForSoftware,
'last' => $lastProvidedForSoftware, // Cake\I18n\Time object
'url' => $providedForSoftwareUrl,
'software' => $providedForSoftwares,
],
......@@ -522,17 +548,22 @@ class UsersController extends AppController
if ($providedForSoftwareNumber === 0) {
$providedForSoftwareNumber = '';
}
if ($taxonomiesSoftwareNumber === 0) {
$taxonomiesSoftwareNumber = '';
}
$csvData .= ''. $user->id .';';
$csvData .= '"'. $user->user_type->cd .'";';
$csvData .= '"'. $user->username .'";';
$csvData .= '' . $user->created .';';
$csvData .= '' . $lastUserUpdate .';';
$csvData .= '' . $user->created .';'; // Cake\I18n\Time->__toString()
$csvData .= '' . $lastUserUpdate .';'; // Cake\I18n\Time->__toString()
$csvData .= ''. $reviewNumber .';';
$csvData .= ''. $usedSoftwareNumber .';';
$csvData .= ''. $taxonomiesSoftwareNumber .';';
$csvData .= ''. $providedForSoftwareNumber .';';
$csvData .= '' . $lastReview .';';
$csvData .= '' . $lastUsedSoftware .';';
$csvData .= '' . $lastProvidedForSoftware .';';
$csvData .= '' . $lastReview .';'; // Cake\I18n\Time->__toString()
$csvData .= '' . $lastUsedSoftware .';'; // Cake\I18n\Time->__toString()
$csvData .= '' . $lastTaxonomiesSoftware .';'; // Cake\I18n\Time->__toString()
$csvData .= '' . $lastProvidedForSoftware .';'; // Cake\I18n\Time->__toString()
$csvData .= "\n";
}
$csvHead = '';
......@@ -543,9 +574,11 @@ class UsersController extends AppController
$csvHead .= "\"modified\";";
$csvHead .= "\"reviews\";";
$csvHead .= "\"using software\";";
$csvHead .= "\"classified software\";";
$csvHead .= "\"providing software\";";
$csvHead .= "\"last review\";";
$csvHead .= "\"last using software\";";
$csvHead .= "\"last classified software\";";
$csvHead .= "\"last providing software\";";
$csvHead .= "\n";
$csv = $csvHead . $csvData;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment