public function actionNeeds()
 {
     $needItems = NeedItem::model()->findAll();
     if (isset($_GET['need_id'])) {
         $need_id = $_GET['need_id'];
         Yii::trace("SR.actionNeeds called for {$need_id}", 'application.controllers.SurveyReportsController');
         if (strlen($need_id) > 0) {
             $crit = array('need_id' => $need_id);
         } else {
             $crit = array();
         }
         $needDist = NeedData::model()->findAllByAttributes($crit, array('select' => 'need_id, need_value, count(id) val_count', 'group' => 'need_id, need_value'));
         $this->renderPartial('need_report', array('needDist' => $needDist, 'needItems' => $needItems));
         return;
     }
     $this->render('needs', array('needItems' => $needItems));
 }
Пример #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 NeedItem the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = NeedItem::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }