| Current Path : /var/www/html/slaas/frontend/models/ |
| Current File : /var/www/html/slaas/frontend/models/FrontendUser.php |
<?php
namespace frontend\models;
use Yii;
use backend\modules\school\models\School;
class FrontendUser extends \yii\db\ActiveRecord {
CONST STATUS_ACTIVE = '1';
public $password;
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'frontend_user';
}
public function rules() {
return [
[
[
'id',
'img_url',
'auth_key',
'password_hash',
'password_reset_token',
'last_login',
'last_login_attempts',
'login_attempts',
'created_at',
'created_by',
'created_user_type',
'updated_at',
'updated_by',
'updated_user_type',
'pic_name2',
'pic_email2',
'pic_phone2',
'pic_position2',
'pic_name3',
'pic_email3',
'pic_phone3',
'pic_position3',
'school_address2',
'school_address3',
'school_id',
'school_parlimen',
'school_dun'
], 'safe'
],
[
[
'username',
'status',
'role',
'school_name',
'school_address1',
'school_postcode',
'school_city',
'school_district',
'school_state',
'school_ppd',
'school_email',
'school_phone',
'school_fax',
'school_student_no',
'school_teacher_no',
'school_staff_no',
'school_grade',
'school_area',
'school_category',
'pic_name1',
'pic_email1',
'pic_phone1',
'pic_position1',
'pic_name2',
'pic_email2',
'pic_phone2',
'pic_position2',
'school_parlimen',
'school_dun',
],
'required',
'message' => Yii::t('app', '{attribute} tidak boleh kosong')
],
['password', 'match', 'pattern' => '/^(?=.*\d)(?=.*[`~!@#$%^&.*])(?=.*[a-z])(?=.*[A-Z])[a-zA-Z0-9`~!@#$%^&*.]{8,15}$/', 'message' => "{attribute} tidak memenuhi syarat"],
[['password'], 'required', 'on' => 'create', 'message' => Yii::t('app', '{attribute} tidak boleh kosong')],
[['school_email', 'pic_email1', 'pic_email2', 'pic_email3'], 'email', 'message' => Yii::t('app', '{attribute} tidak mengikut format emel')],
[['username',], 'unique', 'message' => Yii::t('app', '{attribute} sudah wujud')],
['pic_email2', 'compare', 'compareAttribute' => 'pic_email1', 'operator' => '!=', 'message' => 'Alamat E-mel tidak boleh sama'],
['username', 'checkschool'],
[['school_phone', 'school_fax', 'school_student_no', 'school_teacher_no',
'school_staff_no', 'pic_phone1', 'pic_phone2', 'pic_phone3'], 'number', 'message' => Yii::t('app', '{attribute} mestilah nombor sahaja')],
];
}
public function checkschool($attribute, $params) {
if (!empty($this->school_code)) {
$modelSchool = School::findOne(['school_code' => $this->school_code]);
if (empty($modelSchool))
$this->addError('school_code', 'Sekolah tidak wujud');
}
}
public function attributeLabels() {
return [
'username' => 'ID Pengguna (Kod Sekolah)',
'password' => 'Cipta Kata Laluan',
'status' => 'Status',
'role' => 'Peranan',
'img_url' => 'Imej',
'school_name' => 'Nama Sekolah',
'school_address1' => 'Alamat Sekolah',
'school_postcode' => 'Poskod',
'school_city' => 'Bandar',
'school_district' => 'Daerah',
'school_state' => 'Negeri',
'school_ppd' => 'Pejabat Pendidikan Daerah',
'school_email' => 'E-mel Sekolah',
'school_phone' => 'No. Telefon Sekolah',
'school_fax' => 'No. Faks Sekolah',
'school_student_no' => 'Bilangan Pelajar',
'school_teacher_no' => 'Bilangan Guru',
'school_staff_no' => 'Bilangan Staf Sokongan',
'school_grade' => 'Gred Sekolah',
'school_area' => 'Keluasan Sekolah',
'school_category' => 'Kategori Sekolah',
'pic_name1' => 'Nama',
'pic_email1' => 'Alamat E-mel',
'pic_phone1' => 'No. Telefon',
'pic_position1' => 'Jawatan',
'pic_name2' => 'Nama',
'pic_email2' => 'Alamat E-mel',
'pic_phone2' => 'No. Telefon',
'pic_position2' => 'Jawatan',
'pic_name3' => 'Nama',
'pic_email3' => 'Alamat E-mel',
'pic_phone3' => 'No. Telefon',
'pic_position3' => 'Jawatan',
'school_parlimen' => 'Parlimen',
'school_dun' => 'DUN',
];
/* return [
'id' => Yii::t('app', 'ID'),
'username' => Yii::t('app', 'ID Pengguna'),
'fullname' => Yii::t('app', 'Nama Penuh'),
'confirmpassword' => Yii::t('app', 'Confirm Password'),
'auth_key' => Yii::t('app', 'Auth Key'),
'password_hash' => Yii::t('app', 'Kata Laluan'),
'password_reset_token' => Yii::t('app', 'Password Reset Token'),
'email' => Yii::t('app', 'Emel'),
'last_login' => Yii::t('app', 'Last Login'),
'last_login_attempts' => Yii::t('app', 'Last Login Attempts'),
'login_attempts' => Yii::t('app', 'Login Attempts'),
'status' => Yii::t('app', 'Status'),
'role' => Yii::t('app', 'Role'),
'created_by' => Yii::t('app', 'Created By'),
'created_at' => Yii::t('app', 'Created Date & Time'),
'updated_by' => Yii::t('app', 'Updated By'),
'updated_at' => Yii::t('app', 'Updated Date & Time'),
'mobile_no' => Yii::t('app', 'Nombor Telefon'),
'img_url' => Yii::t('app', 'Gambar'),
'school_code' => 'Kod Sekolah',
'ic' => 'Nombor Kad Pengenalan',
'dept' => 'Bahagian',
'position' => 'Jawatan',
'address1' => 'Alamat',
'address2' => 'Alamat',
'address3' => 'Alamat',
'postcode' => 'Poskod',
'city' => 'Bandar',
'state' => 'Negeri',
'password' => 'Kata Laluan',
]; */
}
}