Esempio n. 1
0
 /**
  * Element method
  * Finds the menu by id or code field
  * 
  * @param mixed $id
  * @return array $data
  */
 public function element($id = null, $userRoleId = null)
 {
     // id can be the code field or the id field, this checks to see which field we look up
     $field = Zuha::is_uuid($id) || is_numeric($id) ? 'id' : 'code';
     if (!empty($userRoleId)) {
         // check to see if we have a menu for a specific user role
         $menuId = $this->WebpageMenu->field('id', array('WebpageMenu.' . $field => $id, 'WebpageMenu.user_role_id' => $userRoleId));
     } elseif ($userRoleId === false) {
         // there might be a logged in user, but we want the menu which has a blank user_role_id field anyway
         $menuId = false;
     } else {
         // check a logged in user if it exists
         $userRoleId = $this->Session->read('Auth.User.id');
         if (!empty($userRoleId)) {
             $menuId = $this->WebpageMenu->field('id', array('WebpageMenu.' . $field => $id, 'WebpageMenu.user_role_id' => $userRoleId));
         }
     }
     if (!empty($menuId)) {
         // we have an exact menu id (from the user role checks above)
         $conditions = array('WebpageMenu.id' => $menuId);
     } else {
         // standard menu look up (with the id or the code field)
         $conditions = array('WebpageMenu.' . $field => $id, 'WebpageMenu.user_role_id' => null);
     }
     $read = $this->WebpageMenu->find('first', array('conditions' => array('WebpageMenu.' . $field => $id), 'fields' => array('WebpageMenu.lft', 'WebpageMenu.rght')));
     $menu = $this->WebpageMenu->find('threaded', array('conditions' => array('WebpageMenu.lft >=' => $read['WebpageMenu']['lft'], 'WebpageMenu.rght <=' => $read['WebpageMenu']['rght'])));
     $menu = $menu[0];
     // we can only edit one menu at a time.
     $menu['WebpageMenu']['children'] = $this->WebpageMenu->find('count', array('conditions' => array('WebpageMenu.lft >' => $read['WebpageMenu']['lft'], 'WebpageMenu.rght <' => $read['WebpageMenu']['rght'])));
     if (!empty($menu['WebpageMenu']['children'])) {
         return $menu;
     } else {
         return null;
     }
 }
Esempio n. 2
0
 public function types()
 {
     $types = array();
     foreach (Zuha::enum('CONTACT_DETAIL') as $type) {
         $types[Inflector::underscore($type)] = $type;
     }
     return array_merge(array('email' => 'Email'), $types);
 }
Esempio n. 3
0
 /**
  * Ratings for contacts
  *
  * @return array
  */
 public function ratings()
 {
     $ratings = array();
     foreach (Zuha::enum('CONTACT_RATING') as $rating) {
         $ratings[Inflector::underscore($rating)] = $rating;
     }
     return array_merge(array('hot' => 'Hot', 'warm' => 'Warm', 'cold' => 'Cold'), $ratings);
 }
Esempio n. 4
0
 /**
  * Url Template
  * 
  * Checks if the selected template is available to the current url
  *
  * @param array Individual template data arrays from the settings.ini (or defaults.ini) file.
  */
 private function _urlTemplate($data)
 {
     if (!empty($data['urls'])) {
         foreach ($data['urls'] as $url) {
             $urlString = str_replace('/', '\\/', trim($url));
             if (substr($urlString, -1) !== '/') {
                 $urlString . '/';
             }
             $urlRegEx = '/' . str_replace('*', '(.*)', $urlString) . '/';
             $urlRegEx = strpos($urlRegEx, '\\/') === 1 ? '/' . substr($urlRegEx, 3) : $urlRegEx;
             $url = Zuha::reverseParams($this->request->params);
             $url = $this->request->action == 'index' ? $this->request->plugin . '/' . $this->request->controller . '/' . $this->request->action . '/' : $url . '/';
             $urlCompare = strpos($url, '/') === 0 ? substr($url, 1) : $url;
             $urlCompare = str_replace("//", "/", $urlCompare);
             if ($urlRegEx !== '//' && preg_match($urlRegEx, $urlCompare)) {
                 $templateId = !empty($data['userRoles']) ? $this->_userTemplate($data) : $data['templateName'];
             }
         }
     }
     if (!empty($templateId)) {
         return $templateId;
     } else {
         return null;
     }
 }
Esempio n. 5
0
 /**
  * Types function
  * An array of options for select inputs
  * 
  * @return array
  */
 public function types($name = null)
 {
     foreach (Zuha::enum('WEBPAGES_PAGE_TYPE') as $type) {
         $types[Inflector::underscore($type)] = $type;
     }
     $this->types = Set::merge($this->types, $types);
     if (!empty($name)) {
         return $this->types[$name];
     } else {
         return $this->types;
     }
 }
Esempio n. 6
0
 /**
  * Edit method
  * 
  * @param uuid $id
  */
 public function edit($id = null)
 {
     if ($this->request->is('post') || $this->request->is('put')) {
         if ($this->Setting->add($this->request->data)) {
             $this->Session->setFlash(__('The Setting has been saved', true), 'flash_success');
             $this->redirect($this->referer());
         } else {
             $this->Session->setFlash(__('The Setting could not be saved. Please, try again.', true), 'flash_warning');
         }
     }
     if (!$id && empty($this->request->data) && empty($this->request->params['named'])) {
         $this->Session->setFlash(__('Invalid Setting', true), 'flash_danger');
         $this->redirect(array('action' => 'index'));
     }
     if (!empty($this->request->params['named'])) {
         $this->request->data = $this->Setting->find('first', array('conditions' => array('type_id' => Zuha::enum(null, $this->request->params['named']['type']), 'name' => $this->request->params['named']['name'])));
         $this->set('typeId', Zuha::enum(null, $this->request->params['named']['type']));
         $this->request->data['Setting']['name'] = $this->request->params['named']['name'];
         $this->request->data['Setting']['description'] = $this->Setting->getDescription($this->request->params['named']['type'], $this->request->params['named']['name']);
     }
     if (empty($this->request->data)) {
         $this->request->data = $this->Setting->read(null, $id);
         $this->request->data['Setting']['description'] = $this->Setting->getDescription($this->request->data['Setting']['type'], $this->request->data['Setting']['name']);
     }
     $types = $this->Setting->types();
     $this->set(compact('types'));
     $this->layout = 'default';
 }