Beispiel #1
0
 protected function afterFind()
 {
     if (self::model()->scenario != 'nolink') {
         $this->link = UtilModel::urlToLink($this->link);
     }
     parent::afterFind();
 }
 /**
  * afterFind
  */
 protected function afterFind()
 {
     $this->description = UtilModel::urlToLink($this->description);
     $this->dataRequired = UtilModel::urlToLink($this->dataRequired);
     $this->expertiseRequired = UtilModel::urlToLink($this->expertiseRequired);
     $this->reference = UtilModel::urlToLink($this->reference);
     parent::afterFind();
 }
Beispiel #3
0
 /**
  * @param WizardEvent $event
  * @return bool
  */
 public function processSurveillance($event)
 {
     $fieldsCriteria = new CDbCriteria();
     $fieldsCriteria->condition = 'sectionId=' . $event->sender->getCurrentStep();
     $fieldsCriteria->order = '`order` ASC, `parentId` ASC';
     $surveillanceFieldsModel = FrameworkFields::model()->findAll($fieldsCriteria);
     $dForm = new DForm($this->getScenario());
     $surveillanceModel = new FrameworkContext();
     $elements = $this->getDefaultElements();
     if ($event->sender->getCurrentStep() === 1) {
         $surveillanceModel->userId = Yii::app()->user->id;
         if ($dForm->scenario == 'update') {
             $surveillanceModel = FrameworkContext::model()->findByPk(Yii::app()->session['surDesign']['id']);
         }
         $elements['elements']['context']['elements'] = self::getElements($surveillanceModel, ['name']);
         $elements['elements']['contextFields']['elements'][] = '<div class="surHeading">' . '1.' . $event->sender->getCurrentStep() . ' ' . $event->sender->getStepLabel() . '</div>';
     }
     $elements['buttons'] = self::getButtons(['name' => 'next', 'label' => 'Next']);
     $elements['elements']['context']['type'] = 'form';
     //$elements['elements']['contextFields']['elements'] = self::getDefaultElements();
     $elements['elements']['contextFields']['type'] = 'form';
     //		$elements['elements']['context'] = array_merge($elements['elements']['context'], $errorArray);
     //		$elements['elements']['contextFields'] = array_merge($elements['elements']['contextFields'], $errorArray);
     //$contextFields = $dForm->findAll();
     $dynamicDataRules = [];
     $childCounter = 0;
     $childCount = 0;
     $parentFieldId = 0;
     //print_r($elements); die;
     $gridFieldIds = [];
     $specialInputs = array_flip(['checkboxlist', 'radiolist', 'dropdownlist']);
     foreach ($surveillanceFieldsModel as $field) {
         //if(!is_null($parentFieldId) &&
         $elements['elements']['contextFields']['elements'][] = '<div class="row">';
         if ($field->inputType == 'label') {
             if ($field->childCount > 0) {
                 $childCount = $field->childCount;
                 $parentFieldId = $field->id;
                 $childCounter++;
                 $elements['elements']['contextFields']['elements'][] = '<fieldset><legend>' . $field->label . '</legend>';
             } else {
                 $elements['elements']['contextFields']['elements'][] = CHtml::label($field->label, false);
             }
             continue;
         }
         if ($field->inputType == 'grid') {
             $elements['elements']['contextFields']['elements'][] = '<div class="row">';
             $elements['elements']['contextFields']['elements'][] = "<fieldset><legend> {$field->label} </legend>";
             $elements['elements']['contextFields']['elements'][] = self::generateGridElements($field->id, $dForm);
             $elements['elements']['contextFields']['elements'][] = '</fieldset>';
             $elements['elements']['contextFields']['elements'][] = '</div>';
             $gridFieldIds[] = $field->id;
             continue;
         }
         if ($field->gridField) {
             continue;
         }
         $attributeName = $field->inputName . '_' . $field->id;
         $dForm->setPropertyName($attributeName);
         //$field->inputName;
         //			$dForm->$attributeName = ''; //$field->inputName;
         $validation = $field->required ? 'required' : 'safe';
         $dynamicDataRules[] = [$attributeName, $validation];
         $dForm->setAttributeLabels([$attributeName => isset($field->label) ? $field->label : $dForm->generateAttributeLabel($field->inputName)]);
         $elements['elements']['contextFields']['elements'][$attributeName] = ['label' => isset($field->label) ? $field->label : $dForm->generateAttributeLabel($field->inputName), 'required' => $field->required, 'type' => $field->inputType, 'hint' => UtilModel::urlToLink($field->description), 'data-field' => $field->id, 'layout' => '{label} {hint} {input} {error}'];
         if ($field->inputType == 'dropdownlist') {
             $elements['elements']['contextFields']['elements'][$attributeName]['items'] = Options::model()->getContextFieldOptions($field->id);
             $elements['elements']['contextFields']['elements'][$attributeName]['prompt'] = 'Choose one';
         }
         if ($field->inputType == 'radiolist') {
             $elements['elements']['contextFields']['elements'][$attributeName]['separator'] = '<br>';
             //'labelOptions'=>array('style'=>'display:inline-block'),
             $elements['elements']['contextFields']['elements'][$attributeName]['style'] = 'width:1em;';
             $elements['elements']['contextFields']['elements'][$attributeName]['template'] = '<span class="radiolist">{input} {label}</span>';
             $elements['elements']['contextFields']['elements'][$attributeName]['items'] = Options::model()->getContextFieldOptions($field->id);
         }
         if ($field->inputType == 'checkboxlist') {
             $elements['elements']['contextFields']['elements'][$attributeName]['items'] = Options::model()->getContextFieldOptions($field->id);
             $elements['elements']['contextFields']['elements'][$attributeName]['class'] = 'checkboxlist';
             $elements['elements']['contextFields']['elements'][$attributeName]['title'] = 'title';
             $elements['elements']['contextFields']['elements'][] = '<div class="clear"></div>';
         }
         if (isset($specialInputs[$field->inputType]) && empty($field->label)) {
             $elements['elements']['contextFields']['elements'][$attributeName]['label'] = '';
         }
         if (isset($field->parentId) && $field->parentId == $parentFieldId) {
             if ($childCount != $childCounter) {
                 //echo $childCounter . '======>' . $childCount . '<br>';
                 $childCounter++;
             } else {
                 $elements['elements']['contextFields']['elements'][] = '</fieldset>';
             }
         }
         $elements['elements']['contextFields']['elements'][] = '</div>';
     }
     //var_dump($elements['elements']['contextFields']);
     //$dForm->setPropertyNames($dynamicDataAttributes);
     //$dForm->setAttributeLabels($dynamicLabels);
     $dForm->setRules($dynamicDataRules);
     //		print_r($elements); die;
     //		var_dump($dForm->getAttributes());
     //		die;
     $form = new CForm($elements);
     if ($event->sender->getCurrentStep() == 1) {
         $form['context']->model = $surveillanceModel;
     }
     $form['contextFields']->model = $dForm;
     //print_r($form); die;
     $fieldData = [];
     //$form->loadData();
     if ($form->submitted('next')) {
         $dForm = $form['contextFields']->model;
         //print_r($form); die;
         $transaction = Yii::app()->db->beginTransaction();
         try {
             if (isset($form['context']->model)) {
                 $surveillanceModel = $form['context']->model;
                 $surveillanceModel->save();
                 Yii::app()->session['surDesign'] = ['id' => $surveillanceModel->frameworkId];
             }
             //var_dump($this->surveillanceId . '   ------>tsergtretgretgerd'); die;
             if (isset($dForm)) {
                 // This can be refactored later
                 $dataIdArray = [];
                 foreach ($dForm->attributes as $attrName => $attrVal) {
                     $frameworkDataModel = new FrameworkFieldData();
                     //var_dump($event->getStep()); die;
                     if (is_array($attrVal)) {
                         $attrVal = json_encode($attrVal);
                     }
                     $fieldNameAndId = explode('_', $attrName);
                     $dataId = $dForm->getFieldDataId($fieldNameAndId[1]);
                     //var_dump($dataId); die;
                     $dataIdArray[$dataId] = $dataId;
                     $frameworkDataModel->frameworkId = Yii::app()->session['surDesign']['id'];
                     $frameworkDataModel->frameworkFieldId = $fieldNameAndId[1];
                     $frameworkDataModel->value = $attrVal;
                     //print_r($frameworkDataModel->getAttribute('value')); die;
                     if (isset($dataId)) {
                         $frameworkDataModel->setIsNewRecord(false);
                         //$frameworkDataModel->id = $dataId;
                         $frameworkDataModel->updateAll(['value' => $frameworkDataModel->value], 'frameworkId=:framework AND frameworkFieldId=:fieldId', [':framework' => $frameworkDataModel->frameworkId, ':fieldId' => $frameworkDataModel->frameworkFieldId]);
                     } else {
                         $frameworkDataModel->save();
                     }
                     //print_r($fieldData); die;
                 }
                 $transaction->commit();
             }
         } catch (Exception $e) {
             $transaction->rollback();
             Yii::log('Error saving surveillance data: ' . $e->getMessage());
             die;
         }
         //			else {
         //				if($form->validate()) {
         //
         //					//print_r($dForm->attributes); die;
         //					foreach($dForm->attributes as $attrName => $attrVal) {
         //						if(!empty($attrVal)) {
         //							$fieldNameAndId = explode('_', $attrName);
         //							$fieldData[$fieldNameAndId[0]]['frameworkFieldId'] = $fieldNameAndId[1];
         //							$val = $attrVal;
         //							if(is_array($attrVal)) {
         //								$val = json_encode($attrVal);
         //							}
         //							$fieldData[$fieldNameAndId[0]]['value'] = $val;
         //							$fieldData[$fieldNameAndId[0]]['id'] = $dForm->getFieldDataId($fieldNameAndId[1]);
         //
         //						}
         //					}
         //
         //				}
         //			}
         //$dForm->fieldId =
         //$dataToSave = array($dForm->getAttributes());
         $dataToSave = [$fieldData];
         if ($event->sender->getCurrentStep() == 1) {
             $event->sender->save($surveillanceModel->getAttributes(), 'surveillanceModel');
         }
         //print_r($event->sender); die;
         $event->sender->save($dataToSave);
         //print_r($_SESSION['Wizard.steps']); die;
         $event->handled = true;
         return true;
     } else {
         //print_r($gridFieldIds); die;
         $sectionCriteria = new CDbCriteria();
         $sectionCriteria->select = 'description';
         $sectionCriteria->condition = 'sectionId=' . $event->sender->getCurrentStep();
         $sectionInfo = SurveillanceSections::model()->find($sectionCriteria);
         //print_r($sectionInfo->description); die();
         //			$this->render($event->step, compact('form'));
         $this->render('create', compact('form', 'event', 'sectionInfo', 'gridFieldIds'));
     }
 }
Beispiel #4
0
 /**
  *
  */
 protected function afterFind()
 {
     $this->description = UtilModel::urlToLink($this->description);
     parent::afterFind();
 }
 /**
  * getElementsAndDynamicAttributes
  * @param array $componentData
  * @access public
  * @return array
  */
 public function getElementsAndDynamicAttributes($componentData = [])
 {
     $elements = [];
     $attributeArray = [];
     $dynamicDataAttributes = [];
     //$getFormCondition = 't.formId=:formId';
     //$getFormParams = array(':formId' => 1);
     $getForm = EvaluationElements::model()->findAll();
     //$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'] = "EvalForm";
     $elements['activeForm']['enableClientValidation'] = true;
     $elements['activeForm']['clientOptions'] = ['validateOnSubmit' => true];
     //$elements['activeForm']['enableAjaxValidation'] = false;
     $elements['activeForm']['class'] = 'CActiveForm';
     //print_r($getForm); die();
     $evalElements = $getForm;
     $dataArray['getForm'] = $elements;
     $inputType = 'text';
     //$dynamicDataAttributes['frameworkId'] = 'frameworkId';
     //$rules[] = ['frameworkId', 'required'];
     $designData = FrameworkContext::model()->findAll(['condition' => 'userId=:userId', 'params' => [':userId' => Yii::app()->user->id]]);
     $designItems = [];
     // process the dropdown data into an array
     foreach ($designData as $params) {
         $designItems[$params->frameworkId] = $params->name;
     }
     $elements['elements'] = EvaluationHeader::getElements();
     // add the dropdown items to the element
     //$elements['elements']['frameworkId']['items'] = $designItems;
     $elements['elements']['evaContext']['type'] = 'form';
     //$elements['elements']['evaluationName']['layout'] = '{label} {input} {hint} {error}';
     $rules = [];
     $labels = [];
     foreach ($evalElements as $element) {
         //set the model attribute array
         $attributeId = $element->inputName . "_" . $element->evalElementsId;
         $dynamicDataAttributes[$attributeId] = '';
         $validation = $element->required ? 'required' : 'safe';
         $rules[] = [$attributeId, $validation];
         if ($element->inputName == 'componentNo') {
             $rules[] = [$attributeId, 'numerical'];
         }
         $highlightClass = "";
         if (isset($attributeArray[$element->evalElementsId])) {
             $highlightClass = "attributeHighlight";
         }
         $labels[$attributeId] = $element->label;
         // add the elements to the CForm array
         $elements['elements']['evaContext']['elements'][$attributeId] = ['label' => $element->label, 'required' => $element->required, 'type' => $element->inputType, 'class' => $highlightClass, 'title' => UtilModel::urlToLink($element->elementMetaData), 'data-field' => $element->evalElementsId];
         // Add an image icon that will be displayed on the ui to show more info
         $button = CHtml::image('', '', ['id' => 'moreInfoButton' . $element->evalElementsId, 'style' => 'cursor:pointer', 'class' => 'ui-icon ui-icon-info', 'title' => 'More Information', 'onClick' => '$("#moreInfoDialog").html($("#popupData' . $element->evalElementsId . '").html());$("#moreInfoDialog").dialog("open")']);
         // Add the image icon and information to the layout/ui
         //			if (!empty($element->moreInfo) && !empty($element->url) && !empty($element->description)) {
         //				$elements['elements']['evaContext']['elements'][$attributeId]['layout'] = '{label}<div class="componentImagePopup">' . $button .
         //					'</div>{hint} {input}' . '<div id="popupData' . $element->evalElementsId . '" style="display:none">' . $element->moreInfo . '</div>' .
         //					'<div class="componentDataPopup">' . $element->description .
         //					' <br/> <a href=' . $element->url . ' target=_blank>' . $element->url . '</a></div> {error}';
         //			}
         // add the values to the form
         if (!empty($componentData[$attributeId])) {
             $elements['elements']['evaContext']['elements'][$attributeId]['value'] = $componentData[$attributeId]['value'];
         }
         // add the component name element value
         if (!empty($componentData['evaluationName'])) {
             $elements['elements']['evaContext']['elements']['evaluationName']['value'] = $componentData['evaluationName'];
         }
         // add the frameworkId element value
         if (!empty($componentData['frameworkId'])) {
             $elements['elements']['evaContext']['elements']['frameworkId']['value'] = $componentData['frameworkId'];
         }
         //add the dropdown parameters
         if ($element->inputType == 'dropdownlist') {
             $items = CHtml::listData(Options::model()->findAll(['condition' => 'elementId=:elementId', 'params' => [':elementId' => $element->evalElementsId]]), 'optionId', 'label');
             // add the dropdown items to the element
             $elements['elements']['evaContext']['elements'][$attributeId]['items'] = $items;
             $elements['elements']['evaContext']['elements'][$attributeId]['prompt'] = 'Choose one';
         }
         if ($element->inputName == 'currentCost' || $element->inputName == 'budgetLimit') {
             $elements['elements']['evaContext']['elements'][$attributeId]['class'] = 'update-able';
         }
     }
     $elements['buttons'] = ['newEvaluation' => ['type' => 'submit', 'label' => 'Create evaluation context']];
     $returnArray = ['elements' => $elements, 'dynamicDataAttributes' => $dynamicDataAttributes, 'labels' => $labels, 'rules' => $rules];
     return $returnArray;
 }
Beispiel #6
0
 /**
  * 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;
 }