public function __construct()
 {
     parent::__construct(self::B2DBNAME, self::ID);
     parent::_addForeignKeyColumn(self::UID, TBGUsersTable::getTable(), TBGUsersTable::ID);
     parent::_addForeignKeyColumn(self::SCOPE, TBGScopesTable::getTable(), TBGScopesTable::ID);
     parent::_addForeignKeyColumn(self::ISSUE_ID, TBGIssuesTable::getTable(), TBGIssuesTable::ID);
     parent::_addForeignKeyColumn(self::FILE_ID, TBGFilesTable::getTable(), TBGFilesTable::ID);
     parent::_addInteger(self::ATTACHED_AT, 10);
 }
 public function getByIssueID($issue_id)
 {
     $crit = $this->getCriteria();
     $crit->addWhere(self::ISSUE_ID, $issue_id);
     $crit->addJoin(TBGFilesTable::getTable(), TBGFilesTable::ID, self::FILE_ID);
     $res = $this->doSelect($crit, false);
     $ret_arr = array();
     if ($res) {
         while ($row = $res->getNextRow()) {
             $file = TBGContext::factory()->TBGFile($row->get(TBGFilesTable::ID), $row);
             $file->setUploadedAt($row->get(self::ATTACHED_AT));
             $ret_arr[$row->get(TBGFilesTable::ID)] = $file;
         }
     }
     return $ret_arr;
 }
Exemple #3
0
 public function runUpdateAttachments(TBGRequest $request)
 {
     switch ($request['target']) {
         case 'issue':
             $target = TBGIssuesTable::getTable()->selectById($request['target_id']);
             $base_id = 'viewissue_files';
             $container_id = 'viewissue_uploaded_files';
             $target_identifier = 'issue_id';
             $target_id = $target->getID();
             break;
         case 'article':
             $target = TBGArticlesTable::getTable()->selectById($request['target_id']);
             $base_id = 'article_' . mb_strtolower(urldecode($request['article_name'])) . '_files';
             $container_id = 'article_' . $target->getID() . '_files';
             $target_identifier = 'article_name';
             $target_id = $request['article_name'];
             break;
     }
     $saved_file_ids = $request['files'];
     $files = array();
     foreach ($request['file_description'] as $file_id => $description) {
         $file = TBGFilesTable::getTable()->selectById($file_id);
         $file->setDescription($description);
         $file->save();
         if (in_array($file_id, $saved_file_ids)) {
             $target->attachFile($file);
         } else {
             $target->detachFile($file);
         }
         $files[] = $this->getComponentHTML('main/attachedfile', array('base_id' => $base_id, 'mode' => $request['target'], $request['target'] => $target, $target_identifier => $target_id, 'file' => $file));
     }
     $attachmentcount = $request['target'] == 'issue' ? $target->countFiles() + $target->countLinks() : $target->countFiles();
     return $this->renderJSON(array('attached' => 'ok', 'container_id' => $container_id, 'files' => $files, 'attachmentcount' => $attachmentcount));
 }
 public function runGetFile(TBGRequest $request)
 {
     $file = TBGFilesTable::getTable()->doSelectById((int) $request->getParameter('id'));
     if ($file instanceof B2DBRow) {
         $this->getResponse()->cleanBuffer();
         $this->getResponse()->clearHeaders();
         $this->getResponse()->setDecoration(TBGResponse::DECORATE_NONE);
         $this->getResponse()->addHeader('Content-disposition: ' . ($request->getParameter('mode') == 'download' ? 'attachment' : 'inline') . '; filename="' . $file->get(TBGFilesTable::ORIGINAL_FILENAME) . '"');
         $this->getResponse()->addHeader('Content-type: ' . $file->get(TBGFilesTable::CONTENT_TYPE) . '; charset=UTF-8');
         $this->getResponse()->renderHeaders();
         if (TBGSettings::getUploadStorage() == 'files') {
             echo fpassthru(fopen(TBGSettings::getUploadsLocalpath() . $file->get(TBGFilesTable::REAL_FILENAME), 'r'));
             exit;
         } else {
             echo $file->get(TBGFilesTable::CONTENT);
             exit;
         }
         return true;
     }
     $this->return404(TBGContext::getI18n()->__('This file does not exist'));
 }