chg: [API] Add description to predicates and values

pull/7444/head
Jakub Onderka 2021-05-25 18:57:58 +02:00
parent 672476001b
commit 0790a12929
2 changed files with 22 additions and 15 deletions

View File

@ -59,12 +59,6 @@ class TaxonomiesController extends AppController
public function view($id)
{
if (isset($this->passedArgs['pages'])) {
$currentPage = $this->passedArgs['pages'];
} else {
$currentPage = 1;
}
$this->set('page', $currentPage);
$urlparams = '';
$passedArgs = array();
App::uses('CustomPaginationTool', 'Tools');
@ -103,12 +97,19 @@ class TaxonomiesController extends AppController
return $this->RestResponse->viewData($taxonomy, $this->response->type());
}
if (isset($this->passedArgs['pages'])) {
$currentPage = $this->passedArgs['pages'];
} else {
$currentPage = 1;
}
$this->set('page', $currentPage);
$this->set('entries', $taxonomy['entries']);
$this->set('urlparams', $urlparams);
$this->set('passedArgs', json_encode($passedArgs));
$this->set('passedArgsArray', $passedArgs);
$this->set('taxonomy', $taxonomy['Taxonomy']);
$this->set('id', $id);
$this->set('id', $taxonomy['Taxonomy']['id']);
$this->set('title_for_layout', __('%s Taxonomy Library', h(strtoupper($taxonomy['Taxonomy']['namespace']))));
}

View File

@ -164,21 +164,21 @@ class Taxonomy extends AppModel
return $this->validationErrors;
}
/**
* @param int|string $id Taxonomy ID or namespace
* @param array $options
* @return array|false
*/
private function __getTaxonomy($id, $options = array('full' => false, 'filter' => false))
{
$recursive = -1;
if ($options['full']) {
$recursive = 2;
}
$filter = false;
if (isset($options['filter'])) {
$filter = $options['filter'];
}
$taxonomy_params = array(
'recursive' => -1,
'contain' => array('TaxonomyPredicate' => array('TaxonomyEntry')),
'conditions' => array('Taxonomy.id' => $id)
'recursive' => -1,
'contain' => array('TaxonomyPredicate' => array('TaxonomyEntry')),
'conditions' => is_numeric($id) ? ['Taxonomy.id' => $id] : ['Taxonomy.namespace' => $id],
);
$taxonomy = $this->find('first', $taxonomy_params);
if (empty($taxonomy)) {
@ -190,6 +190,9 @@ class Taxonomy extends AppModel
foreach ($predicate['TaxonomyEntry'] as $entry) {
$temp = array('tag' => $taxonomy['Taxonomy']['namespace'] . ':' . $predicate['value'] . '="' . $entry['value'] . '"');
$temp['expanded'] = (!empty($predicate['expanded']) ? $predicate['expanded'] : $predicate['value']) . ': ' . (!empty($entry['expanded']) ? $entry['expanded'] : $entry['value']);
if (isset($entry['description']) && !empty($entry['description'])) {
$temp['description'] = $entry['description'];
}
if (isset($entry['colour']) && !empty($entry['colour'])) {
$temp['colour'] = $entry['colour'];
}
@ -202,6 +205,9 @@ class Taxonomy extends AppModel
} else {
$temp = array('tag' => $taxonomy['Taxonomy']['namespace'] . ':' . $predicate['value']);
$temp['expanded'] = !empty($predicate['expanded']) ? $predicate['expanded'] : $predicate['value'];
if (isset($predicate['description']) && !empty($predicate['description'])) {
$temp['description'] = $predicate['description'];
}
if (isset($predicate['colour']) && !empty($predicate['colour'])) {
$temp['colour'] = $predicate['colour'];
}