/** * generate random string and return it. * @param number $len * @param number $type //1-only letter + number //2-full chars * @param number $prefixType //1 Y-M-D H:i:s //2-unixtimestamp * @return string */ public static function randomString($len = 10, $type = 1, $prefixType = 0, $prefixConnection = '') { $string = ''; $prefix = ''; for ($i = 0; $i < $len; $i++) { if ($type == 1) { $t = rand(0, 2); if ($t == 0) { $string .= rand(0, 9); } if ($t == 1) { $string .= chr(rand(65, 90)); } if ($t == 2) { $string .= chr(rand(97, 122)); } } //only letter + number if ($type == 2) { $string .= chr(rand(33, 126)); } //full chars } if ($prefixType == 1) { $prefix = EED::f(); } if ($prefixType == 2) { $prefix = time(); } if (!empty($prefix)) { $prefix .= $prefixConnection; } return $prefix . $string; }
/** * auto save creationUser_id and creationDate */ public function beforeSave() { if (parent::beforeSave()) { if ($this->isNewRecord) { $this->d_creationUser_id = Yii::app()->user->id; $this->d_creationDate = EED::f(); } return true; } else { return false; } }
/** * auto save creationUser_id and creationDate */ public function beforeSave() { if (parent::beforeSave()) { if ($this->isNewRecord) { $this->s_creationUser_id = Yii::app()->user->id; $this->s_creationDate = EED::f(); } //check for s_avatar $avatarFileObj = array(); $avatarFileObj['size'] = 0; if (isset($this->uploadFile['Staff']['size']['s_avatar'])) { $avatarFileObj['size'] = $this->uploadFile['Staff']['size']['s_avatar']; } if (isset($this->uploadFile['Staff']['type']['s_avatar'])) { $avatarFileObj['type'] = $this->uploadFile['Staff']['type']['s_avatar']; } if (isset($this->uploadFile['Staff']['tmp_name']['s_avatar'])) { $avatarFileObj['tmp_name'] = $this->uploadFile['Staff']['tmp_name']['s_avatar']; } if ($avatarFileObj['size'] > 0) { //have avatar upload do file upload and save to model //old avatar path for delete $oldAvatar = $this->s_avatar; $this->s_avatar = EEH::moveUploadFile($avatarFileObj, Yii::app()->params['uploadPathStaffImage']); if ($this->s_avatar != '') { //remove old avatar file unlink(Yii::app()->params['uploadPathStaffImage'] . $oldAvatar); } else { //save old avatar back if upload fail, this is file level fail so we don't need show any message $this->s_avatar = $oldAvatar; } } return true; } else { return false; } }
public function beforeSave() { if (parent::beforeSave()) { if ($this->isNewRecord) { $this->time = EED::f(); } return true; } else { return false; } }