Example #1
0
 /**
  * @param  array $data
  * @throws Exception
  */
 protected function deleteData($data)
 {
     if (!$this->isValidRequest('table')) {
         throw new Exception('Not valid request');
     }
     $session = new SessionNamespace($this->resource);
     if ($_SERVER['REQUEST_METHOD'] !== 'DELETE') {
         throw new Exception('Invalid request method, need DELETE');
     } elseif (empty($data['id_rows']) || !is_array($data['id_rows'])) {
         throw new Exception('Records id not valid');
     } elseif (empty($session->db) || empty($session->db->table)) {
         throw new Exception('No set table');
     } elseif (empty($session->access) || empty($session->access->delete) || !$session->access->delete) {
         throw new Exception('Access denied');
     }
     $table = $session->db->table;
     $primary_key = !empty($session->db->primary_id) ? $session->db->primary_id : 'id';
     $primary_key = $this->db->quoteIdentifier($primary_key);
     $where = $this->db->quoteInto("{$primary_key} IN(?)", $data['id_rows']);
     $is_delete = $this->db->delete($table, $where);
     if (!$is_delete) {
         throw new Exception('Error delete data');
     }
 }