/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Exams::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['ExamId' => $this->ExamId, 'Message' => $this->Message, 'Decription' => $this->Decription, 'MaxScore' => $this->MaxScore, 'NumQuestions' => $this->NumQuestions, 'IsActive' => $this->IsActive, 'SubjectSectionId' => $this->SubjectSectionId]); return $dataProvider; }
public function actionFeed() { $query = "SELECT * FROM exams ORDER BY `ExamId` DESC"; $exams = Exams::findBySql($query)->all(); $model = new NewsFeed(); $newComment = new Comments(); $sql = "SELECT * FROM posts ORDER BY `TimeStamp` DESC"; $models = NewsFeed::findBySql($sql)->all(); $sql2 = "SELECT *, MAX(Likes) FROM posts"; $popular = NewsFeed::findBySql($sql2)->one(); $comments_popular = $popular->comments; $sql3 = "SELECT * FROM posts WHERE Pinned = 1"; $pinned = NewsFeed::findBySql($sql3)->one(); $comments_pinned = $pinned->comments; $sort = new Sort(['attributes' => ['TimeStamp' => ['asc' => ['TimeStamp' => SORT_ASC], 'desc' => ['TimeStamp' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'Latest']]]); $sql4 = "SELECT MAX(PostID) AS PostID FROM posts"; $max_id = NewsFeed::findBySql($sql4)->one(); $upload_id_posts = $max_id->PostID; $sql5 = "SELECT MAX(CommentID) AS CommentID FROM comments"; $max_id2 = Comments::findBySql($sql5)->one(); $upload_id_comments = $max_id2->CommentID; $success = false; if ($model->load(Yii::$app->request->post())) { //$model->PostContent = "Sample na naman"; $model->TimeStamp = date("Y-m-d H:i:s"); $post_title = substr($model->PostContent, 0, 15); $model->PostTitle = $post_title . "..."; $user = Users::find()->where(['UserID' => $model->UserID])->one(); $model->Attachment = UploadedFile::getInstance($model, 'Attachment'); if ($model->Attachment && $model->validate()) { $model->Attachment->saveAs('../uploads/posts/' . $model->Attachment->baseName . '_00000' . $upload_id_posts . '.' . $model->Attachment->extension); $model->Attachment = $model->Attachment->baseName . '_00000' . $upload_id_posts . '.' . $model->Attachment->extension; } if ($model->save()) { $success = true; } } if ($newComment->load(Yii::$app->request->post())) { $newComment->TimeStamp = date("Y-m-d H:i:s"); $newComment->Attachment = UploadedFile::getInstance($newComment, 'Attachment'); if ($newComment->Attachment && $newComment->validate()) { $newComment->Attachment->saveAs('../uploads/comments/' . $newComment->Attachment->baseName . '_11111' . $upload_id_comments . '.' . $newComment->Attachment->extension); $newComment->Attachment = $newComment->Attachment->baseName . '_11111' . $upload_id_comments . '.' . $newComment->Attachment->extension; } if ($newComment->save()) { $success = true; } } //Yii::info($comments, __METHOD__); if ($success) { return $this->refresh(); } else { return $this->render('feed', ['model' => $model, 'models' => $models, 'newComment' => $newComment, 'popular' => $popular, 'comments_popular' => $comments_popular, 'pinned' => $pinned, 'comments_pinned' => $comments_pinned, 'sort' => $sort, 'exams' => $exams]); } }
use app\models\ExamStudent; /* @var $this yii\web\View */ /* @var $model app\models\Exams */ $this->title = $id; $this->params['breadcrumbs'][] = ['label' => 'Exams', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="exams-view"> <h1><?php echo Html::encode($this->title); ?> </h1> <?php $model = Exams::findOne($id); ?> <?php echo DetailView::widget(['model' => $model, 'attributes' => ['Message', 'MaxScore', 'NumQuestions']]); ?> <?php $result = ExamStudent::findOne(['ExamId' => $id, 'StudentId' => Yii::$app->user->identity->UserID]); if ($result) { echo '<h3>Score: ' . $result->Score . '</h3>'; } else { echo '<h2>Questions</h2> <br />'; $i = 1; $questions = ExamQuestion::findAll(['ExamId' => $id]);
/** * Finds the Exams model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Posts the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Exams::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }