/**
  * @param stdClass $o
  * @return \QueryModel
  */
 public static function fromObject($o)
 {
     $query = new QueryModel();
     $query->setId($o->id);
     $query->setStudyId($o->studyId);
     $query->setTitle($o->title);
     $query->setText($o->text);
     $query->setCompiled($o->compiled);
     return $query;
 }
示例#2
0
 function analysis()
 {
     $caseId = $this->session->get('caseId');
     $models = ModelModel::loadAll($caseId);
     $scenarios = ScenarioModel::loadAll($caseId);
     $case = CaseModel::load($caseId);
     $query = QueryModel::load($caseId);
     $this->assign('models', $models);
     $this->assign('scenarios', $scenarios);
     $this->assign('case', $case);
     $this->assign('query', $query);
     $this->load->view('analysis_editor');
 }
示例#3
0
 public function processAction()
 {
     $initId = Zend_Filter::filterStatic($this->getRequest()->getParam('id'), 'StripTags');
     $sDate = Zend_Filter::filterStatic($this->getRequest()->getParam('sdate'), 'StripTags');
     $eDate = Zend_Filter::filterStatic($this->getRequest()->getParam('edate'), 'StripTags');
     $sTime = Zend_Filter::filterStatic($this->getRequest()->getParam('stime'), 'StripTags');
     $eTime = Zend_Filter::filterStatic($this->getRequest()->getParam('etime'), 'StripTags');
     $sum = Zend_Filter::filterStatic($this->getRequest()->getParam('sum'), 'StripTags');
     $format = Zend_Filter::filterStatic($this->getRequest()->getParam('format'), 'StripTags');
     $offset = Zend_Filter::filterStatic($this->getRequest()->getParam('offset'), 'StripTags');
     $limit = Zend_Filter::filterStatic($this->getRequest()->getParam('limit'), 'StripTags');
     $params = array();
     if (isset($initId) && ctype_digit($initId)) {
         if (empty($format) || !in_array($format, $this->_formats)) {
             $format = 'cal';
         }
         $params['format'] = $format;
         $params['offset'] = !empty($offset) && ctype_digit($offset) ? (int) $offset : 0;
         $params['limit'] = !empty($limit) && ctype_digit($limit) ? (int) $limit : Globals::getQsDbLimit();
         if (!empty($sDate)) {
             $sDate = explode("T", strtoupper($sDate));
             $yr = substr($sDate[0], 0, 4);
             $month = substr($sDate[0], 4, 2);
             $day = substr($sDate[0], 6, 2);
             if (ctype_digit($yr) && ctype_digit($month) && ctype_digit($day)) {
                 $sDate = new Zend_Date(array('year' => $yr, 'month' => $month, 'day' => $day));
                 $params['sDate'] = $sDate->get(Zend_Date::ISO_8601);
             }
         }
         if (!empty($eDate)) {
             $eDate = explode("T", strtoupper($eDate));
             $yr = substr($eDate[0], 0, 4);
             $month = substr($eDate[0], 4, 2);
             $day = substr($eDate[0], 6, 2);
             if (ctype_digit($yr) && ctype_digit($month) && ctype_digit($day)) {
                 $eDate = new Zend_Date(array('year' => $yr, 'month' => $month, 'day' => $day));
                 if (is_object($sDate) && $eDate->isEarlier($sDate)) {
                     $this->view->error = 'End date must come after start date.';
                     $this->_forward("errorxhr", "error");
                 } else {
                     $params['eDate'] = $eDate->get(Zend_Date::ISO_8601);
                 }
             }
         }
         if (!empty($sTime) && ctype_digit($sTime) && (int) $sTime > 0 && (int) $sTime < 2400) {
             $sTime = str_pad($sTime, 4, '0', STR_PAD_LEFT);
             $params['sTimeH'] = substr($sTime, 0, 2);
             $params['sTimeM'] = substr($sTime, 2, 2);
         }
         if (!empty($eTime) && ctype_digit($eTime) && (int) $eTime >= 0 && (int) $eTime < 2359) {
             $sTime = str_pad($eTime, 4, '0', STR_PAD_LEFT);
             $params['eTimeH'] = substr($sTime, 0, 2);
             $params['eTimeM'] = substr($sTime, 2, 2);
         }
         try {
             $qModel = new QueryModel($initId);
             if ($this->_getParam('service') == 'debugsessions') {
                 $qModel->bySessions($params);
                 $this->view->qModel = $qModel;
                 $this->view->offset = $params['offset'];
                 $this->view->nextOffset = $params['offset'] + $params['limit'];
                 $this->view->prevOffset = $params['offset'] - $params['limit'] > 0 ? $params['offset'] - $params['limit'] : 0;
                 $this->view->id = $initId;
                 $this->render('debugsessions');
             } else {
                 if ($this->_getParam('service') == 'debugcounts') {
                     $qModel->byCounts($params);
                     $this->view->qModel = $qModel;
                     $this->view->offset = $params['offset'];
                     $this->view->nextOffset = $params['offset'] + $params['limit'];
                     $this->view->prevOffset = $params['offset'] - $params['limit'] > 0 ? $params['offset'] - $params['limit'] : 0;
                     $this->view->id = $initId;
                     $this->render('debugcounts');
                 } else {
                     $sum = strtolower($sum) === 'true' ? true : false;
                     if ($this->_getParam('service') == 'sessions') {
                         $qModel->bySessions($params);
                         $trans = TransformerFactory::factory($this->_transformers[$format], false, $sum);
                     } else {
                         $qModel->byCounts($params);
                         $trans = TransformerFactory::factory($this->_transformers[$format], true, $sum);
                     }
                     $trans->setInitMetadata($qModel->getInitMetadata());
                     $trans->setInitLocs($qModel->getInitLocs());
                     $trans->setInitActs($qModel->getInitActs());
                     $trans->setInitActGroups($qModel->getInitActGroups());
                     while ($row = $qModel->getNextRow()) {
                         $trans->addRow($row);
                     }
                     if ($qModel->hasMore()) {
                         $trans->setHasMore(true, $params['offset'] + $params['limit']);
                     }
                     $this->view->trans = $trans;
                 }
             }
         } catch (Exception $e) {
             $this->view->error = $e->getMessage();
             $this->_forward("error");
         }
     } else {
         $this->view->error = 'Initiative ID must be numeric';
         Globals::getLog()->err('INVALID INITIATIVE ID - QueryController id: ' . $initId);
         $this->_forward("error");
     }
 }
