2018-12-28 12:55:41 +01:00
< ? php
App :: uses ( 'AppController' , 'Controller' );
2020-08-16 16:17:49 +02:00
/**
* @ property TagCollection $TagCollection
*/
2018-12-28 12:55:41 +01:00
class TagCollectionsController extends AppController
{
public $components = array (
2019-01-01 16:38:57 +01:00
'AdminCrud' ,
'RequestHandler'
2018-12-28 12:55:41 +01:00
);
public $paginate = array (
2022-05-22 11:33:57 +02:00
'limit' => 60 ,
'order' => array (
'TagCollection.name' => 'ASC'
),
'recursive' => - 1 ,
'contain' => array (
'TagCollectionTag' => array (
'Tag'
2018-12-28 12:55:41 +01:00
),
2022-05-22 11:33:57 +02:00
'Organisation' => array (
'fields' => array (
'Organisation.id' ,
'Organisation.name' ,
'Organisation.uuid'
)
),
'User' => array (
'fields' => array (
'User.email' ,
'User.id'
2019-01-21 15:15:10 +01:00
)
)
2022-05-22 11:33:57 +02:00
)
2018-12-28 12:55:41 +01:00
);
public function add ()
{
if ( $this -> request -> is ( 'post' )) {
$this -> TagCollection -> create ();
if ( ! isset ( $this -> request -> data [ 'TagCollection' ])) {
$this -> request -> data = array ( 'TagCollection' => $this -> request -> data );
}
$this -> request -> data [ 'TagCollection' ][ 'org_id' ] = $this -> Auth -> user ( 'org_id' );
$this -> request -> data [ 'TagCollection' ][ 'user_id' ] = $this -> Auth -> user ( 'id' );
if ( $this -> TagCollection -> save ( $this -> request -> data )) {
if ( $this -> _isRest ()) {
$tagCollection = $this -> TagCollection -> find ( 'first' , array (
'recursive' => - 1 ,
'conditions' => array ( 'TagCollection.id' => $this -> TagCollection -> id )
));
return $this -> RestResponse -> viewData ( $tagCollection , $this -> response -> type ());
} else {
$this -> Flash -> success ( __ ( 'The tag collection has been saved' ));
$this -> redirect ( array ( 'action' => 'index' ));
}
} else {
$message = json_encode ( $this -> TagCollection -> validationErrors );
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveFailResponse ( 'TagCollection' , 'add' , false , $message , $this -> response -> type ());
} else {
$this -> Flash -> error ( __ ( 'The tag collection could not be added. Reason: ' ) . $message );
}
}
} elseif ( $this -> _isRest ()) {
return $this -> RestResponse -> describe ( 'TagCollection' , 'add' , false , $this -> response -> type ());
}
$this -> set ( 'action' , 'add' );
}
2019-01-21 15:15:10 +01:00
public function import ()
2018-12-28 12:55:41 +01:00
{
2019-01-21 15:15:10 +01:00
if ( $this -> request -> is ( 'post' )) {
if ( isset ( $this -> request -> data [ 'TagCollection' ][ 'json' ])) {
2022-10-25 19:38:15 +02:00
$data = $this -> _jsonDecode ( $this -> request -> data [ 'TagCollection' ][ 'json' ]);
2019-01-21 15:15:10 +01:00
} else {
$data = $this -> request -> data ;
}
$results = $this -> TagCollection -> import ( $data , $this -> Auth -> user ());
if ( $results [ 'successes' ] > 0 ) {
$flashType = 'success' ;
$message = sprintf (
__ ( '%s new tag collections added.' ),
$results [ 'successes' ]
);
} else {
$flashType = 'info' ;
$message = 'No new tag_collections to add.' ;
}
if ( $results [ 'fails' ]) {
$message .= sprintf (
' %s tag collections could not be added (possibly because they already exist)' ,
$results [ 'fails' ]
);
}
if ( $this -> _isRest ()) {
2019-02-21 10:04:43 +01:00
return $this -> RestResponse -> saveSuccessResponse ( 'TagCollections' , 'import' , false , $this -> response -> type (), $message );
2019-01-21 15:15:10 +01:00
} else {
$this -> Flash -> { $flashType }( $message );
2019-02-21 10:04:43 +01:00
$this -> redirect ( array ( 'action' => 'index' ));
2019-01-21 15:15:10 +01:00
}
}
}
2018-12-28 12:55:41 +01:00
2019-01-21 15:15:10 +01:00
public function view ( $id )
{
2022-10-25 19:38:15 +02:00
$conditions = $this -> TagCollection -> createConditions ( $this -> Auth -> user ());
2019-01-21 15:15:10 +01:00
$conditions [ 'TagCollection.id' ] = $id ;
2022-10-25 19:38:15 +02:00
$collection = $this -> TagCollection -> find ( 'first' , array (
2019-01-21 15:15:10 +01:00
'recursive' => - 1 ,
2022-10-25 19:38:15 +02:00
'contain' => array ( 'TagCollectionTag' => array ( 'Tag' ), 'Organisation' => array ( 'fields' => array ( 'id' , 'name' , 'uuid' )), 'User' => array ( 'fields' => array ( 'User.id' , 'User.email' ))),
'conditions' => $conditions ,
));
2019-01-21 15:15:10 +01:00
if ( empty ( $collection )) {
throw new NotFoundException ( 'Invalid Tag Collection' );
}
$collection = $this -> TagCollection -> cullBlockedTags ( $this -> Auth -> user (), $collection );
$this -> loadModel ( 'Event' );
2020-03-12 10:26:09 +01:00
$collection = $this -> Event -> massageTags ( $this -> Auth -> user (), $collection , 'TagCollection' , false , true );
2022-10-25 19:38:15 +02:00
if ( ! $this -> ACL -> canModifyTagCollection ( $this -> Auth -> user (), $collection )) {
2019-01-21 15:15:10 +01:00
unset ( $collection [ 'User' ]);
unset ( $collection [ 'TagCollection' ][ 'user_id' ]);
}
if ( ! empty ( $collection [ 'TagCollectionTag' ])) {
foreach ( $collection [ 'TagCollectionTag' ] as $k => $tct ) {
$collection [ 'TagCollectionTag' ][ $k ][ 'Tag' ] = array (
'id' => $tct [ 'Tag' ][ 'id' ],
'name' => $tct [ 'Tag' ][ 'name' ],
'colour' => $tct [ 'Tag' ][ 'colour' ]
);
}
}
return $this -> RestResponse -> viewData ( $collection , $this -> response -> type ());
2018-12-28 12:55:41 +01:00
}
public function edit ( $id )
{
2022-10-25 19:38:15 +02:00
$conditions = $this -> TagCollection -> createConditions ( $this -> Auth -> user ());
$conditions [ 'TagCollection.id' ] = $id ;
2018-12-28 12:55:41 +01:00
$tagCollection = $this -> TagCollection -> find ( 'first' , array (
2022-10-25 19:38:15 +02:00
'conditions' => $conditions ,
2018-12-28 12:55:41 +01:00
'recursive' => - 1
));
2022-10-25 19:38:15 +02:00
if ( empty ( $tagCollection )) {
throw new NotFoundException ( __ ( 'Invalid Tag Collection' ));
}
if ( ! $this -> ACL -> canModifyTagCollection ( $this -> Auth -> user (), $tagCollection )) {
2018-12-28 12:55:41 +01:00
throw new MethodNotAllowedException ( __ ( 'You don\'t have editing rights on this Tag Collection.' ));
}
if ( $this -> request -> is ( 'post' ) || $this -> request -> is ( 'put' )) {
if ( ! isset ( $this -> request -> data [ 'TagCollection' ])) {
$this -> request -> data = array ( 'TagCollection' => $this -> request -> data );
}
$this -> request -> data [ 'TagCollection' ][ 'id' ] = $tagCollection [ 'TagCollection' ][ 'id' ];
$this -> request -> data [ 'TagCollection' ][ 'uuid' ] = $tagCollection [ 'TagCollection' ][ 'uuid' ];
if ( $this -> TagCollection -> save ( $this -> request -> data )) {
if ( $this -> _isRest ()) {
$tagCollection = $this -> TagCollection -> find ( 'first' , array (
'recursive' => - 1 ,
'conditions' => array ( 'TagCollection.id' => $this -> TagCollection -> id )
));
return $this -> RestResponse -> viewData ( $tagCollection , $this -> response -> type ());
} else {
$this -> Flash -> success ( __ ( 'The tag collection has been saved' ));
$this -> redirect ( array ( 'action' => 'index' ));
}
} else {
$message = json_encode ( $this -> TagCollection -> validationErrors );
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveFailResponse ( 'TagCollection' , 'add' , false , $message , $this -> response -> type ());
} else {
$this -> Flash -> error ( __ ( 'The tag collection could not be added. Reason: ' ) . $message );
}
}
} elseif ( $this -> _isRest ()) {
return $this -> RestResponse -> describe ( 'TagCollection' , 'add' , false , $this -> response -> type ());
} else {
$this -> request -> data = $tagCollection ;
}
$this -> set ( 'action' , 'edit' );
$this -> render ( 'add' );
}
2019-01-01 16:38:57 +01:00
public function delete ( $id )
2018-12-28 12:55:41 +01:00
{
2019-01-01 16:38:57 +01:00
$tagCollection = $this -> TagCollection -> fetchTagCollection ( $this -> Auth -> user (), array ( 'conditions' => array ( 'TagCollection.id' => $id )));
if ( empty ( $tagCollection )) {
throw new NotFoundException ( __ ( 'Invalid tag collection.' ));
}
$tagCollection = $tagCollection [ 0 ];
2022-10-25 19:38:15 +02:00
if ( $this -> ACL -> canModifyTagCollection ( $this -> Auth -> user (), $tagCollection )) {
2019-01-01 16:38:57 +01:00
$result = $this -> TagCollection -> delete ( $id );
if ( $result ) {
$message = __ ( 'Tag collection deleted.' );
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveSuccessResponse ( 'TagCollections' , 'delete' , false , $this -> response -> type (), $message );
} else {
$this -> Flash -> success ( $message );
2019-01-21 15:15:10 +01:00
$this -> redirect ( array ( 'action' => 'index' ));
2019-01-01 16:38:57 +01:00
}
} else {
$message = __ ( 'Tag collection could not be deleted.' );
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveFailResponse ( 'TagCollections' , 'delete' , false , $message , $this -> response -> type ());
} else {
$this -> Flash -> error ( $message );
2019-01-21 15:15:10 +01:00
$this -> redirect ( array ( 'action' => 'index' ));
2019-01-01 16:38:57 +01:00
}
}
} else {
throw new NotFoundException ( __ ( 'You are not allowed to delete that.' ));
}
2018-12-28 12:55:41 +01:00
}
public function addTag ( $id = false , $tag_id = false )
{
$rearrangeRules = array (
'request' => false ,
'TagCollection' => false ,
'tag_id' => 'tag' ,
'tag_collection_id' => 'tag_collection' ,
'id' => 'tag_collection'
);
$RearrangeTool = new RequestRearrangeTool ();
$this -> request -> data = $RearrangeTool -> rearrangeArray ( $this -> request -> data , $rearrangeRules );
if ( $id === false ) {
2019-10-09 09:29:04 +02:00
if ( ! isset ( $this -> request -> data [ 'tag_collection' ])) {
throw new NotFoundException ( __ ( 'Invalid tag collection' ));
}
2018-12-28 12:55:41 +01:00
$id = $this -> request -> data [ 'tag_collection' ];
}
2019-03-20 11:21:40 +01:00
if ( ! $this -> request -> is ( 'post' )) {
$this -> set ( 'object_id' , $id );
$this -> set ( 'scope' , 'TagCollection' );
2020-08-17 10:05:36 +02:00
$this -> set ( 'local' , false );
2019-03-20 11:21:40 +01:00
$this -> layout = false ;
$this -> autoRender = false ;
$this -> render ( '/Events/add_tag' );
} else {
if ( $tag_id === false ) {
2019-10-09 09:29:04 +02:00
if ( ! isset ( $this -> request -> data [ 'tag' ])) {
throw new NotFoundException ( __ ( 'Invalid tag' ));
}
2019-03-20 11:21:40 +01:00
$tag_id = $this -> request -> data [ 'tag' ];
}
2022-10-26 20:48:41 +02:00
$tagConditions = $this -> TagCollection -> TagCollectionTag -> Tag -> createConditions ( $this -> Auth -> user ());
2019-03-20 11:21:40 +01:00
if ( ! is_numeric ( $tag_id )) {
$tag_ids = json_decode ( $tag_id );
$tag_lookups = array ();
foreach ( $tag_ids as $temp ) {
if ( is_numeric ( $temp )) {
$tag_lookups [ 'OR' ][ 'Tag.id' ][] = $temp ;
} else {
$tag_lookups [ 'OR' ][ 'LOWER(Tag.name) LIKE' ][] = strtolower ( trim ( $tag_id ));
}
}
if ( $tag_ids !== null && is_array ( $tag_ids )) { // can decode json
$tag_ids = $this -> TagCollection -> TagCollectionTag -> Tag -> find ( 'list' , array (
'conditions' => array (
'AND' => array (
2022-10-25 19:38:15 +02:00
$tagConditions ,
2019-03-20 11:21:40 +01:00
$tag_lookups
)
),
'fields' => array ( 'Tag.id' , 'Tag.id' )
));
$tag_id_list = array_values ( $tag_ids );
if ( empty ( $tag_id_list )) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => 'Invalid Tag(s).' )), 'status' => 200 , 'type' => 'json' ));
}
2019-01-18 13:35:53 +01:00
} else {
2022-10-25 19:38:15 +02:00
$tag = $this -> TagCollection -> TagCollectionTag -> Tag -> find ( 'first' , array ( 'recursive' => - 1 , 'conditions' => $tagConditions ));
2019-03-20 11:21:40 +01:00
if ( empty ( $tag )) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => 'Invalid Tag.' )), 'status' => 200 , 'type' => 'json' ));
}
$tag_id = $tag [ 'Tag' ][ 'id' ];
2019-01-18 13:35:53 +01:00
}
}
2022-10-25 19:38:15 +02:00
$conditions = $this -> TagCollection -> createConditions ( $this -> Auth -> user ());
$conditions [ 'TagCollection.id' ] = $id ;
2019-03-20 11:21:40 +01:00
$tagCollection = $this -> TagCollection -> find ( 'first' , array (
'recursive' => - 1 ,
2022-10-25 19:38:15 +02:00
'conditions' => $conditions ,
2019-03-20 11:21:40 +01:00
));
if ( empty ( $tagCollection )) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => 'Invalid tag collection.' )), 'status' => 200 , 'type' => 'json' ));
}
2022-10-25 19:38:15 +02:00
if ( ! $this -> ACL -> canModifyTagCollection ( $this -> Auth -> user (), $tagCollection )) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => 'Invalid tag collection.' )), 'status' => 200 , 'type' => 'json' ));
}
if ( ! $this -> ACL -> canModifyTagCollection ( $this -> Auth -> user (), $tagCollection ) || ! $this -> userRole [ 'perm_tagger' ]) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => 'You don\'t have permission to do that.' )), 'status' => 200 , 'type' => 'json' ));
2019-03-20 11:21:40 +01:00
}
$this -> autoRender = false ;
$success = false ;
if ( empty ( $tag_id_list )) {
$tag_id_list = array ( $tag_id );
}
foreach ( $tag_id_list as $tag_id ) {
2022-10-26 20:48:41 +02:00
$tagConditions = $this -> TagCollection -> TagCollectionTag -> Tag -> createConditions ( $this -> Auth -> user ());
$tagConditions [ 'Tag.id' ] = $tag_id ;
2019-03-20 11:21:40 +01:00
$tag = $this -> TagCollection -> TagCollectionTag -> Tag -> find ( 'first' , array (
2022-10-25 19:38:15 +02:00
'conditions' => $tagConditions ,
2019-03-20 11:21:40 +01:00
'recursive' => - 1 ,
'fields' => array ( 'Tag.name' )
));
2020-08-16 16:17:49 +02:00
if ( ! $tag ) {
// Invalid Tag
continue ;
}
2019-03-20 11:21:40 +01:00
$found = $this -> TagCollection -> TagCollectionTag -> find ( 'first' , array (
2019-01-18 11:57:38 +01:00
'conditions' => array (
2019-03-20 11:21:40 +01:00
'tag_collection_id' => $id ,
'tag_id' => $tag_id
2019-01-18 11:57:38 +01:00
),
2019-03-20 11:21:40 +01:00
'recursive' => - 1 ,
2019-01-18 11:57:38 +01:00
));
2019-03-20 11:21:40 +01:00
if ( ! empty ( $found )) {
2020-08-16 16:17:49 +02:00
// Tag is already attached to this collection
2019-03-20 11:21:40 +01:00
continue ;
2019-01-18 11:57:38 +01:00
}
2019-03-20 11:21:40 +01:00
$this -> TagCollection -> TagCollectionTag -> create ();
if ( $this -> TagCollection -> TagCollectionTag -> save ( array ( 'tag_collection_id' => $id , 'tag_id' => $tag_id ))) {
$log = ClassRegistry :: init ( 'Log' );
$log -> createLogEntry ( $this -> Auth -> user (), 'tag' , 'TagCollection' , $id , 'Attached tag (' . $tag_id . ') "' . $tag [ 'Tag' ][ 'name' ] . '" to collection (' . $id . ')' , 'Event (' . $id . ') tagged as Tag (' . $tag_id . ')' );
$success = __ ( 'Tag(s) added.' );
} else {
$fail = __ ( 'Tag(s) could not be added.' );
2019-01-09 16:09:05 +01:00
}
}
2019-03-20 11:21:40 +01:00
if ( $success ) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => true , 'success' => $success )), 'status' => 200 , 'type' => 'json' ));
} elseif ( empty ( $fail )) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => true , 'success' => __ ( 'All tags are already present, nothing to add.' ), 'check_publish' => true )), 'status' => 200 , 'type' => 'json' ));
2019-01-09 16:09:05 +01:00
} else {
2019-03-20 11:21:40 +01:00
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => $fail )), 'status' => 200 , 'type' => 'json' ));
2019-01-09 16:09:05 +01:00
}
}
2018-12-28 12:55:41 +01:00
}
public function removeTag ( $id = false , $tag_id = false )
{
2022-10-25 19:38:15 +02:00
$conditions = $this -> TagCollection -> createConditions ( $this -> Auth -> user ());
$conditions [ 'TagCollection.id' ] = $id ;
2018-12-28 12:55:41 +01:00
if ( ! $this -> request -> is ( 'post' )) {
2022-10-25 19:38:15 +02:00
2020-08-15 15:49:17 +02:00
$tagCollection = $this -> TagCollection -> find ( 'first' , array (
'recursive' => - 1 ,
2022-10-25 19:38:15 +02:00
'conditions' => $conditions ,
2020-08-15 15:49:17 +02:00
));
if ( ! $tagCollection ) {
throw new NotFoundException ( __ ( 'Invalid tag collection.' ));
}
2024-04-10 15:36:09 +02:00
if ( ! $this -> ACL -> canModifyTagCollection ( $this -> Auth -> user (), $tagCollection )) {
2022-10-25 19:38:15 +02:00
throw new ForbiddenException ( __ ( 'You dont have a permission to do that' ));
}
2020-08-15 15:49:17 +02:00
$tagCollectionTag = $this -> TagCollection -> TagCollectionTag -> find ( 'first' , [
'recursive' => - 1 ,
'conditions' => [
'tag_collection_id' => $id ,
'tag_id' => $tag_id ,
],
'contain' => [ 'Tag' ],
]);
if ( ! $tagCollectionTag ) {
throw new NotFoundException ( __ ( 'Invalid tag collection tag.' ));
}
2018-12-28 12:55:41 +01:00
$this -> set ( 'id' , $id );
2020-08-15 15:49:17 +02:00
$this -> set ( 'tag' , $tagCollectionTag );
2018-12-28 12:55:41 +01:00
$this -> set ( 'tag_id' , $tag_id );
$this -> set ( 'model' , 'tag_collection' );
2020-08-15 15:49:17 +02:00
$this -> set ( 'model_name' , $tagCollection [ 'TagCollection' ][ 'name' ]);
2022-04-28 14:51:21 +02:00
$this -> layout = false ;
2018-12-28 12:55:41 +01:00
$this -> render ( '/Attributes/ajax/tagRemoveConfirmation' );
} else {
$rearrangeRules = array (
'request' => false ,
'TagCollection' => false ,
'tag_id' => 'tag' ,
'tag_collection_id' => 'tag_collection' ,
'id' => 'tag_collection'
);
$RearrangeTool = new RequestRearrangeTool ();
$this -> request -> data = $RearrangeTool -> rearrangeArray ( $this -> request -> data , $rearrangeRules );
if ( $id === false ) {
$id = $this -> request -> data [ 'tag_collection' ];
}
if ( $tag_id === false ) {
$tag_id = $this -> request -> data [ 'tag' ];
}
$tagCollection = $this -> TagCollection -> find ( 'first' , array (
'recursive' => - 1 ,
2022-10-25 19:38:15 +02:00
'conditions' => $conditions ,
2018-12-28 12:55:41 +01:00
'contain' => array (
'TagCollectionTag' => array (
'Tag'
)
)
));
if ( empty ( $tagCollection )) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => __ ( 'Invalid tag collection.' ))), 'status' => 200 , 'type' => 'json' ));
}
2022-10-25 19:38:15 +02:00
if ( $this -> ACL -> canModifyTagCollection ( $this -> Auth -> user (), $tagCollection )) {
throw new ForbiddenException ( __ ( 'You dont have a permission to do that' ));
2018-12-28 12:55:41 +01:00
}
2022-10-25 19:38:15 +02:00
$found = false ;
2018-12-28 12:55:41 +01:00
foreach ( $tagCollection [ 'TagCollectionTag' ] as $TagCollectionTag ) {
if (( is_numeric ( $tag_id ) && $TagCollectionTag [ 'Tag' ][ 'id' ] == $tag_id ) || $TagCollectionTag [ 'Tag' ][ 'name' ] === $tag_id ) {
$found = true ;
$tag = $TagCollectionTag ;
$result = $this -> TagCollection -> TagCollectionTag -> delete ( $TagCollectionTag [ 'id' ]);
break ;
}
}
if ( ! $found ) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => __ ( 'Invalid tag or tag not associated with the collection.' ))), 'status' => 200 , 'type' => 'json' ));
}
if ( ! $result ) {
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => false , 'errors' => __ ( 'Failed to remove tag from the collection.' ))), 'status' => 200 , 'type' => 'json' ));
}
$log = ClassRegistry :: init ( 'Log' );
$log -> createLogEntry ( $this -> Auth -> user (), 'tag' , 'TagCollection' , $id , 'Removed tag (' . $tag [ 'Tag' ][ 'id' ] . ') "' . $tag [ 'Tag' ][ 'name' ] . '" from tag collection (' . $id . ')' , 'Tag collection (' . $id . ') - untagged Tag (' . $tag_id . ')' );
return new CakeResponse ( array ( 'body' => json_encode ( array ( 'saved' => true , 'success' => 'Tag removed.' )), 'status' => 200 ));
}
}
public function index ()
{
2022-10-25 19:38:15 +02:00
$user = $this -> Auth -> user ();
$conditions = $this -> TagCollection -> createConditions ( $user );
2019-01-01 16:38:57 +01:00
if ( $this -> _isRest ()) {
$params = array (
'recursive' => - 1 ,
2019-01-21 15:15:10 +01:00
'contain' => array (
'TagCollectionTag' => array (
'Tag'
),
'Organisation' => array (
'fields' => array (
'Organisation.id' ,
'Organisation.name' ,
'Organisation.uuid'
)
),
'User' => array (
'fields' => array (
'User.email' ,
'User.id'
)
)
2022-10-25 19:38:15 +02:00
),
'conditions' => $conditions ,
2019-01-01 16:38:57 +01:00
);
$namedParams = array ( 'limit' , 'page' );
foreach ( $namedParams as $namedParam ) {
if ( ! empty ( $this -> params [ 'named' ][ $namedParam ])) {
$params [ 'limit' ] = $this -> params [ 'named' ][ $namedParam ];
}
}
$list = $this -> TagCollection -> find ( 'all' , $params );
} else {
2022-10-25 19:38:15 +02:00
$this -> paginate [ 'conditions' ] = $conditions ;
2019-01-01 16:38:57 +01:00
$list = $this -> paginate ();
}
2018-12-29 04:25:57 +01:00
$this -> loadModel ( 'Event' );
foreach ( $list as $k => $tag_collection ) {
2022-10-25 19:38:15 +02:00
$tag_collection = $this -> TagCollection -> cullBlockedTags ( $user , $tag_collection );
$tag_collection = $this -> Event -> massageTags ( $user , $tag_collection , 'TagCollection' , false , true );
if ( ! $this -> ACL -> canModifyTagCollection ( $user , $tag_collection )) {
unset ( $tag_collection [ 'User' ]);
unset ( $tag_collection [ 'TagCollection' ][ 'user_id' ]);
}
if ( ! empty ( $tag_collection [ 'TagCollectionTag' ])) {
foreach ( $tag_collection [ 'TagCollectionTag' ] as $k2 => $tct ) {
$tag_collection [ 'TagCollectionTag' ][ $k2 ][ 'Tag' ] = array (
2019-01-21 15:15:10 +01:00
'id' => $tct [ 'Tag' ][ 'id' ],
'name' => $tct [ 'Tag' ][ 'name' ],
'colour' => $tct [ 'Tag' ][ 'colour' ]
);
}
}
2022-10-25 19:38:15 +02:00
$list [ $k ] = $tag_collection ;
2019-01-01 16:38:57 +01:00
}
if ( $this -> _isRest ()) {
return $this -> RestResponse -> viewData ( $list , $this -> response -> type ());
2018-12-29 04:25:57 +01:00
}
2022-05-22 11:33:57 +02:00
$this -> set ( 'list' , $list );
$this -> set ( 'title_for_layout' , __ ( 'Tag Collections' ));
2018-12-28 12:55:41 +01:00
}
public function getRow ( $id )
{
2022-10-25 19:38:15 +02:00
$conditions = $this -> TagCollection -> createConditions ( $this -> Auth -> user ());
$conditions [ 'TagCollection.id' ] = $id ;
$item = $this -> TagCollection -> find ( 'first' , array (
2018-12-28 12:55:41 +01:00
'recursive' => - 1 ,
2019-01-01 16:38:57 +01:00
'contain' => array ( 'TagCollectionTag' => array ( 'Tag' ), 'User' , 'Organisation' ),
2022-10-25 19:38:15 +02:00
'conditions' => $conditions
));
2018-12-28 12:55:41 +01:00
if ( empty ( $item )) {
throw new NotFoundException ( 'Invalid tag collection.' );
}
2022-10-25 19:38:15 +02:00
if ( ! $this -> ACL -> canModifyTagCollection ( $this -> Auth -> user (), $item )) {
2019-01-01 16:38:57 +01:00
unset ( $item [ 'User' ]);
unset ( $item [ 'TagCollection' ][ 'user_id' ]);
}
$this -> loadModel ( 'Event' );
2020-03-12 10:26:09 +01:00
$item = $this -> Event -> massageTags ( $this -> Auth -> user (), $item , 'TagCollection' , false , true );
2018-12-28 12:55:41 +01:00
$this -> layout = false ;
2019-01-01 16:38:57 +01:00
$this -> set ( 'item' , $item );
2018-12-28 12:55:41 +01:00
}
}