public function buildDSRetrievalSQL($data, &$joins, &$where, $andOperation = false) { $isArray = is_array($data); // If filter contains expression, return result of its evaluation if (preg_match('/^\\(if\\s/i', $isArray ? $data[0] : $data)) { // Glue $data back if it was split by data source if ($isArray) { $data = implode($andOperation ? '+ ' : ', ', $data); } // Block data source if there was a valid expression and it did not evaluate to true $e = Conditionalizer::parse($data); if (!empty($e) && !Conditionalizer::evaluate($e)) { return false; } // If expression evaluated to true, remove it from data and see if we need to filter entries by our field value if (!empty($e)) { $data = ltrim(str_replace($e[0], '', $data), $andOperation ? '+ ' : ', '); } // Return true if there is nothing left in $data if (empty($data)) { return true; } // Split $data back to array $data = preg_split('/' . ($andOperation ? '\\+' : '(?<!\\\\),') . '\\s*/', $data, -1, PREG_SPLIT_NO_EMPTY); $data = array_map('trim', $data); // Block data source if not all values are either 'yes' or 'no' // If there were wrong parameter values, or invalid expression, this will make data souce blocked "by default" $e = array_diff($data, array('yes', 'no')); if (!empty($e)) { return false; } } // Filtering by expression was disabled, so perform regular filtering by "yes" and/or "no" $field_id = $this->get('id'); if ($isArray) { $data = array($data); } if ($andOperation) { foreach ($data as $value) { $this->_key++; $or = $value == 'yes' ? " OR t{$field_id}_{$this->_key}.value IS NULL " : ''; $value = $this->cleanValue($value); $joins .= " LEFT JOIN `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key} ON (e.id = t{$field_id}_{$this->_key}.entry_id) "; $where .= " AND (t{$field_id}_{$this->_key}.value = '{$value}'{$or}) "; } } else { $this->_key++; $or = in_array('yes', $data) ? " OR t{$field_id}_{$this->_key}.value IS NULL " : ''; $data = implode("', '", array_map(array($this, 'cleanValue'), $data)); $joins .= " LEFT JOIN `tbl_entries_data_{$field_id}` AS t{$field_id}_{$this->_key} ON (e.id = t{$field_id}_{$this->_key}.entry_id) "; $where .= " AND (t{$field_id}_{$this->_key}.value IN ('{$data}'){$or}) "; } return true; }
public function conditionalize(&$context) { /* 'datasource' => $ds, 'xml' => &$xml, 'param_pool' => &$this->_env['pool'] */ if (empty($context) || !isset($context['datasource']) || !isset($context['datasource']->dsParamConditionalizer) || empty($context['datasource']->dsParamConditionalizer)) { return; } if (!class_exists('Conditionalizer')) { require_once EXTENSIONS . '/conditionalizer/lib/class.conditionalizer.php'; } $data = $context['datasource']->__processParametersInString($context['datasource']->dsParamConditionalizer, array('env' => Frontend::Page()->Env(), 'param' => Frontend::Page()->Params())); $e = Conditionalizer::parse($data); if (!empty($e) && !Conditionalizer::evaluate($e)) { $context['xml'] = new XMLElement($context['datasource']->dsParamROOTELEMENT, '<error>' . __('Condition not met.') . '</error>'); } }