QuestionController.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Created by north.Deng's MAC
  4. * User: north.Deng
  5. * Date: 2018/5/4
  6. * Time: 下午12:34
  7. * description :
  8. */
  9. class QuestionController extends JBaseController
  10. {
  11. public function actionList()
  12. {
  13. /* $tmp = Question::get(new MongoId('5aebc756b292c9171883858a'));
  14. for ($i=0;$i<20;$i++) {
  15. $q = new Question();
  16. $q->title = $tmp->title;
  17. $q->question = $tmp->question;
  18. $q->save();
  19. }*/
  20. $pageParams = CommonFn::getPageParams();
  21. $cursor = Question::model()->findAll();
  22. $rows = CommonFn::getRowsFromCursor($cursor);
  23. $parsedRows = Question::model()->parse($rows);
  24. $total = $cursor->count();
  25. if ($total > 10) {
  26. $offset = rand(0,$total-10);
  27. $limit = 10;
  28. $pageParams['offset'] = $offset;
  29. $pageParams['limit'] = $limit;
  30. $criteria = new EMongoCriteria($pageParams);
  31. $cursor = Question::model()->findAll($criteria);
  32. $rows = CommonFn::getRowsFromCursor($cursor);
  33. $parsedRows = Question::model()->parse($rows);
  34. $total = $cursor->count();
  35. }
  36. echo CommonFn::composeDatagridData($parsedRows, $total);
  37. }
  38. public function actionResult()
  39. {
  40. $user_id = Yii::app()->request->getParam('id','');
  41. $score = Yii::app()->request->getParam('score','');
  42. $jgemp = JGEmploye::get(new MongoId($user_id));
  43. if (!empty($jgemp)) {
  44. $jgemp->score = $score;
  45. $jgemp->degree -= 1;
  46. $jgemp->save();
  47. }
  48. CommonFn::requestAjax(true, '答题完毕', array());
  49. }
  50. }