Created
July 20, 2017 13:43
-
-
Save shabarin/dfe1918f90975dda9eeb11f5b6b00453 to your computer and use it in GitHub Desktop.
umi selector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class catalog_custom extends def_module | |
{ | |
public function mysearch() | |
{ | |
$searchStr = getRequest('search_str'); | |
$pages = new selector_custom('pages'); | |
$pages->types('hierarchy-type')->name('catalog', 'object'); | |
$pages->where('description')->cslike('%'.$searchStr.'%'); | |
$pages->where('photo')->regexp('jpg$'); | |
$items = []; | |
// die ($pages->query()); | |
foreach ($pages->result() as $page) | |
{ | |
$items[] = [ | |
'@id' => $page->getId(), | |
'@name' => $page->getName(), | |
'@photo' => $page->getValue('photo'), | |
'node:value' => $page->getValue('description'), | |
]; | |
} | |
return def_module::parseTemplate(null, [ | |
'subnodes:items' => $items, | |
]); | |
} | |
} | |
class selector_custom extends selector | |
{ | |
protected function createSelectorWhereSysProp($fieldName) | |
{ | |
return new selectorWhereSysProp_custom($fieldName); | |
} | |
protected function createSelectorWhereFieldProp(array $fieldIdList, $searchInRelatedObject = true) | |
{ | |
return new selectorWhereFieldProp_custom($fieldIdList, $searchInRelatedObject); | |
} | |
protected function executor() | |
{ | |
if (!$this->executor) { | |
$this->executor = new selectorExecutor_custom($this); | |
} | |
return $this->executor; | |
} | |
} | |
class selectorWhereSysProp_custom extends selectorWhereSysProp | |
{ | |
public function __construct($name) | |
{ | |
parent::__construct($name); | |
if (!in_array('cslike', $this->modes)) { | |
$this->modes[] = 'cslike'; | |
} | |
if (!in_array('regexp', $this->modes)) { | |
$this->modes[] = 'regexp'; | |
} | |
} | |
} | |
class selectorWhereFieldProp_custom extends selectorWhereFieldProp | |
{ | |
public function __construct(array $fieldIdList, $searchInRelatedObject = true) | |
{ | |
parent::__construct($fieldIdList, $searchInRelatedObject); | |
if (!in_array('cslike', $this->modes)) { | |
$this->modes[] = 'cslike'; | |
} | |
if (!in_array('regexp', $this->modes)) { | |
$this->modes[] = 'regexp'; | |
} | |
} | |
} | |
class selectorExecutor_custom extends selectorExecutor | |
{ | |
protected function parseValue($mode, $value, $column = false, $fieldId = false) | |
{ | |
switch ($mode) { | |
case "cslike": | |
return ' LIKE ' . $this->escapeValue($value) . ' COLLATE utf8_bin'; | |
case "regexp": | |
return ' REGEXP BINARY ' . $this->escapeValue($value); | |
default: | |
return parent::parseValue($mode, $value, $column, $fieldId); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment