set() public méthode

Setter method, allows $model->set('property', 'value') access to data.
public set ( string | array $property, string | null $value = null ) : Model
$property string | array
$value string | null
Résultat Model
 /**
  * @param Model $model
  **/
 public function addParamsToModel(Model $model)
 {
     if ($this->version == '1.1') {
         $model->set('openid.ns.sreg', self::NAMESPACE_1_1);
     }
     $model->set('openid.sreg.optional', implode(',', $this->params));
 }
Exemple #2
0
 public function paginado(Model $objeto, $numeroRegistros = 0)
 {
     if (!isset($this->params["pg_pagina"])) {
         $objeto->set("pg_pagina", 1);
     } else {
         $objeto->set("pg_pagina", (int) $this->params["pg_pagina"]);
     }
     if ($numeroRegistros) {
         $objeto->set("pg_registros", $numeroRegistros);
     }
 }
Exemple #3
0
 private static function criterios($sql, Model $producao)
 {
     if (in_array(ControleSessao::$id_cargo, Constantes::$arrVerRegional)) {
         $sql .= " and pr.id_regional = :id_centro_custo_regional ";
         $producao->set('id_centro_custo_regional', ControleSessao::$id_centro_custo);
     } elseif (ControleSessao::$id_cargo == Constantes::$id_supervisor || ControleSessao::$id_cargo == Constantes::$id_assistente_operacional || ControleSessao::$id_cargo == Constantes::$id_estagiario) {
         $sql .= " and pr.id_base = :id_centro_custo_base ";
         $producao->set('id_centro_custo_base', ControleSessao::$id_centro_custo);
     } elseif (ControleSessao::$id_cargo == Constantes::$id_orientador) {
         $sql .= " and pr.id_orientador = :id_orientador ";
         $producao->set('id_orientador', ControleSessao::$id_usuario);
     }
     return $sql;
 }
Exemple #4
0
 public function verificarLogin()
 {
     $obj = new loginHelper();
     if ($obj->getDataSession("usuario_login") == null) {
         throw new Exception_Form("Você precisa efetuar o login novamente para continuar.");
     } else {
         $model = new Model();
         $model->open();
         $model->set("sql", "\n\t\t\t\t\tINSERT INTO `systemlog` \n\t\t\t\t\t\t(`method`, `url`, `dados`, `login`, `data`) \n\t\t\t\t\t\tVALUES \n\t\t\t\t\t\t(:method,:url,:dados,:login,now())\n\t\t\t\t");
         $model->set('params', array(":method" => $this->_method, ":url" => $_SERVER['REQUEST_URI'], ":dados" => implode(';', $this->_dados), ":login" => $obj->getDataSession("usuario_login")));
         $model->query();
         $model->close();
     }
 }
 public function test_set()
 {
     $model = new Model();
     $model->set(array('foo' => 200, 'bar' => 'test'));
     $this->assertEquals(200, $model->foo);
     $this->assertEquals('test', $model->bar);
 }
 function set($one, $two = null, $protectFields = true)
 {
     if ($protectFields) {
         if (!$one) {
             return;
         }
         if (is_object($one)) {
             $one = Set::reverse($one);
         }
         if (is_array($one)) {
             if (empty($one[$this->alias])) {
                 if ($this->getAssociated(key($one)) === null) {
                     $one = array($this->alias => $one);
                 }
             }
             foreach ($one as $alias => $data) {
                 if ($alias == $this->alias) {
                     $one[$alias] = $this->filterProtectedFields($data);
                 } else {
                     $associated = $this->getAssociated($alias);
                     if (!empty($associated)) {
                         $model = $associated['className'];
                         $one[$alias] = $this->{$model}->filterProtectedFields($data);
                     }
                 }
             }
         }
     }
     parent::set($one, $two);
 }
 public function set($k, $v)
 {
     switch ($k) {
         case 'file':
             $ret = parent::set($k, $v);
             // Clear out the cache
             $this->_file = null;
             // File was updated... load the exif data too!
             // Note, only do this if it was an image!
             $file = $this->getOriginalFile();
             if ($file->isImage() && $file->getExtension() == 'jpg') {
                 $this->_data['exifdata'] = json_encode(exif_read_data($file->getFilename()));
             } else {
                 $this->_data['exifdata'] = null;
             }
             // Also if the file is new and it didn't exist... set the uploader id.
             if (!$this->_exists) {
                 $this->_data['uploaderid'] = \Core\user()->get('id');
             }
             return $ret;
         case 'exifdata':
             // exif data cannot be changed externally!
             return false;
         default:
             return parent::set($k, $v);
     }
 }
 public function setLimit(Model $Model, $data = array())
 {
     if (!empty($data)) {
         $Model->set($data);
     }
     if (empty($Model->data[$Model->alias])) {
         return false;
     }
     $limitField = $this->settings[$Model->alias]['limitField'];
     if (!isset($Model->data[$Model->alias][$limitField])) {
         $billingPlanModel = new BillingPlan();
         $limitValue = $billingPlanModel->field($limitField, array('id' => $Model->data[$Model->alias]['plan_id']));
         $Model->data[$Model->alias][$limitField] = $limitValue;
     }
     $scope = $this->settings[$Model->alias]['scope'];
     $remoteModel = $this->settings[$Model->alias]['remoteModel'];
     App::import('Model', $remoteModel);
     $remoteModel = new $remoteModel();
     if (in_array($Model->data[$Model->alias]['user_id'], $this->ownersWhitelist)) {
         $Model->data[$Model->alias][$limitField] = 199999999999;
     }
     $result = $remoteModel->updateAll(array($remoteModel->alias . '.' . $this->settings[$Model->alias]['remoteField'] => $Model->data[$Model->alias][$limitField]), array($remoteModel->alias . '.' . $scope => $Model->data[$Model->alias]['user_id']));
     if ($result) {
         //hardcoded group members manipulation
         if ($remoteModel == 'GroupLimit') {
             $this->membersOperate($Model);
         }
         return true;
     }
     return false;
 }
 public function set($k, $v)
 {
     switch ($k) {
         case 'status':
             // Update the published date if it's status has changed.
             if ($v == $this->get($k)) {
                 return false;
             }
             if ($v == 'published' && !$this->get('published')) {
                 parent::set('published', Time::GetCurrentGMT());
             } elseif ($v == 'draft' && $this->get('published')) {
                 parent::set('published', '');
             }
             // And resume!
             return parent::set($k, $v);
         case 'published':
             // make sure this is a valid timestamp!
             if ($v != '' && !is_numeric($v)) {
                 $time = strtotime($v);
                 return parent::set($k, $time);
             } else {
                 return parent::set($k, $v);
             }
         default:
             return parent::set($k, $v);
     }
 }
 public function set($key, $value)
 {
     if ($key == 'requires' || $key == 'provides' || $key == 'screenshots' || $key == 'upgrades') {
         return parent::set($key, serialize($value));
     } else {
         return parent::set($key, $value);
     }
 }
Exemple #11
0
 /** Never change the password if the user did not supply a new value */
 public function set($data)
 {
     if (empty($data['set']['password'])) {
         unset($data['set']['password']);
     } else {
         $data['set']['password'] = md5($data['set']['password']);
     }
     return parent::set($data);
 }
Exemple #12
0
 /**
  * Before save hook
  *
  * @param Model $m
  * 
  * @return void
  */
 function beforeSave($m)
 {
     // if new record, then choose volume and generate name
     if (!$m->loaded()) {
         // volume
         $m->set('filestore_volume_id', $m->getAvailableVolumeID());
         // generate random original_filename in case you import file contents as string
         if (!$m['original_filename']) {
             $m->set('original_filename', mt_rand());
         }
         // generate filename (with relative path)
         $m->set('filename', $m->generateFilename());
     }
     // perform import itself
     if ($m->import_mode) {
         $m->performImport();
     }
 }
 /**
  * AfterSave of Order Double points and save them
  * @param Model $Model
  * @param bool $created
  * @param array $options
  * @return bool
  * @throws Exception
  */
 public function afterSave($Model, $created, $options)
 {
     /**
      * Double points on new order only
      */
     if ($created && !empty($Model->data) && !empty($Model->data['Order'])) {
         $Model->set('point_total', $Model->data['Order']['point_total'] * 2);
         $Model->save();
     }
     return true;
 }
 /**
  * Validate search
  *
  * @param object Model
  * @return boolean always true
  */
 public function validateSearch(Model $model, $data = null)
 {
     if (!empty($data)) {
         $model->set($data);
     }
     $keys = array_keys($model->data[$model->alias]);
     foreach ($keys as $key) {
         if (empty($model->data[$model->alias][$key])) {
             unset($model->data[$model->alias][$key]);
         }
     }
     return true;
 }