示例#4
0
 /**
  *
  */
 protected function compile()
 {
     global $objPage;
     $strFormTemplate = $this->f_form_template;
     $strDateFormat = $objPage->dateFormat;
     $arrPageTaxonomy = $this->getPageTaxonomy($objPage->page_taxonomy);
     $arrFEFields = $this->f_form_fields ? deserialize($this->f_form_fields) : array();
     $arrFields = array();
     $arrWidgets = array();
     $strWidget = '';
     $arrActiveOptions = $this->f_active_options ? deserialize($this->f_active_options) : array();
     $objAutoComplete = new AutoCompletion();
     // model information
     $strListViewID = $this->f_list_field;
     $objModule = $this->Database->prepare('SELECT * FROM tl_module WHERE id = ?')->execute($strListViewID)->row();
     $strModuleTableName = $objModule['f_select_module'];
     $strWrapperID = $objModule['f_select_wrapper'];
     $arrModeSettings = deserialize($objModule['f_display_mode']);
     $arrModeSettings = is_array($arrModeSettings) ? array_values($arrModeSettings) : array();
     if (!$strModuleTableName || !$strWrapperID) {
         return;
     }
     // set fields from db
     if (is_array($arrFEFields)) {
         $arrIDs = array();
         foreach ($arrFEFields as $strID => $arrFEField) {
             $arrIDs[] = $strID;
         }
         $strPlaceholder = implode(',', array_fill(0, count($arrIDs), '?'));
         $objFields = $this->Database->prepare('SELECT * FROM tl_fmodules_filters WHERE id IN (' . $strPlaceholder . ')')->execute($arrIDs);
         if ($objFields->count()) {
             while ($objFields->next()) {
                 $arrField = $objFields->row();
                 $arrFields[$arrField['id']] = $arrField;
             }
         }
         // merge field from fe and fields from db
         $_arrFields = array();
         foreach ($arrFEFields as $strID => $arrFEField) {
             // do not display if field has dependency on other field
             if ($arrFEField['dependsOn']) {
                 if (!\Input::get($arrFEField['dependsOn'])) {
                     continue;
                 }
             }
             $_arrFields[$arrFEField['fieldID']] = $arrFEField;
             if (is_array($arrFields[$strID])) {
                 foreach ($arrFields[$strID] as $strKey => $strValue) {
                     $_arrFields[$arrFEField['fieldID']][$strKey] = $strValue;
                 }
             }
         }
         // replace fields array
         $arrFields = $_arrFields;
     }
     // generate action attribute
     $strAction = \Environment::get('request');
     if ($this->fm_redirect_source) {
         $type = $this->fm_redirect_source;
         if ($type == 'siteID') {
             $id = $this->fm_redirect_jumpTo;
             if ($id) {
                 $pageDB = $this->Database->prepare('SELECT * FROM tl_page WHERE id = ?')->execute($id)->row();
             }
             if (!empty($pageDB)) {
                 $strAction = $this->generateFrontendUrl($pageDB);
             }
         }
         if ($type == 'siteURL') {
             $url = $this->fm_redirect_url;
             if ($url) {
                 $strAction = $this->replaceInsertTags($url);
             }
         }
     }
     // get field values
     $arrActiveFields = array();
     $blnStartPoint = true;
     $arrNotRelateAbleFields = array('orderBy', 'sorting_fields', 'pagination');
     foreach ($arrFields as $strFieldID => $arrField) {
         $strValue = \Input::get($strFieldID) ? \Input::get($strFieldID) : '';
         $arrFields[$strFieldID]['value'] = $strValue;
         $arrFields[$strFieldID]['enable'] = false;
         $blnIsValue = QueryModel::isValue($strValue);
         // set labels
         $arrLabel = $this->setLabels($arrField);
         $arrFields[$strFieldID]['title'] = $arrLabel[0];
         $arrFields[$strFieldID]['description'] = $arrLabel[1];
         // set enable
         if ($blnIsValue) {
             $arrFields[$strFieldID]['enable'] = true;
         }
         // do not set start point
         if ($this->fm_related_start_point && $blnStartPoint) {
             $blnStartPoint = false;
             continue;
         }
         // do not set
         if (in_array($arrField['fieldID'], $arrNotRelateAbleFields)) {
             continue;
         }
         $arrActiveFields[] = $strFieldID;
     }
     unset($blnStartPoint);
     $arrFilteredOptions = array();
     if ($this->fm_related_options) {
         // get only active options
         $arrQueryData = HelperModel::generateSQLQueryFromFilterArray($arrFields);
         $strQuery = $arrQueryData['qStr'];
         $qTextSearch = $arrQueryData['isFulltextSearch'] ? $arrQueryData['$qTextSearch'] : '';
         //get text search results
         $textSearchResults = array();
         if ($qTextSearch) {
             $textSearchResults = QueryModel::getTextSearchResult($qTextSearch, $strModuleTableName, $strWrapperID, $arrQueryData['searchSettings']);
         }
         // get only published items
         $qProtectedStr = ' AND published = "1"';
         // preview mode
         if (HelperModel::previewMode()) {
             $qProtectedStr = '';
         }
         // get all items
         $objList = $this->Database->prepare('SELECT * FROM ' . $strModuleTableName . '_data WHERE pid = ' . $strWrapperID . $qProtectedStr . $strQuery)->query();
         // filtered options
         $_arrFilteredOptions = array();
         while ($objList->next()) {
             $arrListItem = $objList->row();
             if ($qTextSearch) {
                 if (!$textSearchResults[$arrListItem['id']]) {
                     continue;
                 }
             }
             foreach ($arrActiveFields as $strActiveField) {
                 $arrFilteredOptions[$strActiveField] = array();
                 $arrValues = explode(',', $arrListItem[$strActiveField]);
                 $_arrFilteredOptions[$strActiveField][] = array_values($arrValues);
             }
         }
         // pluck values
         foreach ($_arrFilteredOptions as $strFieldID => $arrFilteredOption) {
             $arrFilteredOption = call_user_func_array('array_merge', $arrFilteredOption);
             $arrFilteredOption = array_unique($arrFilteredOption);
             $arrFilteredOptions[$strFieldID] = $arrFilteredOption;
         }
     }
     // set options
     $objWrapper = $this->Database->prepare('SELECT * FROM ' . $strModuleTableName . ' WHERE id = ?')->execute($strWrapperID)->row();
     foreach ($arrFields as $strFieldID => $arrField) {
         if ($arrField['type'] == 'multi_choice' || $arrField['type'] == 'simple_choice') {
             $arrWrapperOptions = $objWrapper[$strFieldID] ? deserialize($objWrapper[$strFieldID]) : array();
             if ($arrField['dataFromTaxonomy'] == '1') {
                 $arrWrapperOptions = $this->getDataFromTaxonomy($objWrapper['select_taxonomy_' . $strFieldID]);
             }
             if ($arrField['reactToTaxonomy'] == '1') {
                 $arrWrapperOptions = $this->getDataFromTaxonomyTags($arrField['reactToField'], $objWrapper);
             }
             if ($arrWrapperOptions['table'] && !in_array($strFieldID, $arrActiveOptions)) {
                 $arrFields[$strFieldID]['options'] = $this->getDataFromTable($objWrapper[$strFieldID]);
             }
             if (is_null($arrWrapperOptions['table']) && !in_array($strFieldID, $arrActiveOptions)) {
                 $arrFields[$strFieldID]['options'] = $arrWrapperOptions;
             }
         }
         // set countries
         if ($arrField['fieldID'] == 'address_country') {
             $arrCountries = $this->getCountries();
             $arrFields[$strFieldID]['options'] = DiverseFunction::conformOptionsArray($arrCountries);
         }
         // geo locator
         if ($arrField['type'] == 'geo_locator') {
             if ($arrField['locatorType'] == 'geo_distance') {
                 $arrFields[$strFieldID]['geoDistanceOptions'] = $this->generateGeoDistanceOptions($arrField['geoDistanceOptions']);
             }
         }
         // get options
         if ($strFieldID && in_array($strFieldID, $arrActiveOptions)) {
             $results = $objAutoComplete->getAutoCompletion($strModuleTableName, $strWrapperID, $strFieldID, $objPage->dateFormat, $objPage->timeFormat);
             // taxonomy tags
             if ($arrField['reactToTaxonomy'] == '1') {
                 $tempResults = array();
                 $arrValues = $this->getDataFromTaxonomyTags($arrField['reactToField'], $arrField, true);
                 foreach ($results as $result) {
                     if (!in_array($result['value'], $arrValues)) {
                         continue;
                     }
                     $tempResults[] = $result;
                 }
                 $results = $tempResults;
                 unset($tempResults);
             }
             $arrFields[$strFieldID]['options'] = is_array($results) ? $results : array();
         }
         if ($this->fm_related_options && is_array($arrFields[$strFieldID]['options'])) {
             $arrNewOptions = array();
             foreach ($arrFields[$strFieldID]['options'] as $intIndex => $arrKeyValue) {
                 if (is_array($arrFilteredOptions[$strFieldID]) && !in_array($arrKeyValue['value'], $arrFilteredOptions[$strFieldID])) {
                     continue;
                 }
                 $arrNewOptions[] = $arrKeyValue;
             }
             $arrFields[$strFieldID]['options'] = $arrNewOptions;
         }
         // set table name
         $arrFields[$strFieldID]['tablename'] = !strpos($strModuleTableName, '_data') ? $strModuleTableName . '_data' : $strModuleTableName;
         // date field
         if ($arrField['type'] == 'date_field') {
             $format = $arrField['addTime'] ? $objPage->datimFormat : $strDateFormat;
             $arrFields[$strFieldID]['format'] = $format;
             $arrFields[$strFieldID]['operator'] = $this->getOperator();
             $arrFields[$strFieldID]['selected_operator'] = \Input::get($strFieldID . '_int');
         }
         // search field (int)
         if ($arrField['type'] == 'search_field' && $arrField['isInteger'] == '1') {
             $arrFields[$strFieldID]['operator'] = $this->getOperator();
             $arrFields[$strFieldID]['selected_operator'] = \Input::get($strFieldID . '_int');
         }
         // search field
         if ($arrField['type'] == 'search_field') {
             //backwards compatible
             $arrFields[$strFieldID]['auto_complete'] = $arrFields[$strFieldID]['options'];
         }
         if ($arrField['type'] == 'toggle_field') {
             $arrFields[$strFieldID]['showLabel'] = $GLOBALS['TL_LANG']['MSC']['fm_highlight_show'];
             $arrFields[$strFieldID]['ignoreLabel'] = $GLOBALS['TL_LANG']['MSC']['fm_highlight_ignore'];
         }
         $arrFields[$strFieldID]['wrapperID'] = $strWrapperID;
         $arrFields[$strFieldID]['selected'] = $arrFields[$strFieldID]['value'];
         //
         if ($arrField['type'] == 'search_field' && $arrField['isInteger'] == '1') {
             if (!$arrFields[$strFieldID]['selected'] && !is_null(\Input::get($arrField['fieldID']))) {
                 $arrFields[$strFieldID]['selected'] = '';
             }
         }
         //
         if ($arrField['type'] == 'toggle_field' && !$arrFields[$strFieldID]['value']) {
             $arrFields[$strFieldID]['selected'] = '';
         }
         // set templates
         $strTemplateName = $this->parseTemplateName($arrField['used_templates']);
         $arrWidgets[$strFieldID] = array('data' => $arrFields[$strFieldID], 'tpl' => $strTemplateName);
     }
     foreach ($arrWidgets as $strFieldID => $arrWidget) {
         if ($arrWidget['data']['type'] == 'wrapper_field' && $arrWidget['data']['from_field'] && $arrWidget['data']['to_field']) {
             if ($arrWidget['data']['from_field'] == $arrWidget['data']['to_field']) {
                 $fromFieldData = $arrWidgets[$arrWidget['data']['from_field']]['data'];
                 $arrWidget['data']['title'] = $fromFieldData['title'];
                 $arrWidget['data']['description'] = $fromFieldData['description'];
                 $fromFieldData['operator'] = array('gte' => $GLOBALS['TL_LANG']['MSC']['f_gte']);
                 $fromFieldData['title'] = $GLOBALS['TL_LANG']['MSC']['fm_from_label'];
                 $fromFieldData['description'] = '';
                 $fromTemplateObj = new \FrontendTemplate($arrWidgets[$arrWidget['data']['from_field']]['tpl']);
                 $fromTemplateObj->setData($fromFieldData);
                 $from_template = $fromTemplateObj->parse();
                 $arrWidget['data']['from_template'] = $from_template;
                 //to
                 $toFieldData = $arrWidgets[$arrWidget['data']['to_field']]['data'];
                 $toFieldData['fieldID'] = $toFieldData['fieldID'] . '_btw';
                 $toFieldData['title'] = $GLOBALS['TL_LANG']['MSC']['fm_to_label'];
                 $toFieldData['description'] = '';
                 $selectValue = \Input::get($toFieldData['fieldID']);
                 if (!is_null($selectValue) && !$selectValue && $toFieldData['type'] != 'date_field') {
                     $selectValue = '';
                 }
                 $toFieldData['selected'] = $selectValue;
                 $toFieldData['operator'] = array('lte' => $GLOBALS['TL_LANG']['MSC']['f_lte']);
                 $toTemplateObj = new \FrontendTemplate($arrWidgets[$arrWidget['data']['to_field']]['tpl']);
                 $toTemplateObj->setData($toFieldData);
                 $to_template = $toTemplateObj->parse();
                 $arrWidget['data']['to_template'] = $to_template;
             } else {
                 // generate from field tpl
                 $fromFieldData = $arrWidgets[$arrWidget['data']['from_field']]['data'];
                 $fromFieldData['operator'] = array('gte' => $GLOBALS['TL_LANG']['MSC']['f_gte']);
                 $fromTemplateObj = new \FrontendTemplate($arrWidgets[$arrWidget['data']['from_field']]['tpl']);
                 $fromTemplateObj->setData($fromFieldData);
                 $from_template = $fromTemplateObj->parse();
                 $arrWidget['data']['from_template'] = $from_template;
                 // generate to field tpl
                 $toFieldData = $arrWidgets[$arrWidget['data']['to_field']]['data'];
                 $toFieldData['operator'] = array('lte' => $GLOBALS['TL_LANG']['MSC']['f_lte']);
                 $toTemplateObj = new \FrontendTemplate($arrWidgets[$arrWidget['data']['to_field']]['tpl']);
                 $toTemplateObj->setData($toFieldData);
                 $to_template = $toTemplateObj->parse();
                 $arrWidget['data']['to_template'] = $to_template;
             }
         }
         // sort out fixed field
         if ($this->sortOutFixedField($strFieldID, $arrModeSettings)) {
             continue;
         }
         // disable inactive fields
         if (!$arrWidget['data']['active']) {
             continue;
         }
         //
         if ($arrWidget['data']['overwrite'] == '1') {
             continue;
         }
         //
         if ($arrPageTaxonomy[$strFieldID] && $arrPageTaxonomy[$strFieldID]['set']['overwrite'] == '1') {
             continue;
         }
         $strWidgetTemplate = new \FrontendTemplate($arrWidget['tpl']);
         $strWidgetTemplate->setData($arrWidget['data']);
         $strWidget .= $strWidgetTemplate->parse();
     }
     $strResult = '';
     $objTemplate = new \FrontendTemplate($strFormTemplate);
     $objTemplate->setData(array('widgets' => $strWidget, 'filter' => $GLOBALS['TL_LANG']['MSC']['widget_submit'], 'enableSubmit' => $this->fm_disable_submit));
     $strResult .= $objTemplate->parse();
     $this->Template->action = $strAction;
     $this->Template->reset = $GLOBALS['TL_LANG']['MSC']['fm_ff_reset'];
     $this->Template->cssID = $this->cssID;
     $this->Template->fields = $strResult;
 }
