Ejemplo n.º 1
0
 public function getRolesByUser($user)
 {
     $query = new Query();
     $query->select(['r.id', 'r.category', 'r.name', 'r.description', 'r.is_system', 'r.sort_num']);
     $query->from(['r' => $this->roleTable, 'a' => $this->assignmentTable]);
     $query->where('r.id=a.role');
     $query->andWhere(['a.user' => $user]);
     $rows = $query->indexBy('id')->all();
     return $rows;
 }
Ejemplo n.º 2
0
 /**
  * Change language through $_GET params.
  */
 public function initLanguage()
 {
     $this->language = Yii::$app->language;
     $key = static::className() . 'Languages';
     $this->languages = Yii::$app->cache->get($key);
     if ($this->languages === false) {
         if ($this->langTable) {
             $query = new Query();
             $query->from($this->langTable)->where($this->langWhere)->orderBy($this->langOrder);
             $this->languages = $query->indexBy('id')->all();
         } else {
             $this->languages = [];
         }
         if ($this->languages === []) {
             $this->languages['0'] = ['id' => 0, $this->langColCode => $this->language, $this->langColLabel => $this->language];
         }
         if ($this->enableCaching) {
             if ($this->langTable && $this->langColUpdatedAt) {
                 $query = new Query();
                 $sql = $query->select('COUNT(*),MAX(' . $this->langColUpdatedAt . ')')->from($this->langTable)->createCommand()->getRawSql();
                 Yii::$app->cache->set($key, $this->languages, $this->durationCaching, new DbDependency(['sql' => $sql]));
             } else {
                 if ($this->durationCaching) {
                     Yii::$app->cache->set($key, $this->languages, $this->durationCaching);
                 }
             }
         }
     }
     $langKey = Yii::$app->request->get($this->langParam);
     if ($this->languages) {
         $language = null;
         if ($langKey) {
             foreach ($this->languages as $l) {
                 if ($l[$this->langColCode] == $langKey) {
                     $language = $l;
                     break;
                 }
             }
             if ($language === null) {
                 Yii::$app->on(Application::EVENT_AFTER_REQUEST, function () {
                     throw new HttpException(404, 'Page not exists');
                 });
             }
         }
         if ($language === null) {
             $language = reset($this->languages);
         }
         Yii::$app->language = $language[$this->langColCode];
         $this->language = $language;
         $this->languageId = $language['id'];
     }
     Yii::setAlias('weblang', Yii::getAlias('@web/' . Yii::$app->language));
 }