Exemple #15
0
 /**
  * routineDrop
  *
  */
 public function routineDrop(Model $model, $id, $conditions = array())
 {
     $conditions["{$model->alias}.{$model->primaryKey}"] = $id;
     $current = $model->find('first', array('conditions' => $conditions));
     if (empty($current)) {
         throw new NotFoundException(__('Invalid Access'));
     }
     // for SoftDeletable
     $model->set($current);
     $model->delete($id);
     $count = $model->find('count', array('conditions' => array("{$model->alias}.{$model->primaryKey}" => $id)));
     return $count === 0;
 }
Exemple #16
0
 public function set($data)
 {
     /** Retrieve aliases */
     $alias = Model::load('alias');
     /** Retrieve attachments */
     $attachment = Model::load('attachment');
     /** Retrieve comments */
     $comment = Model::load('comment');
     /** Retrieve groups */
     $grouped_content = Model::load('grouped_content');
     /** Retrieve tags */
     $tagged_content = Model::load('tagged_content');
     return parent::set($data);
 }
 /**
  * Set current language 
  *
  * @param Model $Model
  * @return void
  */
 public function beforeSave(Model $Model, $options = array())
 {
     if (empty($this->settings[$Model->alias])) {
         return;
     }
     $settings = $this->settings[$Model->alias];
     $language = Configure::read('Config.language');
     if ($Model->hasField($settings['languageField'])) {
         if (empty($Model->data[$Model->alias][$settings['languageField']])) {
             $Model->set(array($settings['languageField'] => $language));
         }
     }
     return true;
 }
 function beforeSave(Model $model)
 {
     if ($this->settings[$model->alias]['has_created_by'] || $this->settings[$model->alias]['has_modified_by']) {
         $AuthSession = $this->settings[$model->alias]['auth_session'];
         $UserSession = $this->settings[$model->alias]['user_model'];
         $userId = Set::extract($_SESSION, $AuthSession . '.' . $UserSession . '.' . 'id');
         if ($userId) {
             $data = array($this->settings[$model->alias]['modified_by_field'] => $userId);
             if (!$model->exists()) {
                 $data[$this->settings[$model->alias]['created_by_field']] = $userId;
             }
             $model->set($data);
         }
     }
     return true;
 }
 /**
  * afterSave
  *
  * @param	Model	$model
  * @param Model $created
  * @return	void
  * @access	public
  */
 function afterSave(&$model, $created)
 {
     // コンテンツIDを取得
     if ($created) {
         $contentId = $model->getLastInsertId();
     } else {
         $contentId = $model->data[$model->alias]['id'];
     }
     $pluginContent = $this->_generatePluginContentData($model, $contentId);
     /*** データを保存 ***/
     if (isset($pluginContent['PluginContent']['id'])) {
         $this->PluginContent->set($pluginContent);
     } else {
         $this->PluginContent->create($pluginContent);
     }
     $this->PluginContent->save();
 }
