/** * Delete Record * NOTE: use redirectpage attr of eventhandler to redirect or redirect to previous page by default * * @param string $id * @return void */ public function deleteRecord($id = null) { if ($this->m_Resource != "" && !$this->allowAccess($this->m_Resource . ".delete")) { return BizSystem::clientProxy()->redirectView(ACCESS_DENIED_VIEW); } if ($id == null || $id == '') { $id = BizSystem::clientProxy()->getFormInputs('_selectedId'); } $selIds = BizSystem::clientProxy()->getFormInputs('row_selections', false); if ($selIds == null) { $selIds[] = $id; } foreach ($selIds as $id) { $recArray = $this->getDataObj()->fetchById($id); $this->getDataObj()->setActiveRecord($recArray); $dataRec = new DataRecord($recArray, $this->getDataObj()); // take care of exception try { $dataRec->delete(); } catch (BDOException $e) { // call $this->processBDOException($e); $this->processBDOException($e); return; } } if ($this->m_FormType == "LIST") { $this->rerender(); } $this->runEventLog(); $this->processPostAction(); }
/** * BizForm::deleteRecord() - Delete the record of current row * * @return void */ public function deleteRecord() { // TODO: support delete multiple records // read the id array from the check box list _REQUEST['row_selections'] global $g_BizSystem; $values = BizSystem::clientProxy()->getFormInputs('row_selections', false); if ($values) { foreach ($values as $id) { $recArray = $this->getDataObj()->fetchById($id); $dataRec = new DataRecord($recArray, $this->getDataObj()); // take care of exception try { $dataRec->delete(); } catch (BDOException $e) { // call $this->processBDOException($e); $this->processBDOException($e); return; } } } else { $rec = $this->getActiveRecord(); if (!$rec) { return; } global $g_BizSystem; //$recId = $this->m_ActiveRecord["Id"]; $ok = $this->getDataObj()->deleteRecord($rec); if (!$ok) { return $this->processDataObjError($ok); } } $this->m_RecordId = null; // clean the current record id // TODO: adjust current page. if current page return no record, goto prev page $this->rerender(); }
public function delete($resource, $id, $request, $response) { $DOName = $this->getDOName($resource); if (empty($DOName)) { $response->status(404); $response->body("Resource '{$resource}' is not found."); return; } $dataObj = BizSystem::getObject($DOName); $rec = $dataObj->fetchById($id); if (empty($rec)) { $response->status(404); $response->body("No data is found for {$resource} {$id}"); return; } $dataRec = new DataRecord($rec, $dataObj); try { $dataRec->delete(); } catch (BDOException $e) { $response->status(500); $response->body($e->getMessage()); return; } $format = strtolower($request->params('format')); return $this->setResponse($dataRec->toArray(), $response, $format); }