public function actionOpenQuestions()
 {
     $openQuestions = OpenQuestion::model()->findAll();
     if (isset($_GET['question_id'])) {
         $question_id = $_GET['question_id'];
         Yii::trace("SR.openQuestions called for '{$question_id}'", 'application.controllers.SurveyReportsController');
         if (preg_match('/^\\d+$/', $question_id)) {
             $crit = array('question_id' => $question_id);
         } elseif ('' == $question_id) {
             $questions = OpenQuestion::model()->findAllByAttributes(array('type' => 'yesno'));
             $qids = array();
             foreach ($questions as $qn) {
                 array_push($qids, $qn->id);
             }
             $crit = array('question_id' => $qids);
         } else {
             return;
         }
         $openDist = OpenData::model()->findAllByAttributes($crit, array('select' => 'question_id, value, count(id) val_count', 'group' => 'question_id, value'));
         $this->renderPartial('questions_report', array('openDist' => $openDist, 'openQuestions' => $openQuestions));
         return;
     }
     $this->render('openQuestions', array('openQuestions' => $openQuestions));
 }
예제 #2
0
 public function actionSurvey($id)
 {
     $model = $this->loadModel($id);
     if (isset($_POST['SatisfactionData'])) {
         foreach ($_POST['SatisfactionData'] as $sid => $value) {
             $sd = SatisfactionData::model()->findByAttributes(array('family_id' => $id, 'satisfaction_item_id' => $sid));
             if (!$sd) {
                 $sd = new SatisfactionData();
             }
             $sd->attributes = $value;
             $sd->family_id = $id;
             $sd->satisfaction_item_id = $sid;
             $sd->save();
         }
     }
     if (isset($_POST['NeedData'])) {
         foreach ($_POST['NeedData'] as $nid => $value) {
             $nd = NeedData::model()->findByAttributes(array('family_id' => $id, 'need_id' => $nid));
             if (!$nd) {
                 $nd = new NeedData();
             }
             $nd->attributes = $value;
             $nd->family_id = $id;
             $nd->need_id = $nid;
             $nd->save();
         }
     }
     if (isset($_POST['AwarenessData'])) {
         Yii::trace("FC.survey awareness reached", 'application.controllers.FamilyController');
         $awarenessItems = AwarenessItem::model()->findAll();
         foreach ($awarenessItems as $aRow) {
             $aid = $aRow->id;
             $value = isset($_POST['AwarenessData'][$aid]) ? $_POST['AwarenessData'][$aid] : 1;
             $ad = AwarenessData::model()->findByAttributes(array('family_id' => $id, 'awareness_id' => $aid));
             if (!$ad) {
                 $ad = new AwarenessData();
             }
             $ad->value = $value;
             $ad->family_id = $id;
             $ad->awareness_id = $aid;
             $ad->save();
         }
     }
     if (isset($_POST['OpenData'])) {
         foreach ($_POST['OpenData'] as $qid => $value) {
             $od = OpenData::model()->findByAttributes(array('family_id' => $id, 'question_id' => $qid));
             if (!$od) {
                 $od = new OpenData();
             }
             $od->attributes = $value;
             $od->family_id = $id;
             $od->question_id = $qid;
             $od->save();
         }
     }
     $satisfactionItems = SatisfactionItem::model()->findAll();
     $needItems = NeedItem::model()->findAll();
     $openQuestions = OpenQuestion::model()->findAll(array('order' => 'seq'));
     $awarenessItems = AwarenessItem::model()->findAll();
     $this->render('survey', array('model' => $model, 'satisfactionItems' => $satisfactionItems, 'satisfactionData' => Families::satisfactionData($id), 'needItems' => $needItems, 'needData' => Families::needData($id), 'awarenessItems' => $awarenessItems, 'awarenessData' => Families::awarenessData($id), 'openQuestions' => $openQuestions));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return OpenQuestion the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = OpenQuestion::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }