| Current Path : /var/www/html/school/backend/models/ |
| Current File : /var/www/html/school/backend/models/MessageGroup.php |
<?php
namespace backend\models;
use backend\models\Staff;
use backend\models\MessageGroupMember;
use common\models\Dermaga;
use backend\models\Ref;
use Yii;
class MessageGroup extends Dermaga {
public $stafflist;
public static function tableName() {
return 'dmg_message_group';
}
/**
* @inheritdoc
*/
public function rules() {
return [
[['group_name','group_category'], 'required'],
[['group_name','group_category'], 'required', 'on' => 'staff'],
[['staff_info_id'], 'integer'],
[['stafflist','created_at', 'updated_at'], 'safe'],
[['group_name'], 'string', 'max' => 100],
[['description'], 'string', 'max' => 255],
[['created_by', 'updated_by'], 'string', 'max' => 50],
];
}
/**
* @inheritdoc
*/
public function attributeLabels() {
return [
'id' => 'ID',
'group_name' => yii::t('app','Nama Kumpulan'),
'description' => yii::t('app','Deskripsi'),
'group_category' => yii::t('app','Kategori'),
'staff_info_id' => yii::t('app','Admin'),
'created_by' => yii::t('app','Dicipta Oleh'),
'created_at' => yii::t('app','Tarikh Cipta'),
'updated_by' => yii::t('app','Dikemaskini Oleh'),
'updated_at' => yii::t('app','Tarikh Kemaskini'),
];
}
public static function getMyList() {
$arr2 = [];
$sql = "SELECT DISTINCT a.id,group_name FROM dmg_message_group a INNER JOIN dmg_message_group_member b ON b.message_group_id=a.id
WHERE
b.staff_info_id=".Yii::$app->user->identity->staff->id." UNION
select DISTINCT a.id,group_name from dmg_message_group a inner join dmg_message_group_member b on b.message_group_id=a.id
where
b.staff_info_id='".Yii::$app->user->identity->staff->id."'";
$arr = self::findBySql($sql)->all();
foreach ($arr as $param) {
$arr2[$param->id] = $param->group_name;
}
return $arr2;
}
public function getMembers() {
return $this->hasMany(MessageGroupMember::className(), ['message_group_id' => 'id']);
}
public function getStaff() {
return $this->hasOne(Staff::className(), ['id' => 'created_by']);
}
public function getCategory()
{
return $this->hasOne(Ref::className(), ['code' => 'group_category'])->andWhere(['cat'=>'GRPCAT']);
}
public function getType()
{
return $this->hasOne(Ref::className(), ['code' => 'grptype'])->andWhere(['cat'=>'GRPTYP']);
}
// public function displayActive() {
// if ($this->activeind == 0)
// return 'No';
// else
// return 'Yes';
// }
}