/** * 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; } }
/** * 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; } }