/** * Start a editing session or return an existing one * @param string $uid of the user starting a session * @param \OCA\Documents\File $file - file object * @return array * @throws \Exception */ public static function start($uid, File $file) { list($ownerView, $path) = $file->getOwnerViewAndPath(); // Create a directory to store genesis $genesis = new Genesis($ownerView, $path, $file->getOwner()); $oldSession = new Db_Session(); $oldSession->loadBy('file_id', $file->getFileId()); //If there is no existing session we need to start a new one if (!$oldSession->hasData()) { $newSession = new Db_Session(array($genesis->getPath(), $genesis->getHash(), $file->getOwner(), $file->getFileId())); if (!$newSession->insert()) { throw new \Exception('Failed to add session into database'); } } $session = $oldSession->loadBy('file_id', $file->getFileId())->getData(); $memberColor = Helper::getRandomColor(); $member = new Db_Member(array($session['es_id'], $uid, $memberColor, time())); if ($member->insert()) { // Do we have OC_Avatar in out disposal? if (!class_exists('\\OC_Avatar') || \OC_Config::getValue('enable_avatars', true) !== true) { //$x['avatar_url'] = \OCP\Util::linkToRoute('documents_user_avatar'); $imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw=='; } else { // https://github.com/owncloud/documents/issues/51 // Temporary stub $imageUrl = $uid; /* $avatar = new \OC_Avatar($uid); $image = $avatar->get(64); // User has an avatar if ($image instanceof \OC_Image) { $imageUrl = \OC_Helper::linkToRoute( 'core_avatar_get', array( 'user' => $uid, 'size' => 64) ) . '?requesttoken=' . \OC::$session->get('requesttoken'); } else { //shortcircuit if it's not an image $imageUrl = 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw=='; } */ } $session['member_id'] = (string) $member->getLastInsertId(); $op = new Db_Op(); $op->addMember($session['es_id'], $session['member_id'], \OCP\User::getDisplayName($uid), $memberColor, $imageUrl); } else { throw new \Exception('Failed to add member into database'); } $session['permissions'] = $ownerView->getFilePermissions($path); return $session; }
/** * converts an object to insert/update data * * @return a comma separated string e.g. "a=1,b=2" */ public function getInsertData($doubleEscaped = false) { $values = ''; if ($this->id !== null) { $this->addInsertData($values, 'S_id', DBJson::mysql_real_escape_string($this->id)); } if ($this->studentId !== null) { $this->addInsertData($values, 'U_id', DBJson::mysql_real_escape_string($this->studentId)); } if ($this->file != array() && $this->file !== null) { $this->addInsertData($values, 'F_id_file', DBJson::mysql_real_escape_string($this->file->getFileId())); } if ($this->exerciseId !== null) { $this->addInsertData($values, 'E_id', DBJson::mysql_real_escape_string($this->exerciseId)); } if ($this->comment !== null) { $this->addInsertData($values, 'S_comment', DBJson::mysql_real_escape_string($this->comment)); } if ($this->accepted !== null) { $this->addInsertData($values, 'S_accepted', DBJson::mysql_real_escape_string($this->accepted)); } if ($this->date !== null) { $this->addInsertData($values, 'S_date', DBJson::mysql_real_escape_string($this->date)); } // if ($this->selectedForGroup != null) $this->addInsertData($values, 'S_selected', DBJson::mysql_real_escape_string($this->selectedForGroup)); if ($this->flag !== null) { $this->addInsertData($values, 'S_flag', DBJson::mysql_real_escape_string($this->flag)); } if ($this->leaderId !== null) { $this->addInsertData($values, 'S_leaderId', DBJson::mysql_real_escape_string($this->leaderId)); } if ($this->hideFile !== null) { $this->addInsertData($values, 'S_hideFile', DBJson::mysql_real_escape_string($this->hideFile)); } if ($values != '') { $values = substr($values, 1); } return $doubleEscaped ? DBJson::mysql_real_escape_string($values) : $values; }
/** * writeViewData * @param File $objFile * @author Cornelius Hansjakob <*****@*****.**> * @version 1.0 */ private function writeViewData(File &$objFile) { $this->core->logger->debug('media->controllers->UploadController->writeViewData()'); $this->view->assign('fileId', $objFile->getId()); $this->view->assign('fileFileId', $objFile->getFileId()); $this->view->assign('fileExtension', $objFile->getExtension()); $this->view->assign('fileTitle', $objFile->getTitle()); $this->view->assign('mimeType', $objFile->getMimeType()); $this->view->assign('strDefaultDescription', 'Beschreibung hinzufügen...'); // TODO : guiTexts $this->view->assign('languageId', 1); // TODO : language }
/** * converts an object to insert/update data * * @return a comma separated string e.g. "a=1,b=2" */ public function getInsertData($doubleEscaped = false) { $values = ''; if ($this->id != null) { $this->addInsertData($values, 'A_id', DBJson::mysql_real_escape_string($this->id)); } if ($this->exerciseId != null) { $this->addInsertData($values, 'E_id', DBJson::mysql_real_escape_string($this->exerciseId)); } if ($this->file != null && $this->file->getFileId() != null) { $this->addInsertData($values, 'F_id', DBJson::mysql_real_escape_string($this->file->getFileId())); } if ($this->processId != null) { $this->addInsertData($values, 'PRO_id', DBJson::mysql_real_escape_string(Process::getIdFromProcessId($this->processId))); } if ($values != '') { $values = substr($values, 1); } return $doubleEscaped ? DBJson::mysql_real_escape_string($values) : $values; }
/** * writeViewData * @param File $objFile * @author Cornelius Hansjakob <*****@*****.**> * @version 1.0 */ private function writeViewData(File &$objFile) { $this->core->logger->debug('media->controllers->UploadController->writeViewData()'); $this->view->assign('fileId', $objFile->getId()); $this->view->assign('fileFileId', $objFile->getFileId()); $this->view->assign('fileExtension', $objFile->getExtension()); $this->view->assign('fileTitle', $objFile->getTitle()); $this->view->assign('fileVersion', $objFile->getVersion()); $this->view->assign('filePath', sprintf($this->core->sysConfig->media->paths->icon32, $objFile->getSegmentPath())); $this->view->assign('mimeType', $objFile->getMimeType()); $this->view->assign('strDefaultDescription', $this->core->translate->_('Add_description_')); $this->view->assign('languageId', $this->intLanguageId); }