/**
  * Set session with authenticated user data
  * 
  * 
  * @access public
  * @param Users/Entity/User $user ,default is null
  * @uses AuthenticationService
  */
 public function newSession($user = null)
 {
     if (is_null($user)) {
         $user = $this->query->findOneBy('Users\\Entity\\User', array('username' => $this->request->getPost('username')));
     }
     $auth = new AuthenticationService();
     $storage = $auth->getStorage();
     // here to add new entries to the session
     $storage->write(array('id' => $user->id, 'firstName' => $user->getFirstName(), 'middleName' => $user->getMiddleName(), 'lastName' => $user->getLastName(), 'name' => $user->getFullName(), 'username' => $user->getUsername(), 'email' => $user->getEmail(), 'photo' => $user->getPhoto(), 'status' => $user->getStatus(), 'roles' => $user->getRolesNames(), 'agreements' => $user->getRolesAgreementsStatus()));
 }
 /**
  * Prepare cached data for System usage
  * 
  * 
  * @access public
  * 
  * @param bool $forceFlush ,default is bool false
  * @return array cached System data serialized
  */
 public function prepareCachedSystemData($forceFlush = false)
 {
     if ($forceFlush === false) {
         $cachedSystemDataKeys = array(self::SETTINGS_KEY);
         $existingCachedSystemDataKeys = $this->cache->cacheAdapter->hasItems($cachedSystemDataKeys);
     }
     if ($forceFlush === true || $forceFlush === false && count($existingCachedSystemDataKeys) !== count($cachedSystemDataKeys)) {
         $settings = $this->query->findAll('System\\Entity\\Setting');
         $settingsArray = array();
         foreach ($settings as $setting) {
             $settingsArray[$setting->name] = $setting->value;
         }
         $items = array(self::SETTINGS_KEY => serialize($settingsArray));
         $this->cache->setItems($items);
     } else {
         $items = $this->getCachedSystemData();
         $items = array(self::SETTINGS_KEY => serialize($items[self::SETTINGS_KEY]));
     }
     return $items;
 }
 /**
  * Prepare cached data for CMS usage
  * 
  * 
  * @access public
  * 
  * @param bool $forceFlush ,default is bool false
  * @return array cached CMS data serialized
  */
 public function prepareCachedCMSData($forceFlush = false)
 {
     if ($forceFlush === false) {
         $cachedCMSDataKeys = array(self::MENUS_KEY, self::MENUS_PATHS_KEY);
         $existingCachedCMSDataKeys = $this->cache->cacheAdapter->hasItems($cachedCMSDataKeys);
     }
     if ($forceFlush === true || $forceFlush === false && count($existingCachedCMSDataKeys) !== count($cachedCMSDataKeys)) {
         $menuItems = $this->menuItem->getMenuItems();
         $menuItemsPaths = $this->query->setEntity('CMS\\Entity\\MenuItem')->entityRepository->getMenuItemsSorted(array(), true, true, true, "p.path as path", false);
         $menuItemsPathsFlat = array();
         array_walk_recursive($menuItemsPaths, function ($value) use(&$menuItemsPathsFlat) {
             $menuItemsPathsFlat[] = $value;
         });
         $items = array(self::MENUS_KEY => serialize($menuItems), self::MENUS_PATHS_KEY => serialize($menuItemsPathsFlat));
         $this->cache->setItems($items);
     } else {
         $items = $this->getCachedCMSData();
         $items = array(self::MENUS_KEY => serialize($items[self::MENUS_KEY]), self::MENUS_PATHS_KEY => serialize($items[self::MENUS_PATHS_KEY]));
     }
     return $items;
 }
Example #4
0
 /**
  * Filter menu items
  * 
  * @access public
  * @param array $data filter data
  */
 public function filterMenuItems($data)
 {
     $menuItemFilterFields = array("type", "title", "directUrl", "menu", "status");
     $menuItemFieldsFilterByLike = array("title", "directUrl");
     $data = array_intersect_key($data, array_flip($menuItemFilterFields));
     if (!empty($data["menu"])) {
         $data["menu"] = $this->query->find('CMS\\Entity\\Menu', $data["menu"]);
     }
     $criteria = Criteria::create();
     $expr = Criteria::expr();
     foreach ($data as $fieldName => $fieldValue) {
         // only submitted values are used in filter
         if ($fieldValue != "") {
             $expressionMethod = "eq";
             if (in_array($fieldName, $menuItemFieldsFilterByLike)) {
                 $expressionMethod = "contains";
             }
             $criteria->andWhere($expr->{$expressionMethod}($fieldName, $fieldValue));
         }
     }
     $this->setCriteria($criteria);
 }