Example #1
0
 /**
  * Build method
  * 
  */
 public function build()
 {
     $currentlyLoadedPlugins = CakePlugin::loaded();
     CakePlugin::loadAll();
     foreach (CakePlugin::loaded() as $plugin) {
         $Plugin = ClassRegistry::init($plugin . '.' . $plugin . 'AppModel');
         if (method_exists($Plugin, 'menuInit')) {
             $plugins[] = $plugin;
         }
     }
     $this->set('plugins', $plugins);
     //$plugins = array_diff(CakePlugin::loaded(), array('Activities', 'Answers', 'Categories', 'Connections', 'Contacts', 'Drafts', 'Facebook', 'Feeds', 'Forms', 'Media', 'Privileges', 'Recaptcha', 'Searchable', 'Subscribers', 'Tags', 'Twitter', 'Utils', 'Webpages', 'Wizards', 'Workflows')));
     CakePlugin::unload();
     CakePlugin::load($currentlyLoadedPlugins);
     // create some links to, and install the plugin if it isn't already
     if (($this->request->is('post') || $this->request->is('put')) && $this->request->data['WebpageMenuItem']['page_type'] == 'plugin') {
         $this->request->data['WebpageMenuItem']['item_text'] = $plugins[$this->request->data['WebpageMenuItem']['item_text']];
         // if not already installed, then install the plugin
         if (!in_array($this->request->data['WebpageMenuItem']['item_text'], $currentlyLoadedPlugins)) {
             $this->_plugin($this->request->data['WebpageMenuItem']['item_text']);
         }
         // create the menu (independent of the plugin - we can always install later)
         $MenuItem = ClassRegistry::init('Webpages.WebpageMenuItem');
         if ($MenuItem->saveAll($this->request->data)) {
             $this->Session->setFlash(__('Flow updated.'));
         } else {
             $this->Session->setFlash(__('Error occurred, please try again.'));
         }
     }
     $this->layout = 'default';
     App::uses('UserRole', 'Users.Model');
     $UserRole = new UserRole();
     $this->set('userRoles', $userRoles = $UserRole->find('all'));
     $this->set('userRoleOptions', Set::combine($userRoles, '{n}.UserRole.session_user_role_id', '{n}.UserRole.name'));
     App::uses('Template', 'Model');
     $Template = new Template();
     $this->set('templates', $templates = $Template->find('all', array('conditions' => array('Template.install NOT' => null))));
     $this->set('page_title_for_layout', 'SITE buildrr');
     $this->set('title_for_layout', 'SITE buildrr');
     $defaultTemplate = Set::combine(templateSettings(), '{n}.isDefault', '{n}');
     $defaultTemplate = Set::extract('/Template[layout=' . $defaultTemplate[1]['templateName'] . ']', $templates);
     $defaultTemplate = !empty($defaultTemplate) ? $defaultTemplate : $Template->placeholder();
     $this->set(compact('defaultTemplate'));
     $Menu = ClassRegistry::init('Webpages.WebpageMenu');
     foreach ($userRoles as $userRole) {
         $varName = preg_replace("/[^A-Za-z]/", '', $userRole['UserRole']['name']) . 'Sections';
         $conditions = $userRole['UserRole']['id'] == __SYSTEM_GUESTS_USER_ROLE_ID ? array('OR' => array(array('WebpageMenu.user_role_id' => ''), array('WebpageMenu.user_role_id' => null))) : array('WebpageMenu.user_role_id' => $userRole['UserRole']['id']);
         $menu = $Menu->find('threaded', array('conditions' => $conditions));
         // remove --Home from Home menu
         for ($i = 0; $i < count($menu[0]['children']); $i++) {
             if ($menu[0]['children'][$i]['WebpageMenu']['name'] == $menu[0]['WebpageMenu']['name']) {
                 unset($menu[0]['children'][$i]);
             }
         }
         $this->set($varName, $menu);
     }
     //$this->set('sections', $Menu->find('threaded', array('conditions' => array('WebpageMenu.lft >=' => $menu['WebpageMenu']['lft'], 'WebpageMenu.rght <=' => $menu['WebpageMenu']['rght']))));
     // used for re-ordering items $this->request->data['WebpageMenu']['children'] = $this->WebpageMenu->find('count', array('conditions' => array('WebpageMenu.lft >' => $menu['WebpageMenu']['lft'], 'WebpageMenu.rght <' => $menu['WebpageMenu']['rght'])));
     //$this->set('sections', $sections = $Menu->find('all', array('conditions' => array('OR' => array(array('WebpageMenu.parent_id' => null), array('WebpageMenu.parent_id' => ''))))));
     $menus = $Menu->generateTreeList(null, null, null, '--');
     foreach ($menus as $menu) {
         if (strpos($menu, '-') !== 0) {
             // this key should be removed, because if there is a link to the same page as the menu name
             $menus = ZuhaSet::devalue($menus, '--' . $menu, true);
         }
     }
     $this->set(compact('menus'));
 }