IndexController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. <?php
  2. /**
  3. * 助教端首页控制器类
  4. * @author jiangfei
  5. * @date 2015-09-22 10:00:00
  6. * @company 上海风车教育有限公司.
  7. */
  8. class IndexController extends Controller{
  9. public function actionGetPermission(){
  10. $token = Req::get("t");
  11. if($token == "7c6d4e33c4f0b1de45f25136f3e5bc9f"){
  12. Yii::app()->session["role"] = 2;
  13. echo '<script>alert("已获取超级用户权限,请谨慎进行删除操作");location.href="'.$this->createUrl("index/index").'";</script>';
  14. }
  15. }
  16. // 首页
  17. public function actionIndex(){
  18. $getClass = array();
  19. $printList = array();
  20. $notifyList = array();
  21. if (Yii::app()->session['coachInfo']['leader'] == 1) { // 教练组长
  22. /*+++++++++++ 获取当前学期所有班级 +++++++++++*/
  23. $getClass = ClassModel::model()->findAll('semester_id=:sid',array(':sid'=>Yii::app()->session['session_semester_id']));
  24. /*+++++++++++ 获取所有打印任务 +++++++++++*/
  25. // 获取当前学期班级并组装
  26. $class_array= ClassModel::model()->findAll('semester_id='.Yii::app()->session['session_semester_id']);
  27. $ccArray = array();
  28. $ccName = array();
  29. foreach ($class_array as $cc=>$ca) {
  30. array_push($ccArray, $ca->class_id);
  31. $ccName[$ca->class_id] = $ca->class_name;
  32. }
  33. $ExamModel = Exam::model();
  34. $ClassModel = ClassModel::model();
  35. $resultList = ClassExamPrinter::model()->getPrintList();
  36. foreach ($resultList as $k=>$v) {
  37. if (in_array($v->class_id, $ccArray)) {
  38. $printList[$k] = $v->attributes;
  39. $printList[$k]['class_name'] = @$ccName[$v->class_id];
  40. $pname = @$ExamModel->getExamName($v->exam_id); // 周周练名称
  41. if ($v->type == 1) {
  42. $printList[$k]['print_name']= $pname.'"错题本"打印任务!';
  43. } elseif ($v->type == 2) {
  44. $printList[$k]['print_name']= $pname.'"提分册"打印任务!';
  45. } else {
  46. $printList[$k]['print_name']= $pname.'打印任务!';
  47. }
  48. }
  49. }
  50. /*+++++++++++ 获取所有动态消息 +++++++++++ */
  51. $teacher = Teacher::model();
  52. $getNotify = NotifyModel::model()->getNotifyList(Yii::app()->session['session_semester_id']);
  53. foreach ($getNotify as $key=>$val) {
  54. $notifyList[$key] = $val->attributes;
  55. $notifyList[$key]['teacher_name'] = $teacher->getTeacherName($val->teacher_id);
  56. }
  57. } else { // 教员
  58. /*+++++++++++ 获取当前教员所管理班级 +++++++++++*/
  59. $getClass = ClassModel::model()->getClassArray(Yii::app()->session['session_semester_id'],Yii::app()->session['coachInfo']['coach_id']);
  60. /*+++++++++++ 获取当前教员打印任务 +++++++++++*/
  61. // 获取教员管理的班级
  62. $coachClass = $this->schoolManager->getCoachClassesRelations($this->coachId, "OBJ");
  63. // 获取当前学期班级
  64. $class_array= ClassModel::model()->findAll('semester_id='.Yii::app()->session['session_semester_id']);
  65. if (!empty($coachClass) && !empty($class_array)) {
  66. // 获取当前教师当前学期管理的班级
  67. $cidArray = array();
  68. foreach ($class_array as $t){
  69. foreach ($coachClass as $tt) {
  70. if ($t->class_id == $tt->class_id) {
  71. array_push($cidArray, $tt->class_id);
  72. }
  73. continue;
  74. }
  75. }
  76. // 是否找到班级
  77. if (!empty($cidArray)) {
  78. $ExamModel = Exam::model();
  79. $ClassModel = ClassModel::model();
  80. $resultList = ClassExamPrinter::model()->getPrintList();
  81. foreach ($resultList as $k=>$v) {
  82. $pn = 0;
  83. if (in_array($v->class_id, $cidArray)) {
  84. $printList[$pn] = $v->attributes;
  85. $printList[$pn]['class_name'] = @$ClassModel->getClassName($v->class_id);
  86. $pname = @$ExamModel->getExamName($v->exam_id); // 周周练名称
  87. if ($v->type == 1) {
  88. $printList[$pn]['print_name']= $pname.'"错题本"打印任务!';
  89. } elseif ($v->type == 2) {
  90. $printList[$pn]['print_name']= $pname.'"提分册"打印任务!';
  91. } else {
  92. $printList[$pn]['print_name']= $pname.'打印任务!';
  93. }
  94. }
  95. ++$pn;
  96. continue;
  97. }
  98. /*+++++++++++ (当存在教员直接班级时)获取当前教员动态信息 +++++++++++*/
  99. // 获取当前学期教师对应班级集合
  100. $tidArray = array();
  101. $getRelation = TeacherToClass::model()->findAll('semester_id='.Yii::app()->session['session_semester_id']);
  102. if (!empty($getRelation)) {
  103. foreach ($getRelation as $rl) {
  104. if (in_array($rl->class_id,$cidArray)) {
  105. array_push($tidArray, $rl->teacher_id);
  106. }
  107. }
  108. }
  109. if (!empty($tidArray)) {
  110. $teacher = Teacher::model();
  111. $getNotify = NotifyModel::model()->getNotifyList(Yii::app()->session['session_semester_id']);
  112. foreach ($getNotify as $key=>$val) {
  113. $i = 0;
  114. if (in_array($val->teacher_id,$tidArray)){
  115. $notifyList[$i] = $val->attributes;
  116. $notifyList[$i]['teacher_name'] = $teacher->getTeacherName($val->teacher_id);
  117. }
  118. ++$i;
  119. continue;
  120. }
  121. //dump($notifyList);die;
  122. }
  123. }
  124. }
  125. }
  126. //dump($examList);
  127. $data = array();
  128. $data['classList'] = $getClass;
  129. $data['printList'] = $printList;
  130. $data['notifyList'] = $notifyList;
  131. $this->render('index',$data);
  132. }
  133. // ajax获取教师打印任务等
  134. public function actionGettask(){
  135. $criteria = new CDbCriteria;
  136. $criteria->select = 'exam_id,teacher_id,name,type,status';
  137. $criteria->condition= 'status !=1';
  138. $criteria->limit = 20;
  139. $criteria->order = 'exam_id DESC';
  140. $getLsit = Exam::model()->findAll($criteria);
  141. $teacher = Teacher::model();
  142. $ClassModel = ClassModel::model();
  143. $examList = array();
  144. foreach ($getLsit as $key=>$val) {
  145. //$examList[$key] = $val->attributes;
  146. if ($val->type == 1) {
  147. $typeName = '周周练';
  148. }
  149. $examList[$key]['name'] = $val->name;
  150. $examList[$key]['type_name'] = $typeName;
  151. $examList[$key]['teacher_name'] = $teacher->getTeacherName($val->teacher_id);
  152. $examList[$key]['class_name'] = $ClassModel->getClassName($this->schoolManager->getExamClassId($val->exam_id));
  153. }
  154. echo json_encode($examList);exit;
  155. }
  156. // ajax获取动态信息
  157. public function actionGetnotify(){
  158. $criteria = new CDbCriteria;
  159. $criteria->condition= 'semester_id=:sid and is_hide=0';
  160. $criteria->params=array(':sid'=>Yii::app()->session['session_semester_id']);
  161. $criteria->limit = 20;
  162. $criteria->order = 'id DESC';
  163. $getNotify = NotifyModel::model()->findAll($criteria);
  164. $notifyList = array();
  165. $teacher = Teacher::model();
  166. foreach ($getNotify as $key=>$val) {
  167. $notifyList[$key] = $val->attributes;
  168. $notifyList[$key]['teacher_name'] = $teacher->getTeacherName($val->teacher_id);
  169. }
  170. echo json_encode($notifyList);exit;
  171. }
  172. // 选着学期操作
  173. public function actionSelect(){
  174. if (isset($_POST['smid']) && !empty($_POST['smid'])) {
  175. $json = array();
  176. $smid = safe_replace($_POST['smid']);
  177. $findInfo = Semester::model()->find('semester_id=:smid',array(':smid'=>$smid));
  178. if (empty($findInfo)) {
  179. $json['flag'] = false;
  180. echo json_encode($json);die;
  181. }
  182. // 重新设置学期session
  183. if($this->schoolManager->changeSemester($findInfo->semester_id)){
  184. Yii::app()->session['session_semester_id'] = $findInfo->semester_id;
  185. Yii::app()->session['session_semester_name'] = $findInfo->semester_name;
  186. if ($findInfo->status == 1){
  187. unset(Yii::app()->session['session_semester_state']);
  188. } else {
  189. //Yii::app()->session['session_semester_state'] = 12;
  190. }
  191. }
  192. $json['flag'] = true;
  193. $json['findInfo'] = $findInfo->semester_name;
  194. echo json_encode($json);die;
  195. }
  196. $data = array();
  197. $data['semesterId'] = Yii::app()->session['session_semester_id'];
  198. $data['allSemester']= Semester::model()->findAll();
  199. $this->renderPartial('select',$data);
  200. }
  201. public function actionShowTips(){
  202. if($tips = Yii::app()->cache->get("coach_".Yii::app()->session->sessionID."_tips")){
  203. $this->render("tips", array("tips" => $tips));
  204. //Yii::app()->cache->delete("tips");
  205. }else
  206. {
  207. $tips = array(
  208. 'title' => '失效',
  209. 'result' => '内容失效!',
  210. 'content' => '内容失效!',
  211. 'url' => Yii::app()->createUrl('classes/index')
  212. );
  213. $this->render("tips", array("tips" => $tips));
  214. }
  215. }
  216. public function actionShowTipss(){
  217. if($tips = Yii::app()->cache->get("coach_".Yii::app()->session->sessionID."_tipss")){
  218. $this->render("tipss", array("tips" => $tips));
  219. //Yii::app()->cache->delete("tips");
  220. }else
  221. {
  222. $tips = array(
  223. 'title' => '失效',
  224. 'result' => '内容失效!',
  225. 'content' => '内容失效!',
  226. 'url' => Yii::app()->createUrl('record/index')
  227. );
  228. $this->render("tips", array("tips" => $tips));
  229. }
  230. }
  231. }