예제 #1
0
 /**
  * @internal param $frameworkId
  * @return string
  */
 public function actionGetSurveillanceSummary()
 {
     $surveillanceCriteria = new CDbCriteria();
     $surveillanceCriteria->condition = 'frameworkId=' . $this->frameworkId;
     $surveillanceRs = FrameworkFields::model()->with('data', 'options')->findAll($surveillanceCriteria);
     $surveillanceFields = ['hazardName' => 'Hazard Name', 'survObj' => 'Surveillance objective', 'geographicalArea' => 'Geographical area', 'stateOfDisease' => 'Hazard situation', 'legalReq' => 'Legal Requirements'];
     //		$evaDetails[] = ['Evaluation Name', $model['evaluationName']];
     //		print_r($surveillanceRs); die;
     //		var_dump(DForm::isJson('68')); die;
     $surveillanceSummary = [];
     $surveillanceSummary[] = ['Surveillance system name', Yii::app()->session['surDesign']['name']];
     foreach ($surveillanceRs as $surveillanceFieldKey => $surveillanceField) {
         if (isset($surveillanceFields[$surveillanceField->inputName])) {
             $surveillanceFieldKey++;
             $surveillanceKey = $surveillanceFields[$surveillanceField->inputName];
             $surveillanceSummary[$surveillanceFieldKey] = [$surveillanceKey, isset($surveillanceField->data[0]) ? $surveillanceField->data[0]['value'] : ''];
             //print_r($surveillanceField->data[0]);
             if (isset($surveillanceField->options[0]) && isset($surveillanceField->data[0])) {
                 //die('pop');
                 foreach ($surveillanceField->options as $option) {
                     $dataValue = $surveillanceField->data[0]['value'];
                     if (DForm::isJson($surveillanceField->data[0]['value'])) {
                         $dataValue = json_decode($surveillanceField->data[0]['value'])[0];
                     }
                     //echo $dataValue;
                     if ($dataValue == $option->optionId) {
                         $surveillanceSummary[$surveillanceFieldKey] = [$surveillanceKey, $option->label];
                         break;
                     }
                 }
             }
         }
     }
     //die;
     $surveillanceComponents = CHtml::link('add surveillance components', ['design/addMultipleComponents']);
     // Get surveillance components
     $rsComponents = ComponentHead::model()->findAll('frameworkId=:framework', [':framework' => $this->frameworkId]);
     if (isset($rsComponents[0])) {
         $surveillanceComponents = '';
         foreach ($rsComponents as $component) {
             $surveillanceComponents .= $component->componentName . ', ';
         }
         $surveillanceComponents = rtrim($surveillanceComponents, ', ');
     }
     $surveillanceSummary[] = ['Surveillance components', $surveillanceComponents];
     //print_r($surveillanceSummary); die;
     echo json_encode(["aaData" => array_values($surveillanceSummary)], JSON_UNESCAPED_SLASHES);
     return;
 }
예제 #2
0
 /**
  * @param $fieldId
  * @param $dForm
  * @return string
  */
 private function generateGridElements($fieldId, &$dForm)
 {
     //$model = new DynamicFormDetails('insert', 'frameworkFieldData');
     // get grid fields
     $gridFieldsCriteria = new CDbCriteria();
     $gridFieldsCriteria->condition = 'parentId=' . $fieldId;
     $gridFieldsCriteria->order = '`order` ASC';
     $gridFieldsNames = [];
     $labels = [];
     $properties = [];
     $rules = [];
     $inputs = '';
     if ($dForm->getScenario() == 'insert') {
         $gridFields = FrameworkFields::model()->findAll($gridFieldsCriteria);
         $inputs .= '<tr class="copy' . $fieldId . '">';
         foreach ($gridFields as $field) {
             //$el = new CFormInputElement()
             $attribute = $field->inputName . '_' . $field->id;
             $dForm->setpropertyName($attribute);
             //			continue;
             //$model->setAttribute($attribute, $field->inputName);
             //			$dForm->_dynamicLabels[$attribute] = isset($field->label) ?
             //				$field->label : $dForm->generateAttributeLabel($field->inputName);
             $labels[$attribute] = isset($field->label) ? $field->label : $dForm->generateAttributeLabel($field->inputName);
             $validation = $field->required ? 'required' : 'safe';
             $rules[] = [$attribute, $validation];
             $i = 0;
             //print_r($dForm); die;
             $inputs .= '<td>';
             switch ($field->inputType) {
                 case 'text':
                     $inputs .= CHtml::activeTextField($dForm, "[{$i}]{$attribute}");
                     $inputs .= CHtml::error($dForm, "[{$i}]{$attribute}");
                     break;
                 case 'dropdownlist':
                     $options = [];
                     if ($field->multiple) {
                         $options['multiple'] = true;
                     }
                     $inputs .= CHtml::activeDropDownList($dForm, "[{$i}]{$attribute}", Options::model()->getContextFieldOptions($field->id), $options);
                     $inputs .= CHtml::error($dForm, "[{$i}]{$attribute}");
                     break;
             }
             $inputs .= '</td>';
             //$elements['elements'][] = '</td>';
         }
         $inputs .= '<td></td></tr>';
     } else {
         // get id's of fields that belong to the grid
         //$gridFieldsCriteria->select = 'id';
         $childFields = ModelToArray::convertModelToArray(FrameworkFields::model()->with('data')->findAll($gridFieldsCriteria));
         //				['frameworkFields' => 'id, inputName, label, inputType, required, multiple']);
         //print_r($childFields); die;
         $gridFieldsIds = array_map(function ($item) {
             return $item['id'];
         }, $childFields);
         // get grid data
         $fieldDataCriteria = new CDbCriteria();
         $fieldDataCriteria->condition = 'frameworkId=' . Yii::app()->session['surDesign']['id'];
         $fieldDataCriteria->addInCondition('frameworkFieldId', $gridFieldsIds);
         $gridFields = FrameworkFieldData::model()->findAll($fieldDataCriteria);
         if (empty($gridFields)) {
             $dForm->setScenario('insert');
             //print_r($dForm); die;
             return self::generateGridElements($fieldId, $dForm);
         }
         $dFormGrid = [];
         foreach ($childFields as $child) {
             $elementId = $child['inputName'] . '_' . $child['id'];
             $gridFieldsNames[$child['id']] = $elementId;
             $gridParams[$elementId]['id'] = $child['id'];
             $labels[$elementId] = $child['label'];
             $gridParams[$elementId]['inputType'] = $child['inputType'];
             $gridParams[$elementId]['required'] = $child['required'];
             $gridParams[$elementId]['multiple'] = $child['multiple'];
         }
         //$dFormGrid[$k] = new DForm();
         foreach ($childFields as $child) {
             if (isset($child['data'][0])) {
                 foreach ($child['data'] as $key => $data) {
                     if (!isset($dFormGrid[$key])) {
                         $dFormGrid[$key] = new DForm();
                     }
                     $elementId = $child['inputName'] . '_' . $child['id'];
                     foreach ($gridFieldsNames as $gridElement) {
                         if (empty($dFormGrid[$key]->attributes[$gridElement])) {
                             //echo "new $key $gridElement \n";
                             //print_r($dFormGrid[$key]);
                             //
                             $dFormGrid[$key]->setPropertyName($gridElement);
                         }
                         //var_dump($dFormGrid[$key]->$gridElement);
                     }
                     $dFormGrid[$key]->{$elementId} = $data['value'];
                     if (DForm::isJson($data['value'])) {
                         $dFormGrid[$key]->{$elementId} = json_decode($data['value']);
                     }
                 }
             }
         }
         $copyClass = '';
         foreach ($dFormGrid as $key => $gridItems) {
             $inputs .= '<tr class="copy' . $fieldId . ' ' . $copyClass . '">';
             foreach ($gridItems->attributeNames() as $attr) {
                 //var_dump($gridItems[$attr]); die;
                 $inputs .= '<td>';
                 switch ($gridParams[$attr]['inputType']) {
                     case 'text':
                         $inputs .= CHtml::activeTextField($gridItems, "[{$key}]{$attr}");
                         $inputs .= CHtml::error($gridItems, "[{$key}]{$attr}");
                         break;
                     case 'dropdownlist':
                         $options = [];
                         if ($gridParams[$attr]['multiple']) {
                             $options['multiple'] = true;
                         }
                         $inputs .= CHtml::activeDropDownList($gridItems, "[{$key}]{$attr}", Options::model()->getContextFieldOptions($gridParams[$attr]['id']), $options);
                         $inputs .= CHtml::error($gridItems, "[{$key}]{$attr}");
                         break;
                 }
                 $inputs .= '</td>';
             }
             $inputs .= '<td><a class="remove ui-icon ui-icon-trash" href="#"' . ' onclick="$(this).parent().parent().remove(); return false">remove</a></td></tr>';
             $copyClass = 'copy1';
         }
         //echo $inputs; die;
     }
     //var_dump($data, $cols); die('lklk');
     //die;
     $dForm->setRules($rules);
     $dForm->setAttributeLabels($labels);
     //print_r(array_values($labels));
     $tableHeader = '<th>' . implode('</th><th>', array_values($labels));
     $table = '<table class="jgTabular"><thead><tr>' . $tableHeader . '<th></th></tr></thead>';
     $table .= '<tbody>' . $inputs . '</tbody>';
     $table .= '</table>';
     $table .= CHtml::htmlButton('<span class="ui-icon ui-icon-plusthick"></span>Add new row', ['id' => 'copyLink-' . $fieldId, 'rel' => '.copy' . $fieldId]);
     //		if($fieldId == 37) {
     //			print_r($table); //die('pop');
     //		}
     return $table;
 }
예제 #3
0
 /**
  * @return array
  */
 public function attributeNames()
 {
     return array_merge(parent::attributeNames(), array_keys($this->_properties));
 }