Example #1
0
 /**
  * @author thientd
  */
 public function beforeSave($options = array())
 {
     $result = parent::beforeSave($options);
     if ($result) {
         $exists = $this->exists();
         $dateFields = array('modifier');
         if (!$exists) {
             $dateFields[] = 'creator';
         }
         $fields = array();
         if (isset($this->data[$this->alias])) {
             $fields = array_keys($this->data[$this->alias]);
         }
         $username = $this->__getLoginName();
         foreach ($dateFields as $updateCol) {
             if (in_array($updateCol, $fields) || !$this->hasField($updateCol)) {
                 continue;
             }
             if (!empty($this->whitelist)) {
                 $this->whitelist[] = $updateCol;
             }
             $this->set($updateCol, $username);
         }
     }
     return $result;
 }
Example #2
0
 public function beforeSave()
 {
     parent::beforeSave();
     App::import('Controller', 'App');
     $appController = new AppController();
     ///===> String To Slug
     /// A variável transformUrl deve ser colocada na Model
     if (!empty($this->transformUrl)) {
         foreach ($this->transformUrl as $key => $value) {
             //echo $key ." => ". $value ."<br>";
             $url_amigavel = $appController->stringToSlug($this->data[$this->alias][$value]);
             $this->data[$this->alias][$key] = $url_amigavel;
         }
     }
     ///===> Salvando Imagens, caso existam
     if (!empty($this->type_files)) {
         foreach ($this->type_files as $key => $value) {
             //echo $campo ." => ". $parametros ."<br>";
             if (!empty($this->data[$this->alias][$key . '_nome_imagem'])) {
                 $this->data[$this->alias][$key] = $this->data[$this->alias][$key . '_nome_imagem'];
                 $this->data[$this->alias][$key . '_th_hidden'] = $appController->thumbPath($this->data[$this->alias][$key . '_nome_imagem']);
             }
         }
     }
     return true;
 }
Example #3
0
 /**
  * standard beforeSave() callback
  * Save string IPs as longs
  *
  * @param array $options
  * @return true
  */
 public function beforeSave($options = array())
 {
     foreach ($this->fieldsToLong as $field) {
         if (isset($this->data[$this->alias][$field]) && !is_numeric($this->data[$this->alias][$field])) {
             $this->data[$this->alias][$field] = ip2long($this->data[$this->alias][$field]);
         }
     }
     return parent::beforeSave($options);
 }
Example #4
0
 public function beforeSave($options = array())
 {
     parent::beforeSave($options);
     $formatted = $this->formatDateFields($this->data, $this->datesToSave, "%Y-%m-%d");
     if (isset($formatted[0])) {
         $this->data[$this->alias] = array_replace($this->data[$this->alias], $formatted[0][$this->alias]);
     }
     $this->data = Sanitize::clean($this->data);
     return true;
 }
 public function beforeSave()
 {
     /*if ($this->isNewRecord) {
     			//do nothing
     		}
     	   	else {
     			$this->update_time = new CDbExpression('NOW()');
     		}*/
     $this->update_time = new CDbExpression('NOW()');
     return parent::beforeSave();
 }
 public function beforeSave($options = array())
 {
     if (!empty($_SESSION['ProxyAuth']['realUser'])) {
         //check if user is proxied for logging purposes
         //need to log....
         $proxyUser = $_SESSION['Auth']['User'];
         $realUser = $_SESSION['ProxyAuth']['realUser'];
         $logString = json_encode(array('proxyUser' => $proxyUser, 'realUser' => $realUser, 'accessedPage' => $this->name, 'requestData' => $this->data));
         $this->log($logString, 'proxy');
     }
     return parent::beforeSave($options);
 }
Example #7
0
 public function beforeSave($options = array())
 {
     parent::beforeSave($options);
     $schema = $this->schema();
     $class = get_class($this);
     if (isset($this->data[$class])) {
         $this->data[$class] = $this->addTimeToData($this->data[$class]);
     }
     if (isset($this->data[$class])) {
         $this->data[$class] = $this->addLoggedUserToData($this->data[$class]);
     }
 }
