public function countRate($courseId)
 {
     $criteria = new CDbCriteria();
     $criteria->addCondition('courseId=:courseId');
     $criteria->params[':courseId'] = $courseId;
     $data = StClassTime::model()->findAll($criteria);
     $data = json_decode(CJSON::encode($data), TRUE);
     $dateNew = array();
     $rateNew = array();
     $dataOld = $this->compute($courseId);
     foreach ($data as $key => $value) {
         $dateNew[] = $value['classDate'];
         $rateNew[$key] = 1;
         foreach ($dataOld['date'] as $keyOld => $valueOld) {
             if ($value['classDate'] == $valueOld) {
                 $rateNew[$key] = $dataOld['rate'][$keyOld];
             }
         }
     }
     return array('date' => $dateNew, 'rate' => $rateNew, 'courseName' => $dataOld['courseName']);
 }
 public function actionAttendance($classTimeId)
 {
     try {
         $sql = "SELECT * FROM st_class_time,st_course WHERE st_class_time.classTimeId = " . $classTimeId . " AND st_class_time.courseId=st_course.courseId";
         $course = Yii::app()->db->createCommand($sql)->queryAll();
         $sql = "SELECT * FROM st_student,st_student_course WHERE st_student_course.courseId = '" . $course[0]['courseId'] . "' AND st_student_course.stuId = st_student.stuId";
         //分页获取
         if (XUtils::method() == 'POST') {
             $data = $_POST;
             $class = StClassTime::model()->findByPk($classTimeId);
             if ($class->flag == 1) {
                 $delete = "DELETE FROM st_absent WHERE st_absent.classTimeId = " . $classTimeId;
                 $result = Yii::app()->db->createCommand($sql)->execute();
             }
             foreach ($data as $key => $value) {
                 if ($value == 'on') {
                     $model = new StAbsent();
                     $model->stuId = $key;
                     $model->classTimeId = $classTimeId;
                     $model->state = "旷课";
                     $model->reason = "--";
                     $model->save();
                     // echo var_dump($model);
                 }
             }
             StClassTime::model()->updateByPk($classTimeId, array('flag' => '1'));
             // XUtils::message('success', '考勤成功', $this->createUrl('teacherLogin/todayClass'));
         }
         $result = Yii::app()->db->createCommand($sql)->queryAll();
         $count = count($result);
         $pages = new CPagination($count);
         $pages->pageSize = PAGESIZE;
         $pdata = Yii::app()->db->createCommand($sql . " LIMIT :offset,:limit");
         $pdata->bindValue(':offset', $pages->currentPage * $pages->pageSize);
         $pdata->bindValue(':limit', $pages->pageSize);
         $data = $pdata->queryAll();
         $data = json_decode(CJSON::encode($data), TRUE);
         // echo var_dump($data);
         is_array($data) ? null : ($data = array());
         // 防止空数组
         $this->render('attendance', array('data' => $data, 'pages' => $pages, 'courseName' => $course[0]['courseName']));
     } catch (Exception $e) {
         var_dump($e);
     }
 }