示例#1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMarkActions()
 {
     return $this->hasMany(MarkActions::className(), ['group_id' => 'id']);
 }
示例#2
0
文件: MarkIt.php 项目: roman1970/lis
 /**
  * Средняя оценка юзера
  * @param $group_id
  * @return array|\yii\db\ActiveRecord[]
  */
 public static function getThisGroupUsersAverageMark($group_id)
 {
     $group_users = [];
     $group_actions = MarkActions::findAll(['group_id' => $group_id]);
     $id_actions = [];
     foreach ($group_actions as $act) {
         $id_actions[] = $act->id;
     }
     $usermarks = self::find()->select(['user_id, ball, COUNT(*) as cnt, AVG(ball) as avg '])->where('action_id IN (' . implode(',', $id_actions) . ')')->groupBy('user_id')->orderBy(['avg' => SORT_DESC])->all();
     //SELECT model, COUNT(model) AS Qty_model,
     // AVG(price) AS Avg_price
     //SELECT * FROM dates GROUP BY name;
     return $usermarks;
 }
示例#3
0
 /**
  * Показывает оцениваемые действия
  * @return string
  */
 public function actionMarkact()
 {
     if (Yii::$app->getRequest()->getQueryParam('group') && Yii::$app->getRequest()->getQueryParam('user')) {
         $group = Yii::$app->getRequest()->getQueryParam('group');
         $user = Yii::$app->getRequest()->getQueryParam('user');
         $this->layout = '@app/themes/markself/views/layouts/pagein';
         if ($this->userIfUserLegal($user)) {
             $actions = MarkActions::find()->where(['group_id' => $group])->all();
             $group_name = MarkGroup::findOne($group)->name;
             return $this->render('mark_actions', ['user' => $this->current_user, 'actions' => $actions, 'group_name' => $group_name]);
         }
     }
     return $this->render('index');
 }