<?php

/**
 * Created by PhpStorm.
 * User: james
 * Date: 8/28/15
 * Time: 12:26 PM
 */
//print_r($elements); die;
if (isset($modelArray[0]) && isset($elements['elements'][0])) {
    $formHead = new CForm(array_merge($elements['elements'][0], ContextController::getDefaultElements()), $modelArray[0]);
    echo $formHead->renderBegin();
}
echo CHtml::tag('div', ['class' => 'form'], false, false);
echo CHtml::tag('table', ['class' => 'tabular-container'], false, false);
echo CHtml::tag('thead', ['class' => 'tabular-header'], false, false);
echo CHtml::tag('tr', [], $tableHeader);
echo CHtml::closeTag('thead');
echo CHtml::tag('tbody', ['class' => 'tabular-input-container'], false, false);
foreach ($modelArray as $modelIndex => $model) {
    echo CHtml::tag('tr', ['class' => 'tabular-input'], false, false);
    $form = new CForm($elements['elements'][$modelIndex], $model);
    foreach ($form->getElements() as $element) {
        $element->name = "[{$modelIndex}]{$element->name}";
        echo CHtml::tag('td', [], $element->renderInput());
    }
    echo CHtml::closeTag('tr');
    //$form[$modelIndex] = $model;
}
echo CHtml::closeTag('tbody');
echo CHtml::closeTag('table');
示例#2
0
 public function actionGetDesignElements()
 {
     $designSectionsCriteria = new CDbCriteria();
     $designSectionsCriteria->condition = "tool='design'";
     $rsDesignSections = SurveillanceSections::model()->with('designFields')->findAll($designSectionsCriteria);
     //print_r($rsDesignSections); die;
     $elements = ContextController::getDefaultElements();
     $elements['activeForm']['id'] = 'DesignForm';
     $properties = [];
     $elements['elements'][] = CHtml::tag('div', ['class' => 'accStyle'], false, false);
     $randomIds = [];
     foreach ($rsDesignSections as $sectionKey => $section) {
         if ($section->sectionNumber == '2.0') {
             //				foreach($section->designFields as $sectionField) {
             //					$sectionTwo[$sectionField->inputName] = $sectionField;
             //				}
             continue;
         }
         if ($section->sectionNumber * 10 % 10 == 0) {
             $elements['elements'][] = CHtml::tag('h3', [], $section->sectionNumber . ' ' . $section->sectionName);
             $randomId = rand(0, 100);
             $randomIds[] = $randomId;
             $elements['elements'][] = CHtml::tag('div', [], $section->description, false);
             $elements['elements'][] = CHtml::tag('p', [], false);
             $elements['elements'][] = CHtml::link('Add component', '#', ['id' => 'copyLink-' . $randomId, 'class' => ' btn', 'rel' => '.desCopy' . $randomId]);
             $elements['elements'][] = CHtml::tag('fieldset', ['class' => 'desCopy' . $randomId], false, false);
             $elements['elements']['[0]component'] = ['label' => 'Component Name', 'type' => 'dropdownlist', 'class' => 'componentList', 'items' => CHtml::listData(ComponentHead::model()->findAll('frameworkId=' . Yii::app()->session['surDesign']['id']), 'componentId', 'componentName'), 'prompt' => 'Select component'];
             $properties['propertyNames']['component'] = '';
             $properties['propertyLabels']['component'] = 'Component Name';
             $properties['rules'][] = ['component', 'required'];
         }
         //print_r($displayItems); die;
         //if($section->sectionNumber * 10 % 10 == 0 && $sectionNo !=) {
         $elements['elements'][] = CHtml::closeTag('fieldset');
         $elements['elements'][] = CHtml::closeTag('div');
         //}
     }
     $elements['elements'][] = CHtml::closeTag('div');
     $elements['buttons'] = ['save' => ['label' => 'Save', 'type' => 'submit']];
     $model = new DesignForm();
     $model->setProperties($properties['propertyNames']);
     $model->setAttributeLabels($properties['propertyLabels']);
     $model->setRules($properties['rules']);
     $form = new CFormTabular($elements, $model, null, 0);
     if ($form->submitted('save')) {
         if (self::saveComponents()) {
             Yii::app()->user->setFlash('success', 'Component data saved successfully');
         } else {
             Yii::app()->user->setFlash('error', 'An error occurred while saving the component data, ' . 'please try again or contact your administrator if the problem persists');
         }
     }
     //print_r($model);
     //echo $form->render(); die;
     $this->render('framework', compact('form', 'randomIds'));
 }
示例#3
0
 /**
  * actionSelectComponents
  */
 public function actionSelectComponents()
 {
     $this->setPageTitle('Select components');
     // check if the context supports component selection
     $rsEvaluationType = EvaluationDetails::model()->with('options')->find('evalElementsId=:element AND evalId=:evaId', [':element' => 5, ':evaId' => $this->evaContextId]);
     if (!isset($rsEvaluationType)) {
         Yii::app()->user->setFlash('notice', 'PLease update the evaluation context');
         $this->redirect('listEvaContext');
     }
     //print_r($rsEvaluationType); die;
     if (isset($rsEvaluationType->options) && $rsEvaluationType->options->label == 'System') {
         Yii::app()->user->setFlash('notice', 'You are planning to evaluate at system level hence no selection' . ' of components is required');
         $this->redirect('selectEvaAttributes');
     }
     $model = new DesignForm();
     $elements = ContextController::getDefaultElements();
     $rules = [];
     $componentsCriteria = new CDbCriteria();
     $componentsCriteria->select = 'componentId, componentName';
     $componentsCriteria->condition = 'frameworkId=:framework';
     $componentsCriteria->params = [':framework' => $this->frameworkId];
     $elements['title'] = '<h3>Select Components</h3>';
     $elements['elements'] = ['<p> Please select the components you would like to include in your evaluation from the components' . ' included in this system using the table below.  If the components you want to include are not listed' . ' in this table please go back and enter the information about your components into the ' . CHtml::link('add components', ['design/addMultipleComponents']) . ' screen. </p>', '<table id="componentsDisplay" width="100%" border="0" cellspacing="0" cellpadding="0">', '<thead><tr></tr><th></th><th>Component Name</th><th>Target Species</th><th>Data collection point</th>' . '<th>Study type</th></tr></thead>', '<tbody></tbody>', '</table>'];
     $rules[] = ['components', 'required'];
     $evaModel = EvaluationHeader::model()->find('evalId=:evalId', [':evalId' => $this->evaContextId]);
     $model->setPropertyName('components');
     $elements['buttons'] = ['save' => ['label' => 'Save', 'type' => 'submit'], 'next' => ['label' => 'Next', 'type' => 'submit']];
     $componentsConditions = EvaQuestionGroups::model()->find('section=:section', [':section' => 'evaComponents'])->questions;
     $availableComponents = json_decode($componentsConditions, true);
     $requiredComponents = 1;
     if (isset(array_flip($availableComponents[2])[$this->evaQuestionId])) {
         $requiredComponents = 2;
     }
     //var_dump($availableComponents, $this->evaQuestionId); die;
     // Get number of components
     $componentNo = EvaluationDetails::model()->find('evalId=:evaId AND evalElementsId=:evaElement', [':evaId' => $this->evaContextId, ':evaElement' => 6])->value;
     $rules[] = ['components', 'type', 'type' => 'array'];
     $rules[] = ['components', 'ext.validators.ComponentNumber', 'requiredComponents' => $requiredComponents, 'declaredComponents' => $componentNo];
     //var_dump($requiredComponents, $componentNo); die;
     $model->setRules($rules);
     $tableData = DesignController::getComponentData()['componentListArray'];
     $componentsList = json_encode($tableData);
     //print_r($model); die;
     $form = new CForm($elements, $model);
     //print_r($_POST); die;
     if ($form->submitted('save') || $form->submitted('next')) {
         if ($form->validate()) {
             $evaModel->components = json_encode($form->model->components);
             //				print_r($evaModel->components); die;
             if ($evaModel->save()) {
                 Yii::app()->user->setFlash('success', 'Components successfully saved');
                 if (isset($_POST['next'])) {
                     $this->redirect('selectEvaAttributes');
                 }
             } else {
                 Yii::app()->user->setFlash('error', 'An error occurred while save the components,' . ' please try again or contact your administrator if this problem persists');
             }
         }
     }
     $selectedComponents = is_null($evaModel->components) ? [] : json_decode($evaModel->components);
     //Get evaluation summary
     $evaDetails = $this->getEvaDetails();
     $this->docName = 'selectComponents';
     if (isset($_POST['pageId'])) {
         SystemController::savePage('selectComponents');
     }
     $page = SystemController::getPageContent($this->docName);
     if (!isset($page['content']->docData)) {
         Yii::app()->user->setFlash('notice', 'This page is missing some information, please contact your administrator');
     }
     $this->render('selectComponents', compact('form', 'componentsList', 'selectedComponents', 'page', 'evaDetails'));
     return;
 }
示例#4
0
 /**
  * @return array
  */
 private function getEvaMethodsFormConfig()
 {
     $elements = ContextController::getDefaultElements();
     $elements['elements'] = array('buttonName' => array('type' => 'text'), 'link' => array('type' => 'text'), 'description' => array('type' => 'text'));
     return $elements;
 }