Esempio n. 1
0
 protected function beforeSave()
 {
     $result = parent::beforeSave();
     if (!$result) {
         return false;
     }
     // encrypt myEncrypted Field value
     $this->password = Yii::app()->aes256->encrypt($this->password);
     //echo $this->pass.length();
     return $result;
 }
Esempio n. 2
0
 public function behaviors()
 {
     return array_merge(array(), parent::behaviors());
 }
Esempio n. 3
0
 /**
  * Returns the data model based on the primary key or another attribute.
  * This method is designed to work with the values passed via GET.
  * If the data model is not found or there's a malformed key, an
  * HTTP exception will be raised.
  * #MethodTracker
  * This method is based on the gii generated method controller::loadModel, from version 1.1.7 (r3135). Changes:
  * <ul>
  * <li>Support to composite PK.</li>
  * <li>Support to use any attribute (column) name besides the PK.</li>
  * <li>Support to multiple attributes.</li>
  * <li>Automatically detects the PK column names.</li>
  * </ul>
  * @param mixed $key The key or keys of the model to be loaded.
  * If the key is a string or an integer, the method will use the tables' PK if
  * the PK has a single column. If the table has a composite PK and the key
  * has a separator (see below), the method will detect it and use it.
  * <pre>
  * $key = '12-27'; // PK values with separator for tables with composite PK.
  * </pre>
  * If $key is an array, it can be indexed by integers or by attribute (column)
  * names, as for {@link CActiveRecord::findByAttributes}.
  * If the array doesn't have attribute names, as below, the method will use
  * the table composite PK.
  * <pre>
  * $key = array(
  *   12,
  *   27,
  *   ...,
  * );
  * </pre>
  * If the array is indexed by attribute names, as below, the method will use
  * the attribute names to search for and load the model.
  * <pre>
  * $key = array(
  *   'model_id' => 44,
  *      ...,
  * );
  * </pre>
  * Warning: each attribute used should have an index on the database and the set of
  * attributes used should identify only one item on the database (the attributes being
  * ideally part of or multiple unique keys).
  * @param string $modelClass The model class name.
  * @return AweActiveRecord The loaded model.
  * @see AweActiveRecord::pkSeparator
  * @throws CHttpException if there's an invalid request (with code 400) or if the model is not found (with code 404).
  */
 public function loadModel($key, $modelClass = __CLASS__)
 {
     // Get the static model.
     $staticModel = AweActiveRecord::model($modelClass);
     if (is_array($key)) {
         // The key is an array.
         // Check if there are column names indexing the values in the array.
         reset($key);
         if (key($key) === 0) {
             // There are no attribute names.
             // Check if there are multiple PK values. If there's only one, start again using only the value.
             if (count($key) === 1) {
                 return $this->loadModel($key[0], $modelClass);
             }
             // Now we will use the composite PK.
             // Check if the table has composite PK.
             $tablePk = $staticModel->getTableSchema()->primaryKey;
             if (!is_array($tablePk)) {
                 throw new CHttpException(400, Yii::t('AweCrud.messages', 'Your request is invalid.'));
             }
             // Check if there are the correct number of keys.
             if (count($key) !== count($tablePk)) {
                 throw new CHttpException(400, Yii::t('AweCrud.messages', 'Your request is invalid.'));
             }
             // Get an array of PK values indexed by the column names.
             $pk = $staticModel->fillPkColumnNames($key);
             // Then load the model.
             $model = $staticModel->findByPk($pk);
         } else {
             // There are attribute names.
             // Then we load the model now.
             $model = $staticModel->findByAttributes($key);
         }
     } else {
         // The key is not an array.
         // Check if the table has composite PK.
         $tablePk = $staticModel->getTableSchema()->primaryKey;
         if (is_array($tablePk)) {
             // The table has a composite PK.
             // The key must be a string to have a PK separator.
             if (!is_string($key)) {
                 throw new CHttpException(400, Yii::t('AweCrud.messages', 'Your request is invalid.'));
             }
             // There must be a PK separator in the key.
             if (stripos($key, $staticModel->pkSeparator) === false) {
                 throw new CHttpException(400, Yii::t('AweCrud.messages', 'Your request is invalid.'));
             }
             // Generate an array, splitting by the separator.
             $keyValues = explode($staticModel->pkSeparator, $key);
             // Start again using the array.
             return $this->loadModel($keyValues, $modelClass);
         } else {
             // The table has a single PK.
             // Then we load the model now.
             $model = $staticModel->findByPk($key);
         }
     }
     // Check if we have a model.
     if ($model === null) {
         throw new CHttpException(404, Yii::t('AweCrud.messages', 'The requested page does not exist.'));
     }
     return $model;
 }
Esempio n. 4
0
 public function behaviors()
 {
     return array_merge(array('ActiveRecordRelation' => array('class' => 'EActiveRecordRelationBehavior')), parent::behaviors());
 }
Esempio n. 5
0
 public function behaviors()
 {
     return array_merge(array('CTimestampBehavior' => array('class' => 'zii.behaviors.CTimestampBehavior', 'createAttribute' => 'fecha_creacion', 'updateAttribute' => 'fecha_actualizacion', 'timestampExpression' => new CDbExpression('NOW()'))), parent::behaviors());
 }
Esempio n. 6
0
 /**
  * Finds the relation of the specified column.
  * Note: There's a similar method in the class AweActiveRecord.
  * @param string $modelClass The model class name.
  * @param CDbColumnSchema $column The column.
  * @return array The relation. The array will have 3 values:
  * 0: the relation name,
  * 1: the relation type (will always be AweActiveRecord::BELONGS_TO),
  * 2: the foreign key (will always be the specified column),
  * 3: the related active record class name.
  * Or null if no matching relation was found.
  */
 public function findRelation($modelClass, $column)
 {
     if (!$column->isForeignKey) {
         return null;
     }
     $relations = AweActiveRecord::model($modelClass)->relations();
     // Find the relation for this attribute.
     foreach ($relations as $relationName => $relation) {
         // For attributes on this model, relation must be BELONGS_TO.
         if ($relation[0] == AweActiveRecord::BELONGS_TO && $relation[2] == $column->name) {
             return array($relationName, $relation[0], $relation[2], $relation[1]);
         }
     }
     // None found.
     return null;
 }