/** * (C)reate, (R)ead, (U)pdate, (D)elete function. * * All CRUD activities pass through this method. * @return mixed Status of Add/Update/Delete commands if successful else exception string with header status {@link $errorCode}. */ public function crudAction() { $request = $this->getRequest(); $status = NULL; $errorCode = 400; if ($request->isXmlHttpRequest() and $request->isPost()) { self::createDbCols(); switch ($request->getParam('oper')) { case 'add': $rdata = $request->getParams(); $data = self::paramData($rdata); try { $status = $this->model->insert($data); echo $status; } catch (Zend_Exception $e) { $this->_helper->logger->err($e->getMessage()); $this->_helper->logger->alert('Row insertion failure :'); $this->_helper->logger('Status = ' . $status); $this->_helper->logger->alert('Request Data :'); $this->_helper->logger($rdata); $this->_helper->logger->alert('Processed data :'); $this->_helper->logger($data); throw $e; } if ($status) { $this->_helper->logger->debug('Status :'); $this->_helper->logger($status); } return true; break; case 'del': $id = $request->getParam('id'); $where = self::whereData($id); try { $status = $this->model->delete($where); } catch (Zend_Exception $e) { $this->_helper->logger->err($e->getMessage()); $this->_helper->logger->err('Row deletion failure :'); $this->_helper->logger('Status = ' . $status); $this->_helper->logger->alert('WHERE clause :'); $this->_helper->logger($where); $this->getResponse()->setHttpResponseCode($errorCode); throw $e; } if ($status) { $this->_helper->logger->debug('Status :'); $this->_helper->logger($status); } return true; break; case 'edit': $rdata = $request->getParams(); $data = self::paramData($rdata); $id = $rdata['id']; $where = self::whereData($id); try { $status = $this->model->update($data, $where); } catch (Zend_Exception $e) { $this->_helper->logger->err($e->getMessage()); $this->_helper->logger->err('Row updation failure :'); $this->_helper->logger('Status = ' . $status); $this->getResponse()->setHttpResponseCode($errorCode); throw $e; } if ($status) { $this->_helper->logger->debug('Status :'); $this->_helper->logger($status); } return true; break; default: $this->_helper->logger->crit('The param "oper" has unexpected value :' . $request->getParam('oper')); return false; } } else { $this->_helper->logger->err('Criteria to access CRUD is not fullfilled'); header("HTTP/1.1 403 Forbidden"); die; } }