EnglishWeekController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. class EnglishWeekController extends Controller
  3. {
  4. //单元的短语和词汇数量
  5. public function actionAjaxWordPhraseCount()
  6. {
  7. $unitId = Req::post('ids');
  8. $grade = Req::post('grade');
  9. if(empty($unitId) || empty($grade)){
  10. echo json_encode(array('status'=>0,'message'=>'参数错误'));exit;
  11. }
  12. //全学科逻辑
  13. $textbook_arr = array();
  14. $wordCount = 0;
  15. $phraseCount = 0;
  16. $generateCount = array();
  17. if($unitId){
  18. $unitArr = explode(",",$unitId);
  19. if($unitArr){
  20. foreach($unitArr as $unitIds){
  21. $tempIds = explode("_",$unitIds);
  22. if(isset($tempIds[2]) && $tempIds[2]){
  23. $textbook_arr[] = $tempIds[2];
  24. }
  25. }
  26. }
  27. }
  28. if($textbook_arr){
  29. $data=$this->apiPost('all_library/getWordCouByUnit',array('textbook'=>$textbook_arr,'is_unit'=>true));
  30. $data=json_decode(json_encode($data),true);
  31. if(isset($data['status']) && $data['status'] && isset($data['data']) && $data['data']){
  32. $wordCount = isset($data['data']['word_cou'])?$data['data']['word_cou']:0;
  33. $phraseCount = isset($data['data']['phrase_cou'])?$data['data']['phrase_cou']:0;
  34. }
  35. }
  36. $semesterId = $this->semesterId;
  37. $generateSql = "select s.class_id,count(s.id) as num FROM english_week_setting s inner join class c on s.class_id=c.class_id WHERE c.grade={$grade} and s.semester_id='{$semesterId}' AND s.node_ids like '%{$unitId}%' GROUP BY s.class_id;";
  38. $res = $this->sConn->createCommand($generateSql)->queryAll();
  39. foreach ($res as $item){
  40. $generateCount[$item['class_id']] = (int)$item['num'];
  41. }
  42. $data = array('wordCount'=>(int)$wordCount,'phraseCount'=>$phraseCount, 'classCount'=>$generateCount);
  43. echo json_encode(array('status'=>1,'data'=>$data));
  44. exit;
  45. /*老流程暂时注释
  46. $sql = "select single_word,phrase from en_unit_single_phrase where id='{$unitId}'";
  47. $rs = Yii::app()->enStuffDb->createCommand($sql)->queryRow();
  48. $wordCount = 0;
  49. $phraseCount = 0;
  50. if($rs){
  51. $words = isset($rs['single_word']) && !empty($rs['single_word']) ? json_decode($rs['single_word'],true) : array();
  52. $phraseCount = isset($rs['phrase']) && !empty($rs['phrase']) ? count(json_decode($rs['phrase'],true)) : 0;
  53. }
  54. if(isset($words) && !empty($words)){
  55. $wordsStr = implode(',',$words);
  56. if($grade==3){
  57. $wordSql = "select count(*) from en_single_word WHERE core_words=1 and type_id=2 and levels>=4 and single_word_id in ($wordsStr)";
  58. }else{
  59. $wordSql = "select count(*) from en_single_word WHERE core_words=1 and type_id=2 and single_word_id in ($wordsStr)";
  60. }
  61. $wordCount = Yii::app()->enStuffDb->createCommand($wordSql)->queryScalar();
  62. }
  63. $semesterId = $this->semesterId;
  64. $generateSql = "select s.class_id,count(s.id) as num FROM english_week_setting s inner join class c on s.class_id=c.class_id WHERE c.grade={$grade} and s.semester_id='{$semesterId}' AND s.node_ids like '%{$unitId}%' GROUP BY s.class_id;";
  65. $res = $this->sConn->createCommand($generateSql)->queryAll();
  66. $generateCount = array();
  67. foreach ($res as $item){
  68. $generateCount[$item['class_id']] = (int)$item['num'];
  69. }
  70. $data = array('wordCount'=>(int)$wordCount,'phraseCount'=>$phraseCount, 'classCount'=>$generateCount);
  71. echo json_encode(array('status'=>1,'data'=>$data));
  72. exit;
  73. * */
  74. }
  75. public function actionUnits(){
  76. $this->layout = false;
  77. $data = array();
  78. $data['ids'] = Req::get('ids');
  79. $data['str'] = Req::get('str');
  80. $textboookTree = new MongodbEnglishTree();
  81. $criteria = new EMongoCriteria();
  82. $textbookData = $textboookTree->find($criteria,array());
  83. if($textbookData){
  84. foreach ($textbookData as $doc) {
  85. foreach($doc->attributes as $key => $value){
  86. if($key !== '_id'){
  87. if(isset($value['textbook_id']) && isset($value['name'])){
  88. $data['textbookNames'][$value['textbook_id']] = $value['name'];
  89. if(!isset($textbookId)){
  90. $textbookId = $value['textbook_id'];
  91. }
  92. if($textbookId == $value['textbook_id']){
  93. if(isset($value['module']) && $value['module']){
  94. foreach($value['module'] as $kk=>$vv){
  95. $data['moduleNames'][$vv['textbook_module_id']] = $vv['name'];
  96. if(!isset($moduleId)){
  97. $moduleId = $vv['textbook_module_id'];
  98. }
  99. if($moduleId == $vv['textbook_module_id']){
  100. if(isset($vv['unit']) && $vv['unit']){
  101. foreach($vv['unit'] as $kkk=>$vvv){
  102. $data['unitNames'][$vvv['textbook_unit_id']] = $vvv['name'];
  103. }
  104. }
  105. }
  106. }
  107. }
  108. }
  109. }
  110. }
  111. }
  112. }
  113. }
  114. $this->render('units', $data);
  115. }
  116. /**
  117. * 全学科教材数据
  118. */
  119. public function actionQxkUnits(){
  120. $ids= Req::get('ids');
  121. $str= Req::get('str');
  122. $textbooks=$modules=$units=array();
  123. $textbookResult=$this->apiPost('all_textbook/textbook',array('subject_id'=>8,'query_type'=>2));
  124. $textbookResult=json_decode(json_encode($textbookResult),true);
  125. if(isset($textbookResult['status']) && $textbookResult['status'] && isset($textbookResult['data']) && $textbookResult['data']){
  126. $textbookResult=$textbookResult['data'];
  127. foreach($textbookResult as $textbookKey=>$textbookItem){
  128. $textbooks[]=array('textbook_id'=>$textbookItem['textbook_id'],'textbook_name'=>$textbookItem['textbook_name']);
  129. if($textbookKey==0 && isset($textbookItem['child']) && $textbookItem['child']){
  130. foreach($textbookItem['child'] as $moduleKey=>$moduleItem){
  131. $modules[]=array('textbook_id'=>$moduleItem['textbook_id'],'textbook_name'=>$moduleItem['textbook_name']);
  132. if($moduleKey==0 && isset($moduleItem['child']) && $moduleItem['child']){
  133. foreach($moduleItem['child'] as $unitItem){
  134. $units[]=array('textbook_id'=>$unitItem['textbook_id'],'textbook_name'=>$unitItem['textbook_name']);
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. $data=array(
  142. 'textbooks'=>$textbooks,//版本
  143. 'modules'=>$modules,//模块
  144. 'units'=>$units,//单元
  145. 'ids'=>$ids,
  146. 'str'=>$str
  147. );
  148. $this->render('qxk_units', $data);
  149. }
  150. }