Example #8
0
 public function beforeSave($options = array())
 {
     $parent = parent::beforeSave($options);
     if (empty($this->data[$this->alias]['name'])) {
         return $parent;
     }
     $name = $this->data[$this->alias]['name'];
     $name_slug = strtolower(Inflector::slug($name));
     $name_variable = Inflector::variable($name_slug);
     $this->data[$this->alias] += compact('name_variable', 'name_slug');
     return $parent;
 }
Example #9
0
 /**
  * beforeSave
  *
  * @return	boolean
  * @access	public
  */
 public function beforeSave($options = array())
 {
     $result = parent::beforeSave($options);
     // 日付フィールドが空の場合、nullを保存する
     foreach ($this->_schema as $key => $field) {
         if (('date' == $field['type'] || 'datetime' == $field['type'] || 'time' == $field['type']) && isset($this->data[$this->name][$key])) {
             if ($this->data[$this->name][$key] == '') {
                 $this->data[$this->name][$key] = null;
             }
         }
     }
     return $result;
 }
 public function beforeSave()
 {
     if ($this->isNewRecord) {
         $this->create_time = new CDbExpression('NOW()');
         $this->update_time = new CDbExpression('NOW()');
         $this->create_by = Yii::app()->user->id;
         $this->update_by = Yii::app()->user->id;
     } else {
         $this->update_time = new CDbExpression('NOW()');
         $this->update_by = Yii::app()->user->id;
     }
     return parent::beforeSave();
 }
Example #11
0
 protected function beforeSave()
 {
     $passwordDiffers = true;
     /**
      * If existing user, check password
      */
     if (!$this->getIsNewRecord()) {
         if (isset($this->oldAttributes['password']) && strcmp($this->oldAttributes['password'], $this->password) == 0) {
             $passwordDiffers = false;
         }
     }
     if ($passwordDiffers && !empty($this->password)) {
         $this->password = $this->hashPassword($this->password);
     } elseif (!empty($this->oldAttributes['password'])) {
         $this->password = $this->oldAttributes['password'];
     }
     return parent::beforeSave();
 }
Example #12
0
 /**
  * beforeSave if a file is found, upload it, and then save the filename according to the settings
  *
  */
 function beforeSave(Model $Model, $options = array())
 {
     if (isset($Model->data[$Model->alias][$this->options[$Model->alias]['fileVar']])) {
         $file = $Model->data[$Model->alias][$this->options[$Model->alias]['fileVar']];
         $this->Uploader[$Model->alias]->file = $file;
         if ($this->Uploader[$Model->alias]->hasUpload()) {
             $fileName = $this->Uploader[$Model->alias]->processFile();
             if ($fileName) {
                 $Model->data[$Model->alias][$this->options[$Model->alias]['fields']['name']] = $fileName;
                 $Model->data[$Model->alias][$this->options[$Model->alias]['fields']['size']] = $file['size'];
                 $Model->data[$Model->alias][$this->options[$Model->alias]['fields']['type']] = $file['type'];
             } else {
                 return false;
                 // we couldn't save the file, return false
             }
             unset($Model->data[$Model->alias][$this->options[$Model->alias]['fileVar']]);
         } else {
             unset($Model->data[$Model->alias]);
         }
     }
     return $Model->beforeSave();
 }
Example #13
0
 /**
  * Выполняет действия перед сохранением записи
  */
 public function beforeSave()
 {
     parent::beforeSave();
 }
Example #14
0
 function beforeSave($options = array())
 {
     parent::beforeSave($options);
     return true;
 }
Example #15
0
 /**
  * @brief Called before each save operation, after validation. Return a non-true result
  * to halt the save.
  *
  * @link http://api13.cakephp.org/class/model#method-ModelbeforeSave
  *
  * @param $created True if this save created a new record
  * @access public
  *
  * @return boolean True if the operation should continue, false if it should abort
  */
 public function beforeSave($options = array())
 {
     return parent::beforeSave($options);
 }
