Example #1
0
 /**
  * DataSet Import CSV
  * @return <XiboAPIResponse>
  */
 public function DataSetImportCsv()
 {
     // Auth
     if (!$this->user->PageAuth('dataset')) {
         return $this->Error(1, 'Access Denied');
     }
     $dataSetId = $this->GetParam('dataSetId', _INT);
     $auth = $this->user->DataSetAuth($dataSetId, true);
     if (!$auth->edit) {
         return $this->Error(1, 'Access Denied');
     }
     // Expect a file id
     $fileId = $this->GetParam('fileId', _INT);
     if (!$this->user->FileAuth($fileId)) {
         return $this->Error(1, 'Access Denied');
     }
     $file = new File();
     if (!($csvFileLocation = $file->GetPath($fileId))) {
         return $this->Error($file->GetErrorNumber(), $file->GetErrorMessage());
     }
     // Other parameters
     // Filter using HTML string because _STRING strips some of the JSON characters.
     $spreadSheetMapping = $this->GetParam('spreadSheetMapping', _HTMLSTRING);
     $overwrite = $this->GetParam('overwrite', _INT);
     $ignoreFirstRow = $this->GetParam('ignoreFirstRow', _INT);
     // Convert the spread sheet mapping into an Array
     $spreadSheetMapping = json_decode($spreadSheetMapping, true);
     // Check that the columns match the columns for this dataset
     $dataSetColumnObject = new DataSetColumn();
     // Make an array with the datasetcolumnid as the key
     $columns = array();
     foreach ($dataSetColumnObject->GetColumns($dataSetId) as $col) {
         $columns[$col['datasetcolumnid']] = true;
     }
     // Look through each column we have been provided and see if it matches
     foreach ($spreadSheetMapping as $key => $value) {
         if (!array_key_exists($value, $columns)) {
             return $this->Error(1000, __('The column mappings you have provided are invalid. Please ensure you have the correct DataSetColumnIDs.'));
         }
     }
     $dataSetObject = new DataSetData();
     if (!$dataSetObject->ImportCsv($dataSetId, $csvFileLocation, $spreadSheetMapping, $overwrite == 1, $ignoreFirstRow == 1)) {
         return $this->Error($dataSetObject->GetErrorNumber(), $dataSetObject->GetErrorMessage());
     }
     return $this->Respond($this->ReturnId('success', true));
 }
Example #2
0
 /**
  * Media File Upload
  * Upload a media file in parts
  * @return <XiboAPIResponse>
  */
 public function LibraryMediaFileUpload()
 {
     // Does this user have permission to call this webservice method?
     if (!$this->user->PageAuth('media')) {
         return $this->Error(1, 'Access Denied');
     }
     Kit::ClassLoader('file');
     $file = new File($this->db);
     $fileId = $this->GetParam('fileId', _INT);
     $checkSum = $this->GetParam('checksum', _STRING);
     $payload = $this->GetParam('payload', _STRING);
     $payloadMd5 = md5($payload);
     // Checksum the payload
     if ($payloadMd5 != $checkSum) {
         // Debug::LogEntry('audit', 'Sent Checksum: ' . $checkSum, 'RestXml', 'LibraryMediaFileUpload');
         // Debug::LogEntry('audit', 'Calculated Checksum: ' . $payloadMd5, 'RestXml', 'LibraryMediaFileUpload');
         // Debug::LogEntry('audit', 'Payload: ' . $payload, 'RestXml', 'LibraryMediaFileUpload');
         return $this->Error(2);
     }
     // Payload will be encoded in base64. Need to decode before handing to File class
     $payload = base64_decode($payload);
     if ($fileId == 0) {
         // New upload. All users have permissions to upload files if they have gotten this far
         if (!($fileId = $file->NewFile($payload, $this->user->userid))) {
             return $this->Error($file->GetErrorNumber());
         }
     } else {
         // Check permissions
         if (!$this->user->FileAuth($fileId)) {
             return $this->Error(1, 'Access Denied');
         }
         // Continue upload
         if (!$file->Append($fileId, $payload)) {
             return $this->Error($file->GetErrorNumber());
         }
     }
     // Current offset
     $size = $file->Size($fileId);
     // Return the fileId
     return $this->Respond($this->ReturnAttributes('file', array('id' => $fileId, 'offset' => $size)));
 }