Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 81 |
| StatController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 6 |
72.00 | |
0.00% |
0 / 78 |
| behaviors | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 14 |
|||
| actionIndex | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 16 |
|||
| getMeetingStatsQuery | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 12 |
|||
| getMeetingStatsSummaryQuery | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 10 |
|||
| getNationalMeetingQuery | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 13 |
|||
| getInternationalMeetingQuery | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 13 |
|||
| <?php | |
| namespace backend\controllers; | |
| use Yii; | |
| use common\models\Organization; | |
| use common\models\Participant; | |
| use common\models\Meeting; | |
| use yii\data\ActiveDataProvider; | |
| use yii\db\Query; | |
| use yii\filters\AccessControl; | |
| use yii\helpers\ArrayHelper; | |
| use yii\web\Controller; | |
| /** | |
| * StatsController implements the show stats for Event. | |
| */ | |
| class StatController extends Controller | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| 'access' => [ | |
| 'class' => AccessControl::className(), | |
| 'rules' => [ | |
| [ | |
| 'actions' => ['index'], | |
| 'allow' => true, | |
| 'roles' => ['supervisor', 'admin'], | |
| ], | |
| ], | |
| ], | |
| ]; | |
| } | |
| /** | |
| * List event stats | |
| * @return mixed | |
| */ | |
| public function actionIndex() | |
| { | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => static::getMeetingStatsQuery(), | |
| 'pagination' => false, | |
| ]); | |
| $summary = static::getMeetingStatsSummaryQuery()->one(); | |
| $participants_count = ArrayHelper::getValue($summary, 'participants'); | |
| $national_meetings_count = ArrayHelper::getValue($summary, 'national_meetings'); | |
| $international_meetings_count = ArrayHelper::getValue($summary, 'international_meetings') *2; | |
| return $this->render('index', [ | |
| 'dataProvider' => $dataProvider, | |
| 'participants_count' => $participants_count, | |
| 'national_meetings_count' => $national_meetings_count, | |
| 'international_meetings_count' => $international_meetings_count, | |
| ]); | |
| } | |
| protected static $meetingStatsSelect = 'count(DISTINCT e.id) AS participants, count(DISTINCT mn.id) AS national_meetings, count(DISTINCT mi.id) AS international_meetings'; | |
| protected static function getMeetingStatsQuery() | |
| { | |
| $queryNational = static::getNationalMeetingQuery(); | |
| $queryInternational = static::getInternationalMeetingQuery(); | |
| return (new Query) | |
| ->select(['c.country', static::$meetingStatsSelect]) | |
| ->from(['c' => Organization::tableName()]) | |
| ->innerJoin(['e' => Participant::tableName()], 'e.organization_id = c.id') | |
| ->leftJoin(['mn' => $queryNational], 'mn.host_participant_id = e.id OR mn.guest_participant_id = e.id') | |
| ->leftJoin(['mi' => $queryInternational], 'mi.host_participant_id = e.id OR mi.guest_participant_id = e.id') | |
| ->groupBy('c.country') | |
| ->orderBy('c.country'); | |
| } | |
| protected static function getMeetingStatsSummaryQuery() | |
| { | |
| $queryNational = static::getNationalMeetingQuery(); | |
| $queryInternational = static::getInternationalMeetingQuery(); | |
| return (new Query) | |
| ->select(static::$meetingStatsSelect) | |
| ->from(['c' => Organization::tableName()]) | |
| ->innerJoin(['e' => Participant::tableName()], 'e.organization_id = c.id') | |
| ->leftJoin(['mn' => $queryNational], 'mn.host_participant_id = e.id OR mn.guest_participant_id = e.id') | |
| ->leftJoin(['mi' => $queryInternational], 'mi.host_participant_id = e.id OR mi.guest_participant_id = e.id'); | |
| } | |
| protected static $nationalMeetingQuery; | |
| protected static function getNationalMeetingQuery() | |
| { | |
| if(static::$nationalMeetingQuery === null){ | |
| static::$nationalMeetingQuery = (new Query) | |
| ->select('m.*') | |
| ->from(['m' => Meeting::tableName()]) | |
| ->innerJoin(['eh' => Participant::tableName()], 'eh.id = m.host_participant_id') | |
| ->innerJoin(['eg' => Participant::tableName()], 'eg.id = m.guest_participant_id') | |
| ->innerJoin(['ch' => Organization::tableName()], 'ch.id = eh.organization_id') | |
| ->innerJoin(['cg' => Organization::tableName()], 'cg.id = eg.organization_id') | |
| ->where('ch.country = cg.country'); | |
| } | |
| return static::$nationalMeetingQuery; | |
| } | |
| protected static $internationalMeetingQuery; | |
| protected static function getInternationalMeetingQuery() | |
| { | |
| if(static::$internationalMeetingQuery === null){ | |
| static::$internationalMeetingQuery = (new Query) | |
| ->select('m.*') | |
| ->from(['m' => Meeting::tableName()]) | |
| ->innerJoin(['eh' => Participant::tableName()], 'eh.id = m.host_participant_id') | |
| ->innerJoin(['eg' => Participant::tableName()], 'eg.id = m.guest_participant_id') | |
| ->innerJoin(['ch' => Organization::tableName()], 'ch.id = eh.organization_id') | |
| ->innerJoin(['cg' => Organization::tableName()], 'cg.id = eg.organization_id') | |
| ->where('ch.country <> cg.country'); | |
| } | |
| return static::$internationalMeetingQuery; | |
| } | |
| } |