Example #16
0
 /**
  * beforeSave
  *
  * @return	boolean
  * @access	public
  */
 function beforeSave($options)
 {
     $result = parent::beforeSave($options);
     // 日付フィールドが空の場合、nullを保存する
     foreach ($this->_schema as $key => $field) {
         if (('date' == $field['type'] || 'datetime' == $field['type'] || 'time' == $field['type']) && isset($this->data[$this->name][$key])) {
             if ($this->data[$this->name][$key] == '') {
                 $this->data[$this->name][$key] = null;
             }
         }
     }
     /* 内部文字コードをデータベース文字コードに変換 */
     // MySQL4.0 以下で動作
     if ($this->driver == 'mysql' && mysql_get_server_info() <= 4.0) {
         $this->data = $this->convertEncodingByArray($this->data, Configure::read('Config.dbCharset'), mb_internal_encoding());
     }
     return $result;
 }
Example #17
0
 /**
  * Before saving the data, try uploading the image, if successful save to database.
  *
  * @access public
  * @param Model $model
  * @return mixed
  */
 public function beforeSave(Model $model)
 {
     $model->beforeSave();
     //$this->_attachments[$model->alias]->beforeSave();
     if (empty($model->data[$model->alias])) {
         return true;
     }
     foreach ($model->data[$model->alias] as $field => $file) {
         if (empty($this->_attachments[$model->alias][$field])) {
             continue;
         }
         //debug($model->actsAs['Uploader.Attachment']['file']['uploadDir']);exit;
         $attachment = $this->_attachments[$model->alias][$field];
         $attachment['uploadDir'] = $model->actsAs['Uploader.Attachment']['file']['uploadDir'];
         $data = array();
         //debug($attachment);exit;
         // Not a form upload, so lets treat it as an import
         if (is_string($file) && !empty($file)) {
             $attachment['importFrom'] = $file;
         }
         //debug($attachment);exit;
         // Should we continue if a file threw errors during upload?
         if (empty($file['tmp_name']) || isset($file['error']) && $file['error'] == UPLOAD_ERR_NO_FILE || is_string($file) && empty($attachment['importFrom'])) {
             if ($attachment['stopSave'] && !$attachment['allowEmpty']) {
                 return false;
             } else {
                 if ($attachment['allowEmpty']) {
                     if (empty($attachment['defaultPath'])) {
                         unset($model->data[$model->alias][$attachment['dbColumn']]);
                     } else {
                         $model->data[$model->alias][$attachment['dbColumn']] = $attachment['defaultPath'];
                     }
                     continue;
                 }
             }
         }
         // Save model method for formatting function
         if (!empty($attachment['name']) && method_exists($model, $attachment['name'])) {
             $attachment['name'] = array($model, $attachment['name']);
         }
         // Setup instances
         $this->uploader->setup($attachment);
         $this->s3 = $this->s3($attachment['s3']);
         // Upload or import the file and attach to model data
         $uploadResponse = $this->upload($file, $attachment, array('overwrite' => $attachment['overwrite'], 'name' => $attachment['name'], 'append' => $attachment['append'], 'prepend' => $attachment['prepend']));
         if (empty($uploadResponse)) {
             return $model->invalidate($field, __d('uploader', 'There was an error uploading this file, please try again.'));
         }
         $basePath = $this->transfer($uploadResponse['path']);
         $data[$attachment['dbColumn']] = $attachment['saveAsFilename'] && $this->s3 === null ? basename($basePath) : $basePath;
         $toDelete = array();
         $lastPath = $basePath;
         // Apply image transformations
         if (!empty($attachment['transforms'])) {
             foreach ($attachment['transforms'] as $options) {
                 $method = $options['method'];
                 if (!method_exists($this->uploader, $method)) {
                     trigger_error(sprintf('Uploader.Attachment::beforeSave(): "%s" is not a defined transformation method.', $method), E_USER_WARNING);
                     return false;
                 }
                 $transformResponse = $this->uploader->{$method}($options);
                 // Rollback uploaded files if one fails
                 if (empty($transformResponse)) {
                     foreach ($data as $path) {
                         $this->delete($path);
                     }
                     return $model->invalidate($field, __d('uploader', 'An error occured during image %s transformation.', $method));
                 }
                 // Transform successful
                 $transformPath = $this->transfer($transformResponse);
                 $data[$options['dbColumn']] = $attachment['saveAsFilename'] && $this->s3 === null ? basename($transformPath) : $transformPath;
                 // Delete original if same column name and transform name are not the same file
                 if ($options['dbColumn'] == $attachment['dbColumn'] && $lastPath != $transformPath) {
                     $toDelete[] = $lastPath;
                 }
                 $lastPath = $transformPath;
             }
         }
         // Delete old files if replacing them
         if ($toDelete) {
             foreach ($toDelete as $deleteFile) {
                 $this->delete($deleteFile);
             }
         }
         // Apply meta columns
         if (!empty($attachment['metaColumns'])) {
             foreach ($attachment['metaColumns'] as $field => $column) {
                 if (isset($uploadResponse[$field]) && !empty($column)) {
                     $data[$column] = $uploadResponse[$field];
                 }
             }
         }
         // Reset S3 and delete original files
         if ($this->s3 !== null) {
             foreach ($this->s3->uploads as $path) {
                 $this->delete($path);
             }
             $this->s3 = null;
         }
         // Merge upload data with model data
         $model->data[$model->alias] = $data + $model->data[$model->alias];
     }
     return true;
 }
