2014-01-23 12:25:04 +01:00
< ? php
App :: uses ( 'AppController' , 'Controller' );
class TagsController extends AppController {
public $components = array ( 'Security' , 'RequestHandler' );
public $paginate = array (
'limit' => 50 ,
'order' => array (
2015-06-05 15:34:21 +02:00
'Tag.name' => 'asc'
2016-07-20 00:08:46 +02:00
),
'contain' => array (
'EventTag' => array (
'fields' => array ( 'event_id' )
),
'FavouriteTag' ,
'Organisation' => array (
'fields' => array ( 'id' , 'name' )
)
2014-01-23 12:25:04 +01:00
)
);
2016-06-04 01:08:16 +02:00
2014-01-23 12:25:04 +01:00
public $helpers = array ( 'TextColour' );
2016-06-04 01:08:16 +02:00
2016-04-28 15:39:44 +02:00
public function index ( $favouritesOnly = false ) {
2014-08-20 14:55:10 +02:00
$this -> loadModel ( 'Event' );
2015-11-27 17:41:41 +01:00
$this -> loadModel ( 'Taxonomy' );
$taxonomies = $this -> Taxonomy -> listTaxonomies ( array ( 'full' => false , 'enabled' => true ));
$taxonomyNamespaces = array ();
2016-09-04 23:31:24 +02:00
if ( ! empty ( $taxonomies )) foreach ( $taxonomies as $taxonomy ) $taxonomyNamespaces [ $taxonomy [ 'namespace' ]] = $taxonomy ;
2015-11-27 17:41:41 +01:00
$taxonomyTags = array ();
2014-08-20 14:55:10 +02:00
$this -> Event -> recursive = - 1 ;
2016-04-28 15:39:44 +02:00
if ( $favouritesOnly ) {
$tag_id_list = $this -> Tag -> FavouriteTag -> find ( 'list' , array (
'conditions' => array ( 'FavouriteTag.user_id' => $this -> Auth -> user ( 'id' )),
'fields' => array ( 'FavouriteTag.tag_id' )
));
if ( empty ( $tag_id_list )) $tag_id_list = array ( - 1 );
$this -> paginate [ 'conditions' ][ 'AND' ][ 'Tag.id' ] = $tag_id_list ;
}
2014-08-20 14:55:10 +02:00
$paginated = $this -> paginate ();
2016-09-04 23:31:24 +02:00
foreach ( $paginated as $k => $tag ) {
if ( empty ( $tag [ 'EventTag' ])) $paginated [ $k ][ 'Tag' ][ 'count' ] = 0 ;
2014-08-20 14:55:10 +02:00
else {
2016-09-21 03:20:22 +02:00
$eventIDs = array ();
2014-08-20 14:55:10 +02:00
foreach ( $tag [ 'EventTag' ] as $eventTag ) {
$eventIDs [] = $eventTag [ 'event_id' ];
}
$conditions = array ( 'Event.id' => $eventIDs );
2015-02-05 17:16:40 +01:00
if ( ! $this -> _isSiteAdmin ()) $conditions = array_merge (
$conditions ,
array ( 'OR' => array (
array ( 'AND' => array (
array ( 'Event.distribution >' => 0 ),
array ( 'Event.published =' => 1 )
)),
2015-11-28 23:49:52 +01:00
array ( 'Event.orgc_id' => $this -> Auth -> user ( 'org_id' ))
2015-02-05 17:16:40 +01:00
)));
2014-08-20 14:55:10 +02:00
$events = $this -> Event -> find ( 'all' , array (
2015-11-28 23:49:52 +01:00
'fields' => array ( 'Event.id' , 'Event.distribution' , 'Event.orgc_id' ),
2014-08-20 14:55:10 +02:00
'conditions' => $conditions
));
2016-09-04 23:31:24 +02:00
$paginated [ $k ][ 'Tag' ][ 'count' ] = count ( $events );
2014-08-20 14:55:10 +02:00
}
2016-09-04 23:31:24 +02:00
unset ( $paginated [ $k ][ 'EventTag' ]);
2016-04-28 15:39:44 +02:00
if ( ! empty ( $tag [ 'FavouriteTag' ])) {
2016-09-04 23:31:24 +02:00
foreach ( $tag [ 'FavouriteTag' ] as $ft ) if ( $ft [ 'user_id' ] == $this -> Auth -> user ( 'id' )) $paginated [ $k ][ 'Tag' ][ 'favourite' ] = true ;
if ( ! isset ( $tag [ 'Tag' ][ 'favourite' ])) $paginated [ $k ][ 'Tag' ][ 'favourite' ] = false ;
} else $paginated [ $k ][ 'Tag' ][ 'favourite' ] = false ;
unset ( $paginated [ $k ][ 'FavouriteTag' ]);
2015-11-27 17:41:41 +01:00
if ( ! empty ( $taxonomyNamespaces )) {
2015-12-16 00:48:30 +01:00
$taxonomyNamespaceArrayKeys = array_keys ( $taxonomyNamespaces );
2016-09-04 23:31:24 +02:00
foreach ( $taxonomyNamespaceArrayKeys as $tns ) {
2015-11-27 17:41:41 +01:00
if ( substr ( strtoupper ( $tag [ 'Tag' ][ 'name' ]), 0 , strlen ( $tns )) === strtoupper ( $tns )) {
2016-09-04 23:31:24 +02:00
$paginated [ $k ][ 'Tag' ][ 'Taxonomy' ] = $taxonomyNamespaces [ $tns ];
2015-11-29 22:36:14 +01:00
if ( ! isset ( $taxonomyTags [ $tns ])) $taxonomyTags [ $tns ] = $this -> Taxonomy -> getTaxonomyTags ( $taxonomyNamespaces [ $tns ][ 'id' ], true );
2016-09-04 23:31:24 +02:00
$paginated [ $k ][ 'Tag' ][ 'Taxonomy' ][ 'expanded' ] = $taxonomyTags [ $tns ][ strtoupper ( $tag [ 'Tag' ][ 'name' ])];
2015-11-27 17:41:41 +01:00
}
}
}
2014-08-20 14:55:10 +02:00
}
2015-10-30 16:28:51 +01:00
if ( $this -> _isRest ()) {
2016-09-04 23:31:24 +02:00
foreach ( $paginated as $key => $tag ) {
$paginated [ $key ] = $tag [ 'Tag' ];
2015-10-30 16:28:51 +01:00
}
$this -> set ( 'Tag' , $paginated );
$this -> set ( '_serialize' , array ( 'Tag' ));
} else {
$this -> set ( 'list' , $paginated );
2016-04-28 15:39:44 +02:00
$this -> set ( 'favouritesOnly' , $favouritesOnly );
2015-10-30 16:28:51 +01:00
}
2014-01-23 12:25:04 +01:00
// send perm_tagger to view for action buttons
}
2016-06-04 01:08:16 +02:00
2014-01-23 12:25:04 +01:00
public function add () {
2016-03-30 18:32:17 +02:00
if ( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tag_editor' ]) throw new NotFoundException ( 'You don\'t have permission to do that.' );
2014-01-23 12:25:04 +01:00
if ( $this -> request -> is ( 'post' )) {
2016-06-04 01:10:45 +02:00
if ( isset ( $this -> request -> data [ 'Tag' ][ 'request' ])) $this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Tag' ][ 'request' ];
2015-10-30 16:28:51 +01:00
if ( ! isset ( $this -> request -> data [ 'Tag' ][ 'colour' ])) $this -> request -> data [ 'Tag' ][ 'colour' ] = $this -> Tag -> random_color ();
if ( isset ( $this -> request -> data [ 'Tag' ][ 'id' ])) unset ( $this -> request -> data [ 'Tag' ][ 'id' ]);
2014-01-23 12:25:04 +01:00
if ( $this -> Tag -> save ( $this -> request -> data )) {
2015-10-30 16:28:51 +01:00
if ( $this -> _isRest ()) $this -> redirect ( array ( 'action' => 'view' , $this -> Tag -> id ));
2014-01-23 12:25:04 +01:00
$this -> Session -> setFlash ( 'The tag has been saved.' );
$this -> redirect ( array ( 'action' => 'index' ));
} else {
2015-10-30 16:28:51 +01:00
if ( $this -> _isRest ()) {
$error_message = '' ;
2016-06-04 01:10:45 +02:00
foreach ( $this -> Tag -> validationErrors as $k => $v ) $error_message .= '[' . $k . ']: ' . $v [ 0 ];
2015-10-30 16:28:51 +01:00
throw new MethodNotAllowedException ( 'Could not add the Tag. ' . $error_message );
} else {
$this -> Session -> setFlash ( 'The tag could not be saved. Please, try again.' );
}
2014-01-23 12:25:04 +01:00
}
}
2016-07-20 00:08:46 +02:00
$this -> loadModel ( 'Organisation' );
$temp = $this -> Organisation -> find ( 'all' , array (
'conditions' => array ( 'local' => 1 ),
'fields' => array ( 'id' , 'name' ),
'recursive' => - 1
));
$orgs = array ( 0 => 'Unrestricted' );
if ( ! empty ( $temp )) {
2016-09-04 23:31:24 +02:00
foreach ( $temp as $org ) {
2016-07-20 00:08:46 +02:00
$orgs [ $org [ 'Organisation' ][ 'id' ]] = $org [ 'Organisation' ][ 'name' ];
}
}
$this -> set ( 'orgs' , $orgs );
2014-01-23 12:25:04 +01:00
}
2016-06-04 01:08:16 +02:00
2015-11-24 03:27:14 +01:00
public function quickAdd () {
2016-03-30 18:32:17 +02:00
if (( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tag_editor' ]) || ! $this -> request -> is ( 'post' )) throw new NotFoundException ( 'You don\'t have permission to do that.' );
2015-11-24 03:27:14 +01:00
if ( isset ( $this -> request -> data [ 'Tag' ][ 'request' ])) $this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Tag' ][ 'request' ];
if ( $this -> Tag -> quickAdd ( $this -> request -> data [ 'Tag' ][ 'name' ])) {
$this -> Session -> setFlash ( 'The tag has been saved.' );
} else {
$this -> Session -> setFlash ( 'The tag could not be saved. Please, try again.' );
}
$this -> redirect ( $this -> referer ());
}
2016-06-04 01:08:16 +02:00
2014-01-23 12:25:04 +01:00
public function edit ( $id ) {
2016-03-30 18:32:17 +02:00
if ( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tag_editor' ]) {
2014-01-23 12:25:04 +01:00
throw new NotFoundException ( 'You don\'t have permission to do that.' );
}
$this -> Tag -> id = $id ;
if ( ! $this -> Tag -> exists ()) {
throw new NotFoundException ( 'Invalid tag' );
}
if ( $this -> request -> is ( 'post' ) || $this -> request -> is ( 'put' )) {
2015-04-20 11:46:55 +02:00
$this -> request -> data [ 'Tag' ][ 'id' ] = $id ;
2015-10-30 16:28:51 +01:00
if ( isset ( $this -> request -> data [ 'Tag' ][ 'request' ])) $this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Tag' ][ 'request' ];
2015-11-08 23:26:19 +01:00
2014-01-23 12:25:04 +01:00
if ( $this -> Tag -> save ( $this -> request -> data )) {
2015-10-30 16:28:51 +01:00
if ( $this -> _isRest ()) $this -> redirect ( array ( 'action' => 'view' , $id ));
2014-01-23 12:25:04 +01:00
$this -> Session -> setFlash ( 'The Tag has been edited' );
$this -> redirect ( array ( 'action' => 'index' ));
} else {
2015-10-30 16:28:51 +01:00
if ( $this -> _isRest ()) {
$error_message = '' ;
foreach ( $this -> Tag -> validationErrors as $k => $v ) $error_message .= '[' . $k . ']: ' . $v [ 0 ];
throw new MethodNotAllowedException ( 'Could not add the Tag. ' . $error_message );
}
2014-01-23 12:25:04 +01:00
$this -> Session -> setFlash ( 'The Tag could not be saved. Please, try again.' );
}
}
2016-07-20 00:08:46 +02:00
$this -> loadModel ( 'Organisation' );
$temp = $this -> Organisation -> find ( 'all' , array (
'conditions' => array ( 'local' => 1 ),
'fields' => array ( 'id' , 'name' ),
'recursive' => - 1
));
$orgs = array ( 0 => 'Unrestricted' );
if ( ! empty ( $temp )) {
2016-09-04 23:31:24 +02:00
foreach ( $temp as $org ) {
2016-07-20 00:08:46 +02:00
$orgs [ $org [ 'Organisation' ][ 'id' ]] = $org [ 'Organisation' ][ 'name' ];
}
}
$this -> set ( 'orgs' , $orgs );
2014-01-23 12:25:04 +01:00
$this -> request -> data = $this -> Tag -> read ( null , $id );
}
2016-06-04 01:08:16 +02:00
2014-01-23 12:25:04 +01:00
public function delete ( $id ) {
2016-03-30 18:32:17 +02:00
if ( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tag_editor' ]) {
2014-01-23 12:25:04 +01:00
throw new NotFoundException ( 'You don\'t have permission to do that.' );
}
if ( ! $this -> request -> is ( 'post' )) {
throw new MethodNotAllowedException ();
}
$this -> Tag -> id = $id ;
if ( ! $this -> Tag -> exists ()) {
throw new NotFoundException ( 'Invalid tag' );
}
2014-02-19 17:38:31 +01:00
if ( $this -> Tag -> delete ()) {
2015-10-30 16:28:51 +01:00
if ( $this -> _isRest ()) {
$this -> set ( 'name' , 'Tag deleted.' );
$this -> set ( 'message' , 'Tag deleted.' );
$this -> set ( 'url' , '/tags/delete/' . $id );
$this -> set ( '_serialize' , array ( 'name' , 'message' , 'url' ));
}
$this -> Session -> setFlash ( __ ( 'Tag deleted' ));
2014-01-23 12:25:04 +01:00
} else {
2015-10-30 16:28:51 +01:00
if ( $this -> _isRest ()) throw new MethodNotAllowedException ( 'Could not delete the tag, or tag doesn\'t exist.' );
$this -> Session -> setFlash ( __ ( 'Tag was not deleted' ));
2014-01-23 12:25:04 +01:00
}
2015-10-30 16:28:51 +01:00
if ( ! $this -> _isRest ()) $this -> redirect ( array ( 'action' => 'index' ));
}
2016-06-04 01:08:16 +02:00
2015-10-30 16:28:51 +01:00
public function view ( $id ) {
if ( $this -> _isRest ()) {
$tag = $this -> Tag -> find ( 'first' , array (
'conditions' => array ( 'id' => $id ),
'recursive' => - 1 ,
'contain' => array ( 'EventTag' => array ( 'fields' => 'event_id' ))
));
2016-09-21 02:06:26 +02:00
if ( empty ( $tag )) throw new MethodNotAllowedException ( 'Invalid Tag' );
2015-10-30 16:28:51 +01:00
if ( empty ( $tag [ 'EventTag' ])) $tag [ 'Tag' ][ 'count' ] = 0 ;
else {
2016-09-21 03:20:22 +02:00
$eventIDs = array ();
2015-10-30 16:28:51 +01:00
foreach ( $tag [ 'EventTag' ] as $eventTag ) {
$eventIDs [] = $eventTag [ 'event_id' ];
}
$conditions = array ( 'Event.id' => $eventIDs );
if ( ! $this -> _isSiteAdmin ()) $conditions = array_merge (
$conditions ,
array ( 'OR' => array (
array ( 'AND' => array (
array ( 'Event.distribution >' => 0 ),
array ( 'Event.published =' => 1 )
)),
2015-11-28 23:49:52 +01:00
array ( 'Event.orgc_id' => $this -> Auth -> user ( 'org_id' ))
2015-10-30 16:28:51 +01:00
)));
$events = $this -> Tag -> EventTag -> Event -> find ( 'all' , array (
2015-11-28 23:49:52 +01:00
'fields' => array ( 'Event.id' , 'Event.distribution' , 'Event.orgc_id' ),
2015-10-30 16:28:51 +01:00
'conditions' => $conditions
));
$tag [ 'Tag' ][ 'count' ] = count ( $events );
}
unset ( $tag [ 'EventTag' ]);
$this -> set ( 'Tag' , $tag [ 'Tag' ]);
$this -> set ( '_serialize' , 'Tag' );
} else throw new MethodNotAllowedException ( 'This action is only for REST users.' );
2016-06-04 01:08:16 +02:00
2014-01-23 12:25:04 +01:00
}
2016-06-04 01:08:16 +02:00
2014-04-24 15:10:08 +02:00
public function showEventTag ( $id ) {
$this -> helpers [] = 'TextColour' ;
$this -> loadModel ( 'EventTag' );
$tags = $this -> EventTag -> find ( 'all' , array (
'conditions' => array (
'event_id' => $id
),
2016-03-30 18:32:17 +02:00
'contain' => array ( 'Tag' ),
2014-04-24 15:10:08 +02:00
'fields' => array ( 'Tag.id' , 'Tag.colour' , 'Tag.name' ),
));
$this -> set ( 'tags' , $tags );
2016-03-30 18:32:17 +02:00
$event = $this -> Tag -> EventTag -> Event -> find ( 'first' , array (
'recursive' => - 1 ,
'fields' => array ( 'Event.id' , 'Event.orgc_id' , 'Event.org_id' , 'Event.user_id' ),
'conditions' => array ( 'Event.id' => $id )
));
2014-04-24 15:10:08 +02:00
$this -> set ( 'event' , $event );
$this -> layout = 'ajax' ;
$this -> render ( '/Events/ajax/ajaxTags' );
}
2016-06-04 01:08:16 +02:00
2014-06-12 13:59:54 +02:00
public function viewTag ( $id ) {
$tag = $this -> Tag -> find ( 'first' , array (
'conditions' => array (
'id' => $id
),
'recursive' => - 1 ,
));
$this -> layout = null ;
$this -> set ( 'tag' , $tag );
$this -> set ( 'id' , $id );
$this -> render ( 'ajax/view_tag' );
}
2016-06-04 01:08:16 +02:00
2015-11-27 17:41:41 +01:00
public function selectTaxonomy ( $event_id ) {
if ( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) throw new NotFoundException ( 'You don\'t have permission to do that.' );
2016-04-28 15:39:44 +02:00
$favourites = $this -> Tag -> FavouriteTag -> find ( 'count' , array ( 'conditions' => array ( 'FavouriteTag.user_id' => $this -> Auth -> user ( 'id' ))));
2015-11-27 17:41:41 +01:00
$this -> loadModel ( 'Taxonomy' );
2015-12-16 00:48:30 +01:00
$options = $this -> Taxonomy -> find ( 'list' , array ( 'conditions' => array ( 'enabled' => true ), 'fields' => array ( 'namespace' ), 'order' => array ( 'Taxonomy.namespace ASC' )));
2016-09-04 23:31:24 +02:00
foreach ( $options as $k => $option ) {
2015-11-27 17:41:41 +01:00
$tags = $this -> Taxonomy -> getTaxonomyTags ( $k , false , true );
if ( empty ( $tags )) unset ( $options [ $k ]);
}
$this -> set ( 'event_id' , $event_id );
$this -> set ( 'options' , $options );
2016-04-28 15:39:44 +02:00
$this -> set ( 'favourites' , $favourites );
2015-11-27 17:41:41 +01:00
$this -> render ( 'ajax/taxonomy_choice' );
}
2016-06-04 01:08:16 +02:00
2015-11-27 17:41:41 +01:00
public function selectTag ( $event_id , $taxonomy_id ) {
if ( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) throw new NotFoundException ( 'You don\'t have permission to do that.' );
$this -> loadModel ( 'Taxonomy' );
$expanded = array ();
2016-04-28 15:39:44 +02:00
if ( $taxonomy_id === '0' ) {
2015-11-27 17:41:41 +01:00
$options = $this -> Taxonomy -> getAllTaxonomyTags ( true );
$expanded = $options ;
2016-04-28 15:39:44 +02:00
} else if ( $taxonomy_id === 'favourites' ) {
$tags = $this -> Tag -> FavouriteTag -> find ( 'all' , array (
'conditions' => array ( 'FavouriteTag.user_id' => $this -> Auth -> user ( 'id' )),
'recursive' => - 1 ,
'contain' => array ( 'Tag.name' )
));
foreach ( $tags as $tag ) {
$options [ $tag [ 'FavouriteTag' ][ 'tag_id' ]] = $tag [ 'Tag' ][ 'name' ];
$expanded = $options ;
}
2015-11-27 17:41:41 +01:00
} else {
$taxonomies = $this -> Taxonomy -> getTaxonomy ( $taxonomy_id );
$options = array ();
2016-09-04 23:31:24 +02:00
foreach ( $taxonomies [ 'entries' ] as $entry ) {
2015-11-27 17:41:41 +01:00
if ( ! empty ( $entry [ 'existing_tag' ][ 'Tag' ])) {
$options [ $entry [ 'existing_tag' ][ 'Tag' ][ 'id' ]] = $entry [ 'existing_tag' ][ 'Tag' ][ 'name' ];
$expanded [ $entry [ 'existing_tag' ][ 'Tag' ][ 'id' ]] = $entry [ 'expanded' ];
}
}
}
2016-07-20 00:08:46 +02:00
// Unset all tags that this user cannot use for tagging, determined by the org restriction on tags
if ( ! $this -> _isSiteAdmin ()) {
$banned_tags = $this -> Tag -> find ( 'list' , array (
'conditions' => array (
'NOT' => array (
'Tag.org_id' => array (
2016-08-22 02:54:51 +02:00
0 ,
2016-07-20 00:08:46 +02:00
$this -> Auth -> user ( 'org_id' )
)
)
),
'fields' => array ( 'Tag.id' )
));
foreach ( $banned_tags as $banned_tag ) {
unset ( $options [ $banned_tag ]);
unset ( $expanded [ $banned_tag ]);
}
}
2015-11-27 17:41:41 +01:00
$this -> set ( 'event_id' , $event_id );
$this -> set ( 'options' , $options );
$this -> set ( 'expanded' , $expanded );
$this -> set ( 'custom' , $taxonomy_id == 0 ? true : false );
$this -> render ( 'ajax/select_tag' );
}
2016-06-04 01:08:16 +02:00
2016-05-22 23:47:29 +02:00
public function tagStatistics ( $percentage = false , $keysort = false ) {
2016-05-22 23:35:24 +02:00
$result = $this -> Tag -> EventTag -> find ( 'all' , array (
'recursive' => - 1 ,
'fields' => array ( 'count(EventTag.id) as count' , 'tag_id' ),
'contain' => array ( 'Tag' => array ( 'fields' => array ( 'Tag.name' ))),
'group' => array ( 'tag_id' )
));
$tags = array ();
$taxonomies = array ();
$totalCount = 0 ;
$this -> loadModel ( 'Taxonomy' );
$temp = $this -> Taxonomy -> listTaxonomies ( array ( 'enabled' => true ));
foreach ( $temp as $t ) {
if ( $t [ 'enabled' ]) $taxonomies [ $t [ 'namespace' ]] = 0 ;
}
foreach ( $result as $r ) {
if ( $r [ 'Tag' ][ 'name' ] == null ) continue ;
$tags [ $r [ 'Tag' ][ 'name' ]] = $r [ 0 ][ 'count' ];
$totalCount += $r [ 0 ][ 'count' ];
foreach ( $taxonomies as $taxonomy => $count ) {
2016-06-04 01:10:45 +02:00
if ( substr ( strtolower ( $r [ 'Tag' ][ 'name' ]), 0 , strlen ( $taxonomy )) === strtolower ( $taxonomy )) $taxonomies [ $taxonomy ] += $r [ 0 ][ 'count' ];
2016-05-22 23:35:24 +02:00
}
}
2016-05-22 23:47:29 +02:00
if ( $keysort === 'true' ) {
2016-05-22 23:42:48 +02:00
ksort ( $tags , SORT_NATURAL | SORT_FLAG_CASE );
ksort ( $taxonomies , SORT_NATURAL | SORT_FLAG_CASE );
} else {
arsort ( $tags );
arsort ( $taxonomies );
2016-06-04 01:10:45 +02:00
}
2016-05-22 23:42:48 +02:00
if ( $percentage === 'true' ) {
2016-09-04 23:31:24 +02:00
foreach ( $tags as $tag => $count ) {
$tags [ $tag ] = round ( 100 * $count / $totalCount , 3 ) . '%' ;
2016-05-22 23:35:24 +02:00
}
2016-09-04 23:31:24 +02:00
foreach ( $taxonomies as $taxonomy => $count ) {
$taxonomies [ $taxonomy ] = round ( 100 * $count / $totalCount , 3 ) . '%' ;
2016-05-22 23:35:24 +02:00
}
}
$results = array ( 'tags' => $tags , 'taxonomies' => $taxonomies );
$this -> autoRender = false ;
$this -> layout = false ;
$this -> set ( 'data' , $results );
$this -> set ( 'flags' , JSON_PRETTY_PRINT );
$this -> response -> type ( 'json' );
$this -> render ( '/Servers/json/simple' );
}
2015-01-27 10:10:22 +01:00
}