Browse Source

[UPDATE] move crits merging to Utils_RecordBrowser_Crits class

experimental
Georgi Hristov 2 years ago
parent
commit
5d7ddad249
2 changed files with 54 additions and 30 deletions
  1. +53
    -8
      modules/Utils/RecordBrowser/Crits.php
  2. +1
    -22
      modules/Utils/RecordBrowser/RecordBrowserCommon_0.php

+ 53
- 8
modules/Utils/RecordBrowser/Crits.php View File

@@ -385,12 +385,11 @@ class Utils_RecordBrowser_Crits extends Utils_RecordBrowser_CritsInterface

public function __construct($crits = null, $or = false)
{
if ($crits) {
if ($crits && !is_bool($crits)) {
if (is_array($crits)) {
$builder = new Utils_RecordBrowser_CritsBuilder();
$crits = $builder->build_single($crits);
$crits = Utils_RecordBrowser_CritsBuilder::create()->build_single($crits);
$this->component_crits = $crits;
} else {
} else {
$this->component_crits[] = $crits;
}
if (count($crits) > 1) {
@@ -511,15 +510,61 @@ class Utils_RecordBrowser_Crits extends Utils_RecordBrowser_CritsInterface
*/
public static function from_array($crits)
{
$builder = new Utils_RecordBrowser_CritsBuilder();
$ret = $builder->build_from_array($crits);
return $ret;
return Utils_RecordBrowser_CritsBuilder::create()->build_from_array($crits);
}
public static function merge($a = array(), $b = array(), $or = false)
{
if (is_array($a)) {
$a = self::from_array($a);
}
if (!($a instanceof self)) {
$a = new self($a);
}
if (is_array($b)) {
$b = self::from_array($b);
}
if (!($b instanceof self)) {
$b = new self($b);
}
if ($a->is_empty()) {
return clone $b;
}
if ($b->is_empty()) {
return clone $a;
}
$a = clone $a;
$b = clone $b;
return $or ? $a->_or($b) : $a->_and($b);
}
public static function and($crits, $_ = null)
{
$ret = [];
foreach (func_get_args() as $crits) {
$ret = self::merge($ret, $crits);
}
return $ret;
}
public static function or($crits, $_ = null)
{
$ret = [];
foreach (func_get_args() as $crits) {
$ret = self::merge($ret, $crits, true);
}
return $ret;
}
}

class Utils_RecordBrowser_CritsBuilder
{

public static function create() {
return new static();
}
public function build_single($crits)
{
$ret = array();


+ 1
- 22
modules/Utils/RecordBrowser/RecordBrowserCommon_0.php View File

@@ -1562,28 +1562,7 @@ class Utils_RecordBrowserCommon extends ModuleCommon {
date('Y-m-d H:i:s')));
}
public static function merge_crits($a = array(), $b = array(), $or=false) {
if (is_array($a)) {
$a = Utils_RecordBrowser_Crits::from_array($a);
}
if (!($a instanceof Utils_RecordBrowser_Crits)) {
$a = new Utils_RecordBrowser_Crits($a);
}
if (is_array($b)) {
$b = Utils_RecordBrowser_Crits::from_array($b);
}
if (!($b instanceof Utils_RecordBrowser_Crits)) {
$b = new Utils_RecordBrowser_Crits($b);
}
if ($a->is_empty()) {
return clone $b;
}
if ($b->is_empty()) {
return clone $a;
}
$a = clone $a;
$b = clone $b;
$ret = $or ? $a->_or($b) : $a->_and($b);
return $ret;
return Utils_RecordBrowser_Crits::merge($a, $b, $or);
}
public static function build_query($tab, $crits = null, $admin = false, $order = array(), $tab_alias = 'r') {
static $stack = array();


Loading…
Cancel
Save