/**
  * 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;
 }
Example #2
0
 /**
  * @param $id
  */
 public function actionDeleteEvaContext($id)
 {
     Yii::log("actionDeleteEvaContext called", "trace", self::LOG_CAT);
     if (EvaluationElements::model()->deleteByPk($id) > 0) {
         echo 'Form field successfully deleted';
         return;
     }
     echo 'An error occurred when deleting the form field, ' . 'please try again or contact your administrator if the problem persists';
     return;
 }