Ejemplo n.º 1
0
 /**
  * Returns the post data to be editted.
  * @return PostRecord the post data to be editted.
  * @throws THttpException if the post data is not found.
  */
 protected function getProblem()
 {
     // the ID of the post to be editted is passed via GET parameter 'id'
     $problemID = (int) $this->Request['id'];
     // use Active Record to look for the specified post ID
     $problemRecord = ProblemRecord::finder()->findByPk($problemID);
     if ($problemRecord === null) {
         throw new THttpException(500, 'Problem is not found.');
     }
     return $problemRecord;
 }
Ejemplo n.º 2
0
 /**
  * Fetches problems from database with offset and limit.
  */
 protected function getProblems($offset, $limit)
 {
     $chapterID = (int) $this->Request['chapter'];
     // Construct a query criteria
     $criteria = new TActiveRecordCriteria();
     $criteria->Condition = 'chapter_id = :chap';
     $criteria->Parameters[':chap'] = $chapterID;
     $criteria->OrdersBy['problem_id'] = 'asc';
     $criteria->Limit = $limit;
     $criteria->Offset = $offset;
     // query for the posts with the above criteria and with author information
     return ProblemRecord::finder()->findAll($criteria);
 }