예제 #1
2
 /**
  * Gets our attached files as an array of arrays with the elements "name"
  * and "size" of the attached file.
  *
  * The displayed file name is relative to the tx_seminars upload directory
  * and is linked to the actual file's URL.
  *
  * The file size will have, depending on the file size, one of the following
  * units appended: K for Kilobytes, M for Megabytes and G for Gigabytes.
  *
  * The returned array will be sorted like the files are sorted in the back-
  * end form.
  *
  * If this event is an event date, this function will return both the
  * topic's file and the date's files (in that order).
  *
  * Note: This functions' return values already are htmlspecialchared.
  *
  * @param tslib_pibase $plugin a tslib_pibase object for a live page
  *
  * @return array[] an array of arrays with the elements "name" and
  *               "size" of the attached file, will be empty if
  *               there are no attached files
  */
 public function getAttachedFiles(tslib_pibase $plugin)
 {
     if (!$this->hasAttachedFiles()) {
         return array();
     }
     if ($this->isTopicOkay()) {
         $filesFromTopic = $this->topic->getAttachedFiles($plugin);
     } else {
         $filesFromTopic = array();
     }
     $result = $filesFromTopic;
     $uploadFolderPath = PATH_site . 'uploads/tx_seminars/';
     $uploadFolderUrl = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . 'uploads/tx_seminars/';
     $attachedFiles = t3lib_div::trimExplode(',', $this->getRecordPropertyString('attached_files'), TRUE);
     foreach ($attachedFiles as $attachedFile) {
         $matches = array();
         preg_match('/\\.(\\w+)$/', basename($attachedFile), $matches);
         $result[] = array('name' => $plugin->cObj->typoLink(htmlspecialchars(basename($attachedFile)), array('parameter' => $uploadFolderUrl . $attachedFile)), 'type' => htmlspecialchars(isset($matches[1]) ? $matches[1] : 'none'), 'size' => t3lib_div::formatSize(filesize($uploadFolderPath . $attachedFile)));
     }
     return $result;
 }
예제 #2
0
 /**
  * @test
  */
 public function getAttachedFilesForDateWithFileAndTopicWithFileReturnsFilesFromTopicAndThenDate()
 {
     $this->createPi1();
     $topicDummyFile = $this->testingFramework->createDummyFile();
     $topicDummyFileName = $this->testingFramework->getPathRelativeToUploadDirectory($topicDummyFile);
     $topicRecordUid = $this->testingFramework->createRecord('tx_seminars_seminars', array('object_type' => tx_seminars_Model_Event::TYPE_TOPIC, 'attached_files' => $topicDummyFileName));
     $dateDummyFile = $this->testingFramework->createDummyFile();
     $dateDummyFileName = $this->testingFramework->getPathRelativeToUploadDirectory($dateDummyFile);
     $dateRecordUid = $this->testingFramework->createRecord('tx_seminars_seminars', array('object_type' => tx_seminars_Model_Event::TYPE_DATE, 'attached_files' => $dateDummyFileName, 'topic' => $topicRecordUid));
     $eventDate = new tx_seminars_seminar($dateRecordUid);
     $attachedFiles = $eventDate->getAttachedFiles($this->pi1);
     self::assertContains($topicDummyFileName, $attachedFiles[0]['name']);
     self::assertContains($dateDummyFileName, $attachedFiles[1]['name']);
 }