public function safeUp()
 {
     $this->originalMigration->up();
     $authManager = Yii::$app->authManager;
     $this->alterColumn($authManager->assignmentTable, 'user_id', $this->integer()->notNull());
     //fk
     $this->addForeignKey("fk_assignment_user_id", $authManager->assignmentTable, 'user_id', '{{%radiata_user}}', 'id', 'CASCADE', 'CASCADE');
     $developerRole = $authManager->createRole('developer');
     $adminRole = $authManager->createRole('admin');
     $managerRole = $authManager->createRole('manager');
     $userRole = $authManager->createRole('user');
     $authManager->add($developerRole);
     $authManager->add($adminRole);
     $authManager->add($managerRole);
     $authManager->add($userRole);
     $authManager->addChild($managerRole, $userRole);
     $authManager->addChild($adminRole, $managerRole);
     $authManager->addChild($developerRole, $adminRole);
     $permissionRadiataModule = $authManager->createPermission('Radiata Module');
     $authManager->add($permissionRadiataModule);
     $permissionRadiataModuleDashboard = $authManager->createPermission('Radiata Module. Dashboard');
     $authManager->add($permissionRadiataModuleDashboard);
     $authManager->addChild($permissionRadiataModule, $permissionRadiataModuleDashboard);
     $permissionRadiataModuleAdminLog = $authManager->createPermission('Radiata Module. Admin Log');
     $authManager->add($permissionRadiataModuleAdminLog);
     $authManager->addChild($permissionRadiataModule, $permissionRadiataModuleAdminLog);
     $permissionRadiataModuleLangs = $authManager->createPermission('Radiata Module. Languages');
     $authManager->add($permissionRadiataModuleLangs);
     $authManager->addChild($permissionRadiataModule, $permissionRadiataModuleLangs);
     $permissionRadiataModuleUsers = $authManager->createPermission('Radiata Module. Users');
     $authManager->add($permissionRadiataModuleUsers);
     $authManager->addChild($permissionRadiataModule, $permissionRadiataModuleUsers);
     $user = new User();
     $user->username = '******';
     $user->first_name = 'Developer';
     $user->last_name = 'Developer';
     $user->email = '*****@*****.**';
     $user->setPassword('developer^^');
     $user->generateAuthKey();
     $user->status = User::STATUS_ACTIVE;
     $user->created_at = time();
     $user->updated_at = time();
     Yii::$app->db->createCommand()->insert(User::tableName(), $user->attributes, ArrayHelper::getColumn($user, 'attributes'))->execute();
     $authManager->assign($developerRole, Yii::$app->db->getLastInsertID());
     $user = new User();
     $user->username = '******';
     $user->first_name = 'Admin';
     $user->last_name = 'Admin';
     $user->email = '*****@*****.**';
     $user->setPassword('admin^^');
     $user->generateAuthKey();
     $user->status = User::STATUS_ACTIVE;
     $user->created_at = time();
     $user->updated_at = time();
     Yii::$app->db->createCommand()->insert(User::tableName(), $user->attributes, ArrayHelper::getColumn($user, 'attributes'))->execute();
     $authManager->assign($adminRole, Yii::$app->db->getLastInsertID());
     $user = new User();
     $user->username = '******';
     $user->first_name = 'Manager';
     $user->last_name = 'Manager';
     $user->email = '*****@*****.**';
     $user->setPassword('manager^^');
     $user->generateAuthKey();
     $user->status = User::STATUS_ACTIVE;
     $user->created_at = time();
     $user->updated_at = time();
     Yii::$app->db->createCommand()->insert(User::tableName(), $user->attributes, ArrayHelper::getColumn($user, 'attributes'))->execute();
     $authManager->assign($managerRole, Yii::$app->db->getLastInsertID());
     $user = new User();
     $user->username = '******';
     $user->first_name = 'User';
     $user->last_name = 'User';
     $user->email = '*****@*****.**';
     $user->setPassword('user^^');
     $user->generateAuthKey();
     $user->status = User::STATUS_ACTIVE;
     $user->created_at = time();
     $user->updated_at = time();
     Yii::$app->db->createCommand()->insert(User::tableName(), $user->attributes, ArrayHelper::getColumn($user, 'attributes'))->execute();
     $authManager->assign($userRole, Yii::$app->db->getLastInsertID());
 }
Esempio n. 2
0
 /**
  * 判断指定的管理员组中是否有管理员
  * @param mixed $ids
  * @return boolean
  */
 public function isExistUser(array $ids)
 {
     $rows = (new Query())->select(['id'])->from(User::tableName())->where(['user_group_id' => $ids])->all();
     return !empty($rows);
 }
 public function getComment($operateId)
 {
     $query = (new Query())->select('a.*')->addSelect('b.username as username')->addSelect('c.avatar')->from(PhotoComment::tableName() . ' as a')->leftJoin(['b' => User::tableName()], 'a.user_id = b.id')->leftJoin(['c' => UserExtend::tableName()], 'a.user_id = c.user_id')->where('1=1')->andWhere(['a.photo_id' => $operateId])->orderBy(['a.created_at' => SORT_ASC]);
     return $query->createCommand()->queryAll();
 }
 public function getUserResponse($userId)
 {
     $Query = (new Query())->select('b.comment_content,b.created_at')->addSelect('c.username')->addSelect('c.realname')->addSelect('d.avatar')->from(Diary::tableName() . ' as a')->leftJoin(['b' => DiaryComment::tableName()], 'b.diary_id = a.id')->leftJoin(['c' => User::tableName()], 'b.user_id = c.id')->leftJoin(['d' => UserExtend::tableName()], 'd.user_id = c.id')->where('1=1')->andFilterWhere(['a.created_by' => $userId])->andFilterWhere(['b.comment_id' => 0])->andFilterWhere(['b.comment_type' => 0])->orderBy(['b.created_at' => SORT_DESC])->limit(10);
     $result = $Query->createCommand()->queryAll();
     return $result;
 }