Beispiel #1
0
 /**
  * add appropriate WHERE clause that filters metafiles linked to given article
  *
  * @param Article $article
  * @return MetaFileQuery
  */
 public function filterByArticle(Article $article)
 {
     if ($article->getId()) {
         $this->innerJoin('articles_files af', 'af.filesID = f.filesID');
         $this->addCondition("af.articlesID = ?", $article->getId());
     }
     return $this;
 }
Beispiel #2
0
 /**
  * retrieves all articles assigned to this article category
  *
  * @return array
  */
 public function getArticles()
 {
     if (is_null($this->articles)) {
         $this->articles = Article::getArticlesForCategory($this);
     }
     return $this->articles;
 }
Beispiel #3
0
 /**
  * return all metafile instances linked to an article with mimetype 'image/jpeg', 'image/png', 'image/gif'
  *
  * @param Article $article
  * @param callback $callBackSort
  * @throws MetaFileException
  * @return array:\vxPHP\File\MetaFile
  */
 public static function getImagesForArticle(Article $article, $callBackSort = NULL)
 {
     $result = array();
     $mimeTypes = array('image/jpeg', 'image/png', 'image/gif');
     $files = Application::getInstance()->getDb()->doPreparedQuery("\n\t\t\tSELECT\n\t\t\t\tf.*,\n\t\t\t\tCONCAT(fo.Path, IFNULL(f.Obscured_Filename, f.File)) as FullPath\n\t\t\tFROM\n\t\t\t\tfiles f\n\t\t\t\tINNER JOIN folders fo ON f.foldersID = fo.foldersID\n\t\t\t\tINNER JOIN articles_files af ON af.filesID = f.filesID\n\t\t\tWHERE\n\t\t\t\taf.articlesID = ?\n\t\t\t\tAND f.Mimetype IN ('" . implode("','", $mimeTypes) . "')\n\t\t\tORDER BY\n\t\t\t\taf.customSort\n\t\t\t", array($article->getId()));
     foreach ($files as &$f) {
         if (isset(self::$instancesById[$f['filesID']])) {
             $file = self::$instancesById[$f['filesID']];
         } else {
             $file = new self(NULL, NULL, $f);
             self::$instancesById[$f['filesID']] = $file;
             self::$instancesByPath[$file->filesystemFile->getPath()] = $file;
         }
         $result[] = $file;
     }
     if (is_null($callBackSort)) {
         return $result;
     } else {
         if (is_callable($callBackSort)) {
             usort($result, $callBackSort);
             return $result;
         } else {
             if (is_callable("self::{$callBackSort}")) {
                 usort($result, "self::{$callBackSort}");
                 return $result;
             } else {
                 throw new MetaFileException("'{$callBackSort}' is not callable.");
             }
         }
     }
 }
Beispiel #4
0
 /**
 	/* (non-PHPdoc)
 * @see \vxPHP\Orm\Query::selectFromTo()
 * @return Article[]
 * @throws \RangeException
 */
 public function selectFromTo($from, $to)
 {
     if (empty($this->columnSorts)) {
         throw new \RangeException("'" . __METHOD__ . "' requires a SORT criteria.");
     }
     if ($to < $from) {
         throw new \RangeException("'to' value is less than 'from' value.");
     }
     $this->buildQueryString();
     $this->buildValuesArray();
     $this->sql .= ' LIMIT ' . (int) $from . ', ' . ($to - $from + 1);
     $ids = array();
     foreach ($this->executeQuery() as $row) {
         $ids[] = $row['articlesID'];
     }
     return Article::getInstances($ids);
 }