Example #1
0
 public function insert(File $file)
 {
     $this->mysqliInstanse->query('START TRANSACTION');
     $query = "INSERT INTO {$this->table} (name, size, mime, unixtime, md5)\n    VALUES (?, ?, ?, ?, ?)";
     if ($stmt = $this->mysqliInstanse->prepare($query)) {
         $name = $file->name;
         $size = $file->size;
         $mime = $file->mime;
         $unixtime = $file->unixtime;
         $md5 = $file->md5;
         $stmt->bind_param("sisis", $name, $size, $mime, $unixtime, $md5);
     } else {
         throw new Exception("Не удалось подготовить SQL запрос");
     }
     if (!$stmt->execute()) {
         throw new Exception("Не удалось добавить данные о файле в таблицу: (" . $stmt->errno . ") " . $stmt->error);
     }
     $stmt->close();
     $id = $this->mysqliInstanse->insert_id;
     $file->setId($id);
     return $file;
 }
Example #2
0
 /**
  * @param int $id
  * @return File|null
  */
 public function loadFile($id)
 {
     $query = 'SELECT id, name, size, created_time, modified_time, folder_id, path FROM files WHERE id = :id';
     $sql = $this->pdo->prepare($query);
     $sql->execute(array('id' => $id));
     if (!$sql->rowCount()) {
         return null;
     }
     $row = $sql->fetch(\PDO::FETCH_ASSOC);
     $file = new File();
     $file->setId($row['id'])->setName($row['name'])->setSize($row['size'])->setCreatedTime(new \DateTime($row['created_time']))->setPath($row['path'])->setParentFolder($this->loadFolder($row['folder_id']));
     return $file;
 }
 /**
  * Get File Revisions
  *
  * @param fileId - required -
  *		The id of the file.
  *
  * @return 	A File object is return with all the revisions
  * or the error code and message returned by the server.
  */
 public function getFileRevisions($fileId)
 {
     $urld = 'dpi/v1/folder/file/' . $fileId . '/revisions';
     $parameters = array();
     $this->response = $this->restTransportInstance->sendRequest($urld, $parameters, self::HTTP_GET, $this->authToken);
     $responseBody = simplexml_load_string($this->response);
     $returnObject = new File();
     if ($responseBody === false) {
         $errorCode = 'N/A';
         $errorMessage = 'The server has encountered an error, please try again.';
         $errorObject = new ErrorStatus($errorCode, $errorMessage);
         $returnObject->setErrorStatus($errorObject);
     } else {
         $errorStatus = $responseBody->errorStatus;
         if (empty($errorStatus)) {
             $returnObject->setRevision((string) $responseBody->attributes()->revision);
             $returnObject->setId((string) $responseBody->attributes()->id);
             $returnObject->setStatus((string) $responseBody->status);
             $returnObject->setCreatedOn((string) $responseBody->createdOn);
             $returnObject->setName((string) $responseBody->name);
             $returnObject->setOwnedByStorage((string) $responseBody->ownedByStorage);
             $returnObject->setParentId((string) $responseBody->parentid);
             $returnObject->setRevisionCount((string) $responseBody->revisionCount);
             $returnObject->setSize((string) $responseBody->size);
             $revisions = array();
             $revisionsTag = (string) $responseBody->revisions->count();
             if ($revisionsTag > 0) {
                 foreach ($responseBody->revisions->children() as $currentRevision) {
                     if ($currentRevision->count() > 0) {
                         $revision = new Revision();
                         $revision->setId((string) $currentRevision->attributes()->id);
                         $revision->setCurrent((string) $currentRevision->current);
                         $revision->setDownloadUrl((string) $currentRevision->downloadUrl);
                         $revision->setSize((string) $currentRevision->size);
                         array_push($revisions, $revision);
                     }
                 }
                 $returnObject->setRevisions($revisions);
             }
         } else {
             $errorCode = (string) $responseBody->errorStatus->code;
             $errorMessage = (string) $responseBody->errorStatus->message;
             $errorObject = new ErrorStatus($errorCode, $errorMessage);
             $returnObject->setErrorStatus($errorObject);
         }
     }
     return $returnObject;
 }
 public static function getDocumentById($id)
 {
     global $bdd;
     $sql = "SELECT *\n\t\t\t\tFROM document\n\t\t\t\tWHERE id = ?";
     $rq = $bdd->prepare($sql);
     $rq->execute(array($id));
     $data = $rq->fetch();
     $doc = new File();
     $doc->setId($data["id"]);
     $doc->setRang($data["rang"]);
     $doc->setPromo($data["promo"]);
     $doc->setLibelle($data["libelle"]);
     $doc->setFichier($data["fichier"]);
     return $doc;
 }
 /**
  * Get Item Info
  *
  * @param itemId - required -
  *         Item id
  * @return An Item object with details like itemId, expiration date, file details etc.
  * or the error code and message returned by the server.
  * 	 */
 public function getItemInfo($itemId)
 {
     $parameters = array();
     $urld = 'dpi/v1/item/' . $itemId;
     $this->response = $this->_restTransportInstance->sendRequest($urld, $parameters, 'GET', $this->_authToken);
     $responseBody = simplexml_load_string($this->response);
     $returnObject = new Item();
     if ($responseBody === false) {
         $errorCode = 'N/A';
         $errorMessage = 'The server has encountered an error, please try again.';
         $errorObject = new ErrorStatus($errorCode, $errorMessage);
         $returnObject->setErrorStatus($errorObject);
     } else {
         if (empty($responseBody->errorStatus)) {
             $create = (string) $responseBody->create;
             $returnObject->setCreate($create);
             $expiration = (string) $responseBody->expiration;
             $returnObject->setExpiration($expiration);
             $id = (string) $responseBody->id;
             $returnObject->setId($id);
             $subject = (string) $responseBody->subject;
             $returnObject->setSubject($subject);
             $message = (string) $responseBody->message;
             $returnObject->setMessage($message);
             $recipients = (string) $responseBody->recipients;
             $returnObject->setRecipients(explode(",", $recipients));
             $theFiles = array();
             $filesTag = $responseBody->file;
             if (!empty($filesTag)) {
                 foreach ($responseBody->file as $currentFile) {
                     if ($currentFile->count() > 0) {
                         $file = new File();
                         $file->setDownloadUrl((string) $currentFile->downloadUrl);
                         $file->setDownloads((string) $currentFile->downloads);
                         $file->setId((string) $currentFile->id);
                         $file->setName((string) $currentFile->name);
                         $file->setPasswordProtect((string) $currentFile->passwordProtect);
                         $file->setReturnReceipt((string) $currentFile->returnReceipt);
                         $file->setSize((string) $currentFile->size);
                         $file->setVerifyIdentity((string) $currentFile->verifyIdentity);
                         $tracking = array();
                         $trackTag = $currentFile->tracking;
                         if (!empty($trackTag)) {
                             foreach ($currentFile->tracking as $currentTrack) {
                                 if ($currentTrack->count() > 0) {
                                     $track = new Tracking();
                                     $track->setEmail((string) $currentTrack->email);
                                     $track->setWhen((string) $currentTrack->when);
                                     array_push($tracking, $track);
                                 }
                             }
                             $file->setTracking($tracking);
                         }
                         array_push($theFiles, $file);
                     }
                 }
                 $returnObject->setFiles($theFiles);
             }
         } else {
             $errorCode = (string) $responseBody->errorStatus->code;
             $errorMessage = (string) $responseBody->errorStatus->message;
             $errorObject = new ErrorStatus($errorCode, $errorMessage);
             $returnObject->setErrorStatus($errorObject);
         }
     }
     return $returnObject;
 }
 /**
  * handleFileVersionUpload
  * @author Thomas Schedler <*****@*****.**>
  */
 private function handleFileVersionUpload()
 {
     $this->core->logger->debug('media->controllers->UploadController->handleFileVersionUpload()');
     $objFile = new File();
     $objFile->setUpload($this->objUpload);
     $objFile->setId($this->intFileId);
     $objFile->setSegmenting($this->core->sysConfig->upload->documents->segmenting->enabled == 'true' ? true : false);
     $objFile->setNumberOfSegments($this->core->sysConfig->upload->documents->segmenting->number_of_segments);
     $objFile->setUploadPath(GLOBAL_ROOT_PATH . $this->core->sysConfig->upload->documents->path->local->private);
     $objFile->setPublicFilePath(GLOBAL_ROOT_PATH . $this->core->sysConfig->upload->documents->path->local->public);
     $objFile->setLanguageId($this->intLanguageId);
     $objFile->addVersion(self::UPLOAD_FIELD);
 }