public function actionFollowedprograms($id) { $followings = FollowerProgram::find()->where(['user_id' => $id])->all(); $following_programs_ids = ArrayHelper::getColumn($followings, 'program_id'); $query = ProgramRecord::find()->where(['id' => $following_programs_ids]); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $models = $query->offset($pages->offset)->limit($pages->limit)->all(); return $this->render('showFollowedPrograms', ['models' => $models, 'caller' => $id]); }
public function suggestionsForPrograms() { $current_user = \Yii::$app->user->identity->getId(); $programsFollowedByCurrentUser = FollowerProgram::find()->where(['user_id' => $current_user])->all(); if (empty($programsFollowedByCurrentUser)) { $programs = ProgramRecord::find()->all(); $scoresOfEachProgram = []; $models = []; foreach ($programs as $program) { $follows = $program->noOfFollowers; $likes = $program->noOLikes; $dislikes = $program->noOfDislikes; $score = 2 * $follows + $likes - 0.5 * $dislikes; $scoresOfEachProgram[$program->id] = $score; } arsort($scoresOfEachProgram); foreach (array_keys($scoresOfEachProgram) as $id) { $program = ProgramRecord::findOne($id); array_push($models, $program); } return $models; } else { $targetPrograms = []; foreach ($programsFollowedByCurrentUser as $followedProgram) { $allFollowersOfFollowedProgram = FollowerProgram::find()->where(['program_id' => $followedProgram->program_id])->all(); foreach ($allFollowersOfFollowedProgram as $singleFollowerOfFollowee) { $followeesOfFollowerOfFolloweesOfCurrentUser = FollowerProgram::find()->where(['user_id' => $singleFollowerOfFollowee->user_id])->all(); foreach ($followeesOfFollowerOfFolloweesOfCurrentUser as $targetProgram) { array_push($targetPrograms, $targetProgram); } } } $followingProgramsIds = ArrayHelper::getColumn($programsFollowedByCurrentUser, 'program_id'); $targetProgramsIds = ArrayHelper::getColumn($targetPrograms, 'program_id'); $resultProgramsIds = array_diff($targetProgramsIds, $followingProgramsIds); $countOfPrograms = array_count_values($resultProgramsIds); $scoresOfEachProgram = []; foreach (array_unique($resultProgramsIds) as $programId) { $followersOfProgram = FollowerProgram::find()->where(['program_id' => $programId])->all(); $firstWeight = count($followersOfProgram); $secondWeight = $countOfPrograms[$programId]; $scoresOfEachProgram[$programId] = ($firstWeight + $secondWeight) / 2; } $models = []; arsort($scoresOfEachProgram); foreach (array_keys($scoresOfEachProgram) as $id) { $program = ProgramRecord::findOne($id); array_push($models, $program); } return $models; } }
use yii\helpers\Html; $university = \common\models\university\UniversityRecord::findOne($university_id)->name; $this->params['breadcrumbs'][] = $university; ?> <!--1 Coulm horizontal listing--> <div class="card-panel horizontal-listing no-padding search-class"> <div class="container-fluid"> <h4 class="black-text"><?php echo $university; ?> <i class="material-icons"></i></h4> <hr> <?php foreach ($models as $model) { $programs = \common\models\program\ProgramRecord::find()->where(['faculty_id' => $model->id]); ?> <a> <div class="row hoverable"> <div class="col-sm-4"> <img src="http://mdbootstrap.com/images/reg/reg%20(54).jpg" class="img-responsive z-depth-2"> </div> <div class="col-sm-8"> <?php $link_faculty = '<h5 class="title">' . $model->name . '</h5>'; echo Html::a($link_faculty, ['/program/index', 'university' => $university, 'faculty_id' => $model->id]); ?> <ul class="list-inline item-details"> <li><i class="fa fa-clock-o"> 05/10/2015 | </i></li> <li><a>Programs <?php echo $programs->count();