Example #18
0
 /**
  * Manipulate data before it is saved.
  *
  * @todo    Move this record level access stuff to a behavior
  */
 public function beforeSave($options = array())
 {
     // Start Record Level Access Save
     // If the model needs Record Level Access add an Aco
     if (!empty($this->data['RecordLevelAccess']['UserRole'])) {
         // There may be a potential problem with this.
         // It saves an ArosAco record for every record being created.
         // For example, when creating a webpage, it also creates an Aco for the Alias
         // Left it in as is, because we may want this.  (ie. when a contact is record level,
         // we probably want the user to have access to the Contact and Contact Person
         // if a project issue is created, we probably want the user to have access to the project too.
         $this->Behaviors->attach('Acl', array('type' => 'controlled'));
         $this->Behaviors->attach('AclExtra', $this->data);
     } else {
         if (defined('__APP_RECORD_LEVEL_ACCESS_ENTITIES')) {
             if ($this->data['RecordLevelAccess'] = $this->_isRecordLevelRecord(__APP_RECORD_LEVEL_ACCESS_ENTITIES)) {
                 $this->Behaviors->attach('Acl', array('type' => 'controlled'));
                 $this->Behaviors->attach('AclExtra', $this->data);
             }
         }
     }
     // Start Auto Creator & Modifier Id Saving #
     $exists = $this->exists();
     $user = class_exists('CakeSession') ? CakeSession::read('Auth.User') : null;
     if (!$exists && $this->hasField('creator_id') && empty($this->data[$this->alias]['creator_id'])) {
         $this->data[$this->alias]['creator_id'] = $user['id'];
     }
     if ($this->hasField('modifier_id') && empty($this->data[$this->alias]['modifier_id'])) {
         $this->data[$this->alias]['modifier_id'] = $user['id'];
     }
     // End Auto Creator & Modifier Id Saving
     // you have to return true to make the save continue.
     return parent::beforeSave($options);
 }
Example #19
0
 /**
  * beforeSave method
  *
  * @var array
  */
 public function beforeSave($options = array())
 {
     $this->removeSpace();
     parent::beforeSave($options);
 }
Example #20
0
 /**
  * Called before each save operation, after validation. Return a non-true result
  * to halt the save.
  *
  * This method is being used for processing of the `_auditdate` field (when present).
  *
  * @param array $options Options passed from Model::save().
  * @return bool True if the operation should continue, false if it should abort
  * @link http://book.cakephp.org/2.0/en/models/callback-methods.html#beforesave
  * @see Model::save()
  */
 public function beforeSave($options = array())
 {
     $parentReturn = parent::beforeSave($options);
     if ($parentReturn && $this->hasField('_auditdate')) {
         $this->data[$this->alias]['_auditdate'] = date('Y-m-d H:i:s');
     }
     return true;
 }
Example #21
0
 /**
  * Hrki se bori protiv ovog frameworka :D
  * 
  * @param type $options
  * @return type
  */
 public function beforeSave($options = array())
 {
     // it's an insert, so add `created`
     if (empty($this->data[$this->alias][$this->primaryKey])) {
         $this->data[$this->alias]['creation_date'] = $this->getDataSource()->expression('NOW()');
     }
     // modified is set anyway
     $this->data[$this->alias]['modified_date'] = $this->getDataSource()->expression('NOW()');
     return parent::beforeSave($options);
 }