/** * index method * * @return void */ public function index($course_type = null, $department_id = null, $semester_id = null, $course_id = null) { $conditions = array(); if (isset($this->request->query['department_id']) && !($this->request->query['department_id'] == '')) { $department_id = $this->request->query['department_id']; } if (isset($this->request->query['course_type']) && !($this->request->query['course_type'] == '')) { $course_type = $this->request->query['course_type']; } if (isset($this->request->query['semester_id']) && !($this->request->query['semester_id'] == '')) { $semester_id = $this->request->query['semester_id']; $conditions['semester_id'] = $semester_id; } if (isset($this->request->query['course_id']) && !($this->request->query['course_id'] == '')) { $course_id = $this->request->query['course_id']; $conditions['Elective.course_id'] = $course_id; } if ($course_type != null) { $conditions['Elective.course_type'] = $course_type; } if ($department_id != null) { App::import('Controller', 'Departments'); $DepartmentsController = new DepartmentsController(); $department = $DepartmentsController->view($department_id); // debug($department); $dept_number = $department['Department']['dept_number']; $conditions['Elective.dept_number like '] = $dept_number . '%'; } $this->Elective->recursive = 0; $success = true; $this->Paginator->settings['conditions'] = $conditions; $page = $this->request->query['page']; $limit = $this->request->query['limit']; $this->Paginator->settings['page'] = $page; $this->Paginator->settings['limit'] = $limit; // $this->set('electives',$this->Elective->find('all')); // $electives = $this->Paginator->paginate(); // debug($this->Paginator->settings); $this->set('electives', $electives); $this->set('success', $success); $this->layout = 'ajax'; }
public function stat_scores_section($department_id = 38, $semester_id = 1, $course_id = 4, $exam_name = 'final') { $this->layout = 'ajax'; /* 检查$department_id的子节点 */ if ($department_id == 0) { $conditions = array(1 => 1); // $dept_number=''; } else { $conditon = array('$department_id' => $department_id); App::import('Controller', 'Departments'); $DepartmentsController = new DepartmentsController(); $depts = $DepartmentsController->getChildren($department_id); $dept_count = count($depts); if ($dept_count == 1) { $filer_dept_number = $depts[0]['dept_number']; //如果是查找一个班级的成绩,则将其作为过滤条件 $parent_dept = $DepartmentsController->getparent($department_id); $parent_dept_id = $parent_dept['Department']['id']; // debug($parent_dept_id); $department_id = $parent_dept_id; } /* $deptdata = array (); foreach ( $depts as $dept ) { $deptdata [] = $dept ['dept_number']; } $logdept = array (); // debug(count($deptdata)); for($i = 0; $i < count ( $deptdata ); $i ++) { $logdept [] = array ( 'logdept like' => $deptdata [$i] . '%' ); } if (count ( $depts ) == 0) { $deptdata = $dept_number; $logdept = array ( 'logdept like' => $deptdata . '%' ); } // debug($deptdata); $conditions = array ( 'Score.dept_number' => $deptdata, );endif*/ } /* 根据$department_id,$semester_id,$course_id查找课程计划 $Courseplan*/ App::import('Model', 'Courseplan'); $condition = array('conditions' => array('department_id' => $department_id, 'semester_id' => $semester_id, 'course_id' => $course_id)); $Courseplan = new Courseplan(); // debug($condition); $Courseplan->unbindModel(array('belongsTo' => array('Semester', 'User', 'Course', 'Department'))); $courseplan = $Courseplan->find('all', $condition); // debug($courseplan); if ($courseplan == array()) { /* 结果为空,没有此项课程计划 */ $full_score_sections = array(); $departments = array(); $maximum = 0; } else { /* 如果查到了$courseplan */ $courseplan_id = $courseplan[0]['CoursePlan']['id']; // debug($courseplan_id); /* 查找所有的班级的分数段 */ $condition = array('fields' => array('dept_number', '(' . $exam_name . ' div 10) AS section', 'count(*) AS number'), 'group' => array('dept_number', 'section'), 'conditions' => array('course_plan_id' => $courseplan_id), 'order' => array('dept_number ASC')); if (isset($filer_dept_number)) { $condition['conditions']['Score.dept_number'] = $filer_dept_number; } // 'conditions'=>array($conditions) // debug($condition); // 根据条件从数据库中提取数据处理为分数段 $sections = $this->Score->find('all', $condition); // 设定用数据库处理平均分的条件 $condition_average = array('fields' => array('dept_number', 'AVG(' . $exam_name . ') AS average'), 'group' => array('dept_number'), 'conditions' => array('course_plan_id' => $courseplan_id), 'order' => array('dept_number ASC')); // 根据条件由数据库处理得到平均分 $averages = $this->Score->find('all', $condition_average); // debug($averages); /* 查找所有的班级 */ $condition = array('fields' => array('dept_number', 'count(*) as num_of_stu'), 'group' => array('dept_number'), 'conditions' => array('course_plan_id' => $courseplan_id)); $this->Score->unbindModel(array('belongsTo' => array('Student'))); if (isset($filer_dept_number)) { $condition['conditions']['Score.dept_number'] = $filer_dept_number; } $departments = $this->Score->find('all', $condition); // debug($departments); //如果查询结果为空 if (count($sections) == 0) { $sections[0][0] = array('section' => 0, 'number' => 0); } $parts = 0; $score_sections = array(); //范围 /* 获得最大值和分数段 */ foreach ($sections as $section) { // debug($section); if ($section[0]['section'] > $parts) { $parts = $section[0]['section']; } $range['section'][] = $section[0]['section']; $range['number'][] = $section[0]['number']; } // debug($range); $part_down = min($range['section']); $maximum = max($range['number']); // die(); // debug($parts); /* $j = 0; for($i = 0; $i <= $parts; $i ++) { $score_sections [$i] ['section']=$i*10; if ($sections [$j] [0] ['section'] == $i) { // debug($sections[$j][0]); $score_sections [$i] ['number'] = $sections [$j] [0] ['number']; $j ++; } else { $score_sections [$i] ['number'] = 0; } } */ $length = count($sections); $dept = 0; $part = 0; foreach ($sections as $section) { $dept_number = $section['Score']['dept_number']; $section_number = $section[0]['section'] * 10; $number = $section[0]['number']; $score_sections[$section_number][$dept_number] = $number; } // debug($score_sections); $full_score_sections = array(); // $full_score_sections[0][0]=1; for ($part = $part_down; $part <= $parts; $part++) { foreach ($departments as $department) { $tmp_part = $part * 10; $dept_number = $department['Score']['dept_number']; $full_score_sections[$tmp_part][$dept_number] = 0; // debug($score_sections[0][$department]); if (isset($score_sections[$part * 10][$dept_number])) { $full_score_sections[$part * 10][$dept_number] = $score_sections[$part * 10][$dept_number]; } else { $full_score_sections[$part * 10][$dept_number] = '0'; } } } // debug($full_score_sections); } // die(); $this->set('scoreSections', $full_score_sections); $this->set('departments', $departments); $this->set('maximum', $maximum); $this->set('averages', $averages); }
public function statNativePlace($deppartment_id = 0) { $this->layout = 'ajax'; if ($deppartment_id == 0) { $conditions = array(1 => 1); // $dept_number=''; } else { $conditon = array('$deppartment_id' => $deppartment_id); App::import('Controller', 'Departments'); $DepartmentsController = new DepartmentsController(); $depts = $DepartmentsController->getChildren($deppartment_id); $deptdata = array(); foreach ($depts as $dept) { $deptdata[] = $dept['dept_number']; } $logdept = array(); // debug(count($deptdata)); for ($i = 0; $i < count($deptdata); $i++) { $logdept[] = array('logdept like' => $deptdata[$i] . '%'); } if (count($depts) == 0) { $deptdata = $dept_number; $logdept = array('logdept like' => $deptdata . '%'); } // debug($deptdata); $conditions = array('or' => array('dept_number' => $deptdata, 'or' => $logdept)); } // debug($conditions); $condition = array('fields' => array('((CASE WHEN native_place not like \'%江苏省%\' THEN \'外省\' WHEN native_place not like \'%南京市%\' THEN \'本省外市\' ELSE SUBSTRING(native_place,LOCATE(\'市\',native_place)+1) END)) AS region', 'count(native_place) AS number'), 'group' => array('region'), 'conditions' => array($conditions)); $tmp_nativePlaces = $this->Student->find('all', $condition); $nativePlaces = array('1' => array('region' => '玄武区', 'number' => 0), '2' => array('region' => '秦淮区', 'number' => 0), '3' => array('region' => '建邺区', 'number' => 0), '4' => array('region' => '鼓楼区', 'number' => 0), '5' => array('region' => '雨花台区', 'number' => 0), '6' => array('region' => '栖霞区', 'number' => 0), '7' => array('region' => '江宁区', 'number' => 0), '8' => array('region' => '浦口区', 'number' => 0), '9' => array('region' => '六合区', 'number' => 0), '10' => array('region' => '溧水区', 'number' => 0), '11' => array('region' => '高淳区', 'number' => 0), '12' => array('region' => '本省外市', 'number' => 0), '13' => array('region' => '外省', 'number' => 0), '14' => array('region' => '其他', 'number' => 0)); // debug($tmp_nativePlaces); foreach ($tmp_nativePlaces as $tmp_nativePlace) { $regin = $tmp_nativePlace['0']['region']; $number = $tmp_nativePlace['0']['number']; switch ($regin) { case '玄武区': $nativePlaces[1]['number'] = $number; break; case '秦淮区': $nativePlaces[2]['number'] += $number; break; case '建邺区': $nativePlaces[3]['number'] = $number; break; case '鼓楼区': $nativePlaces[4]['number'] += $number; break; case '雨花台区': $nativePlaces[5]['number'] = $number; break; case '栖霞区': $nativePlaces[6]['number'] = $number; break; case '江宁区': $nativePlaces[7]['number'] = $number; break; case '浦口区': $nativePlaces[8]['number'] = $number; break; case '六合区': $nativePlaces[9]['number'] = $number; break; case '溧水区': $nativePlaces[10]['number'] = $number; break; case '溧水县': $nativePlaces[10]['number'] += $number; break; case '高淳区': $nativePlaces[11]['number'] += $number; break; case '高淳县': $nativePlaces[11]['number'] += $number; break; case '本省外市': $nativePlaces[12]['number'] = $number; break; case '外省': $nativePlaces[13]['number'] = $number; break; case '白下区': $nativePlaces[2]['number'] += $number; break; case '下关区': $nativePlaces[4]['number'] += $number; break; default: $nativePlaces[14]['number'] += $number; break; } } // die(); $this->set('nativePlaces', $nativePlaces); // debug($nativePlaces); }
public function listCoursePlans($department_id = null, $semester_id = null, $course_id = null, $course_type = null, $returnback = null, $score_type = null) { if (isset($this->request->query['department_id']) && !($this->request->query['department_id'] == '')) { $department_id = $this->request->query['department_id']; // $condition['conditions']['department_id']=$department_id; } if (isset($this->request->query['course_id']) && !($this->request->query['course_id'] == '')) { $course_id = $this->request->query['course_id']; // $condition['conditions']['course_id']=$course_id; } if (isset($this->request->query['semester_id']) && !($this->request->query['semester_id'] == '')) { $semester_id = $this->request->query['semester_id']; // $condition['conditions']['semester_id']=$semester_id; } $this->CoursePlan->recursive = 0; $this->layout = 'ajax'; if ($department_id == null || $department_id == 'null') { $condition = array(1 => 1); } else { App::import('Controller', 'Departments'); $DepartmentsController = new DepartmentsController(); $depts = $DepartmentsController->getChildren($department_id); $dept_count = count($depts); if ($dept_count == 1) { $parent_dept = $DepartmentsController->getparent($department_id); $parent_dept_id = $parent_dept['Department']['id']; $department_id = $parent_dept_id; } } $condition = array('conditions' => array('department_id' => $department_id)); if ($semester_id != null && $semester_id != 'null') { $condition['conditions']['semester_id'] = $semester_id; } if ($course_id != null && $course_id != 'null') { $condition['conditions']['course_id'] = $course_id; } if ($course_type != null && $course_type != 'null') { $condition['conditions']['CoursePlan.course_type'] = $course_type; } if ($score_type != null && $score_type != 'null') { $condition['conditions']['CoursePlan.score_type'] = $score_type; } // debug($condition); $condition['order'] = 'course_id'; $coursePlans = $this->CoursePlan->find('all', $condition); $this->set('coursePlans', $this->CoursePlan->find('all', $condition)); $result['success'] = true; $this->set('result', $result); if ($returnback == true) { return $coursePlans; } }