2015-11-24 03:27:14 +01:00
< ? php
App :: uses ( 'AppController' , 'Controller' );
2020-12-09 17:44:03 +01:00
/**
* @ property Taxonomy $Taxonomy
*/
2018-07-19 11:48:22 +02:00
class TaxonomiesController extends AppController
{
public $components = array ( 'Session' , 'RequestHandler' );
2015-11-24 03:27:14 +01:00
2018-07-19 11:48:22 +02:00
public $paginate = array (
'limit' => 60 ,
2019-02-10 13:08:12 +01:00
'maxLimit' => 9999 , // LATER we will bump here on a problem once we have more than 9999 events <- no we won't, this is the max a user van view/page.
2018-07-19 11:48:22 +02:00
'contain' => array (
'TaxonomyPredicate' => array (
'fields' => array ( 'TaxonomyPredicate.id' ),
'TaxonomyEntry' => array ( 'fields' => array ( 'TaxonomyEntry.id' ))
)
),
'order' => array (
'Taxonomy.id' => 'DESC'
),
);
2015-11-24 03:27:14 +01:00
2018-07-19 11:48:22 +02:00
public function index ()
{
$this -> paginate [ 'recursive' ] = - 1 ;
2020-01-29 19:45:57 +01:00
if ( $this -> _isRest ()) {
$keepFields = array ( 'conditions' , 'contain' , 'recursive' , 'sort' );
$searchParams = array ();
foreach ( $keepFields as $field ) {
if ( ! empty ( $this -> paginate [ $field ])) {
$searchParams [ $field ] = $this -> paginate [ $field ];
}
}
$taxonomies = $this -> Taxonomy -> find ( 'all' , $searchParams );
} else {
$taxonomies = $this -> paginate ();
}
2018-07-19 11:48:22 +02:00
$this -> loadModel ( 'Tag' );
foreach ( $taxonomies as $key => $taxonomy ) {
$total = 0 ;
foreach ( $taxonomy [ 'TaxonomyPredicate' ] as $predicate ) {
$total += empty ( $predicate [ 'TaxonomyEntry' ]) ? 1 : count ( $predicate [ 'TaxonomyEntry' ]);
}
$taxonomies [ $key ][ 'total_count' ] = $total ;
$taxonomies [ $key ][ 'current_count' ] = $this -> Tag -> find ( 'count' , array ( 'conditions' => array ( 'lower(Tag.name) LIKE ' => strtolower ( $taxonomy [ 'Taxonomy' ][ 'namespace' ]) . ':%' , 'hide_tag' => 0 )));
unset ( $taxonomies [ $key ][ 'TaxonomyPredicate' ]);
}
if ( $this -> _isRest ()) {
return $this -> RestResponse -> viewData ( $taxonomies , $this -> response -> type ());
} else {
$this -> set ( 'taxonomies' , $taxonomies );
}
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
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' );
$filter = isset ( $this -> passedArgs [ 'filter' ]) ? $this -> passedArgs [ 'filter' ] : false ;
$taxonomy = $this -> Taxonomy -> getTaxonomy ( $id , array ( 'full' => true , 'filter' => $filter ));
if ( empty ( $taxonomy )) {
2019-03-21 15:38:40 +01:00
throw new NotFoundException ( __ ( 'Taxonomy not found.' ));
2018-07-19 11:48:22 +02:00
}
2019-03-19 16:40:35 +01:00
$this -> loadModel ( 'EventTag' );
$this -> loadModel ( 'AttributeTag' );
2018-07-19 11:48:22 +02:00
foreach ( $taxonomy [ 'entries' ] as $key => $value ) {
2019-03-19 16:40:35 +01:00
$count = 0 ;
2019-04-11 12:05:55 +02:00
$count_a = 0 ;
2019-03-19 16:40:35 +01:00
if ( ! empty ( $value [ 'existing_tag' ])) {
foreach ( $value [ 'existing_tag' ] as $et ) {
$count = $this -> EventTag -> find ( 'count' , array (
'conditions' => array ( 'EventTag.tag_id' => $et [ 'id' ])
));
$count_a = $this -> AttributeTag -> find ( 'count' , array (
'conditions' => array ( 'AttributeTag.tag_id' => $et [ 'id' ])
));
}
}
$taxonomy [ 'entries' ][ $key ][ 'events' ] = $count ;
$taxonomy [ 'entries' ][ $key ][ 'attributes' ] = $count_a ;
2018-07-19 11:48:22 +02:00
}
$this -> set ( 'filter' , $filter );
$customPagination = new CustomPaginationTool ();
$params = $customPagination -> createPaginationRules ( $taxonomy [ 'entries' ], $this -> passedArgs , 'TaxonomyEntry' );
if ( $params [ 'sort' ] == 'id' ) {
$params [ 'sort' ] = 'tag' ;
}
$this -> params -> params [ 'paging' ] = array ( $this -> modelClass => $params );
$params = $customPagination -> applyRulesOnArray ( $taxonomy [ 'entries' ], $params , 'taxonomies' );
if ( $this -> _isRest ()) {
return $this -> RestResponse -> viewData ( $taxonomy , $this -> response -> type ());
} else {
$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 );
}
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
public function enable ( $id )
{
if ( ! $this -> _isSiteAdmin () || ! $this -> request -> is ( 'Post' )) {
2019-03-21 15:38:40 +01:00
throw new MethodNotAllowedException ( __ ( 'You don\'t have permission to do that.' ));
2018-07-19 11:48:22 +02:00
}
$taxonomy = $this -> Taxonomy -> find ( 'first' , array (
'recursive' => - 1 ,
'conditions' => array ( 'Taxonomy.id' => $id ),
));
$taxonomy [ 'Taxonomy' ][ 'enabled' ] = true ;
$this -> Taxonomy -> save ( $taxonomy );
$this -> Log = ClassRegistry :: init ( 'Log' );
$this -> Log -> create ();
$this -> Log -> save ( array (
'org' => $this -> Auth -> user ( 'Organisation' )[ 'name' ],
'model' => 'Taxonomy' ,
'model_id' => $id ,
'email' => $this -> Auth -> user ( 'email' ),
'action' => 'enable' ,
'user_id' => $this -> Auth -> user ( 'id' ),
'title' => 'Taxonomy enabled' ,
'change' => $taxonomy [ 'Taxonomy' ][ 'namespace' ] . ' - enabled' ,
));
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveSuccessResponse ( 'Taxonomy' , 'enable' , $id , $this -> response -> type ());
} else {
2019-03-21 15:38:40 +01:00
$this -> Flash -> success ( __ ( 'Taxonomy enabled.' ));
2018-07-19 11:48:22 +02:00
$this -> redirect ( $this -> referer ());
}
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
public function disable ( $id )
{
if ( ! $this -> _isSiteAdmin () || ! $this -> request -> is ( 'Post' )) {
2019-03-21 15:38:40 +01:00
throw new MethodNotAllowedException ( __ ( 'You don\'t have permission to do that.' ));
2018-07-19 11:48:22 +02:00
}
$taxonomy = $this -> Taxonomy -> find ( 'first' , array (
'recursive' => - 1 ,
'conditions' => array ( 'Taxonomy.id' => $id ),
));
2019-01-17 15:46:40 +01:00
$this -> Taxonomy -> disableTags ( $id );
2018-07-19 11:48:22 +02:00
$taxonomy [ 'Taxonomy' ][ 'enabled' ] = 0 ;
$this -> Taxonomy -> save ( $taxonomy );
$this -> Log = ClassRegistry :: init ( 'Log' );
$this -> Log -> create ();
$this -> Log -> save ( array (
'org' => $this -> Auth -> user ( 'Organisation' )[ 'name' ],
'model' => 'Taxonomy' ,
'model_id' => $id ,
'email' => $this -> Auth -> user ( 'email' ),
'action' => 'disable' ,
'user_id' => $this -> Auth -> user ( 'id' ),
'title' => 'Taxonomy disabled' ,
'change' => $taxonomy [ 'Taxonomy' ][ 'namespace' ] . ' - disabled' ,
));
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveSuccessResponse ( 'Taxonomy' , 'disable' , $id , $this -> response -> type ());
} else {
2019-03-21 15:38:40 +01:00
$this -> Flash -> success ( __ ( 'Taxonomy disabled.' ));
2018-07-19 11:48:22 +02:00
$this -> redirect ( $this -> referer ());
}
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
public function update ()
{
if ( ! $this -> _isSiteAdmin ()) {
2019-03-21 15:38:40 +01:00
throw new MethodNotAllowedException ( __ ( 'You don\'t have permission to do that.' ));
2018-07-19 11:48:22 +02:00
}
$result = $this -> Taxonomy -> update ();
$this -> Log = ClassRegistry :: init ( 'Log' );
$fails = 0 ;
$successes = 0 ;
if ( ! empty ( $result )) {
if ( isset ( $result [ 'success' ])) {
foreach ( $result [ 'success' ] as $id => $success ) {
if ( isset ( $success [ 'old' ])) {
$change = $success [ 'namespace' ] . ': updated from v' . $success [ 'old' ] . ' to v' . $success [ 'new' ];
} else {
$change = $success [ 'namespace' ] . ' v' . $success [ 'new' ] . ' installed' ;
}
$this -> Log -> create ();
$this -> Log -> save ( array (
'org' => $this -> Auth -> user ( 'Organisation' )[ 'name' ],
'model' => 'Taxonomy' ,
'model_id' => $id ,
'email' => $this -> Auth -> user ( 'email' ),
'action' => 'update' ,
'user_id' => $this -> Auth -> user ( 'id' ),
'title' => 'Taxonomy updated' ,
'change' => $change ,
));
$successes ++ ;
}
}
if ( isset ( $result [ 'fails' ])) {
foreach ( $result [ 'fails' ] as $id => $fail ) {
$this -> Log -> create ();
$this -> Log -> save ( array (
'org' => $this -> Auth -> user ( 'Organisation' )[ 'name' ],
'model' => 'Taxonomy' ,
'model_id' => $id ,
'email' => $this -> Auth -> user ( 'email' ),
'action' => 'update' ,
'user_id' => $this -> Auth -> user ( 'id' ),
'title' => 'Taxonomy failed to update' ,
'change' => $fail [ 'namespace' ] . ' could not be installed/updated. Error: ' . $fail [ 'fail' ],
));
$fails ++ ;
}
}
} else {
$this -> Log -> create ();
$this -> Log -> save ( array (
'org' => $this -> Auth -> user ( 'Organisation' )[ 'name' ],
'model' => 'Taxonomy' ,
'model_id' => 0 ,
'email' => $this -> Auth -> user ( 'email' ),
'action' => 'update' ,
'user_id' => $this -> Auth -> user ( 'id' ),
'title' => 'Taxonomy update (nothing to update)' ,
'change' => 'Executed an update of the taxonomy library, but there was nothing to update.' ,
));
}
$message = '' ;
if ( $successes == 0 && $fails == 0 ) {
$flashType = 'info' ;
2019-03-21 15:38:40 +01:00
$message = __ ( 'All taxonomy libraries are up to date already.' );
2018-07-19 11:48:22 +02:00
} elseif ( $successes == 0 ) {
$flashType = 'error' ;
2019-03-21 15:38:40 +01:00
$message = __ ( 'Could not update any of the taxonomy libraries' );
2018-07-19 11:48:22 +02:00
} else {
$flashType = 'success' ;
2019-03-21 15:38:40 +01:00
$message = __ ( 'Successfully updated ' ) . $successes . __ ( ' taxonomy libraries.' );
2018-07-19 11:48:22 +02:00
if ( $fails != 0 ) {
2019-03-21 15:38:40 +01:00
$message .= __ ( ' However, could not update ' ) . $fails . __ ( ' taxonomy libraries.' );
2018-07-19 11:48:22 +02:00
}
}
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveSuccessResponse ( 'Taxonomy' , 'update' , false , $this -> response -> type (), $message );
} else {
$this -> Flash -> { $flashType }( $message );
$this -> redirect ( array ( 'controller' => 'taxonomies' , 'action' => 'index' ));
}
}
2016-06-04 01:08:16 +02:00
2018-07-19 11:48:22 +02:00
public function addTag ( $taxonomy_id = false )
{
if (( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) || ! $this -> request -> is ( 'post' )) {
2019-03-21 15:38:40 +01:00
throw new NotFoundException ( __ ( 'You don\'t have permission to do that.' ));
2018-07-19 11:48:22 +02:00
}
if ( $taxonomy_id ) {
$result = $this -> Taxonomy -> addTags ( $taxonomy_id );
} else {
if ( isset ( $this -> request -> data [ 'Taxonomy' ])) {
$this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Taxonomy' ];
unset ( $this -> request -> data [ 'Taxonomy' ]);
}
if ( isset ( $this -> request -> data [ 'Tag' ][ 'request' ])) {
$this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Tag' ][ 'request' ];
}
if ( ! isset ( $this -> request -> data [ 'Tag' ][ 'nameList' ])) {
$this -> request -> data [ 'Tag' ][ 'nameList' ] = array ( $this -> request -> data [ 'Tag' ][ 'name' ]);
} else {
$this -> request -> data [ 'Tag' ][ 'nameList' ] = json_decode ( $this -> request -> data [ 'Tag' ][ 'nameList' ], true );
}
$result = $this -> Taxonomy -> addTags ( $this -> request -> data [ 'Tag' ][ 'taxonomy_id' ], $this -> request -> data [ 'Tag' ][ 'nameList' ]);
}
if ( $result ) {
2019-07-29 17:01:28 +02:00
$message = __ ( 'The tag(s) has been saved.' );
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveSuccessResponse ( 'Taxonomy' , 'addTag' , $taxonomy_id , $this -> response -> type (), $message );
}
$this -> Flash -> success ( $message );
2018-07-19 11:48:22 +02:00
} else {
2019-07-29 17:01:28 +02:00
$message = __ ( 'The tag(s) could not be saved. Please, try again.' );
if ( $this -> _isRest ()) {
return $this -> RestResponse -> saveFailResponse ( 'Taxonomy' , 'addTag' , $taxonomy_id , $message , $this -> response -> type ());
}
$this -> Flash -> error ( $message );
2018-07-19 11:48:22 +02:00
}
$this -> redirect ( $this -> referer ());
}
2016-06-04 01:08:16 +02:00
2018-09-10 12:53:33 +02:00
public function hideTag ( $taxonomy_id = false )
{
if (( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) || ! $this -> request -> is ( 'post' )) {
2019-03-21 15:38:40 +01:00
throw new NotFoundException ( __ ( 'You don\'t have permission to do that.' ));
2018-09-10 12:53:33 +02:00
}
if ( $taxonomy_id ) {
$result = $this -> Taxonomy -> hideTags ( $taxonomy_id );
} else {
if ( isset ( $this -> request -> data [ 'Taxonomy' ])) {
$this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Taxonomy' ];
unset ( $this -> request -> data [ 'Taxonomy' ]);
}
if ( isset ( $this -> request -> data [ 'Tag' ][ 'request' ])) {
$this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Tag' ][ 'request' ];
}
if ( ! isset ( $this -> request -> data [ 'Tag' ][ 'nameList' ])) {
$this -> request -> data [ 'Tag' ][ 'nameList' ] = array ( $this -> request -> data [ 'Tag' ][ 'name' ]);
} else {
$this -> request -> data [ 'Tag' ][ 'nameList' ] = json_decode ( $this -> request -> data [ 'Tag' ][ 'nameList' ], true );
}
$result = $this -> Taxonomy -> hideTags ( $this -> request -> data [ 'Tag' ][ 'taxonomy_id' ], $this -> request -> data [ 'Tag' ][ 'nameList' ]);
}
if ( $result ) {
2019-03-21 15:38:40 +01:00
$this -> Flash -> success ( __ ( 'The tag(s) has been saved.' ));
2018-09-10 12:53:33 +02:00
} else {
2019-03-21 15:38:40 +01:00
$this -> Flash -> error ( __ ( 'The tag(s) could not be saved. Please, try again.' ));
2018-09-10 12:53:33 +02:00
}
$this -> redirect ( $this -> referer ());
}
public function unhideTag ( $taxonomy_id = false )
{
if (( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) || ! $this -> request -> is ( 'post' )) {
2019-03-21 15:38:40 +01:00
throw new NotFoundException ( __ ( 'You don\'t have permission to do that.' ));
2018-09-10 12:53:33 +02:00
}
if ( $taxonomy_id ) {
$result = $this -> Taxonomy -> unhideTags ( $taxonomy_id );
} else {
if ( isset ( $this -> request -> data [ 'Taxonomy' ])) {
$this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Taxonomy' ];
unset ( $this -> request -> data [ 'Taxonomy' ]);
}
if ( isset ( $this -> request -> data [ 'Tag' ][ 'request' ])) {
$this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Tag' ][ 'request' ];
}
if ( ! isset ( $this -> request -> data [ 'Tag' ][ 'nameList' ])) {
$this -> request -> data [ 'Tag' ][ 'nameList' ] = array ( $this -> request -> data [ 'Tag' ][ 'name' ]);
} else {
$this -> request -> data [ 'Tag' ][ 'nameList' ] = json_decode ( $this -> request -> data [ 'Tag' ][ 'nameList' ], true );
}
$result = $this -> Taxonomy -> unhideTags ( $this -> request -> data [ 'Tag' ][ 'taxonomy_id' ], $this -> request -> data [ 'Tag' ][ 'nameList' ]);
}
if ( $result ) {
2019-03-21 15:38:40 +01:00
$this -> Flash -> success ( __ ( 'The tag(s) has been saved.' ));
2018-09-10 12:53:33 +02:00
} else {
2019-03-21 15:38:40 +01:00
$this -> Flash -> error ( __ ( 'The tag(s) could not be saved. Please, try again.' ));
2018-09-10 12:53:33 +02:00
}
$this -> redirect ( $this -> referer ());
}
2018-07-19 11:48:22 +02:00
public function disableTag ( $taxonomy_id = false )
{
if (( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) || ! $this -> request -> is ( 'post' )) {
2019-03-21 15:38:40 +01:00
throw new NotFoundException ( __ ( 'You don\'t have permission to do that.' ));
2018-07-19 11:48:22 +02:00
}
if ( $taxonomy_id ) {
$result = $this -> Taxonomy -> disableTags ( $taxonomy_id );
} else {
if ( isset ( $this -> request -> data [ 'Taxonomy' ])) {
$this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Taxonomy' ];
unset ( $this -> request -> data [ 'Taxonomy' ]);
}
if ( isset ( $this -> request -> data [ 'Tag' ][ 'request' ])) {
$this -> request -> data [ 'Tag' ] = $this -> request -> data [ 'Tag' ][ 'request' ];
}
if ( ! isset ( $this -> request -> data [ 'Tag' ][ 'nameList' ])) {
$this -> request -> data [ 'Tag' ][ 'nameList' ] = array ( $this -> request -> data [ 'Tag' ][ 'name' ]);
} else {
$this -> request -> data [ 'Tag' ][ 'nameList' ] = json_decode ( $this -> request -> data [ 'Tag' ][ 'nameList' ], true );
}
$result = $this -> Taxonomy -> disableTags ( $this -> request -> data [ 'Tag' ][ 'taxonomy_id' ], $this -> request -> data [ 'Tag' ][ 'nameList' ]);
}
if ( $result ) {
2019-03-21 15:38:40 +01:00
$this -> Flash -> success ( __ ( 'The tag(s) has been hidden.' ));
2018-07-19 11:48:22 +02:00
} else {
2019-03-21 15:38:40 +01:00
$this -> Flash -> error ( __ ( 'The tag(s) could not be hidden. Please, try again.' ));
2018-07-19 11:48:22 +02:00
}
$this -> redirect ( $this -> referer ());
}
2017-04-14 17:10:47 +02:00
2018-07-19 11:48:22 +02:00
public function taxonomyMassConfirmation ( $id )
{
if ( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) {
2019-03-21 15:38:40 +01:00
throw new NotFoundException ( __ ( 'You don\'t have permission to do that.' ));
2018-07-19 11:48:22 +02:00
}
$this -> set ( 'id' , $id );
$this -> render ( 'ajax/taxonomy_mass_confirmation' );
}
2016-08-22 02:52:51 +02:00
2018-09-10 12:53:33 +02:00
public function taxonomyMassHide ( $id )
{
if ( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) {
2019-03-21 15:38:40 +01:00
throw new NotFoundException ( __ ( 'You don\'t have permission to do that.' ));
2018-09-10 12:53:33 +02:00
}
$this -> set ( 'id' , $id );
$this -> render ( 'ajax/taxonomy_mass_hide' );
}
public function taxonomyMassUnhide ( $id )
{
if ( ! $this -> _isSiteAdmin () && ! $this -> userRole [ 'perm_tagger' ]) {
2019-03-21 15:38:40 +01:00
throw new NotFoundException ( __ ( 'You don\'t have permission to do that.' ));
2018-09-10 12:53:33 +02:00
}
$this -> set ( 'id' , $id );
$this -> render ( 'ajax/taxonomy_mass_unhide' );
}
2018-07-19 11:48:22 +02:00
public function delete ( $id )
{
if ( $this -> request -> is ( 'post' )) {
$result = $this -> Taxonomy -> delete ( $id , true );
if ( $result ) {
2020-12-09 17:44:03 +01:00
$this -> Flash -> success ( __ ( 'Taxonomy successfully deleted.' ));
2018-07-19 11:48:22 +02:00
$this -> redirect ( array ( 'controller' => 'taxonomies' , 'action' => 'index' ));
} else {
2019-03-21 15:38:40 +01:00
$this -> Flash -> error ( __ ( 'Taxonomy could not be deleted.' ));
2018-07-19 11:48:22 +02:00
$this -> redirect ( array ( 'controller' => 'taxonomies' , 'action' => 'index' ));
}
} else {
if ( $this -> request -> is ( 'ajax' )) {
$this -> set ( 'id' , $id );
$this -> render ( 'ajax/taxonomy_delete_confirmation' );
} else {
2019-03-21 15:38:40 +01:00
throw new MethodNotAllowedException ( __ ( 'This function can only be reached via AJAX.' ));
2018-07-19 11:48:22 +02:00
}
}
}
2019-03-19 15:59:31 +01:00
public function toggleRequired ( $id )
{
$taxonomy = $this -> Taxonomy -> find ( 'first' , array (
'recursive' => - 1 ,
'conditions' => array ( 'Taxonomy.id' => $id )
));
if ( empty ( $taxonomy )) {
return $this -> RestResponse -> saveFailResponse ( 'Taxonomy' , 'toggleRequired' , $id , 'Invalid Taxonomy' , $this -> response -> type ());
}
if ( $this -> request -> is ( 'post' )) {
$taxonomy [ 'Taxonomy' ][ 'required' ] = $this -> request -> data [ 'Taxonomy' ][ 'required' ];
$result = $this -> Taxonomy -> save ( $taxonomy );
if ( $result ) {
return $this -> RestResponse -> saveSuccessResponse ( 'Taxonomy' , 'toggleRequired' , $id , $this -> response -> type ());
} else {
return $this -> RestResponse -> saveFailResponse ( 'Taxonomy' , 'toggleRequired' , $id , $this -> validationError , $this -> response -> type ());
}
} else {
$this -> set ( 'required' , ! $taxonomy [ 'Taxonomy' ][ 'required' ]);
$this -> set ( 'id' , $id );
$this -> autoRender = false ;
$this -> layout = 'ajax' ;
$this -> render ( 'ajax/toggle_required' );
}
}
2015-11-24 03:27:14 +01:00
}