public function actionSurvey() { $this->setauth(); //检查有无权限 $db = Yii::app()->m_db; if ($_POST) { $a = count($_POST['ids']); $result = VcosSurvey::model()->count(); if ($a == $result) { die(Helper::show_message(yii::t('vcos', '不能把所有记录删除!'))); } $ids = implode('\',\'', $_POST['ids']); //事务处理 $transaction = $db->beginTransaction(); try { $count = VcosSurvey::model()->deleteAll("survey_id in('{$ids}')"); $count2 = VcosSurveyLanguage::model()->deleteAll("survey_id in('{$ids}')"); $count_result = VcosSurveyResult::model()->deleteAll("survey_id in('{$ids}')"); $transaction->commit(); Helper::show_message(yii::t('vcos', '删除成功。'), Yii::app()->createUrl("Commentandhelp/survey")); } catch (Exception $e) { $transaction->rollBack(); Helper::show_message(yii::t('vcos', '删除失败。')); } } if (isset($_GET['id'])) { $result = VcosSurvey::model()->count(); if ($result <= 1) { die(Helper::show_message(yii::t('vcos', '不能把所有记录删除!'))); } $did = $_GET['id']; //事务处理 $transaction2 = $db->beginTransaction(); try { $count = VcosSurvey::model()->deleteByPk($did); $count2 = VcosSurveyLanguage::model()->deleteAll("survey_id in('{$did}')"); $count_result = VcosSurveyResult::model()->deleteAll("survey_id in('{$did}')"); $transaction2->commit(); Helper::show_message(yii::t('vcos', '删除成功。'), Yii::app()->createUrl("Commentandhelp/survey")); } catch (Exception $e) { $transaction2->rollBack(); Helper::show_message(yii::t('vcos', '删除失败。')); } } $count_sql = "SELECT count(*) count FROM vcos_survey a LEFT JOIN vcos_survey_language b ON a.survey_id = b.survey_id WHERE b.iso = '" . Yii::app()->language . "' ORDER BY a.survey_id DESC"; $count = Yii::app()->m_db->createCommand($count_sql)->queryRow(); $criteria = new CDbCriteria(); $count = $count['count']; $pager = new CPagination($count); $pager->pageSize = 10; $pager->applyLimit($criteria); $sql = "SELECT * FROM vcos_survey a LEFT JOIN vcos_survey_language b ON a.survey_id = b.survey_id WHERE b.iso = '" . Yii::app()->language . "' ORDER BY a.survey_id DESC LIMIT {$criteria->offset}, {$pager->pageSize}"; $survey = Yii::app()->m_db->createCommand($sql)->queryAll(); $this->render('survey', array('pages' => $pager, 'auth' => $this->auth, 'survey' => $survey)); }
public function actionSurvey_statistics() { $this->setauth(); //检查有无权限 $id = $_GET['id']; $db = Yii::app()->m_db; $sql = "SELECT b.survey_title FROM vcos_survey a LEFT JOIN vcos_survey_language b ON a.survey_id = b.survey_id WHERE a.survey_id = {$id} AND b.iso = '" . Yii::app()->language . "'"; $title = $db->createCommand($sql)->queryRow(); $sql2 = "SELECT a.survey_choose_id, b.survey_choose_name FROM vcos_survey_choose a LEFT JOIN vcos_survey_choose_language b ON a.survey_choose_id = b.survey_choose_id WHERE b.iso = '" . Yii::app()->language . "'"; $grade = $db->createCommand($sql2)->queryAll(); $grade_num = VcosSurveyChoose::model()->count(); $condition = array(); $result = array(); for ($i = 1, $j = 0; $i <= $grade_num; $i++, $j++) { $condition[] = "survey_id={$id} and survey_choose_id={$grade[$j]['survey_choose_id']}"; } foreach ($condition as $row) { $result[] = VcosSurveyResult::model()->count($row); } $this->render('survey_statistics', array('grade' => $grade, 'result' => $result, 'title' => $title)); }