public function loadModel($id) { $model = SurveillanceSections::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** * @param null $systemId * @param null $ajax */ public function actionReport($systemId = null, $ajax = null) { $surveillanceReport = []; if (isset($ajax)) { if ($systemId == -1) { echo json_encode(['aaData' => []]); return; } $rsSurveillance = Yii::app()->db->createCommand()->select('s.sectionId, s.sectionName, ff.id, ff.sectionId, ff.order AS childCount, ff.parentId, ff.label, ff.inputName, fd.frameworkFieldId, fd.value, grid.label AS parentLabel')->from('surveillanceSections s')->leftJoin('frameworkFields ff', 'ff.sectionId = s.sectionId')->leftJoin('frameworkFieldData fd', 'fd.frameworkFieldId = ff.id')->leftJoin('frameworkFields grid', 'grid.id = ff.parentId')->where('fd.frameworkId = :framework ', [':framework' => $systemId])->order('ff.sectionId ASC, ff.order ASC')->queryAll(); // print_r($rsSurveillance); die; if (!isset($rsSurveillance[0])) { Yii::app()->user->setFlash('notice', 'The surveillance system you have selected has no data, please update it'); $this->redirect('list'); return; } $rsSurvHead = FrameworkContext::model()->findByPk($systemId); $sectionKey = 0; $labelCount = 0; $oldLabel = ''; $surveillanceReport[200]['sectionName'] = " "; $surveillanceReport[200]['parentLabel'] = " "; $surveillanceReport[200]['labelIndex'] = $labelCount; $surveillanceReport[200]['field'] = "Surveillance System Name"; $surveillanceReport[200]['data'] = $rsSurvHead->name; foreach ($rsSurveillance as $section) { //foreach ($section->frameworkFields as $field) {} $surveillanceReport[$sectionKey]['sectionName'] = '1.' . $section['sectionId'] . ' ' . $section['sectionName']; $surveillanceReport[$sectionKey]['parentLabel'] = " "; $surveillanceReport[$sectionKey]['labelIndex'] = $labelCount; //$surveillanceReport[$sectionKey]['parenLabelIndex'] = $parentLabelCount; if (isset($section['parentLabel'])) { $surveillanceReport[$sectionKey]['parentLabel'] = $section['parentLabel']; } if ($section['label'] == $oldLabel) { $surveillanceReport[$sectionKey]['labelIndex'] = ++$labelCount; } $surveillanceReport[$sectionKey]['field'] = isset($section['label']) ? $section['label'] : SurveillanceSections::model()->getAttributeLabel($section['inputName']); //foreach ($section->survData as $fieldData) {} //if($field->id == $fieldData->frameworkFieldId) {} $surveillanceReport[$sectionKey]['data'] = $section['value']; if (DForm::isJson($section['value'])) { //print_r(json_decode($fieldData->value, true)); die; $optionsCriteria = new CDbCriteria(); $optionsArray = json_decode($section['value']); //var_dump($optionsArray); //die; if (is_array($optionsArray)) { $optionsCriteria->addInCondition('optionId', $optionsArray); } if (is_int($optionsArray)) { $optionsCriteria->addCondition('optionId=:option'); $optionsCriteria->params = [':option' => $optionsArray]; } $optionsCriteria->select = 'label'; $rsOptions = ModelToArray::convertModelToArray(Options::model()->findAll($optionsCriteria), ['options' => 'label']); $options = ''; array_walk($rsOptions, function ($opt) use(&$options) { $options .= $opt['label'] . ', '; }); $options = rtrim($options, ', '); $surveillanceReport[$sectionKey]['data'] = $options; //print_r($rsOptions); die; } $sectionKey++; // if(!isset($section['parentLabel']) || $oldParentLabel != $section['parentLabel']) { // $parentLabelCount = 1; // } $oldLabel = $section['label']; } echo json_encode(['aaData' => array_values($surveillanceReport)]); return; //print_r($surveillanceReport); die; } $surveillanceSystems = CHtml::listData(FrameworkContext::model()->findAll('userId=:user', [':user' => Yii::app()->user->id]), 'frameworkId', 'name'); $this->render('report', ['surveillanceSystems' => $surveillanceSystems, 'sysId' => $systemId]); return; }
<?php $form = $this->beginWidget('CActiveForm', array('id' => 'sur-form-details-form', 'enableClientValidation' => true, 'clientOptions' => array('validateOnSubmit' => true), 'enableAjaxValidation' => false)); ?> <p class="note">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model, Yii::app()->params['headerErrorSummary'], Yii::app()->params['footerErrorSummary']); ?> <!-- status is active by default --> <div class="row"> <?php echo $form->labelEx($model, 'sectionId'); ?> <?php echo $form->dropDownList($model, 'sectionId', CHtml::listData(SurveillanceSections::model()->findAll("tool='design'"), 'sectionId', 'sectionName')); ?> <?php echo $form->error($model, 'sectionId'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'inputName'); ?> <?php echo $form->textField($model, 'inputName', array('size' => 50, 'maxlength' => 50)); ?> <?php echo $form->error($model, 'inputName');
/** * getElementsAndDynamicAttributes * @param array $componentData * @param bool $multiForm * @return array */ private function getElementsAndDynamicAttributes($componentData = [], $multiForm = false) { $elements = []; $attributeArray = []; $dynamicDataAttributes = []; $dynamicLabels = []; $dynamicRules = []; if (!empty(Yii::app()->session['surDesign'])) { $getFormCondition = "tool=:design AND sectionNumber=:sectNo"; $getFormParams = [':design' => 'design', ':sectNo' => '2.0']; // show only the elements where showOnMultiForm = true for multi form layout if ($multiForm) { $getFormCondition .= ' AND showOnMultiForm=:showOnMulti'; $getFormParams['showOnMulti'] = 1; } $getForm = SurveillanceSections::model()->with('designFields')->find(['condition' => $getFormCondition, 'params' => $getFormParams]); // if (!empty(Yii::app()->session['performanceAttribute'])) { // $attributeList = AttributeFormRelation::model()->findAll([ // 'condition' => 'attributeId=:attributeId', // 'params' => [ // ':attributeId' => Yii::app()->session['performanceAttribute']['id'], // ], // ]); // foreach ($attributeList as $attrs) { // $attributeArray[$attrs->subFormId] = $attrs->subFormId; // } // } $elements['title'] = "Components Form"; $elements['showErrorSummary'] = true; $elements['showErrors'] = true; $elements['errorSummaryHeader'] = Yii::app()->params['headerErrorSummary']; $elements['errorSummaryFooter'] = Yii::app()->params['footerErrorSummary']; $elements['activeForm'] = ['id' => "DesignForm", 'class' => 'CActiveForm', 'enableClientValidation' => true, 'enableAjaxValidation' => true, 'clientOptions' => ['validateOnSubmit' => true, 'validateOnChange' => true, 'validateOnType' => false]]; //print_r($getForm); die(); $components = $getForm->designFields; $dataArray['getForm'] = $components; // add componentName form element $dynamicDataAttributes['componentName'] = ''; $dynamicLabels['componentName'] = "Component Name"; //$elements['elements']['type'] = 'form'; $elements['elements']['componentName'] = ['label' => "Component Name", 'required' => true, 'type' => 'text']; $dynamicRules[] = ['componentName', 'required']; // hide the label for multiple form layout $elements['elements']['componentName']['layout'] = '{label} {input} {hint} {error}'; if ($multiForm) { $elements['elements']['componentName']['layout'] = '{input} {hint} {error}'; } foreach ($components as $valu) { $attributeId = $valu->inputName . "_" . $valu->subFormId; $dynamicRules[] = [$attributeId, $valu->required ? 'required' : 'safe']; //set the model attribute array $dynamicDataAttributes[$attributeId] = ''; $dynamicLabels[$attributeId] = $valu->label; $hightlightClass = ""; if (isset($attributeArray[$valu->subFormId])) { $hightlightClass = "attributeHighlight"; } // add the elements to the CForm array $elements['elements'][$attributeId] = ['label' => $valu->label, 'required' => $valu->required, 'type' => $valu->inputType, 'class' => $hightlightClass, 'data-field' => $valu->subFormId]; // hide the label for multiple form layout if ($multiForm) { $elements['elements'][$attributeId]['layout'] = '{input} {hint} {error}'; } if (!empty($valu->description)) { $elements['elements'][$attributeId]['title'] = UtilModel::urlToLink($valu->description); } // add the values to the form //if (!empty($componentData[$attributeId])) { //$elements['elements'][$attributeId]['value'] = $componentData[$attributeId]['value']; //} // add the component name element value //if (!empty($componentData['componentName'])) { //$elements['elements']['componentName']['value'] = $componentData['componentName']; //} //add the dropdown parameters if ($valu->inputType == 'dropdownlist') { // add the dropdown items to the element $elements['elements'][$attributeId]['items'] = CHtml::listData(Options::model()->findAll(['condition' => 'componentId=:componentId', 'params' => [':componentId' => $valu->subFormId]]), 'optionId', 'label'); $elements['elements'][$attributeId]['prompt'] = 'Select one'; } } $elements['buttons'] = ['newComponent' => ['type' => 'submit', 'label' => 'Create Component']]; } $returnArray = ['elements' => $elements, 'dynamicDataAttributes' => $dynamicDataAttributes, 'dynamicLabels' => $dynamicLabels, 'dynamicRules' => $dynamicRules]; return $returnArray; }