/** * Prepares the data, then fetch and encode to json * @return json */ protected function fillgridfinal() { $response = $this->grid->prepareResponse(); $result = $this->grid->fetchdata(); $pkey = $this->model->info('primary'); foreach ($result as $key => $row) { $gridTuplekey = null; foreach ($pkey as $num => $col) { $gridTuplekey[] = $row[$col]; } $response->rows[$key]['id'] = implode('__', $gridTuplekey); $response->rows[$key]['cell'] = array_values($row); } $this->_helper->json($response); }
public function insert(array $data) { if (isset($data['acc_no'])) { if (strchr($data['acc_no'], '-')) { $range = explode('-', $data['acc_no']); if (2 == count($range) and (string) $range[0] === (string) (int) $range[0] and (string) $range[1] === (string) (int) $range[1] and $range[0] <= $range[1]) { $cols = array(); $vals = array(); foreach ($data as $col => $val) { $cols[] = $this->getAdapter()->quoteIdentifier($col, true); for ($acc = $range[0]; $acc <= $range[1]; $acc++) { if ('acc_no' == $col) { $vals[$acc][] = $this->getAdapter()->quote($acc); } else { $vals[$acc][] = $val ? $this->getAdapter()->quote($val) : 'null'; } } } //build values statement $tmpVals = array(); foreach ($vals as $acc => $values) { $tmpVals[] = ' (' . implode(', ', $values) . ') '; } // build the statement $sql = "INSERT INTO " . $this->getAdapter()->quoteIdentifier(self::TABLE_NAME, true) . ' (' . implode(', ', $cols) . ') ' . 'VALUES ' . implode(', ', $tmpVals); // execute the statement and return the number of affected rows $stmt = $this->getAdapter()->query($sql); $result = $stmt->rowCount(); return $result; } else { throw new Zend_Db_Table_Exception('The range ' . $range[0] . ' - ' . $range[1] . ' is not acceptable.'); } } elseif ((string) $data['acc_no'] === (string) (int) $data['acc_no']) { return parent::insert($data); } else { throw new Zend_Db_Table_Exception("acc_no is not acceptable."); } } else { if ($this->debug) { throw new Zend_Db_Table_Exception('Books cannot be added without acc_no!!'); } } }
public function update($data, $where) { try { $status = parent::update($data, $where); } catch (Exception $e) { if (23000 == $e->getCode()) { $this->getLogger()->info('Duplicate ISBN found:' . $where); $this->getLogger()->notice('Dependent books are updated to new ISBN and current ISBN deleted'); try { $newData = array_intersect_key($data, array('isbn_id' => 0)); $status = $this->getAdapter()->update('book', $newData, $where); $this->delete($where); return $status; } catch (Exception $e) { throw $e; } } throw $e; } return $status; }