/** * Used by select2. Automatically takes a value request and converts it into tag/text key value pairs. * New options are just text/tag, whereas existing ones are SelectAttributeOption:ID/text */ public function action_load_autocomplete_selected_value() { $r = \Request::getInstance(); $value = $r->query->get('value'); $values = explode(',', $value); $response = array(); foreach ($values as $value) { $value = trim($value); $o = new \stdClass(); if (strpos($value, 'SelectAttributeOption:') === 0) { $optionID = substr($value, 22); $option = Option::getByID($optionID); if (is_object($option)) { $o->id = $value; $o->text = $option->getSelectAttributeOptionValue(); } } else { $o->id = $value; $o->text = $value; } $response[] = $o; } print json_encode($response); \Core::shutdown(); }
public function saveOrCreate($ak) { if ($this->tempID != false || $this->ID == 0) { return Option::add($ak, $this->value); } else { $db = Loader::db(); $th = Loader::helper('text'); $db->Execute('update atSelectOptions set value = ? where ID = ?', array($th->sanitize($this->value), $this->ID)); return Option::getByID($this->ID); } }
public function searchForm($list) { $options = $this->request('atSelectOptionID'); $db = Database::get(); $tbl = $this->attributeKey->getIndexedSearchTable(); if (!is_array($options)) { return $list; } $optionQuery = array(); foreach ($options as $id) { if ($id > 0) { $opt = Option::getByID($id); if (is_object($opt)) { $optionQuery[] = $opt->getSelectAttributeOptionValue(false); } } } if (count($optionQuery) == 0) { return false; } $i = 0; foreach ($optionQuery as $val) { $val = $db->quote('%||' . $val . '||%'); $multiString .= 'REPLACE(ak_' . $this->attributeKey->getAttributeKeyHandle() . ', "\\n", "||") like ' . $val . ' '; if ($i + 1 < count($optionQuery)) { $multiString .= 'OR '; } $i++; } $list->filter(false, '(' . $multiString . ')'); return $list; }