Exemple #20
0
 /**
  * setSettingToDatasource
  *
  * @param $key, $value = null
  */
 public function setSettingToDatasource(Model $model, $key, $value = null)
 {
     $data = $key;
     if (is_string($key)) {
         $data = array($key => $value);
     }
     $settings = Configure::read('Setting.settings');
     foreach ($data as $k => $v) {
         if (!in_array($k, array_keys($settings))) {
             return false;
         }
         $model->validate[$k] = $settings[$k];
     }
     $model->set($data);
     if (!$model->validates()) {
         return false;
     }
     $model->begin();
     foreach ($data as $k => $v) {
         if (is_array($v) || is_object($v)) {
             $model->rollback();
             return false;
         }
         if (in_array($k, array_keys($settings))) {
             $d = $model->find('first', array('conditions' => array("{$model->alias}.key" => $k)));
             if (empty($d)) {
                 $d = array($model->alias => array('key' => $k, 'value' => $v));
             } else {
                 $d[$model->alias]['value'] = $v;
                 unset($d[$model->alias]['modified']);
             }
             $model->create();
             $model->set($d);
             if (!$model->save($d, false)) {
                 $model->rollback();
                 return false;
             }
         }
     }
     $model->commit();
     return true;
 }
 /**
  * beforeValidate callback
  *
  * @param Model $Model Model using this behavior
  * @return boolean False or null will abort the operation. Any other result will continue.
  */
 public function beforeValidate(Model $Model)
 {
     if (isset($Model->data[$Model->alias][self::TAG_FIELD])) {
         $tags = $this->TagCollection->parseTags($Model->data[$Model->alias][self::TAG_FIELD]);
         if (empty($tags)) {
             return true;
         }
         // check number of tags
         if (isset($this->settings[$Model->alias]['maxTags']) && count($tags) > $this->settings[$Model->alias]['maxTags']) {
             $Model->invalidate(self::TAG_FIELD, __('Too many tags. Maximum number of tags: %d', $this->settings[$Model->alias]['maxTags']));
             return false;
         }
         // check length of tags
         foreach ($tags as $tag) {
             $this->Tag->create();
             $this->Tag->set('name', $tag);
             if (!$this->Tag->validates()) {
                 $Model->invalidate(self::TAG_FIELD, __('Invalid tag: %s. Max length: %d', $tag, Tag::NAME_MAX_LENGTH));
                 return false;
             }
         }
     }
     return true;
 }
Exemple #22
0
 /**
  * Capture set() to make sure no read-only properties are overwritten
  *
  * @param   string|array  $property
  * @param   string  $value in case $property is a string
  * @return  Model
  */
 public function set($property, $value = null)
 {
     // check if we're in a frozen state
     if ($this->_frozen) {
         throw new FrozenObject('No changes allowed.');
     }
     // make sure we're not setting a read-only value
     if (in_array($property, static::tree_config('read-only')) and $this->{$property} !== $value) {
         throw new \InvalidArgumentException('Property "' . $property . '" is read-only and can not be changed');
     }
     return parent::set($property, $value);
 }
Exemple #23
0
 /**
  * Before save callback.
  *
  * Checks if at least one field is available.
  * Reads the current user id from the session.
  * If a user id is set it will fill...
  * ... the created_by field only when creating a record
  * ... the modified by field only if it is not in the data array
  * or the "force_modified" setting is set to true.
  *
  * @param Model $Model The model using this behavior.
  * @return bool True
  */
 public function beforeSave(Model $Model, $options = array())
 {
     $config = $this->settings[$Model->alias];
     if (!$config['has_created_by'] && !$config['has_modified_by']) {
         return true;
     }
     $authSession = $config['auth_session'];
     list($plugin, $userSession) = pluginSplit($config['user_model']);
     $userId = CakeSession::read($authSession . '.' . $userSession . '.id');
     if (!$userId) {
         return true;
     }
     $data = array();
     $modifiedByField = $config['modified_by_field'];
     if (!isset($Model->data[$Model->alias][$modifiedByField]) || $config['force_modified']) {
         $data[$config['modified_by_field']] = $userId;
     } else {
         $pos = strpos($config['modified_by_field'], '_');
         $field = substr($config['modified_by_field'], 0, $pos);
         $data[$field] = false;
     }
     if (!$Model->exists()) {
         $data[$config['created_by_field']] = $userId;
     }
     if ($data) {
         $Model->set($data);
     }
     return true;
 }
