/** * @return string */ public function get($field, $default = NULL) { $data = $this->_row->toArray(); if (array_key_exists($field, $data)) { return $data[$field]; } else { return $default; } }
/** * Get the default form values */ protected function _getDefaultFormValues() { $return = array(); if ($this->_item !== null) { $return = $this->_item->toArray(); } return $return; }
public function process(array $post, Zend_Db_Table_Row $row) { $this->setDefaults($row->toArray()); // if (sizeof($post) && $this->isValid($post)) { try { $row->setFromArray($this->getValues()); $row->save(); return true; } catch (Exception $e) { $this->addDescription('There was an error saving your details'); return $this; } } return $this; }
/** * Seta o form como de edição de registro * * A diferença entre o form de cadastro e edição é que o no form de edição * não se deve comparar o ID do usuário na hora de procurar por um nome * ou email existentes na base de dados. * Por isso, adicionamos a option 'exclude' do validator * Zend_Validate_Db_NoRecordExists passando o campo ID e o valor do usuário * que está sendo editado para ser utilizado na clausua where da query, * buscando apenas registros cujo id seja diferente do id do usuário * * @param Zend_Db_Table_Row $row * @return Application_Form_User */ public function setAsEditForm(Zend_Db_Table_Row $row) { $this->populate($row->toArray()); $this->setAction(sprintf('/users/edit/id/%d', $row->id)); $this->getElement('name') ->getValidator('Db_NoRecordExists') ->setExclude(array( 'field' => 'id', 'value' => $row->id )); $this->getElement('email') ->getValidator('Db_NoRecordExists') ->setExclude(array( 'field' => 'id', 'value' => $row->id )); return $this; }
/** * Factory method to turn one * database row into an * instantiated object * @param Zend_Db_Table_Row $item * @return mixed */ public function factoryItem(Zend_Db_Table_Row $item) { $arr_data = $item->toArray(); $object = new $this->model_class($arr_data); return $object; }
/** * Persists the intal Fields to the primary table row. * * @return string The id of the primary table row is returned. */ protected function _storeInternalFields() { try { // Store basic simple fields to complete the table row foreach ($this->_fields as $fieldname => $field) { // Skip external fields. if (isset($this->_externalFields[$fieldname])) { continue; } // map field values: Cannot process array-valued fields $fieldValue = $field->getValue(); // Check if the store mechanism for the field is overwritten in model. $callname = '_store' . $fieldname; if (method_exists($this, $callname) === true) { // Call custom store method $this->{$callname}($fieldValue); } else { if ($field->isModified() === false) { // Skip non-modified field. continue; } else { $colname = self::convertFieldnameToColumn($fieldname); $this->_primaryTableRow->{$colname} = $fieldValue; } } // Clear modification status of successfully stored field. $field->clearModified(); } // Backing up values to check for truncated fields after save(). $backupValues = $this->_primaryTableRow->toArray(); // Save the row. // This returnes the id needed to store external fields. $id = $this->_primaryTableRow->save(); // Hack to check truncated fields. (See ticket OPUSVIER-2111) // TODO: Better use MySQL strict mode "STRICT_TRANS_TABLES". foreach ($this->_primaryTableRow->toArray() as $key => $new_value) { // skip id-field if ($key === 'id') { continue; } // if field was empty/too short before storing, skip it! if (!isset($backupValues[$key]) || strlen($backupValues[$key]) <= 4) { continue; } if (strlen($backupValues[$key]) > strlen($new_value)) { $truncateLength = strlen($backupValues[$key]) - strlen($new_value); $msg = get_class($this); $msg .= ": Database column '{$key}' has been truncated"; $msg .= " by {$truncateLength} characters!"; throw new Opus_Model_DbTruncateException(get_class($this) . ": {$msg}"); } } } catch (Zend_Db_Statement_Exception $ze) { if ($ze->getChainedException() instanceof PDOException and $ze->getCode() === 23000) { throw new Opus_Model_DbConstrainViolationException($ze->getMessage(), $ze->getCode(), $ze); } throw new Opus_Model_DbException($ze->getMessage(), $ze->getCode(), $ze); } catch (Opus_Model_Exception $ome) { // Needed to let instances of Opus_Model_Exception pass without // modifying their type. throw $ome; } catch (Exception $e) { $msg = $e->getMessage() . ' Model: ' . get_class($this); // this works with php >= 5.3.0: throw new Opus_Model_Exception($msg, $e->getCode(), $e); // workaround: $msg .= "\nThrown in " . $e->getFile() . ':' . $e->getLine(); throw new Opus_Model_Exception($msg); } return $id; }
/** * * @param Zend_Db_Table_Row $row */ protected function _saveTransactionAuditing($row) { $description = 'FEFOP - SALVA LANSAMENTU FINANSEIRO: %s'; $description = sprintf($description, print_r($row->toArray(), true)); $this->_sysAudit($description); }