Example #1
0
 public function beforeSave()
 {
     $this->password = md5($this->password);
     $this->activated = false;
     $this->activationKey = $this->createActivationKey();
     return parent::beforeSave();
 }
Example #2
0
File: user.php Project: taq/torm
            $this->name = "Unnamed User";
        }
    }
}
User::setOrder("name");
User::validates("name", array("presence" => true));
User::validates("name", array("format" => "^[\\p{L},]{2,} [\\p{L}\\s\\.]{2,}"));
User::validates("email", array("presence" => true));
User::validates("email", array("format" => "^[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,4})\$"));
User::validates("email", array("uniqueness" => true, "allow_null" => true, "allow_blank" => true));
User::validates("user_level", array("numericality" => true));
User::validates("code", array("format" => "^[0-9]{5}\$", "allow_null" => true));
User::hasMany("tickets", array("class_name" => "Ticket"));
User::hasOne("account");
User::beforeSave("before_save");
User::beforeSave("strip_invalid");
User::afterSave("after_save");
User::beforeDestroy("before_destroy");
User::afterDestroy("after_destroy");
User::beforeCreate("before_create");
User::afterCreate("after_create");
User::beforeUpdate("before_update");
User::afterUpdate("after_update");
User::scope("first_level", array("user_level" => 1));
User::scope("by_level", function ($args) {
    return "user_level=" . $args[0];
});
User::scope("by_level_and_date", function ($args) {
    return "user_level=" . $args[0] . " and created_at<'" . $args[1] . " 23:59:59'";
});
User::scope("doe", "email like '%doe.com'");
Example #3
0
 public function beforeSave($insert)
 {
     $this->passhash = User::hashPassword($this->password);
     return parent::beforeSave($insert);
 }
Example #4
0
 function beforeSave()
 {
     if (array_key_exists($this->alias, $this->data) && empty($this->data[$this->alias][$this->primaryKey])) {
         // Drupal doesn't use auto increment on the uid column.
         // This hack is adapted from Drupal's methods...
         // It will leave extra records in the sequences table,
         // but Drupal will take care of that for us.
         global $databases;
         if (!$this->query("INSERT INTO {$databases['default']['default']['prefix']}sequences () VALUES ();", false)) {
             return false;
         }
         $id = $this->query('SELECT LAST_INSERT_ID();', false);
         $id = array_shift(array_shift(array_shift($id)));
         $this->data[$this->alias][$this->primaryKey] = $id;
         $this->data[$this->alias]['status'] = 1;
         // don't require further activation in Drupal
     }
     return parent::beforeSave();
 }
Example #5
0
 public function beforeSave()
 {
     parent::beforeSave();
     $p = $this->getAttributes();
     $p['userRoles'] = Helper::uniqueArray($p['userRoles'], 'role_id');
     foreach ($p['userRoles'] as $k => $v) {
         if ($k == 0) {
             $p['userRoles'][$k]['is_default_role'] = 'Yes';
         } else {
             $p['userRoles'][$k]['is_default_role'] = 'No';
         }
     }
     return true;
 }
Example #6
0
 public function beforeSave()
 {
     //If the delivery_day is not available for the Location, set it to null
     if ($this->Location) {
         $dds = $this->Location->getDeliveryDays();
         if (!in_array($this->delivery_day, array_keys($dds))) {
             $this->delivery_day = null;
         }
     }
     //Set the delivery day to the next available delivery day by default
     if (empty($this->delivery_day) && $this->Location) {
         $this->delivery_day = date('N', strtotime($this->Location->getNextDeliveryDate()->date));
     }
     return parent::beforeSave();
 }