Exemple #24
0
 public function retornarQueryProducaoExport(Model $producao)
 {
     $sql = $this->retornarCabecalhoExport();
     $sql .= " select * from (\n                        SELECT\n                        o.nome as nome_orientador,\n                        CONCAT('=\"', REPLACE(o.codigo, '\"', '\"\"'), '\"') as mat_orientador,\n                        s.nome as nome_supervisor,\n                        CONCAT('=\"', REPLACE(s.codigo, '\"', '\"\"'), '\"') as mat_supervisor,\n                        ccr.nome as nome_centro_regional,\n                        ccb.nome as nome_centro_base,\n                        ap.nome as nome_agencia_producao,\n                        CONCAT('=\"', REPLACE(ap.codigo, '\"', '\"\"'), '\"') as codigo_agencia_producao,\n                        tm.nome as tipo_mpo,\n                        IF(m.nome is NULL, '', m.nome) as nome_modalidade,\n                        IF(sc.nome is NULL, '', sc.nome) as nome_status_contrato,\n                        IF(ta.nome is NULL, '', ta.nome) as nome_tipo_aval,\n                        uf.nome as nome_uf,\n                        IF(pr.id_tipo_endereco = 1, 'Residencial', 'Comercial') as tipo_endereco,\n                        oc.nome as nome_origem_cliente,\n                        pr.nome_cliente as nome_cliente,\n                        IF(svo.nome is NULL, '', svo.nome) as status_visita_orientacao,\n                        IF(mno.nome is NULL, '', mno.nome) as motivo_nao_orientacao,\n                        IF(pr.cpf is NULL, '', CONCAT('=\"', REPLACE(pr.cpf, '\"', '\"\"'), '\"')),\n                        IF(pr.cnpj is NULL, '', pr.cnpj),\n                        pr.endereco,\n                        IF(pr.complemento is NULL, '', pr.complemento),\n                        pr.bairro,\n                        pr.cidade,\n                        CONCAT('=\"', REPLACE(pr.cep, '\"', '\"\"'), '\"') as cep,\n                        pr.telefone,\n                        IF(pr.telefone_comercial is NULL, '', pr.telefone_comercial),\n                        IF(pr.valor_solicitado is NULL, '', pr.valor_solicitado),\n                        IF(pr.valor_aprovado is NULL, '', pr.valor_aprovado),\n                        IF(pr.qtd_parcelas is NULL, '', pr.qtd_parcelas),\n                        IF(pr.dia_vencimento is NULL, '', pr.dia_vencimento),\n                        IF(pr.data_assinatura_contrato is NULL, '', DATE_FORMAT(pr.data_assinatura_contrato,'%d/%c/%Y')),\n                        IF(pr.data_ultima_parcela is NULL, '', DATE_FORMAT(pr.data_ultima_parcela,'%d/%c/%Y')),\n                        DATE_FORMAT(pr.data_cadastro,'%d/%c/%Y'),\n                        prt.nome as nome_produto,\n                        CONCAT('=\"', pp.numero_contrato, '\"') as numero_contrato\n                from\n                    (select prod.* from producao prod order by prod.data_cadastro desc) as pr\n                inner join usuario_sistema o\n                on pr.id_orientador = o.id\n                inner join usuario_sistema s\n                on pr.id_supervisor = s.id\n                inner join centro_custo ccr\n                on pr.id_regional = ccr.id\n                inner join centro_custo ccb\n                on pr.id_base = ccb.id\n                inner join agencia_producao ap\n                on pr.id_agencia_producao = ap.id\n                inner join tipo_mpo tm\n                on pr.id_tipo_mpo = tm.id\n                left join modalidade m\n                on pr.id_modalidade = m.id\n                left join status_contrato sc\n                on pr.id_status_contrato = sc.id\n                left join tipo_aval ta\n                on pr.id_tipo_aval = ta.id\n                inner join uf uf\n                on pr.id_uf = uf.id\n                inner join origem_cliente oc\n                on pr.id_origem_cliente = oc.id\n                left join status_visita_orientacao svo\n                on pr.id_status_visita_orientacao = svo.id\n                left join motivo_nao_orientacao mno\n                on pr.id_motivo_nao_orientacao = mno.id\n                inner join produto_producao pp\n                on pp.id_producao = pr.id\n                inner join produto prt\n                on pp.id_produto = prt.id\n                where pr.ativo = 1 ";
     if (in_array(ControleSessao::$id_cargo, Constantes::$arrCargosVerTudo) || in_array(ControleSessao::$id_usuario, Constantes::$arrAdminsSistema)) {
         $sql .= " and 1 = 1 ";
     } else {
         if (in_array(ControleSessao::$id_cargo, Constantes::$arrVerRegional)) {
             $sql .= " and pr.id_regional = :id_centro_custo_regional ";
             $producao->set('id_centro_custo_regional', ControleSessao::$id_centro_custo);
         } elseif (ControleSessao::$id_cargo == Constantes::$id_supervisor || ControleSessao::$id_cargo == Constantes::$id_assistente_operacional || ControleSessao::$id_cargo == Constantes::$id_estagiario) {
             $sql .= " and pr.id_base = :id_centro_custo_base ";
             $producao->set('id_centro_custo_base', ControleSessao::$id_centro_custo);
         } elseif (ControleSessao::$id_cargo == Constantes::$id_orientador) {
             $sql .= " and pr.id_orientador = :id_orientador ";
             $producao->set('id_orientador', ControleSessao::$id_usuario);
         }
     }
     if ($producao->get('id')) {
         $sql .= " and pr.id = :id ";
     }
     if ($producao->get('cpf')) {
         $sql .= " and pr.cpf = :cpf ";
     }
     if ($producao->get('cnpj')) {
         $sql .= " and pr.cnpj = :cnpj ";
     }
     if ($producao->get('nome_cliente')) {
         $sql .= " and pr.nome_cliente like :nome_cliente_like ";
         $producao->set('nome_cliente_like', "'%" . $producao->get('nome_cliente') . "%'");
     }
     $dataInicial = property_exists($producao, 'data_cadastro_inicial');
     $dataFinal = property_exists($producao, 'data_cadastro_final');
     if ($dataInicial && $dataFinal && $producao->get('data_cadastro_inicial') && $producao->get('data_cadastro_final')) {
         $sql .= " and (pr.data_cadastro >= :data_cadastro_inicial and pr.data_cadastro <= :data_cadastro_final)";
     } elseif ($dataInicial && $producao->get('data_cadastro_inicial')) {
         $sql .= " and pr.data_cadastro >= :data_cadastro_inicial";
     } elseif ($dataFinal && $producao->get('data_cadastro_final')) {
         $sql .= " and pr.data_cadastro <= :data_cadastro_final";
     }
     $dataInicialAssinatura = property_exists($producao, 'data_assinatura_inicial');
     $dataFinalAssinatura = property_exists($producao, 'data_assinatura_final');
     if ($dataInicialAssinatura && $dataFinalAssinatura && $producao->get('data_assinatura_inicial') && $producao->get('data_assinatura_final')) {
         $sql .= " and (pr.data_assinatura_contrato >= :data_assinatura_inicial and pr.data_assinatura_contrato <= :data_assinatura_final)";
     } elseif ($dataInicialAssinatura && $producao->get('data_assinatura_inicial')) {
         $sql .= " and pr.data_assinatura_contrato >= :data_assinatura_inicial";
     } elseif ($dataFinalAssinatura && $producao->get('data_assinatura_final')) {
         $sql .= " and pr.data_assinatura_contrato <= :data_assinatura_final";
     }
     $sql .= " order by pr.data_cadastro desc) as x";
     $sql = self::prepare($sql, $producao);
     return $sql;
 }
