/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new AwarenessData();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['AwarenessData'])) {
         $model->attributes = $_POST['AwarenessData'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 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));
 }