public function actionShow($id)
 {
     $program = ProgramRecord::findOne($id);
     $courses = CourseRecord::find()->where(['program_id' => $id])->all();
     $course_ids = ArrayHelper::getColumn($courses, 'id');
     $topics = TopicRecord::find()->where(['course_id' => $course_ids])->all();
     $topic_ids = ArrayHelper::getColumn($topics, 'id');
     $program_videos = ContentRecord::find()->where(['topic_id' => $topic_ids, 'type' => 'video'])->all();
     $program_pdf = ContentRecord::find()->where(['topic_id' => $topic_ids, 'type' => 'pdf'])->all();
     $program_img = ContentRecord::find()->where(['topic_id' => $topic_ids, 'type' => 'img'])->all();
     return $this->render('show', ['model_videos' => $program_videos, 'model_pdf' => $program_pdf, 'model_img' => $program_img, 'id' => $id, 'program' => $program]);
 }
 public function actionNotifications()
 {
     $user = Yii::$app->user->identity->getId();
     $userRecord = User::findOne($user);
     if ($userRecord->role == 10) {
         $models = ContentRecord::find()->where(['uploadedBy' => $user])->all();
         //$models=$modelsUsers->filterWhere(['flag'=>1])->orWhere(['flag'=>-1]);
     } else {
         $models = [];
     }
     return $this->render('/notifications/index', ['models' => $models]);
 }
Пример #3
0
                                                <li><i class="fa fa-clock-o"><?php 
    echo Yii::t('user', '{0, date}', $model->created_at);
    ?>
</i></li>
                                                <li>
                                                    <a href="#"><i class="fa fa-users">
                                                            <?php 
    echo \common\models\FollowerUsertoUser::find()->where(['followed_user_id' => $model->id])->count();
    ?>
</i>
                                                    </a>
                                                </li>
                                                <li>
                                                    <a href="#"><i class="fa fa-thumbs-o-up"> </i>
                                                        <?php 
    $contents = \common\models\content\ContentRecord::find()->where(['uploadedBy' => $model->id])->all();
    $contentsIds = \yii\helpers\ArrayHelper::getColumn($contents, 'id');
    $likeRecords = \common\models\LikeDislikeContent::find()->where(['content' => $contentsIds, 'likeOrDislike' => 1]);
    echo $likeRecords->count();
    ?>
                                                    </a>
                                                </li>
                                                <li>
                                                    <a href="#"><i class="fa fa-thumbs-o-down"> </i>
                                                        <?php 
    $dislikeRecords = \common\models\LikeDislikeContent::find()->where(['content' => $contentsIds, 'likeOrDislike' => 0]);
    echo $dislikeRecords->count();
    ?>
                                                    </a>
                                                </li>
                                            </ul>
 public function actionCreate($topic_id)
 {
     if (0 < $_FILES['file']['error']) {
         echo json_encode(['error' => 'error']);
     }
     if ($_FILES['file']['size'] > 2000000) {
         echo json_encode(['error' => 'File size exceeded']);
     } else {
         $ext = end(explode(".", $_FILES['file']['name']));
         if ($ext == 'mp4' || $ext == 'webm' || $ext == 'flv' || $ext == '3gp') {
             $type = 'video';
         } elseif ($ext == 'pdf') {
             $type = 'pdf';
         } elseif ($ext == 'jpg' || $ext == 'jpeg' || $ext == 'gif' || $ext == 'png') {
             $type = 'img';
         } else {
             echo json_encode(['error' => 'Check file type']);
             return;
         }
         $target = md5(uniqid());
         if (move_uploaded_file($_FILES['file']['tmp_name'], 'assets/Uploads/' . $target . '.' . $ext)) {
             $model = new ContentRecord();
             $model->name = $_FILES['file']['name'];
             $model->ext = $ext;
             $model->uploadedBy = \Yii::$app->user->identity->getId();
             $model->type = $type;
             $model->topic_id = $topic_id;
             $model->address = $target . '.' . $ext;
             $model->posted_at = time();
             if (User::findOne($model->uploadedBy)->role == 10) {
                 $model->flag = -1;
             } else {
                 $model->flag = 1;
             }
             //direct approved if teacher or admin
             if ($model->save()) {
                 echo json_encode(['error' => 'File successfully uploaded']);
             } else {
                 unlink(getcwd() . '/assets/Uploads/' . $target . '.' . $ext);
                 echo json_encode(['error' => $target . '.' . $ext]);
             }
         } else {
             echo json_encode(['error' => 'Could not upload file.']);
         }
     }
 }