Ejemplo n.º 1
0
 /**
  * add or update group
  * @param int $groupId
  * @param string $groupName
  * @param string $groupDesc
  * @return bool
  */
 public static function saveGroup($groupId, $groupName, $groupDesc)
 {
     if ($groupId) {
         $group = static::findOne($groupId);
         if ($group) {
             $group->groupName = $groupName;
             $group->groupDesc = $groupDesc;
             return $group->save();
         }
     }
     $group = new Group();
     $group->groupName = $groupName;
     $group->groupDesc = $groupDesc;
     return $group->save();
 }
Ejemplo n.º 2
0
 /**
  * 将用户分配到一个组中去
  * @param int $userId  user id
  * @param string $group  grounpName 
  */
 public static function addUserToGroup($userId, $group)
 {
     if (!intval($userId)) {
         return false;
     }
     $groups = Group::getGroup();
     if ($key = array_search($group, $groups)) {
         $sql = 'REPLACE INTO user_group (userId,groupId) VALUES (' . $userId . ',' . $key . ')';
         static::getDb()->createCommand($sql)->execute();
         return true;
     } else {
         return false;
     }
 }
Ejemplo n.º 3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Group::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['group_id' => $this->group_id, 'program_id' => $this->program_id]);
     $query->andFilterWhere(['like', 'group_code', $this->group_code]);
     return $dataProvider;
 }
Ejemplo n.º 4
0
 /**
  * 用户分组
  */
 public function actionGroup()
 {
     $view = \Yii::$app->view->params['moduleName'] = '用户分组';
     $search = \Yii::$app->request->_get('search', '');
     $where = 1;
     if ($search) {
         $where .= ' AND groupName LIKE \'%' . $search . '%\'';
     }
     $group = Group::find()->where($where);
     $pageSize = \Yii::$app->params['pageSize'];
     $total = $group->count();
     $pagination = new Pagination(['defaultPageSize' => $pageSize, 'totalCount' => $total]);
     $data = $group->asArray()->offset($pagination->offset)->limit($pagination->limit)->all();
     $token = Token::getToken();
     $userId = \Yii::$app->user->id;
     $savegroupIdentity = EasyHelpers::dataEncrypt('savegroup,' . $userId);
     $deletegroupIdentity = EasyHelpers::dataEncrypt('deletegroup,' . $userId);
     return $this->render('group', ['data' => $data, 'search' => $search, 'token' => $token, 'pagination' => $pagination, 'savegroupIdentity' => $savegroupIdentity, 'deletegroupIdentity' => $deletegroupIdentity]);
 }
Ejemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getGroup()
 {
     return $this->hasOne(Group::className(), ['id' => 'group_post']);
 }
Ejemplo n.º 6
0
use backend\models\Group;
use dosamigos\ckeditor\CKEditor;
use backend\models\Status;
/* @var $this yii\web\View */
/* @var $model backend\models\Post */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="post-form">

    <?php 
$form = ActiveForm::begin();
?>
    
    <?php 
echo $form->field($model, 'group_post')->dropDownList(ArrayHelper::map(Group::find()->all(), 'id', 'name'), ['prompt' => 'Select Group']);
?>

    <?php 
echo $form->field($model, 'name_post')->textInput(['maxlength' => true]);
?>
    
    <?php 
echo $form->field($model, 'content')->widget(CKEditor::className(), ['options' => ['rows' => 6], 'preset' => 'full']);
?>

    <?php 
echo $form->field($model, 'create_day')->textInput();
?>

    <?php 
Ejemplo n.º 7
0
 public function getGroup()
 {
     return $this->hasMany(Group::className(), ['program_id' => 'program_id']);
 }
Ejemplo n.º 8
0
 /**
  * 组管理(删除)
  */
 public function actionDeletegroup()
 {
     $request = \Yii::$app->request;
     $identity = Identity::checkIdentity('deletegroup', '/app-backend/backend/adminmanage/deletegroup');
     if (is_array($identity)) {
         return $identity;
     }
     $groupId = intval($request->_get('groupId', 0));
     if (!$groupId) {
         return ['code' => 1, 'msg' => '数据非法', 'data' => []];
     }
     $groupName = Group::find()->where('groupId=' . $groupId)->select('groupName')->scalar();
     $defaultGroup = \Yii::$app->params['defaultGroup'];
     if (in_array($groupName, $defaultGroup)) {
         return ['code' => 1, 'msg' => '默认组不能删除', 'data' => []];
     }
     $checkUser = UserGroup::checkGroupUser($groupId);
     if ($checkUser) {
         return ['code' => 3, 'msg' => '组内有成员,不能删除', 'data' => []];
     }
     $res = Group::deleteAll('groupId=' . $groupId);
     if ($res !== false) {
         return ['code' => 0, 'msg' => '操作成功', 'data' => []];
     } else {
         return ['code' => 2, 'msg' => '操作失败,请重试', 'data' => []];
     }
 }