protected function initRecord() { $request = CoreServices2::getRequest(); $id = $request->getFromGet('id'); $fileDAO = new FileDAO(); $this->record = $fileDAO->getRecordById($id); if (empty($this->record['id'])) { $this->error(1); } }
public static function getInstance() { if (!self::$instance) { self::$instance = new FileDAO(); } return self::$instance; }
/** * Usuwa te rekordy z tabeli _tmpRecord, dla których sesja już na pewno wygasła. * Usuwa też przypisane do tych rekordów pliki. */ public function clean() { $calendar = new Calendar(); $time = $calendar->addSeconds(CoreUtils::getDateTime(), -CoreConfig::get('Cron', 'tmpRecordOldAgeSeconds')); $tmpRecordDAO = new TmpRecordDAO(); $oldRecords = $tmpRecordDAO->getOldRecords($time, CoreConfig::get('Cron', 'tmpRecordsToDeletePerExecution')); $fileDAO = new FileDAO(); foreach ($oldRecords as $record) { if ($this->isForDeletion($record)) { $files = $fileDAO->getListByRecord('_tmpRecord', $record['id']); foreach ($files as $file) { $fileDAO->delete($file); } $tmpRecordDAO->delete($record); } } }
protected function saveFileRecord() { $this->fileRecord = $this->fileDAO->getRecordTemplate(); $this->form->setRecordValuesFromFields($this->fileRecord); $this->fileRecord['id'] = null; $recordId = $this->form->getField('id')->getValue(); $this->fileRecord['recordId'] = !empty($recordId) ? $recordId : $this->form->getField('_tmpId')->getValue(); $this->fileRecord['recordType'] = !empty($recordId) ? $this->form->getField('recordType')->getValue() : '_tmpRecord'; $this->fileRecord['fileUpdateTime'] = CoreUtils::getDateTime(); $maxOrder = $this->fileDAO->getMaxOrderByRecord($this->fileRecord['recordType'], $this->fileRecord['recordId'], $this->fileRecord['fileCategory'], $this->fileRecord['filePosition']); // numerowanie od 0! $this->fileRecord['fileOrder'] = $maxOrder + 1; $uploadStruct = $this->form->getField('_fileUpload')->getValue(); $this->fileDAO->save($this->fileRecord, $uploadStruct); }
protected function initBannerList() { // tworzymy nazwę modułu według której w configu będziemy odszukiwać ilość banerów do wyświetlenia $modules = CoreServices2::getModules(); $subpageModuleAndMode = $modules->getControllerModule() . $modules->getControllerMode(); $subpageBannerLocationsAndAmounts = CoreConfig::get('Data', 'subpageBannerLocationsAndAmounts'); if (!empty($subpageBannerLocationsAndAmounts[$subpageModuleAndMode])) { // jeśli odnajdziemy w configu ustawienia specyficzne dla danej podstrony serwisu, to odczytujemy je $bannerAmount = $subpageBannerLocationsAndAmounts[$subpageModuleAndMode]; } else { // w przeciwnym wypadku pobieramy ustawienia domyślne $bannerAmount = $subpageBannerLocationsAndAmounts['default']; } // Można tu zacząć tranzakcję b.d. ale jak baner się wyświetli raz za dużo // to nic się strasznego nie stanie - wydajność ważniejsza // pobieramy losową listę banerów pochodzących z aktywnych kampanii, indeksowanych według ich położeń $this->bannerList = $this->bannerDAO->getBannerListIndexedByLocation(); $bannerList = array(); // skracamy listę wylosowanych banerów do ilości potrzebnej w widoku (UWAGA, na niektórych pozycjach może nie być banerów) foreach ($bannerAmount as $bannerLocation => $bannerAmount) { if (!empty($this->bannerList[$bannerLocation])) { $bannerList[$bannerLocation] = array_slice($this->bannerList[$bannerLocation], 0, $bannerAmount); } else { $bannerList[$bannerLocation] = array(); } } $this->bannerList = $bannerList; // pobieramy tablicę ID banerów $bannerIds = $this->getBannerIds(); // pobieramy listę plików banerów $bannerImageList = $this->fileDAO->getListByRecordList('banner', $bannerIds, null, 'banner'); $this->bannerImageList = array(); foreach ($bannerImageList as $bannerId => $files) { $fileIds = array_keys($files); if (!empty($files[$fileIds[0]])) { $this->bannerImageList[$bannerId] = $files[$fileIds[0]]; } } $this->updateBannerCampaigns(); }
/** * UWAGA! * Z założenia to jest odporne na takie sytuacje jak dodanie lub usunięcie załączników * współbieżnie przez innego użytkownika, w wyniku czego lista identyfikatorów jest * nieaktualna. Na tej liście mogą niektóre identyfikatory wystepowac po klika razy * a moga też byc kompletne smiecie. */ protected function updateFilesOrder() { foreach ($this->swfAttachmentTypes as $listName => $listInfo) { if ($this->isSWFUploadOrderingActive($listName)) { $orderFieldValue = $this->form->getField($listName . '_order')->getValue(); if (!empty($orderFieldValue)) { $ids = explode(',', $orderFieldValue); $order = array_flip($ids); $files = $this->fileDAO->getListByRecord($this->getRecordType(), $this->record['id'], $listInfo['fileCategory'], $listName); $i = 0; foreach ($files as $file) { if (array_key_exists($file['id'], $order)) { $file['fileOrder'] = $order[$file['id']]; } else { $file['fileOrder'] = sizeof($files) + $i; $i++; } $this->fileDAO->save($file); } } } } }
/** * inicia internamente a DAO * @return void */ public function startDAO() { $this->DAO = FileDAO::getInstance(); }
/** * Ta funkcja nie poprawia fileOrder w pozostałych plikach, * dziury nam tak bardzo nie wadzą */ protected function deleteFileRecord() { $this->fileDAO->delete($this->fileRecord); }
protected function getDirectlyRelatedRecords(&$record) { $fileDAO = new FileDAO(); return array('SubpageDAO' => $this->getChildren($record), 'FileDAO' => $fileDAO->getListByRecord('subpage', $record['id'])); }
protected function getDirectlyRelatedRecords(&$record) { $creditsPackageDAO = new CreditsPackageDAO(); $downloadDAO = new DownloadDAO(); $clipboardDAO = new ClipboardDAO(); $fileDAO = new FileDAO(); $forumThreadDAO = new ForumThreadDAO(); $forumPostDAO = new ForumPostDAO(); $authorDAO = new AuthorDAO(); return array('CreditsPackageDAO' => $creditsPackageDAO->getListByForeignKey('userId', $record['id']), 'DownloadDAO' => $downloadDAO->getListByForeignKey('userId', $record['id']), 'ClipboardDAO' => $clipboardDAO->getListByForeignKey('userId', $record['id']), 'FileDAO' => $fileDAO->getListByRecord('user', $record['id']), 'ForumThreadDAO' => $forumThreadDAO->getListByForeignKey('userId', $record['id']), 'ForumPostDAO' => $forumPostDAO->getListByForeignKey('userId', $record['id']), 'AuthorDAO' => $authorDAO->getListByForeignKey('userId', $record['id'])); }
protected function getDirectlyRelatedRecords(&$record) { $fileDAO = new FileDAO(); return array('FileDAO' => $fileDAO->getListByRecord('_tmpRecord', $record['id'])); }
public function initAdditionalData() { parent::initAdditionalData(); $fileDAO = new FileDAO(); $this->gallery = $fileDAO->getListByRecord('subpage', $this->subpage['id'], 'image', 'gallery'); }