示例#5
0
 static function getInitiatives()
 {
     $db = Globals::getDBConn();
     $select = $db->select()->from(array('i' => 'initiative'), array('title', 'id', 'description', 'enabled', 'rootLocation' => 'fk_root_location'))->join(array('s' => 'session'), 'i.id = s.fk_initiative', array())->where('s.deleted = 0')->group('i.id')->order(array('i.title ASC'));
     $initiatives = $select->query()->fetchAll();
     // This block is to cast string id into an int
     $parentArray = array();
     foreach ($initiatives as $init) {
         $array = array();
         foreach ($init as $key => $val) {
             if ($key === 'id' || $key === 'rootLocation') {
                 $array[$key] = (int) $val;
             } elseif ($key === 'enabled') {
                 $array[$key] = (bool) $val;
             } else {
                 $array[$key] = $val;
             }
         }
         $qModel = new QueryModel($array['id']);
         $array['dictionary']['locations'] = $qModel->getInitLocs();
         $array['dictionary']['activities'] = $qModel->getInitActs();
         $array['dictionary']['activityGroups'] = $qModel->getInitActGroups();
         $parentArray[] = $array;
     }
     return $parentArray;
 }
示例#6
0
 /**
  * @param $strTableName
  * @param string $strWrapperID
  * @return array
  */
 protected function getModule($strTableName, $strWrapperID = '')
 {
     $objModule = $this->Database->prepare('SELECT tl_fmodules.id AS moduleID, tl_fmodules.*, tl_fmodules_filters.*  FROM tl_fmodules LEFT JOIN tl_fmodules_filters ON tl_fmodules.id = tl_fmodules_filters.pid WHERE tablename = ? ORDER BY tl_fmodules_filters.sorting')->execute($strTableName);
     $arrFields = array();
     $widgetsArr = array();
     $mapFields = array();
     $arrCleanOptions = array();
     while ($objModule->next()) {
         $arrModule = $objModule->row();
         if (in_array($arrModule['fieldID'], $this->doNotSetByID) || in_array($arrModule['type'], $this->doNotSetByType)) {
             continue;
         }
         $getFilter = $this->getFilter($arrModule['fieldID'], $arrModule['type']);
         $arrModule['value'] = $getFilter['value'];
         $arrModule['operator'] = $getFilter['operator'];
         $arrModule['overwrite'] = null;
         $arrModule['active'] = null;
         $val = QueryModel::isValue($arrModule['value'], $arrModule['type']);
         if ($val) {
             $arrModule['enable'] = true;
         }
         // check if has an wrapper
         if ($arrModule['type'] === 'search_field' && $arrModule['isInteger'] || $arrModule['type'] === 'date_field') {
             $btw = \Input::get($arrModule['fieldID'] . '_btw') ? \Input::get($arrModule['fieldID'] . '_btw') : '';
             $btwHasValue = QueryModel::isValue($btw, $arrModule['type']);
             if ($btwHasValue && !$val) {
                 $arrModule['enable'] = true;
                 $arrModule['value'] = 0;
             }
         }
         // map
         if ($arrModule['type'] == 'map_field') {
             // set map settings
             $mapFields[] = HelperModel::setGoogleMap($arrModule);
             // set loadMapScript to true
             $this->loadMapScript = true;
             // load map libraries
             if (!$GLOBALS['loadGoogleMapLibraries']) {
                 $GLOBALS['loadGoogleMapLibraries'] = $arrModule['mapInfoBox'] ? true : false;
             }
         }
         // field
         if ($arrModule['type'] == 'widget') {
             $tplName = $arrModule['widgetTemplate'];
             $tpl = '';
             if (!$tplName) {
                 $tplNameType = explode('.', $arrModule['widget_type'])[0];
                 $tplNameArr = $this->getTemplateGroup('fm_field_' . $tplNameType);
                 $tpl = current($tplNameArr);
                 $tpl = $this->parseTemplateName($tpl);
             }
             $fieldWidgets[$arrModule['fieldID']] = array('fieldID' => $arrModule['fieldID'], 'widgetType' => $arrModule['widget_type'], 'widgetTemplate' => $arrModule['widgetTemplate'] ? $arrModule['widgetTemplate'] : $tpl);
         }
         // has options
         if ($arrModule['type'] == 'simple_choice' || $arrModule['type'] == 'multi_choice') {
             $dcaHelper = new DCAHelper();
             $arrCleanOptions[$arrModule['fieldID']] = $dcaHelper->getOptions($arrModule, $strTableName, $strWrapperID);
         }
         $arrFields[$arrModule['fieldID']] = $arrModule;
     }
     return array('arrFields' => $arrFields, 'arrWidgets' => $widgetsArr, 'mapFields' => $mapFields, 'arrCleanOptions' => $arrCleanOptions);
 }
示例#7
0
 /**
  *
  */
 protected function compile()
 {
     global $objPage;
     $listID = $this->f_list_field;
     $strDetailTemplate = $this->f_detail_template;
     $listModuleDB = $this->Database->prepare('SELECT * FROM tl_module WHERE id = ?')->execute($listID)->row();
     $tablename = $listModuleDB['f_select_module'];
     $wrapperID = $listModuleDB['f_select_wrapper'];
     $moduleDB = $this->Database->prepare('SELECT tl_fmodules.id AS moduleID, tl_fmodules.*, tl_fmodules_filters.*  FROM tl_fmodules LEFT JOIN tl_fmodules_filters ON tl_fmodules.id = tl_fmodules_filters.pid WHERE tablename = ? ORDER BY tl_fmodules_filters.sorting')->execute($tablename);
     $alias = \Input::get('auto_item');
     $isAlias = QueryModel::isValue($alias);
     if (!$isAlias) {
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
         exit;
     }
     $doNotSetByID = array('orderBy', 'sorting_fields', 'pagination');
     $doNotSetByType = array('legend_end', 'legend_start', 'wrapper_field');
     $fieldWidgets = array();
     $arrModules = array();
     $mapFields = array();
     $arrCleanOptions = array();
     //
     while ($moduleDB->next()) {
         $arrModule = $moduleDB->row();
         if (in_array($arrModule['fieldID'], $doNotSetByID) || in_array($arrModule['type'], $doNotSetByType)) {
             continue;
         }
         // map
         if ($arrModule['type'] == 'map_field') {
             $mapFields[] = HelperModel::setGoogleMap($arrModule);
             // set loadMapScript to true
             $this->loadMapScript = true;
             // load map libraries
             if (!$GLOBALS['loadGoogleMapLibraries']) {
                 $GLOBALS['loadGoogleMapLibraries'] = $arrModule['mapInfoBox'] ? true : false;
             }
         }
         if ($arrModule['type'] == 'widget') {
             $tplName = $arrModule['widgetTemplate'];
             $tpl = '';
             if (!$tplName) {
                 $tplNameType = explode('.', $arrModule['widget_type'])[0];
                 $tplNameArr = $this->getTemplateGroup('fm_field_' . $tplNameType);
                 $tpl = current($tplNameArr);
                 $tpl = $this->parseTemplateName($tpl);
             }
             $fieldWidgets[$arrModule['fieldID']] = array('fieldID' => $arrModule['fieldID'], 'widgetType' => $arrModule['widget_type'], 'widgetTemplate' => $arrModule['widgetTemplate'] ? $arrModule['widgetTemplate'] : $tpl);
         }
         // has options
         if ($arrModule['type'] == 'simple_choice' || $arrModule['type'] == 'multi_choice') {
             $dcaHelper = new DCAHelper();
             $arrCleanOptions[$arrModule['fieldID']] = $dcaHelper->getOptions($arrModule, $tablename, $wrapperID);
         }
         $arrModules[$arrModule['fieldID']] = $arrModule;
     }
     $qProtectedStr = ' AND published = "1"';
     if (HelperModel::previewMode()) {
         $qProtectedStr = '';
     }
     $itemDB = $this->Database->prepare('SELECT * FROM ' . $tablename . '_data WHERE pid = ? AND (alias = ? OR id = ?) ' . $qProtectedStr . '')->execute($wrapperID, $alias, (int) $alias)->row();
     $wrapperDB = $this->Database->prepare('SELECT * FROM ' . $tablename . ' WHERE id = ?')->execute($wrapperID)->row();
     $strResult = '';
     // overwrite template
     if ($itemDB['auto_detail_template'] && strcmp($itemDB['auto_detail_template'], 'fmodule_full')) {
         $strDetailTemplate = $itemDB['auto_detail_template'];
     }
     $objTemplate = new \FrontendTemplate($strDetailTemplate);
     if (count($itemDB) < 1) {
         $objHandler = new $GLOBALS['TL_PTY']['error_404']();
         $objHandler->generate($objPage->id);
         exit;
     }
     if (HelperModel::sortOutProtected($itemDB, $this->User->groups)) {
         $objHandler = new $GLOBALS['TL_PTY']['error_403']();
         $objHandler->generate($objPage->id);
         exit;
     }
     // image
     $imagePath = $this->generateSingeSrc($itemDB);
     if ($imagePath) {
         $itemDB['singleSRC'] = $imagePath;
     }
     // size
     $imgSize = false;
     // Override the default image size
     if ($this->imgSize != '') {
         $size = deserialize($this->imgSize);
         if ($size[0] > 0 || $size[1] > 0 || is_numeric($size[2])) {
             $imgSize = $this->imgSize;
         }
     }
     if ($imgSize) {
         $itemDB['size'] = $imgSize;
     }
     //set css and id
     $itemDB['cssID'] = deserialize($itemDB['cssID']);
     $itemDB['itemID'] = $itemDB['cssID'][0];
     $itemDB['itemCSS'] = $itemDB['cssID'][1] ? ' ' . $itemDB['cssID'][1] : '';
     $itemDB['cssClass'] = '';
     $objCte = \ContentModel::findPublishedByPidAndTable($itemDB['id'], $tablename . '_data');
     $detail = array();
     $teaser = array();
     if ($objCte !== null) {
         $intCount = 0;
         $intLast = $objCte->count() - 1;
         while ($objCte->next()) {
             $arrCss = array();
             $objRow = $objCte->current();
             if ($intCount == 0 || $intCount == $intLast) {
                 if ($intCount == 0) {
                     $arrCss[] = 'first';
                 }
                 if ($intCount == $intLast) {
                     $arrCss[] = 'last';
                 }
             }
             $objRow->classes = $arrCss;
             if ($objRow->fview == 'list') {
                 $teaser[] = $this->getContentElement($objRow, $this->strColumn);
             } else {
                 $detail[] = $this->getContentElement($objRow, $this->strColumn);
             }
             ++$intCount;
         }
     }
     // seo
     if ($this->fm_overwrite_seoSettings) {
         $descriptionColName = $this->fm_seoDescription ? $this->fm_seoDescription : 'description';
         $pageTitleColName = $this->fm_seoPageTitle ? $this->fm_seoPageTitle : 'title';
         $seoDescription = strip_tags($itemDB[$descriptionColName]);
         $objPage->description = $seoDescription;
         $objPage->pageTitle = $itemDB[$pageTitleColName];
         // set hreflang
         if ($this->fm_seoHrefLang) {
             $strHrefLangAttributes = HelperModel::getHrefAttributes($tablename, $alias, null, $itemDB, $wrapperDB);
             $GLOBALS['TL_HEAD'][] = $strHrefLangAttributes;
         }
     }
     // author
     $authorDB = null;
     if ($itemDB['author']) {
         $authorDB = $this->Database->prepare('SELECT * FROM tl_user WHERE id = ?')->execute($itemDB['author'])->row();
         unset($authorDB['password']);
         unset($authorDB['session']);
     }
     $itemDB['teaser'] = $teaser;
     $itemDB['detail'] = $detail;
     $itemDB['author'] = $authorDB;
     $itemDB['date'] = $itemDB['date'] ? date($objPage->dateFormat, $itemDB['date']) : '';
     $itemDB['time'] = $itemDB['time'] ? date($objPage->timeFormat, $itemDB['time']) : '';
     $itemDB['filter'] = $arrModules;
     if (!empty($fieldWidgets)) {
         $arrayAsValue = array('list.blank', 'list.keyValue', 'table.blank');
         foreach ($fieldWidgets as $widget) {
             $id = $widget['fieldID'];
             $tplName = $widget['widgetTemplate'];
             $type = $widget['widgetType'];
             $value = $itemDB[$id];
             if (in_array($type, $arrayAsValue)) {
                 $value = deserialize($value);
             }
             $objFieldTemplate = new \FrontendTemplate($tplName);
             $objFieldTemplate->setData(array('value' => $value, 'type' => $type, 'item' => $itemDB));
             $itemDB[$id] = $objFieldTemplate->parse();
         }
     }
     // add gallery
     if ($itemDB['addGallery'] && $itemDB['multiSRC']) {
         $objGallery = new GalleryGenerator();
         $objGallery->id = $itemDB['id'];
         $objGallery->sortBy = $itemDB['sortBy'];
         $objGallery->orderSRC = $itemDB['orderSRC'];
         $objGallery->metaIgnore = $itemDB['metaIgnore'];
         $objGallery->numberOfItems = $itemDB['numberOfItems'];
         $objGallery->perPage = $itemDB['perPageGallery'];
         $objGallery->perRow = $itemDB['perRow'];
         $objGallery->size = $itemDB['size'];
         $objGallery->fullsize = $itemDB['fullsize'];
         $objGallery->galleryTpl = $itemDB['galleryTpl'];
         $objGallery->getAllImages($itemDB['multiSRC']);
         $itemDB['gallery'] = $objGallery->renderGallery();
     }
     // create marker path
     if ($itemDB['addMarker'] && $itemDB['markerSRC']) {
         if ($this->markerCache[$itemDB['markerSRC']]) {
             $itemDB['markerSRC'] = $this->markerCache[$itemDB['markerSRC']];
         } else {
             $markerDB = $this->Database->prepare('SELECT * FROM tl_files WHERE uuid = ?')->execute($itemDB['markerSRC']);
             if ($markerDB->count()) {
                 $pathInfo = $markerDB->row()['path'];
                 if ($pathInfo) {
                     $this->markerCache[$itemDB['markerSRC']] = $pathInfo;
                     $itemDB['markerSRC'] = $pathInfo;
                 }
             }
         }
     }
     // map
     if (!empty($mapFields)) {
         foreach ($mapFields as $map) {
             $objMapTemplate = new \FrontendTemplate($map['template']);
             $itemDB['mapSettings'] = $map;
             $objMapTemplate->setData($itemDB);
             $itemDB[$map['fieldID']] = $objMapTemplate->parse();
         }
     }
     // set clean options
     if (!empty($arrCleanOptions)) {
         $itemDB['cleanOptions'] = $arrCleanOptions;
         // overwrite clean options
         foreach ($arrCleanOptions as $fieldID => $options) {
             if ($itemDB[$fieldID] && is_string($itemDB[$fieldID])) {
                 $arrValues = explode(',', $itemDB[$fieldID]);
                 $arrValuesAsString = array();
                 $arrValuesAsArray = array();
                 if (is_array($arrValues)) {
                     foreach ($arrValues as $val) {
                         $arrValuesAsArray[$val] = $options[$val];
                         $arrValuesAsString[] = $options[$val];
                     }
                 }
                 $itemDB[$fieldID . 'AsArray'] = $arrValuesAsArray;
                 $itemDB[$fieldID] = implode(', ', $arrValuesAsString);
             }
         }
     }
     // floating class
     $itemDB['floatClass'] = 'float_' . $itemDB['floating'];
     $objTemplate->setData($itemDB);
     $strTitle = $itemDB['title'];
     //enclosure
     $objTemplate->enclosure = array();
     if ($itemDB['addEnclosure']) {
         $this->addEnclosuresToTemplate($objTemplate, $itemDB);
     }
     //add image
     if ($itemDB['addImage']) {
         $this->addImageToTemplate($objTemplate, array('singleSRC' => $itemDB['singleSRC'], 'title' => $itemDB['imgTitle'], 'alt' => $itemDB['alt'], 'size' => $itemDB['size'], 'fullsize' => $itemDB['fullsize'], 'caption' => $itemDB['caption']));
     }
     $objTemplate->title = $strTitle;
     $objTemplate->addBefore = $itemDB['floatClass'] == 'float_below' ? false : true;
     $strResult .= $objTemplate->parse();
     $this->Template->referer = 'javascript:history.go(-1)';
     $this->Template->back = $GLOBALS['TL_LANG']['MSC']['goBack'];
     $this->Template->result = $strResult;
     //allow comments
     $this->Template->allowComments = $wrapperDB['allowComments'];
     if ($wrapperDB['allowComments']) {
         $this->import('Comments');
         $arrNotifies = array();
         if ($wrapperDB['notify'] != 'notify_author') {
             $arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
         }
         if ($wrapperDB['notify'] != 'notify_admin') {
             if ($authorDB != null && $authorDB['email'] != '') {
                 $arrNotifies[] = $authorDB['email'];
             }
         }
         $objConfig = new \stdClass();
         $objConfig->perPage = $wrapperDB['perPage'];
         $objConfig->order = $wrapperDB['sortOrder'];
         $objConfig->template = $this->com_template;
         $objConfig->requireLogin = $wrapperDB['requireLogin'];
         $objConfig->disableCaptcha = $wrapperDB['disableCaptcha'];
         $objConfig->bbcode = $wrapperDB['bbcode'];
         $objConfig->moderate = $wrapperDB['moderate'];
         $this->Comments->addCommentsToTemplate($this->Template, $objConfig, $tablename . '_data', $itemDB['id'], $arrNotifies);
     }
     // set js files
     if ($this->loadMapScript) {
         $language = $objPage->language ? $objPage->language : 'en';
         $GLOBALS['TL_HEAD']['mapJS'] = DiverseFunction::setMapJs($language);
     }
 }
 function delete_query($studyId, $queryId)
 {
     $this->load->model('QueryModel');
     QueryModel::delete($queryId);
     $this->location('/study/' . $studyId);
 }
 function add_report($studyId)
 {
     $this->assign('study', StudyModel::loadById($studyId));
     $this->assign('models', ModelModel::loadByStudy($studyId));
     $this->assign('scenarios', ScenarioModel::loadByStudy($studyId));
     $this->assign('queries', QueryModel::loadByStudy($studyId));
     $this->load->view('header');
     $this->load->view('add_report');
     $this->load->view('footer');
 }
 /**
  * @AjaxCallable=TRUE
  * @AjaxMethod=POST
  * @AjaxAsync=TRUE
  */
 function run_query()
 {
     $caseId = $this->session->get('caseId');
     $text = filter_input(INPUT_POST, 'text');
     QueryModel::add($caseId, $text);
     $res = QueryModel::run($caseId);
     return $res;
     //        // Retrieve script path
     //        $path = $this->config->get_item('main', 'decimill_path');
     //
     //        $out = NULL;
     //        $res = NULL;
     //
     //        // Execute query
     //        exec('java -jar ' . $path . 'decimill-client.jar -a runQuery -c ' . $caseId, $out, $res);
     //
     //        if ($res === 0) {
     //            return [
     //                'body' => json_decode($out[0])->body,
     //                'isError' => false,
     //                'errCode' => 0
     //            ];
     //        } else {
     //            return [
     //                'body' => json_decode($out[0])->body,
     //                'isError' => true,
     //                'errCode' => $res
     //            ];
     //        }
 }