Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function actionEventList($pagin = null)
- {
- $pagin = isset($_REQUEST['pagin']) ? $_REQUEST['pagin']: null;
- /* find all lectors & admins as array id=>fullName*/
- $queryLectorAdmin = new Query();
- $lectorsRows = $queryLectorAdmin->select(['id','username','secondname','role'])
- ->from('cultusers')
- ->where(['role'=>[Cultusers::ROLE_LECTOR, Cultusers::ROLE_MODERATOR]])->all();
- $lectorsArr = [];
- $adminsArr = [];
- foreach($lectorsRows as $row) {
- $username = array_key_exists('username',$row) ? $row['username'] : null;
- $secondname = array_key_exists('secondname',$row) ? $row['secondname'] : null;
- $id = (string)$row['_id'];
- if($row['role'] == 5){
- $lectorsArr[$id] = $username.' '.$secondname;
- } elseif($row['role'] == 10){
- $adminsArr[$id] = $username.' '.$secondname;
- }
- }
- /* END find all lectors & admins as array id=>fullName*/
- /* find all courses array id=>courseName */
- $queryCourse = new Query();
- $courseRows = $queryCourse ->select(['id','course','season.name'])->from('courses')->all();
- $coursesArr =[];
- foreach($courseRows as $courseRow){
- $id = (string)$courseRow['_id'];
- $courseName = $courseRow['course'].' ('.$courseRow['season']['name'].')';
- $coursesArr[$id] = $courseName;
- }
- /* END find all courses array id=>courseName */
- /* find all places array id=>placeName */
- $queryPlace = new Query();
- $placesRows = $queryPlace->select(['_id','place'])->from('places')->all();
- $placesArr = [];
- foreach($placesRows as $placeRow){
- $id = (string)$placeRow['_id'];
- $placeName = $placeRow['place'];
- $placesArr[$id] = $placeName;
- }
- /* END find all places array id=>placeName */
- $lections = \common\models\Lections::find()->indexBy('_id')
- // ->where(
- // [
- // 'season.name' => [Lections::season(date('Y', time()) - 2009),
- // Lections::season(date('Y', time()) - 2010)] // "2014-2015"
- // ]
- // )
- ->orderBy(['dates' => SORT_DESC])
- ->limit(40)->offset($pagin)
- ->all();
- $lectionIds = array_keys($lections);
- $lec = '';
- foreach($lectionIds as $l) {
- $lec .= sprintf("'%s'".', ',$l);
- }
- $lec = trim($lec, ", ");
- $db = Yii::$app->db;
- $msql = "SELECT lection_id, lection_timestamp, admin_id, COUNT( lection_id ) AS visit_count
- FROM `visit`
- WHERE lection_id IN($lec)
- GROUP BY lection_id";
- $command = $db->createCommand($msql);
- $result = $command->queryAll();
- $command->execute();
- $lectionAdmins = [];
- foreach($result as $rezRow){
- $lectionAdmins[$rezRow['lection_id']] =
- array_key_exists($rezRow['admin_id'],$adminsArr) ?
- $adminsArr[$rezRow['admin_id']] : '';
- $lectionAdmins = array_filter($lectionAdmins);
- }
- $lectorIds = array_map(
- function ($lection) {
- return $lection->lectorId;
- },
- $lections
- );
- $lectionLectors = [];
- foreach ($lectorIds as $lectionId => $lectorId) {
- foreach ($lectorId as $val) {
- $lectorName = array_key_exists($val, $lectorsArr) ? $lectorsArr[$val] : '' ;
- if(array_key_exists($lectionId, $lectionLectors)){
- $lectionLectors[$lectionId] = $lectionLectors[$lectionId].' '. $lectorName ;
- $lectionLectors = array_filter($lectionLectors);
- } else {
- $lectionLectors[$lectionId] = $lectorName ;
- $lectionLectors = array_filter($lectionLectors);
- }
- }
- }
- $coursesIds = array_map(
- function ($lection) {
- return $lection->course;
- },
- $lections
- );
- $lectionCourses = [];
- foreach ($coursesIds as $lectionId => $courseId) {
- $lectionCourses[$lectionId] = array_key_exists($courseId,$coursesArr) ?
- $coursesArr[$courseId] : '';
- $lectionCourses = array_filter($lectionCourses);
- }
- $placesIds = array_map(
- function ($lection) {
- return $lection->place;
- },
- $lections
- );
- $placesIds = array_filter($placesIds);
- $lectionPlaces = [];
- foreach($placesIds as $lectionId => $placeId){
- $lectionPlaces[$lectionId] = array_key_exists($placeId, $placesArr) ?
- $placesArr[$placeId] : '';
- $lectionPlaces = array_filter($lectionPlaces);
- }
- if(\Yii::$app->request->method == 'POST'){
- $resp = $this->renderPartial("add-evlist",
- [
- 'result' => $result,
- 'lections' => $lections,
- 'lectionAdmins' => $lectionAdmins,
- 'lectionLectors' => $lectionLectors,
- 'lectionCourses' => $lectionCourses,
- 'lectionPlaces' => $lectionPlaces,
- 'now' => $now = time()
- ]);
- return $resp;
- } else {
- return $this->render(
- 'event-list',
- [
- 'admins' => $adminsArr,
- 'places' => $placesArr,
- 'courses' => $coursesArr,
- 'lectors' => $lectorsArr,
- 'result' => $result,
- 'lections' => $lections,
- 'lectionAdmins' => $lectionAdmins,
- 'lectionLectors' => $lectionLectors,
- 'lectionCourses' => $lectionCourses,
- 'lectionPlaces' => $lectionPlaces,
- 'now' => $now = time()
- ]
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement