Example #1
0
 /**
  * Additional get data with clear mode
  *
  * @param string $key
  * @param bool $clear
  * @return mixed
  */
 public function getData($key = '', $clear = false)
 {
     $data = parent::getData($key);
     if ($clear && isset($this->_data[$key])) {
         unset($this->_data[$key]);
     }
     return $data;
 }
Example #2
0
 /**
  * Prepare the object data for saving to the database
  * If $table is null, the main table is used and the fields are identified 
  *
  * @param Core_Model_Abstract $object
  * @param bool $graceful
  * @param string $table
  * @return type 
  */
 protected function _prepareDataForSave(Core_Model_Abstract $object, $graceful = false, $table = false)
 {
     $data = array();
     $table = !$table ? $this->getMainTable() : $table;
     $fields = $this->_getWriteAdapter()->describeTable($table);
     foreach ($fields as $field => $fieldInfo) {
         if (!$object->hasData($field) && $fieldInfo['Null'] == 'NO') {
             if (isset($fieldInfo['Default'])) {
                 continue;
             }
             if (isset($fieldInfo['Key']) && $fieldInfo['Key'] == 'PRI') {
                 continue;
             }
             //@# ToDO add the check to auto increment here if needed
         }
         if ($object->hasData($field)) {
             $data[$field] = $this->_prepareValueForSave($object->getData($field), $fieldInfo['data_type']);
         } else {
             if ($fieldInfo['Null'] == 'NO' && !isset($fieldInfo['Default']) && $graceful) {
                 //set empty string for those field which does not have default value and is nullable
                 $data[$field] = $this->_prepareValueForSave('');
             } else {
                 continue;
             }
         }
     }
     return $data;
 }