/**
  * Loads a news page object.
  *
  * @param string $dataDir Defines the dir, where the news content is located.
  * @param int $page Desired page number.
  *
  * @return NewsItem The NewsItem domain object.
  * @throws IncludeException In case no news files are found.
  *
  * @author Christian Achatz
  * @version
  * Version 0.1, 02.02.2007<br />
  * Version 0.2, 18.09.2008 (Introduced variable data dir)<br />
  * Version 0.3, 23.08.2012 (Change to new File-/Folder-class)<br />
  */
 public function getNewsByPage($dataDir, $page)
 {
     // cut trailing slash if necessary
     if (substr($dataDir, strlen($dataDir) - 1) == '/') {
         $dataDir = substr($dataDir, 0, strlen($dataDir) - 1);
     }
     // read all files located there
     $folder = new Folder();
     $rawFiles = $folder->open($dataDir)->getContent();
     // get files, that match the current language
     /* @var $files FilesystemItem[] */
     $files = [];
     foreach ($rawFiles as $data) {
         if (substr_count($data->getName(), 'news_' . $this->getLanguage() . '_') > 0) {
             $files[] = $data;
         }
     }
     // throw error when page count is zero!
     $newsCount = count($files);
     if ($newsCount == 0) {
         throw new IncludeException('[NewsPagerProvider::getNewsByPage()] No news files are ' . 'given for language ' . $this->getLanguage(), E_USER_ERROR);
     }
     // if page number is lower then zero, correct it!
     if ($page <= 0) {
         $page = 1;
     }
     // if page number is higher then max, correct it!
     if ($page > $newsCount) {
         $page = $newsCount;
     }
     // read content of file
     $rawItem = json_decode(file_get_contents($dataDir . '/' . $files[$page - 1]->getName()));
     // fill a new news content object
     $item = new NewsItem();
     $item->setHeadline($rawItem->headline);
     $item->setSubHeadline($rawItem->subline);
     $item->setContent($rawItem->content);
     $item->setNewsCount($newsCount);
     return $item;
 }
Exemple #2
0
 /**
  * @param   Folder $folder The Folder into which it should be moved
  *
  * @return  boolean
  *
  * @author  Nicolas Pecher
  * @version Version 0.1, 01.05.2012
  */
 public function moveTo(Folder $folder)
 {
     copy($this->getPath(), $folder->getPath() . '/' . $this->getName());
     $this->delete();
     $this->basePath = $folder->getPath();
     return $this;
 }
 /**
  * Löscht die Übergebene Datei. Wird nichts übergeben, werden alle Datein gelöscht.
  *
  * @param string $uploadname
  *
  * @author Werner Liemberger <*****@*****.**>
  * @version 1.0, 14.03.2011<br>
  * @version 1.1, 14.08.2012 (Change to new File-/Folder-class)<br>
  */
 public function deleteFile($uploadname = null)
 {
     $uploadpath = $this->getUploadPath();
     if ($uploadname === null) {
         $folder = new Folder();
         $files = $folder->open($uploadpath)->getContent();
         foreach ($files as $file) {
             if (file_exists($file)) {
                 $file->delete();
             }
         }
     } else {
         if (file_exists($uploadpath . '/' . $uploadname)) {
             $file = new File();
             $file->open($uploadpath . '/' . $uploadname)->delete();
         }
     }
     $this->deleteFileFromSession($uploadname);
 }
 /**
  * Creates a new file for each the base class and the DO class with the code for
  * the object with the given name. Will overwrite existing file!
  *
  * @param string $name The object's name.
  * @param string $baseFileName The file name the base class will be written to.
  * @param string $fileName The file name the class will be written to.
  *
  * @author Ralf Schubert
  * @version
  * Version 0.1, 15.01.2011<br />
  * Version 0.2, 24.06.2014 (ID#194: split base class and DO class into separate files to better support auto loading.)<br />
  */
 protected function createNewServiceObject($name, $baseFileName, $fileName)
 {
     $namespace = $this->getNamespaceByObjectName($name);
     $path = dirname($fileName);
     if (!file_exists($path)) {
         $folder = new Folder();
         $folder->create($path);
     }
     // create base class file
     $content = '<?php' . PHP_EOL . 'namespace ' . $namespace . ';' . PHP_EOL . PHP_EOL . $this->generateBaseObjectCode($name) . PHP_EOL;
     $baseFile = new File();
     $baseFile->create($baseFileName)->writeContent($content);
     // create class file
     $content = '<?php' . PHP_EOL . 'namespace ' . $namespace . ';' . PHP_EOL . PHP_EOL . $this->generateObjectCode($name) . PHP_EOL;
     $file = new File();
     $file->create($fileName)->writeContent($content);
 }