Ejemplo n.º 1
0
 /**
  * adds LIMIT clause, executes query and returns array of MetaFile instances
  *
  * @param number $rows
  * @return array
  */
 public function selectFirst($rows = 1)
 {
     $this->buildQueryString();
     $this->buildValuesArray();
     $this->sql .= " LIMIT {$rows}";
     $rows = $this->executeQuery();
     $ids = array();
     foreach ($rows as $row) {
         $ids[] = $row['filesID'];
     }
     return MetaFile::getInstancesByIds($ids);
 }
Ejemplo n.º 2
0
 /**
  * returns array of MetaFile instances linked to the article
  * 
  * @return MetaFile[]
  */
 public function getLinkedMetaFiles()
 {
     if (!is_null($this->id) && is_null($this->linkedFiles)) {
         $this->linkedFiles = MetaFile::getFilesForArticle($this);
     }
     return $this->linkedFiles;
 }
Ejemplo n.º 3
0
 /**
  * creates a meta file based on filesystem file
  * @return MetaFile
  * @throws FilesystemFileException
  */
 public function createMetaFile()
 {
     $db = Application::getInstance()->getDb();
     if (count($db->doPreparedQuery("\n\t\t\tSELECT\n\t\t\t\tf.filesID\n\t\t\tFROM\n\t\t\t\tfiles f\n\t\t\t\tINNER JOIN folders fo ON fo.foldersID = f.foldersID\n\t\t\tWHERE\n\t\t\t\tf.File  COLLATE utf8_bin = ? AND\n\t\t\t\tfo.Path COLLATE utf8_bin = ?\n\t\t\tLIMIT 1", array($this->filename, $this->folder->getRelativePath())))) {
         throw new FilesystemFileException("Metafile '{$this->filename}' in '{$this->folder->getRelativePath()}' already exists.", FilesystemFileException::METAFILE_ALREADY_EXISTS);
     }
     $mf = $this->folder->createMetaFolder();
     $user = User::getSessionUser();
     if (!($filesID = $db->insertRecord('files', array('foldersID' => $mf->getId(), 'File' => $this->filename, 'Mimetype' => $this->getMimetype(), 'createdBy' => is_null($user) ? NULL : $user->getAdminId())))) {
         throw new FilesystemFileException("Could not create metafile for '{$this->filename}'.", FilesystemFileException::METAFILE_CREATION_FAILED);
     } else {
         $mf = MetaFile::getInstance(NULL, $filesID);
         FileEvent::create(FileEvent::AFTER_METAFILE_CREATE, $this)->trigger();
         return $mf;
     }
 }
Ejemplo n.º 4
0
 /**
  * return all metafiles within this folder
  *
  * @param boolean $force forces re-reading of metafolder
  *
  * @return MetaFile[]
  */
 public function getMetaFiles($force = FALSE)
 {
     if (!isset($this->metaFiles) || $force) {
         $this->metaFiles = [];
         foreach (Application::getInstance()->getDb()->doPreparedQuery('SELECT filesID FROM files WHERE foldersID = ?', [(int) $this->id]) as $f) {
             $this->metaFiles[] = MetaFile::getInstance(NULL, $f['filesID']);
         }
     }
     return $this->metaFiles;
 }