/** * Insert a new row * @param Garp_Model $model * @param Array $data Collection of data * @param Array $mapping Collection of column names * @return Mixed primary key */ protected function _insert(Garp_Model $model, array $data, array $mapping) { $newData = array(); // Remove unused mappings $mapping = array_filter($mapping); foreach ($mapping as $key => $val) { $newData[$val] = $data[$key]; } return $model->insert($newData); }
/** * Create new record * * @param array $data The new record's data as key => value pairs. * @return mixed The primary key of the new record */ public function create(array $data) { $this->_checkAcl('create'); $pk = $this->_model->insert($data); return $pk; }
/** * Insert a new row * @param Garp_Model $model * @param Array $cellData Collection of data * @param Array $mapping Collection of column names * @return Mixed primary key */ protected function _insert(Garp_Model $model, array $cellData, array $mapping) { if (count($cellData) !== count($mapping)) { throw new Exception("Cannot create rowdata from these keys and values.\nKeys:" . implode(', ', $mapping) . "\n" . "Values:" . implode(', ', $cellData)); } $data = array_combine($mapping, $cellData); // ignored columns have an empty key unset($data['']); return $model->insert($data); }