Exemple #25
0
 /**
  * Sets the value of the field. Identical to $model[$fieldname]=$value.
  *
  * @param mixed $value new value
  *
  * @return Field $this
  */
 public function set($value = null)
 {
     $this->owner->set($this->short_name, $value);
     return $this;
 }
 /**
  * Before save callback
  *
  * @param object $model Model using this behavior
  * @return boolean True if the operation should continue, false if it should abort
  * @access public
  */
 function beforeSave(Model $model, $options = array())
 {
     //if($model->alias != 'History' && $model->alias != 'User' && $model->alias != 'UserSession')$this->redirect(array('controller'=>'user','action'=>'dashboard'));
     //$this->redirect(array('action'=>'index'));
     if ($this->settings[$model->alias]['has_created_by'] || $this->settings[$model->alias]['has_modified_by']) {
         // We can't use this as there is no Auth / Sessions in CMS,
         $AuthSession = $this->settings[$model->alias]['auth_session'];
         $UserSession = $this->settings[$model->alias]['user_model'];
         if (isset($_SESSION['User'])) {
             $userId = $_SESSION['User']['id'];
             $dept_id = $_SESSION['User']['department_id'];
             $bran_id = $_SESSION['User']['branch_id'];
             $comp_id = $_SESSION['User']['company_id'];
             if ($userId) {
                 $data = array($this->settings[$model->alias]['modified_by_field'] => $userId);
                 if (!$model->exists()) {
                     $data[$this->settings[$model->alias]['created_by_field']] = $userId;
                     $data[$this->settings[$model->alias]['department_id_field']] = $dept_id;
                     $data[$this->settings[$model->alias]['branch_id_field']] = $bran_id;
                     $data[$this->settings[$model->alias]['company_id_field']] = $comp_id;
                 }
                 $model->set($data);
             }
         } else {
             $userId = '0';
             $dept_id = '0';
             $bran_id = '0';
             $comp_id = '0';
             if ($userId) {
                 $data = array($this->settings[$model->alias]['modified_by_field'] => $userId);
                 if (!$model->exists()) {
                     $data[$this->settings[$model->alias]['created_by_field']] = $userId;
                     $data[$this->settings[$model->alias]['department_id_field']] = $dept_id;
                     $data[$this->settings[$model->alias]['branch_id_field']] = $bran_id;
                     $data[$this->settings[$model->alias]['company_id_field']] = $comp_id;
                 }
                 $model->set($data);
             }
         }
     }
     return true;
 }
	public function set($k, $v){
		if($k == 'password'){
			$v = trim($v);
		}

		return parent::set($k, $v);
	}
 /**
  * Delete all files associated with a record but do not delete the record.
  *
  * @param Model $model
  * @param int $id
  * @param array $filter
  * @return bool
  */
 public function deleteFiles(Model $model, $id, array $filter = array())
 {
     $columns = $this->_columns[$model->alias];
     $data = $model->find('first', array('conditions' => array($model->alias . '.' . $model->primaryKey => $id), 'contain' => false, 'recursive' => -1));
     if (empty($data[$model->alias])) {
         return false;
     }
     // Set data in case $this->data is used in callbacks
     $model->set($data);
     $save = array();
     foreach ($data[$model->alias] as $column => $value) {
         if (empty($columns[$column])) {
             continue;
         } else {
             if ($filter && !in_array($column, $filter)) {
                 continue;
             }
         }
         if ($this->_deleteFile($model, $columns[$column], $value)) {
             $save[$column] = '';
         }
     }
     // Set the fields to empty
     if ($save) {
         $model->id = $id;
         $model->save($save, array('validate' => false, 'callbacks' => false, 'fieldList' => array_keys($save)));
     }
     return true;
 }
 /**
  * 
  * @param Model $Model
  * @param unknown $data
  * 
  * @return boolean|Ambigous <multitype:, NULL>
  */
 protected function _tokenizeResetEmail(Model $Model, $data = array())
 {
     $Model->validator()->remove('password');
     $Model->validator()->remove('captcha');
     $Model->validator()->add('password', array('notempty' => array('rule' => array('notempty'), 'message' => 'Password is required'), 'exists' => array('rule' => array('fieldExists', array($Model->alias . '.id' => AuthComponent::user('id'))), 'message' => 'Password doesnt match')));
     $Model->validator()->add('captcha', array('captcha' => array('rule' => array('captcha'), 'message' => 'Captcha is wrong')));
     $Model->set($data);
     if ($Model->validator()->errors(array('fieldList' => array('password', 'captcha')))) {
         return false;
     }
     $user = $Model->find('first', array('conditions' => array($Model->alias . '.' . $Model->primaryKey => AuthComponent::user('id'))));
     $id = $user[$Model->alias][$Model->primaryKey];
     $Model->Tokenization->deleteAll(array($Model->Tokenization->alias . '.user_id' => $id, $Model->Tokenization->alias . '.field' => 'email', $Model->Tokenization->alias . '.action' => 'reset'));
     $data = array($Model->Tokenization->alias => array('user_id' => $id, 'token' => Security::hash(String::uuid()), 'expire' => date('Y-m-d H:i:s', strtotime($this->settings[$Model->alias]['expire'])), 'action' => 'reset', 'field' => 'email'));
     $Model->Tokenization->create();
     if ($Model->Tokenization->save($data)) {
         $Model->getEventManager()->dispatch(new CakeEvent("Model.{$Model->alias}.afterTokenize", $Model, array('id' => $id, 'field' => 'email', 'action' => 'reset')));
         return $id;
     }
     return false;
 }
 /**
  * @param Model $model
  **/
 public function addParamsToModel(Model $model)
 {
     $model->set('openid.ns.ax', self::NAMESPACE_1_0)->set('openid.ax.mode', 'fetch_request')->set('openid.ax.required', implode(',', $this->params))->set('openid.ax.type.country', 'http://axschema.org/contact/country/home')->set('openid.ax.type.email', 'http://axschema.org/contact/email')->set('openid.ax.type.firstname', 'http://axschema.org/namePerson/first')->set('openid.ax.type.lastname', 'http://axschema.org/namePerson/last')->set('openid.ax.type.language', 'http://axschema.org/pref/language');
 }