Ejemplo n.º 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));
 }
Ejemplo n.º 2
0
 public function DeleteDataSetColumn()
 {
     // Check the token
     if (!Kit::CheckToken()) {
         trigger_error('Token does not match', E_USER_ERROR);
     }
     $db =& $this->db;
     $user =& $this->user;
     $response = new ResponseManager();
     $dataSetId = Kit::GetParam('datasetid', _POST, _INT);
     $dataSet = Kit::GetParam('dataset', _POST, _STRING);
     $auth = $this->user->DataSetAuth($dataSetId, true);
     if (!$auth->edit) {
         trigger_error(__('Access Denied'));
     }
     $dataSetColumnId = Kit::GetParam('datasetcolumnid', _POST, _INT);
     $dataSetObject = new DataSetColumn($db);
     if (!$dataSetObject->Delete($dataSetColumnId)) {
         trigger_error($dataSetObject->GetErrorMessage(), E_USER_ERROR);
     }
     $response->SetFormSubmitResponse(__('Column Deleted'));
     $response->hideMessage = true;
     $response->loadForm = true;
     $response->loadFormUri = 'index.php?p=dataset&q=DataSetColumnsForm&datasetid=' . $dataSetId . '&dataset=' . $dataSet;
     $response->Respond();
 }
Ejemplo n.º 3
0
 /**
  * Delete DataSet
  * @param <type> $dataSetId
  */
 public function Delete($dataSetId)
 {
     try {
         $dbh = PDOConnect::init();
         // Delete the Data
         $data = new DataSetData();
         $data->DeleteAll($dataSetId);
         // Delete security
         $security = new DataSetGroupSecurity($this->db);
         $security->UnlinkAll($dataSetId);
         // Delete columns
         $dataSetObject = new DataSetColumn($this->db);
         if (!$dataSetObject->DeleteAll($dataSetId)) {
             return $this->SetError(25005, __('Cannot delete dataset, columns could not be deleted.'));
         }
         // Delete data set
         $sth = $dbh->prepare('DELETE FROM dataset WHERE DataSetID = :datasetid');
         $sth->execute(array('datasetid' => $dataSetId));
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25005, sprintf(__('Cannot edit dataset %s'), $dataSet));
         }
         return false;
     }
 }
Ejemplo n.º 4
0
 /**
  * Delete DataSet
  * @param <type> $dataSetId
  */
 public function Delete($dataSetId)
 {
     try {
         $dbh = PDOConnect::init();
         // First check to see if we have any data
         $sth = $dbh->prepare('SELECT * FROM `datasetdata` INNER JOIN `datasetcolumn` ON datasetcolumn.DataSetColumnID = datasetdata.DataSetColumnID WHERE datasetcolumn.DataSetID = :datasetid');
         $sth->execute(array('datasetid' => $dataSetId));
         if ($row = $sth->fetch()) {
             return $this->SetError(25005, __('There is data assigned to this data set, cannot delete.'));
         }
         // Delete security
         Kit::ClassLoader('datasetgroupsecurity');
         $security = new DataSetGroupSecurity($this->db);
         $security->UnlinkAll($dataSetId);
         // Delete columns
         $dataSetObject = new DataSetColumn($this->db);
         if (!$dataSetObject->DeleteAll($dataSetId)) {
             return $this->SetError(25005, __('Cannot delete dataset, columns could not be deleted.'));
         }
         // Delete data set
         $sth = $dbh->prepare('DELETE FROM dataset WHERE DataSetID = :datasetid');
         $sth->execute(array('datasetid' => $dataSetId));
         return true;
     } catch (Exception $e) {
         Debug::LogEntry('error', $e->getMessage());
         if (!$this->IsError()) {
             $this->SetError(25005, sprintf(__('Cannot edit dataset %s'), $dataSet));
         }
         return false;
     }
 }