QuestionController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /**
  3. * Created by north.Deng's MAC
  4. * User: north.Deng
  5. * Date: 2018/5/4
  6. * Time: 上午10:15
  7. * description :
  8. */
  9. class QuestionController extends AdminController {
  10. public function actionIndex()
  11. {
  12. $this->render('index',array(
  13. ));
  14. }
  15. public function actionList()
  16. {
  17. $pageParams = CommonFn::getPageParams();
  18. $status = intval(Yii::app()->request->getParam('status', 100));
  19. $criteria = new EMongoCriteria($pageParams);
  20. /*if ($status != 100 ) {
  21. $criteria->status('==',$status);
  22. }*/
  23. $cursor = Question::model()->findAll($criteria);
  24. $rows = CommonFn::getRowsFromCursor($cursor);
  25. $parsedRows = Question::model()->parse($rows);
  26. $total = $cursor->count();
  27. echo CommonFn::composeDatagridData($parsedRows, $total);
  28. }
  29. public function actionEdit()
  30. {
  31. $id = Yii::app()->request->getParam('id','');
  32. $title = Yii::app()->request->getParam('title','');
  33. $questions = Yii::app()->request->getParam('questions','');
  34. $question = Question::get(new MongoId($id));
  35. if (!empty($title)) {
  36. $question->title = $title;
  37. }
  38. if (!empty($questions)) {
  39. $data = array();
  40. foreach ($questions as $key => $value) {
  41. if ($key == 4) {
  42. $data['result'] = $value;
  43. } else {
  44. $data['question'][] = $value;
  45. }
  46. }
  47. $question->question = $data;
  48. }
  49. $question->save();
  50. CommonFn::requestAjax(true,'保存成功');exit;
  51. }
  52. public function actionAdd()
  53. {
  54. $title = Yii::app()->request->getParam('title','');
  55. $questions = Yii::app()->request->getParam('questions','');
  56. $data =array();
  57. foreach ($questions as $key => $value) {
  58. if (empty($value)) {
  59. CommonFn::requestAjax(false,'题目不能为空');exit;
  60. }
  61. if ($key == 4) {
  62. $data['result'] = $value;
  63. } else {
  64. $data['question'][] = $value;
  65. }
  66. }
  67. $question = new Question();
  68. $question->title = $title;
  69. $question->question = $data;
  70. $question->save();
  71. CommonFn::requestAjax(true,'保存成功');exit;
  72. }
  73. }