Created
December 13, 2014 14:19
-
-
Save mtancoigne/ee41d9b5df8334e35eec to your computer and use it in GitHub Desktop.
PluginActivation simplification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Events Activation | |
* | |
* Activation class for Events plugin. | |
* This is optional, and is required only if you want to perform tasks when your plugin is activated/deactivated. | |
*/ | |
class EventsActivation { | |
/** | |
* onActivate will be called if this returns true | |
* | |
* @param object $controller Controller | |
* @return boolean | |
*/ | |
public function beforeActivation(&$controller) { | |
return true; | |
} | |
/** | |
* Called after activating the plugin in ExtensionsPluginsController::admin_toggle() | |
* | |
* @param object $controller Controller | |
* @return void | |
*/ | |
public function onActivation(&$controller) { | |
// | |
// Permissions | |
// | |
// | |
// Permissions for the Events controller | |
$controller->Croogo->addAco('Events/Events/public_index', array('registered', 'public')); | |
$controller->Croogo->addAco('Events/Events/public_view', array('registered', 'public')); | |
$controller->Croogo->addAco('Events/Events/users_index', array('registered')); | |
$controller->Croogo->addAco('Events/Events/users_view', array('registered')); | |
$controller->Croogo->addAco('Events/Events/users_add', array('registered')); | |
$controller->Croogo->addAco('Events/Events/users_delete', array('registered')); | |
$controller->Croogo->addAco('Events/Events/users_edit', array('registered')); | |
$controller->Croogo->addAco('Events/Events/admin_index'); | |
$controller->Croogo->addAco('Events/Events/admin_view'); | |
$controller->Croogo->addAco('Events/Events/admin_add'); | |
$controller->Croogo->addAco('Events/Events/admin_delete'); | |
$controller->Croogo->addAco('Events/Events/admin_edit'); | |
$controller->Croogo->addAco('Events/Events/admin_dashboard'); | |
// Loading menu class | |
$this->Link = ClassRegistry::init('Menus.Link'); | |
$this->Menu = ClassRegistry::init('Menus.Menu'); | |
// | |
// main menu | |
// | |
$mainMenu = $this->Link->Menu->findByAlias('main'); | |
$this->Link->Behaviors->attach('Tree', array( | |
'scope' => array( | |
'Link.menu_id' => $mainMenu['Menu']['id'], | |
), | |
)); | |
$this->Link->save(array( | |
'menu_id' => $mainMenu['Menu']['id'], | |
'title' => 'Events', | |
'link' => 'admin:false/plugin:events/controller:events/action:index', | |
'status' => 1, | |
'class' => 'events', | |
// Default visibility | |
'visibility_roles' => '["1","2","3"]', | |
)); | |
} | |
/** | |
* onDeactivate will be called if this returns true | |
* | |
* @param object $controller Controller | |
* @return boolean | |
*/ | |
public function beforeDeactivation(&$controller) { | |
return true; | |
} | |
/** | |
* Called after deactivating the plugin in ExtensionsPluginsController::admin_toggle() | |
* | |
* @param object $controller Controller | |
* @return void | |
*/ | |
public function onDeactivation(&$controller) { | |
// | |
// Remove permissions | |
// | |
$controller->Croogo->removeAco('Events'); // EventsController ACO and it's actions will be removed | |
$this->Link = ClassRegistry::init('Menus.Link'); | |
// | |
// Remove menus | |
// | |
// | |
// Deleting main menu links | |
$link = $this->Link->find('first', array( | |
'joins' => array( | |
array( | |
'table' => 'menus', | |
'alias' => 'JoinMenu', | |
'conditions' => array( | |
'JoinMenu.alias' => 'main', | |
), | |
), | |
), | |
'conditions' => array( | |
'Link.link' => 'admin:false/plugin:events/controller:events/action:index', | |
), | |
)); | |
if (empty($link)) { | |
return; | |
} | |
$this->Link->Behaviors->attach('Tree', array( | |
'scope' => array( | |
'Link.menu_id' => $link['Link']['menu_id'], | |
), | |
)); | |
if (isset($link['Link']['id'])) { | |
$this->Link->delete($link['Link']['id']); | |
} | |
}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment