Beispiel #1
0
 public function getSelectRoles($id = null)
 {
     $cache = $this->getEntityCache();
     $data = $cache->load(self::SELECT_COLLECTION);
     try {
         if ($data === null) {
             $data = $this->roleDao->findPairs([], 'name');
             $opt = [Cache::TAGS => [self::ENTITY_COLLECTION]];
             $cache->save(self::SELECT_COLLECTION, $data, $opt);
         }
         if ($id != null) {
             if (is_numeric($id)) {
                 unset($data[$id]);
             } else {
                 if (is_string($id)) {
                     $data = array_flip($data);
                     unset($data[$id]);
                     $data = array_flip($data);
                 }
             }
         }
         return $data;
     } catch (\Exception $e) {
         $this->logError($e);
         throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious());
     }
 }
 public static function getPairs(EntityDao $dao, array $options = [])
 {
     $options += ['criteria' => [], 'orderBy' => [], 'key' => $dao->getClassMetadata()->getSingleIdentifierFieldName()];
     if (empty($options['value'])) {
         $options['value'] = self::getValueFieldFallback($dao->getClassMetadata());
     }
     if (is_string($options['orderBy'])) {
         $options['orderBy'] = [$options['orderBy'] => 'asc'];
     }
     if (is_string($options['value']) && $dao->getClassMetadata()->hasField($options['value']) && !array_filter($options['criteria'], 'is_callable')) {
         return $dao->findPairs($options['criteria'], $options['value'], $options['orderBy'], $options['key']);
     } else {
         return self::getPairsAdvanced($dao, $options);
     }
 }
Beispiel #3
0
 public function getSelectSeasons()
 {
     $cache = $this->getEntityCache();
     $data = $cache->load(self::SELECT_COLLECTION);
     try {
         if ($data === null) {
             $data = $this->seasonDao->findPairs([], 'label');
             $opt = [Cache::TAGS => [self::ENTITY_COLLECTION]];
             $cache->save(self::SELECT_COLLECTION, $data, $opt);
         }
         return $data;
     } catch (\Exception $ex) {
         $this->logError($ex->getMessage());
         throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
     }
 }
Beispiel #4
0
 public function getSelectForums($id = null)
 {
     try {
         $cache = $this->getEntityCache();
         $data = $cache->load(self::SELECT_COLLECTION);
         if ($data === null) {
             $data = $this->forumDao->findPairs([], "title");
             $opt = [Cache::TAGS => [self::SELECT_COLLECTION]];
             $cache->save(self::SELECT_COLLECTION, $data, $opt);
         }
         if ($id != null) {
             unset($data[$id]);
         }
         return $data;
     } catch (\Exception $ex) {
         $this->logError($ex->getMessage());
         throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
     }
 }
Beispiel #5
0
 public function getSelectStaticPages($useCache = true)
 {
     try {
         if (!$useCache) {
             return $data = $this->pageDao->findPairs([], "title");
         }
         $cache = $this->getEntityCache();
         $data = $cache->load(self::SELECT_COLLECTION);
         if ($data === null) {
             $data = $this->pageDao->findPairs([], "title");
             $opt = [Cache::TAGS => [self::SELECT_COLLECTION]];
             $cache->save(self::SELECT_COLLECTION, $data, $opt);
         }
         return $data;
     } catch (\Exception $ex) {
         $this->logError($ex->getMessage());
         throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious());
     }
 }
Beispiel #6
0
 /**
  * @param FileUpload $file
  *
  * @return ArrayHash
  */
 private function getFileData(FileUpload $file)
 {
     $name = $file->getSanitizedName();
     $extension = '';
     if (Strings::contains($name, '.')) {
         $fragments = explode('.', $name);
         array_shift($fragments);
         $extension = implode('.', $fragments);
     }
     $pairs = $this->storageDao->findPairs([], 'name', [], 'id');
     $data = new ArrayHash();
     while (true) {
         $name = Random::generate(10, '0-9A-Za-z');
         if (!in_array($name, $pairs)) {
             $data->name = $name;
             $data->extension = $extension;
             break;
         }
     }
     return $data;
 }