/** * make selectbox options tag about search condition * * @param Xcck_DefinitionObject $def * @param int $num * @param Enum[] $conditions list of Xcck_Cond * @param Enum $selected selected condition * * @return string **/ public static function makeCondSelector(Xcck_DefinitionObject $def, $num, $conditions, $selected) { $optionTag = '<option value="%s"%s>%s</option>' . "\n"; $html = sprintf('<select name="%s[%d][1]">', $def->getShow('field_name'), $num); foreach ($conditions as $cond) { $selectedTag = $cond === $selected ? 'selected="selected"' : null; $html .= sprintf($optionTag, $cond, $selectedTag, Xcck_Cond::getString($cond)); } $html .= '</select>'; return $html; }
function smarty_function_xcck_search_form($params, &$smarty) { define('_XCCK_TAG_INPUT', '<input type="text" name="%s[%d][0]" value="%s" size="%d" />' . "\n"); define('_XCCK_TAG_HIDDEN', '<input type="hidden" name="%s[%d][1]" value="%s" />' . "\n"); define('_XCCK_TAG_CHECKBOX', '<input type="checkbox" name="%s" value="1"%s />' . "\n"); define('_XCCK_TAG_DATE', '<input type="text" name="%s[%d][0]" value="%s" size="%d" maxlength="%d" class="%s" />' . "\n"); define('_XCCK_TAG_SELECT', '<select name="%s">%s</select>' . "\n"); define('_XCCK_TAG_OPTION', '<option value="%s"%s>%s</option>' . "\n"); $html = null; //parameters $def = $params['def']; if (!isset($params['condition'])) { $condition = Xcck_Cond::EQ; } elseif ($params['condition'] === '*') { $condition = $params['condition']; } else { $condition = Xcck_Cond::getValue($params['condition']); } $default = isset($params['default']) ? $params['default'] : null; $num = isset($params['num']) ? intval($params['num']) : 0; $option = isset($params['option']) ? $params['option'] : null; //main switch ($def->get('field_type')) { case Xcck_FieldType::STRING: case Xcck_FieldType::TEXT: case Xcck_FieldType::URI: $html .= sprintf(_XCCK_TAG_INPUT, $def->get('field_name'), $num, $default, 20); if ($condition == '*') { $html .= Xcck_Utils::makeCondSelector($def, $num, array(Xcck_Cond::EQ, Xcck_Cond::NE, Xcck_Cond::LIKE)); } else { $html .= sprintf(_XCCK_TAG_HIDDEN, $def->get('field_name'), $num, $condition); } break; case Xcck_FieldType::INT: case Xcck_FieldType::FLOAT: $html .= sprintf(_XCCK_TAG_INPUT, $def->get('field_name'), $num, $default, 5); if ($condition == '*') { $html .= Xcck_Utils::makeCondSelector($def, $num, array(Xcck_Cond::EQ, Xcck_Cond::NE, Xcck_Cond::LT, Xcck_Cond::LE, Xcck_Cond::GT, Xcck_Cond::GE)); } else { $html .= sprintf(_XCCK_TAG_HIDDEN, $def->get('field_name'), $num, $condition); } break; case Xcck_FieldType::DATE: if ($option === 'yyyy') { //input year $html .= sprintf(_XCCK_TAG_DATE, $def->get('field_name'), $num, $default, 10, 4, 'year'); } elseif ($option === 'yyyymm') { //input year-month $html .= sprintf(_XCCK_TAG_DATE, $def->get('field_name'), $num, $default, 10, 7, 'year'); } elseif ($option === 'yyyymmdd') { //input year-month-day $html .= sprintf(_XCCK_TAG_DATE, $def->get('field_name'), $num, $default, 10, 10, 'datepicker'); } elseif (isset($option['yyyy']) || $option['yyyymm']) { //select year $optionHtml = null; $options = isset($option['yyyy']) ? $option['yyyy'] : $option['yyyymm']; $selected = null; foreach (array_keys($options) as $k) { //$k is value $selected = $k == $default ? ' selected="selected"' : null; $optionHtml .= sprintf(_XCCK_TAG_OPTION, $k, $selected, $option[$k]); } $html = sprintf(_XCCK_TAG_SELECT, $def->get('field_name'), $optionHtml); $html .= sprintf(_XCCK_TAG_HIDDEN, $def->get('field_name'), $num, $condition); } if ($condition == '*') { $html .= Xcck_Utils::makeCondSelector($def, $num, array(Xcck_Cond::EQ, Xcck_Cond::LIKE, Xcck_Cond::LE, Xcck_Cond::GE)); } else { $html .= sprintf(_XCCK_TAG_HIDDEN, $def->get('field_name'), $num, $condition); } break; case Xcck_FieldType::CHECKBOX: $checked = isset($default) ? ' checked="checked"' : null; $html = sprintf(_XCCK_TAG_CHECKBOX, $def->get('field_name'), $checked); break; case Xcck_FieldType::SELECTBOX: $optionHtml = null; $options = $def->getOptions(); foreach ($options as $opt) { $selected = $opt == $default ? ' selected="selected"' : null; $optionHtml .= sprintf(_XCCK_TAG_OPTION, $opt, $selected, $opt); } $html = sprintf(_XCCK_TAG_SELECT, $def->get('field_name'), $optionHtml); $html .= sprintf(_XCCK_TAG_HIDDEN, $def->get('field_name'), $num, $condition); break; case Xcck_FieldType::CATEGORY: $tree = null; $category = Xcck_Utils::getAccessController($def->getDirname()); XCube_DelegateUtils::call('Legacy_Category.' . $category->dirname() . '.GetTree', new XCube_Ref($tree)); require_once "function.legacy_category_select.php"; $params = array('tree' => $tree); $html .= smarty_function_legacy_category_select($params, null); $html .= sprintf(_XCCK_TAG_HIDDEN, $def->get('field_name'), $num, $condition); break; } print $html; }
/** * _setRequest * * @param Xcck_DefinitionObject $definition * @param mixed[] $request * * @return void **/ protected function _setRequest(Xcck_DefinitionObject $definition, $request) { if (!isset($request)) { return; } foreach (array_keys($request) as $key) { if (count($request[$key]) !== 2) { continue; } $value = $request[$key][0]; $cond = (int) $request[$key][1]; //Xcck_Cond search condition //set criteria switch ($definition->get('field_type')) { case Xcck_FieldType::STRING: case Xcck_FieldType::TEXT: case Xcck_FieldType::URI: if ($cond === Xcck_Cond::LIKE || $cond === Xcck_Cond::NOTLIKE) { $reqArr = Xcck_SearchUtils::splitKeywords($value); if (count($reqArr) === 0) { continue 2; } $cri = new CriteriaCompo(); foreach ($reqArr as $value) { $cri->add(new Criteria($definition->get('field_name'), Xcck_SearchUtils::makeKeyword($value), Xcck_Cond::getString($cond))); } $this->_mCriteria->add($cri); } else { $this->_mCriteria->add(new Criteria($definition->get('field_name'), $value, Xcck_Cond::getString($cond))); } break; case Xcck_FieldType::DATE: if ($cond === Xcck_Cond::LIKE) { $this->_mCriteria->add(new Criteria($definition->get('field_name'), $this->_makeUnixtime($value, 'start'), Xcck_Cond::getString(Xcck_Cond::GE))); $this->_mCriteria->add(new Criteria($definition->get('field_name'), $this->_makeUnixtime($value, 'end'), Xcck_Cond::getString(Xcck_Cond::LT))); } elseif ($cond === Xcck_Cond::LE) { $this->_mCriteria->add(new Criteria($definition->get('field_name'), $this->_makeUnixtime($value, 'end'), Xcck_Cond::getString(Xcck_Cond::LT))); } else { $this->_mCriteria->add(new Criteria($definition->get('field_name'), $this->_makeUnixtime($value, 'start'), Xcck_Cond::getString($cond))); } break; default: $this->_mCriteria->add(new Criteria($definition->get('field_name'), $value, Xcck_Cond::getString($cond))); break; } //set page navi $this->mNavi->addExtra($definition->get('field_name'), $request); // $this->mNavi->addExtra(sprintf('%s[%d][%d]', $definition->get('field_name'), $key, 1), $request[$key][1]); } }