SStudentClassRelation.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <?php
  2. /**
  3. * @author: CeeFee
  4. * @description: 班级
  5. */
  6. class SStudentClassRelation extends MyActiveRecord
  7. {
  8. public static function model($className = __CLASS__)
  9. {
  10. return parent::model($className);
  11. }
  12. public function tableName()
  13. {
  14. return 'student_class_relation';
  15. }
  16. public function getRelationsByClassId_Status_0($classId)
  17. {
  18. $result = array();
  19. if ($classId AND is_numeric($classId))
  20. {
  21. $criteria = new CDbCriteria();
  22. $criteria->addCondition("class_id = '". $classId ."' AND status = '0'");
  23. $result = $this->findAll($criteria);
  24. }
  25. return $result;
  26. }
  27. public function getRelationsByClassId_Status_0_count($classId)
  28. {
  29. $result = array();
  30. if ($classId AND is_numeric($classId))
  31. {
  32. $criteria = new CDbCriteria();
  33. $criteria->addCondition("class_id = '". $classId ."' AND status = '0'");
  34. $result = $this->count($criteria);
  35. }
  36. return $result;
  37. }
  38. public function getRelationsByClassIds_Status_0($classIds)
  39. {
  40. $result = array();
  41. if ($classIds AND is_array($classIds))
  42. {
  43. $criteria = new CDbCriteria();
  44. $criteria->addCondition("class_id IN (". implode(',', $classIds) .") AND status = '0'");
  45. $result = $this->findAll($criteria);
  46. }
  47. return $result;
  48. }
  49. public function getStudentIdsByClassId_Status_0($classId)
  50. {
  51. $relations = $this->getRelationsByClassId_Status_0($classId);
  52. $result = array();
  53. if ($relations)
  54. {
  55. foreach ($relations AS $relation)
  56. {
  57. $result[] = $relation['student_id'];
  58. }
  59. }
  60. return $result ? array_unique($result) : $result;
  61. }
  62. public function getStudentNosByClassId_Status_0($classId)
  63. {
  64. $relations = $this->getRelationsByClassId_Status_0($classId);
  65. $result = array();
  66. if ($relations)
  67. {
  68. foreach ($relations AS $relation)
  69. {
  70. $result[$relation['student_id']] = $relation['userno'];
  71. }
  72. }
  73. return $result;
  74. }
  75. public function getClassStudentIdsByClassIds_Status_0($classIds)
  76. {
  77. $relations = $this->getRelationsByClassIds_Status_0($classIds);
  78. $result = array();
  79. if ($relations)
  80. {
  81. foreach ($relations AS $relation)
  82. {
  83. if ( ! isset($result[$relation['class_id']]))
  84. {
  85. $result[$relation['class_id']] = array();
  86. }
  87. $result[$relation['class_id']][] = $relation['student_id'];
  88. }
  89. }
  90. return $result;
  91. }
  92. public function getStudentInfoByClassId($classId,$studentName='')
  93. {
  94. if($studentName){
  95. $sql = "SELECT s.realname,p.student_id,p.serial_number
  96. FROM student_class_relation as p
  97. LEFT JOIN student_info as s on s.student_id = p.student_id
  98. WHERE p.class_id = {$classId} AND p.status = 0 AND s.realname like '%".$studentName."%'
  99. ";
  100. }else{
  101. $sql = "SELECT s.realname,p.student_id,p.serial_number
  102. FROM student_class_relation as p
  103. LEFT JOIN student_info as s on s.student_id = p.student_id
  104. WHERE p.class_id = {$classId} AND p.status = 0
  105. ";
  106. }
  107. $result = $this->getDbConnection()->createCommand($sql)->queryAll();
  108. return $result;
  109. }
  110. public function getStudentInfoByClassIds($classIds)
  111. {
  112. $sql = "SELECT s.realname,p.student_id,p.class_id
  113. FROM student_class_relation as p
  114. LEFT JOIN student_info as s on s.student_id = p.student_id
  115. WHERE p.class_id IN {$classIds} AND p.status = 0
  116. ";
  117. $result = $this->getDbConnection()->createCommand($sql)->queryAll();
  118. return $result;
  119. }
  120. //分页获取学生数据
  121. public function getStudentsByPages($class_ids){
  122. $result = array();
  123. $sql = "select count(0) as count from student_class_relation where class_id in ('{$class_ids}')";
  124. $connect = $this->getDbConnection();
  125. $countArr = $connect->createCommand($sql)->queryRow();
  126. return $countArr;
  127. if($countArr && $countArr['count']){
  128. $count = $countArr['count'];
  129. $limit = 10000;
  130. $page = ceil($count/$limit);
  131. $_sql = "select * from student_info";
  132. for($a = 1;$a <= $page;$a++){
  133. $offset = ($a - 1)*$limit;
  134. $_sqls = $_sql." limit {$offset},{$limit}";
  135. $data = $connect->createCommand($_sqls)->queryAll();
  136. foreach($data as $k=>$v){
  137. $result['school_student_info'][$v['student_id']] = $v;
  138. $result['$school_student_names'][$v['student_id']] = $v['realname'];
  139. }
  140. unset($data);
  141. }
  142. }
  143. return $result;
  144. }
  145. }