Created
January 11, 2015 00:01
-
-
Save mtancoigne/91827c9af124b1491fda to your computer and use it in GitHub Desktop.
Cant create all links with this...
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 | |
/** | |
* Snr Activation | |
* | |
* Activation class for Snr plugin. | |
* This is optional, and is required only if you want to perform tasks when your plugin is activated/deactivated. | |
*/ | |
class SnrActivation { | |
/** | |
* 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 Artists controller | |
$controller->Croogo->addAco('Snr/Artists/index', array('registered', 'public')); | |
// Big code illipsis :) | |
$controller->Croogo->addAco('Snr/SoundsInstruments/admin_edit'); | |
// | |
// Here is the links section | |
// | |
// 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'], | |
), | |
)); | |
// Artists | |
$this->Link->save(array( | |
'menu_id' => $mainMenu['Menu']['id'], | |
'title' => 'Artists', | |
'link' => 'admin:false/plugin:snr/controller:artists/action:index', | |
'status' => 1, | |
// Default visibility | |
'visibility_roles' => '["1","2","3"]', | |
)); | |
// Events | |
$this->Link->save(array( | |
'menu_id' => $mainMenu['Menu']['id'], | |
'title' => 'Events', | |
'link' => 'admin:false/plugin:snr/controller:events/action:index', | |
'status' => 1, | |
// Default visibility | |
'visibility_roles' => '["1","2","3"]', | |
)); | |
// Sounds | |
$this->Link->save(array( | |
'menu_id' => $mainMenu['Menu']['id'], | |
'title' => 'Artists', | |
'link' => 'admin:false/plugin:snr/controller:sounds/action:index', | |
'status' => 1, | |
// Default visibility | |
'visibility_roles' => '["1","2","3"]', | |
)); | |
// Medias | |
$this->Link->save(array( | |
'menu_id' => $mainMenu['Menu']['id'], | |
'title' => 'Artists', | |
'link' => 'admin:false/plugin:snr/controller:images/action:index', | |
'status' => 1, | |
// Default visibility | |
'visibility_roles' => '["1","2","3"]', | |
)); | |
// Instruments | |
$this->Link->save(array( | |
'menu_id' => $mainMenu['Menu']['id'], | |
'title' => 'Artists', | |
'link' => 'admin:false/plugin:snr/controller:instruments/action:index', | |
'status' => 1, | |
// Default visibility | |
'visibility_roles' => '["1","2","3"]', | |
)); | |
// | |
// Artists menu (in block) | |
// | |
$artistsMenu = $this->Link->Menu->findByAlias('artists_menu'); | |
if (empty($artistsMenu)) { | |
$this->Menu->create(); | |
$this->Menu->save(array( | |
'title' => __d('artists', 'Contents'), | |
'alias' => 'artists_menu', | |
'status' => '1', | |
)); | |
// Load the new menu :) | |
$artistsMenu = $this->Link->Menu->findByAlias('artists'); | |
} | |
$this->Link->Behaviors->attach('Tree', array( | |
'scope' => array( | |
'Link.menu_id' => $artistsMenu['Menu']['id'], | |
), | |
)); | |
$this->Link->Create(); | |
$this->Link->save(array( | |
'menu_id' => $artistsMenu['Menu']['id'], | |
'title' => 'My profile', | |
'link' => 'users:true/plugin:snr/controller:artists/action:dashboard', | |
'status' => 1, | |
'class' => 'artists', | |
// Default visibility | |
'visibility_roles' => '["2"]', | |
)); | |
$this->Link->Create(); | |
$this->Link->save(array( | |
'menu_id' => $artistsMenu['Menu']['id'], | |
'title' => 'Edit my profile', | |
'link' => 'users:true/plugin:snr/controller:artists/action:edit', | |
'status' => 1, | |
'class' => 'artists', | |
// Default visibility | |
'visibility_roles' => '["2"]', | |
)); | |
//Logout link, created once and not deleted... | |
$logoutLink = $this->Link->findByLink('admin:true/plugin:users/controller:users/action:logout'); | |
if (empty($logoutLink)) { | |
$this->Link->Create(); | |
$this->Link->save(array( | |
'menu_id' => $artistsMenu['Menu']['id'], | |
'title' => 'Log out', | |
'link' => 'admin:true/plugin:users/controller:users/action:logout', | |
'status' => 1, | |
'class' => 'artists', | |
// Default visibility | |
'visibility_roles' => '["2"]', | |
)); | |
} | |
//... | |
// | |
// User block | |
// | |
$this->Block = ClassRegistry::init('Blocks.Block'); | |
// Search for the the user block | |
$artistsBlock = $this->Block->findByAlias('artists-block'); | |
// Check if the menu exists | |
if (empty($artistsBlock)) { | |
// Create the menu | |
$this->Block->create(); | |
$this->Block->save(array( | |
'title' => 'My menu', | |
'alias' => 'artist-block', | |
'body' => '[menu:artists_menu]', | |
'show_title' => 1, | |
'weight' => 1, | |
'region_id' => '4', | |
'visibility_roles' => Configure::read('Snr.artists.role_id'), | |
'status' => 1,) | |
); | |
} | |
} | |
/** | |
* 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('Artists'); // ArtistsController ACO and it's actions will be removed | |
$controller->Croogo->removeAco('Events'); // EventsController ACO and it's actions will be removed | |
$controller->Croogo->removeAco('Instruments'); // InstrumentsController ACO and it's actions will be removed | |
$controller->Croogo->removeAco('UsersInstruments'); // UsersInstrumentsController ACO and it's actions will be removed | |
$controller->Croogo->removeAco('Genres'); // GenresController ACO and it's actions will be removed | |
$controller->Croogo->removeAco('UsersGenres'); // UsersGenresController ACO and it's actions will be removed | |
$controller->Croogo->removeAco('Images'); // ImagesController ACO and it's actions will be removed | |
$controller->Croogo->removeAco('Sounds'); // SoundsController ACO and it's actions will be removed | |
$controller->Croogo->removeAco('SoundsInstruments'); // SoundsInstrumentsController ACO and it's actions will be removed | |
$this->Link = ClassRegistry::init('Menus.Link'); | |
// | |
// Remove menus | |
// | |
// | |
// Deleting main menu links | |
$links = $this->Link->find('list', array( | |
'conditions' => array( | |
'Link.link LIKE' => '%plugin\:snr%', | |
), | |
)); | |
foreach ($links as $link => $linkName) { | |
$this->Link->delete($link); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment