예제 #1
0
 /**
  * Remove the __pk_val from data
  *
  * @return  null
  */
 protected function removePkVal()
 {
     $data = $this->model->getData();
     foreach ($data as $group) {
         foreach ($group as $row) {
             unset($row->__pk_val);
         }
     }
 }
예제 #2
0
파일: form.php 프로젝트: glauberm/cinevi
 /**
  * Get the form's list model
  * (was getTable but that clashed with J1.5 func)
  *
  * @return  FabrikFEModelList  fabrik list model
  */
 public function getListModel()
 {
     if (!isset($this->listModel)) {
         $this->listModel = JModelLegacy::getInstance('List', 'FabrikFEModel');
         $item = $this->getForm();
         $this->listModel->loadFromFormId($item->id);
         $this->listModel->setFormModel($this);
     }
     return $this->listModel;
 }
예제 #3
0
 /**
  * Build the sql query to filter the data
  *
  * @param   object  $params  plugin params
  *
  * @return  string  query's where statement
  */
 protected function getQuery($params)
 {
     $input = $this->app->input;
     $lookUps = $input->get('radius_lookup' . $this->renderOrder, array(), 'array');
     $lookUps = array_filter($lookUps, function ($v) {
         return (string) $v === '1';
     });
     $ids = array_keys($lookUps);
     $ids = ArrayHelper::toInteger($ids);
     $listModel = new FabrikFEModelList();
     $listModel->setId($params->get('radius_lookup_list'));
     $listModel->setLimits(0, -1);
     $key = $listModel->getPrimaryKey();
     $listModel->setPluginQueryWhere('list.radius_lookup', $key . ' IN (' . implode(',', $ids) . ')');
     $data = $listModel->getData();
     $distanceField = $params->get('distance_field') . '_raw';
     $data = $listModel->getData();
     list($latitude, $longitude) = $this->getSearchLatLon();
     if (trim($latitude) === '' && trim($longitude) === '') {
         $input->set('radius_search_active' . $this->renderOrder, array(0));
         return;
     }
     // Need to unset for multiple radius searches to work
     unset($this->mapElement);
     $el = $this->getMapElement();
     $el = FabrikString::safeColName($el->getFullName(false, false));
     // Crazy sql to get the lat/lon from google map element
     $latField = "SUBSTRING_INDEX(TRIM(LEADING '(' FROM {$el}), ',', 1)";
     $lonField = "SUBSTRING_INDEX(SUBSTRING_INDEX({$el}, ',', -1), ')', 1)";
     $query = array();
     $unit = $params->get('radius_lookup_unit', 'km');
     foreach ($data as $group) {
         foreach ($group as $row) {
             $v = $row->{$distanceField};
             if ($unit == 'km') {
                 $query[] = "((((acos(sin((" . $latitude . "*pi()/180)) * sin(({$latField} *pi()/180))+cos((" . $latitude . "*pi()/180)) * cos(({$latField} *pi()/180)) * cos(((" . $longitude . "- {$lonField})*pi()/180))))*180/pi())*60*1.1515*1.609344) <= " . $v . ')';
             } else {
                 $query[] = "((((acos(sin((" . $latitude . "*pi()/180)) * sin(({$latField} *pi()/180))+cos((" . $latitude . "*pi()/180)) * cos(({$latField} *pi()/180)) * cos(((" . $longitude . "- {$lonField})*pi()/180))))*180/pi())*60*1.1515) <= " . $v . ')';
             }
         }
     }
     $query = '(' . implode(' OR ', $query) . ')';
     return $query;
 }
예제 #4
0
파일: list.php 프로젝트: jfquestiaux/fabrik
 /**
  * Alter the db table's collation
  *
  * @param   FabrikFEModelList $feModel       Front end list model
  * @param   string            $origCollation Original collection name
  * @param   JTable            $row           New collation
  *
  * @since   3.0.7
  *
  * @return boolean
  */
 protected function collation($feModel, $origCollation, $row)
 {
     // Don't attempt to alter new table, or a view, or if we shouldn't alter the table
     if ($row->get('id') == 0 || $feModel->isView() || !$feModel->canAlterFields()) {
         return false;
     }
     $params = new Registry($row->get('params'));
     $newCollation = $params->get('collation');
     if ($newCollation !== $origCollation) {
         $db = $feModel->getDb();
         $item = $feModel->getTable();
         $db->setQuery('ALTER TABLE ' . $item->db_table_name . ' COLLATE  ' . $newCollation);
         $db->execute();
     }
     return true;
 }
예제 #5
0
파일: view.csv.php 프로젝트: LGBGit/tierno
 /**
  * Start the download process
  *
  * @param   FabrikFEModelList       $model
  * @param   FabrikFEModelCSVExport  $exporter
  * @param   string                  $key
  *
  * @throws Exception
  */
 protected function download($model, $exporter, $key)
 {
     $input = $this->app->input;
     $input->set('limitstart' . $model->getId(), 0);
     // Remove the total from the session
     $this->session->clear($key);
     $exporter->downloadFile();
 }
예제 #6
0
 /**
  * load up filters stored in the session from previous searches
  *
  * @param   array  &$filters  list filters
  *
  * @return  void
  */
 private function getSessionFilters(&$filters)
 {
     $profiler = JProfiler::getInstance('Application');
     $elements = $this->listModel->getElements('id');
     $identifier = $this->app->input->get('listref', $this->listModel->getRenderContext());
     $key = 'com_' . $this->package . '.list' . $identifier . '.filter';
     $sessionFilters = JArrayHelper::fromObject($this->app->getUserState($key));
     $filterKeys = array_keys($filters);
     if (!is_array($sessionFilters) || !array_key_exists('key', $sessionFilters)) {
         return;
     }
     // If we are coming from a search form ignore session filters
     $fromFormId = $this->getSearchFormId();
     $formModel = $this->listModel->getFormModel();
     if (!is_null($fromFormId) && $fromFormId !== $formModel->getId()) {
         return;
     }
     // End ignore
     $request = $this->getPostFilterArray();
     JDEBUG ? $profiler->mark('listfilter:session filters getPostFilterArray') : null;
     $key = 'com_' . $this->package . '.list' . $identifier . '.filter.searchall';
     $requestKey = $this->getSearchAllRequestKey();
     JDEBUG ? $profiler->mark('listfilter:session filters getSearchAllRequestKey') : null;
     $pluginKeys = $this->getPluginFilterKeys();
     JDEBUG ? $profiler->mark('listfilter:session filters getPluginFilterKeys') : null;
     $search = $this->app->getUserStateFromRequest($key, $requestKey);
     $postKeys = FArrayHelper::getValue($request, 'key', array());
     for ($i = 0; $i < count($sessionFilters['key']); $i++) {
         $elid = FArrayHelper::getValue($sessionFilters['elementid'], $i);
         $key = FArrayHelper::getValue($sessionFilters['key'], $i, null);
         $index = FArrayHelper::getValue($filters['elementid'], $key, false);
         $origCondition = FArrayHelper::getValue($filters['orig_condition'], $i, '');
         // Used by radius search plugin
         $sqlConds = FArrayHelper::getValue($sessionFilters, 'sqlCond', array());
         if ($index !== false) {
             foreach ($filterKeys as $fKey) {
                 if (is_array($filters[$fKey]) && array_key_exists($index, $filters[$fKey])) {
                     /**
                      * $$$rob test1
                      * with the line below uncomment, the unset caused only first filter from query string to work, e..g
                      * &element_test___user[value][0]=aaassss&element_test___user[value][1]=X Administrator&element_test___user[join][1]=OR
                      * converted to:
                      * WHERE `#__users`.`name` REGEXP 'aaassss' OR `#___users`.`name` REGEXP ' X Administrator'
                      *
                      * unset($filters[$fKey][$index]);
                      */
                     $filters[$fKey] = array_values($filters[$fKey]);
                 }
             }
         }
         $value = $sessionFilters['value'][$i];
         $key2 = array_key_exists('key2', $sessionFilters) ? FArrayHelper::getValue($sessionFilters['key2'], $i, '') : '';
         if ($elid == -1) {
             // Search all boolean mode
             $eval = 0;
             $condition = 'AGAINST';
             $origCondition = 'AGAINST';
             $join = 'AND';
             $noFiltersSetup = 0;
             $hidden = 0;
             $search_type = 'searchall';
             $match = 1;
             $fullWordsOnly = 0;
             $required = 0;
             $access = $this->defaultAccessLevel();
             $grouped = 1;
             $label = '';
             /**
              * $$$ rob force the counter to always be the same for extended search all
              * stops issue of multiple search alls being applied
              */
             $counter = 9999;
             $raw = 0;
             $sqlCond = null;
         } else {
             $elementModel = FArrayHelper::getValue($elements, $elid);
             if (!is_a($elementModel, 'plgFabrik_Element') && !in_array($elid, $pluginKeys)) {
                 continue;
             }
             // Check list plugins
             if (in_array($elid, $pluginKeys)) {
                 $condition = $sessionFilters['condition'][$i];
                 $origCondition = $sessionFilters['orig_condition'][$i];
                 $eval = $sessionFilters['eval'][$i];
                 $search_type = $sessionFilters['search_type'][$i];
                 $join = $sessionFilters['join'][$i];
                 $grouped = $sessionFilters['grouped_to_previous'][$i];
                 $noFiltersSetup = $sessionFilters['no-filter-setup'][$i];
                 $hidden = $sessionFilters['hidden'][$i];
                 $match = $sessionFilters['match'][$i];
                 $fullWordsOnly = $sessionFilters['full_words_only'][$i];
                 $required = $sessionFilters['required'][$i];
                 $access = $sessionFilters['access'][$i];
                 $label = $sessionFilters['label'][$i];
                 $sqlCond = FArrayHelper::getValue($sqlConds, $i);
                 $raw = $sessionFilters['raw'][$i];
                 $counter = $elid;
             } else {
                 $sqlCond = null;
                 $condition = array_key_exists($i, $sessionFilters['condition']) ? $sessionFilters['condition'][$i] : $elementModel->getDefaultFilterCondition();
                 $origFound = array_key_exists('orig_condition', $sessionFilters) && array_key_exists($i, $sessionFilters['orig_condition']);
                 $origCondition = $origFound ? $sessionFilters['orig_condition'][$i] : $elementModel->getDefaultFilterCondition();
                 $raw = array_key_exists($i, $sessionFilters['raw']) ? $sessionFilters['raw'][$i] : 0;
                 $eval = array_key_exists($i, $sessionFilters['eval']) ? $sessionFilters['eval'][$i] : FABRIKFILTER_TEXT;
                 if (!is_a($elementModel, 'PlgFabrik_ElementDatabasejoin')) {
                     $fieldDesc = $elementModel->getFieldDescription();
                     if (JString::stristr($fieldDesc, 'INT')) {
                         if (is_numeric($search) && $condition == '=') {
                             $eval = FABRKFILTER_NOQUOTES;
                         }
                     }
                 }
                 /**
                  * add request filter to end of filter array
                  * with advanced search and then page nav this wasn't right
                  */
                 $search_type = array_key_exists($i, $sessionFilters['search_type']) ? $sessionFilters['search_type'][$i] : $elementModel->getDefaultFilterCondition();
                 $join = $sessionFilters['join'][$i];
                 $grouped = array_key_exists($i, $sessionFilters['grouped_to_previous']) ? $sessionFilters['grouped_to_previous'][$i] : 0;
                 $element = $elementModel->getElement();
                 $elParams = $elementModel->getParams();
                 $noFiltersSetup = $element->filter_type == '' ? 1 : 0;
                 $hidden = $element->filter_type == '' ? 1 : 0;
                 $match = $element->filter_exact_match;
                 $fullWordsOnly = $elParams->get('full_words_only');
                 $required = $elParams->get('filter_required');
                 $access = $elParams->get('filter_access');
                 $label = $elementModel->getListHeading();
                 /**
                  * $$$ rob if the session filter is also in the request data then set it to use the same key as the post data
                  * when the post data is processed it should then overwrite these values
                  */
                 $counter = array_search($key, $postKeys) !== false ? array_search($key, $postKeys) : $this->counter;
             }
         }
         /**
          * $$$ hugh - attempting to stop plugin filters getting overwritten
          * PLUGIN FILTER SAGA
          * So ... if this $filter is a pluginfilter, lets NOT overwrite it
          */
         if (array_key_exists('search_type', $filters) && array_key_exists($counter, $filters['search_type']) && $filters['search_type'][$counter] == 'jpluginfilters') {
             continue;
         }
         $filters['value'][$counter] = $value;
         $filters['condition'][$counter] = $condition;
         $filters['join'][$counter] = $join;
         $filters['no-filter-setup'][$counter] = $noFiltersSetup;
         $filters['hidden'][$counter] = $hidden;
         $filters['key'][$counter] = $key;
         $filters['key2'][$counter] = $key2;
         $filters['search_type'][$counter] = $search_type;
         $filters['match'][$counter] = $match;
         $filters['full_words_only'][$counter] = $fullWordsOnly;
         $filters['eval'][$counter] = $eval;
         $filters['required'][$counter] = $required;
         $filters['access'][$counter] = $access;
         $filters['grouped_to_previous'][$counter] = $grouped;
         $filters['label'][$counter] = $label;
         $filters['elementid'][$counter] = $elid;
         $filters['sqlCond'][$counter] = $sqlCond;
         $filters['raw'][$counter] = $raw;
         $filters['orig_condition'][$counter] = $origCondition;
         if (array_search($key, $postKeys) === false) {
             $this->counter++;
         }
     }
 }