diff --git a/application/Espo/Core/SelectManagers/Base.php b/application/Espo/Core/SelectManagers/Base.php index 614296bb82..de9e598cd2 100644 --- a/application/Espo/Core/SelectManagers/Base.php +++ b/application/Espo/Core/SelectManagers/Base.php @@ -210,8 +210,17 @@ class Base if (!empty($item['value'])) { $methodName = 'apply' . ucfirst($type); - if (method_exists($this, $methodName)) {; - $this->$methodName($item['field'], $item['value'], $result); + if (method_exists($this, $methodName)) { + $attribute = null; + if (isset($item['field'])) { + $attribute = $item['field']; + } + if (isset($item['attribute'])) { + $attribute = $item['attribute']; + } + if ($attribute) { + $this->$methodName($attribute, $item['value'], $result); + } } } } @@ -689,13 +698,20 @@ class Base protected function checkWhere($where) { foreach ($where as $w) { + $attribute = null; if (isset($w['field'])) { + $attribute = $w['field']; + } + if (isset($w['attribute'])) { + $attribute = $w['attribute']; + } + if ($attribute) { if (isset($w['type']) && $w['type'] === 'linkedWith') { - if (in_array($w['field'], $this->getAcl()->getScopeForbiddenFieldList($this->getEntityType()))) { + if (in_array($attribute, $this->getAcl()->getScopeForbiddenFieldList($this->getEntityType()))) { throw new Forbidden(); } } else { - if (in_array($w['field'], $this->getAcl()->getScopeForbiddenAttributeList($this->getEntityType()))) { + if (in_array($attribute, $this->getAcl()->getScopeForbiddenAttributeList($this->getEntityType()))) { throw new Forbidden(); } } @@ -728,7 +744,15 @@ class Base $value = null; $timeZone = 'UTC'; - if (empty($item['field'])) { + $attribute = null; + if (isset($item['field'])) { + $attribute = $item['field']; + } + if (isset($item['attribute'])) { + $attribute = $item['attribute']; + } + + if (!$attribute) { return null; } if (empty($item['type'])) { @@ -741,14 +765,13 @@ class Base $timeZone = $item['timeZone']; } $type = $item['type']; - $field = $item['field']; if (empty($value) && in_array($type, array('on', 'before', 'after'))) { return null; } $where = array(); - $where['field'] = $field; + $where['attribute'] = $attribute; $dt = new \DateTime('now', new \DateTimeZone($timeZone)); @@ -875,8 +898,16 @@ class Base { $part = array(); - if (!empty($item['field']) && !empty($item['type'])) { - $methodName = 'getWherePart' . ucfirst($item['field']) . ucfirst($item['type']); + $attribute = null; + if (!empty($item['field'])) { // for backward compatibility + $attribute = $item['field']; + } + if (!empty($item['attribute'])) { + $attribute = $item['attribute']; + } + + if (!empty($attribute) && !empty($item['type'])) { + $methodName = 'getWherePart' . ucfirst($attribute) . ucfirst($item['type']); if (method_exists($this, $methodName)) { $value = null; if (!empty($item['value'])) { @@ -909,74 +940,74 @@ class Base } break; case 'like': - $part[$item['field'] . '*'] = $item['value']; + $part[$attribute . '*'] = $item['value']; break; case 'equals': case 'on': - $part[$item['field'] . '='] = $item['value']; + $part[$attribute . '='] = $item['value']; break; case 'startsWith': - $part[$item['field'] . '*'] = $item['value'] . '%'; + $part[$attribute . '*'] = $item['value'] . '%'; break; case 'endsWith': - $part[$item['field'] . '*'] = '%' . $item['value']; + $part[$attribute . '*'] = '%' . $item['value']; break; case 'contains': - $part[$item['field'] . '*'] = '%' . $item['value'] . '%'; + $part[$attribute . '*'] = '%' . $item['value'] . '%'; break; case 'notEquals': case 'notOn': - $part[$item['field'] . '!='] = $item['value']; + $part[$attribute . '!='] = $item['value']; break; case 'greaterThan': case 'after': - $part[$item['field'] . '>'] = $item['value']; + $part[$attribute . '>'] = $item['value']; break; case 'lessThan': case 'before': - $part[$item['field'] . '<'] = $item['value']; + $part[$attribute . '<'] = $item['value']; break; case 'greaterThanOrEquals': - $part[$item['field'] . '>='] = $item['value']; + $part[$attribute . '>='] = $item['value']; break; case 'lessThanOrEquals': - $part[$item['field'] . '<'] = $item['value']; + $part[$attribute . '<'] = $item['value']; break; case 'in': - $part[$item['field'] . '='] = $item['value']; + $part[$attribute . '='] = $item['value']; break; case 'notIn': - $part[$item['field'] . '!='] = $item['value']; + $part[$attribute . '!='] = $item['value']; break; case 'isNull': - $part[$item['field'] . '='] = null; + $part[$attribute . '='] = null; break; case 'isNotNull': case 'ever': - $part[$item['field'] . '!='] = null; + $part[$attribute . '!='] = null; break; case 'isTrue': - $part[$item['field'] . '='] = true; + $part[$attribute . '='] = true; break; case 'isFalse': - $part[$item['field'] . '='] = false; + $part[$attribute . '='] = false; break; case 'today': - $part[$item['field'] . '='] = date('Y-m-d'); + $part[$attribute . '='] = date('Y-m-d'); break; case 'past': - $part[$item['field'] . '<'] = date('Y-m-d'); + $part[$attribute . '<'] = date('Y-m-d'); break; case 'future': - $part[$item['field'] . '>='] = date('Y-m-d'); + $part[$attribute . '>='] = date('Y-m-d'); break; case 'lastSevenDays': $dt1 = new \DateTime(); $dt2 = clone $dt1; $dt2->modify('-7 days'); $part['AND'] = array( - $item['field'] . '>=' => $dt2->format('Y-m-d'), - $item['field'] . '<=' => $dt1->format('Y-m-d'), + $attribute . '>=' => $dt2->format('Y-m-d'), + $attribute . '<=' => $dt1->format('Y-m-d'), ); break; case 'lastXDays': @@ -986,8 +1017,8 @@ class Base $dt2->modify('-'.$number.' days'); $part['AND'] = array( - $item['field'] . '>=' => $dt2->format('Y-m-d'), - $item['field'] . '<=' => $dt1->format('Y-m-d'), + $attribute . '>=' => $dt2->format('Y-m-d'), + $attribute . '<=' => $dt1->format('Y-m-d'), ); break; case 'nextXDays': @@ -996,22 +1027,22 @@ class Base $number = strval(intval($item['value'])); $dt2->modify('+'.$number.' days'); $part['AND'] = array( - $item['field'] . '>=' => $dt1->format('Y-m-d'), - $item['field'] . '<=' => $dt2->format('Y-m-d'), + $attribute . '>=' => $dt1->format('Y-m-d'), + $attribute . '<=' => $dt2->format('Y-m-d'), ); break; case 'currentMonth': $dt = new \DateTime(); $part['AND'] = array( - $item['field'] . '>=' => $dt->modify('first day of this month')->format('Y-m-d'), - $item['field'] . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'), + $attribute . '>=' => $dt->modify('first day of this month')->format('Y-m-d'), + $attribute . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'), ); break; case 'lastMonth': $dt = new \DateTime(); $part['AND'] = array( - $item['field'] . '>=' => $dt->modify('first day of last month')->format('Y-m-d'), - $item['field'] . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'), + $attribute . '>=' => $dt->modify('first day of last month')->format('Y-m-d'), + $attribute . '<' => $dt->add(new \DateInterval('P1M'))->format('Y-m-d'), ); break; case 'currentQuarter': @@ -1019,8 +1050,8 @@ class Base $quarter = ceil($dt->format('m') / 3); $dt->modify('first day of January this year'); $part['AND'] = array( - $item['field'] . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'), - $item['field'] . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'), + $attribute . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'), + $attribute . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'), ); break; case 'lastQuarter': @@ -1033,29 +1064,29 @@ class Base $dt->sub('P1Y'); } $part['AND'] = array( - $item['field'] . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'), - $item['field'] . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'), + $attribute . '>=' => $dt->add(new \DateInterval('P'.(($quarter - 1) * 3).'M'))->format('Y-m-d'), + $attribute . '<' => $dt->add(new \DateInterval('P3M'))->format('Y-m-d'), ); break; case 'currentYear': $dt = new \DateTime(); $part['AND'] = array( - $item['field'] . '>=' => $dt->modify('first day of January this year')->format('Y-m-d'), - $item['field'] . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'), + $attribute . '>=' => $dt->modify('first day of January this year')->format('Y-m-d'), + $attribute . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'), ); break; case 'lastYear': $dt = new \DateTime(); $part['AND'] = array( - $item['field'] . '>=' => $dt->modify('first day of January last year')->format('Y-m-d'), - $item['field'] . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'), + $attribute . '>=' => $dt->modify('first day of January last year')->format('Y-m-d'), + $attribute . '<' => $dt->add(new \DateInterval('P1Y'))->format('Y-m-d'), ); break; case 'between': if (is_array($item['value'])) { $part['AND'] = array( - $item['field'] . '>=' => $item['value'][0], - $item['field'] . '<=' => $item['value'][1], + $attribute . '>=' => $item['value'][0], + $attribute . '<=' => $item['value'][1], ); } break; diff --git a/application/Espo/Modules/Crm/SelectManagers/Meeting.php b/application/Espo/Modules/Crm/SelectManagers/Meeting.php index 97f4bc8c92..9722a50bbf 100644 --- a/application/Espo/Modules/Crm/SelectManagers/Meeting.php +++ b/application/Espo/Modules/Crm/SelectManagers/Meeting.php @@ -87,7 +87,7 @@ class Meeting extends \Espo\Core\SelectManagers\Base { $result['whereClause'][] = $this->convertDateTimeWhere(array( 'type' => 'today', - 'field' => 'dateStart', + 'attribute' => 'dateStart', 'timeZone' => $this->getUserTimeZone() )); } diff --git a/application/Espo/Modules/Crm/SelectManagers/Task.php b/application/Espo/Modules/Crm/SelectManagers/Task.php index e62d63398b..0b50bdc894 100644 --- a/application/Espo/Modules/Crm/SelectManagers/Task.php +++ b/application/Espo/Modules/Crm/SelectManagers/Task.php @@ -64,12 +64,12 @@ class Task extends \Espo\Core\SelectManagers\Base 'OR' => array( $this->convertDateTimeWhere(array( 'type' => 'past', - 'field' => 'dateStart', + 'attribute' => 'dateStart', 'timeZone' => $this->getUserTimeZone() )), $this->convertDateTimeWhere(array( 'type' => 'today', - 'field' => 'dateStart', + 'attribute' => 'dateStart', 'timeZone' => $this->getUserTimeZone() )) ) @@ -91,7 +91,7 @@ class Task extends \Espo\Core\SelectManagers\Base $result['whereClause'][] = [ $this->convertDateTimeWhere(array( 'type' => 'past', - 'field' => 'dateEnd', + 'attribute' => 'dateEnd', 'timeZone' => $this->getUserTimeZone() )), [ @@ -106,7 +106,7 @@ class Task extends \Espo\Core\SelectManagers\Base { $result['whereClause'][] = $this->convertDateTimeWhere(array( 'type' => 'today', - 'field' => 'dateEnd', + 'attribute' => 'dateEnd', 'timeZone' => $this->getUserTimeZone() )); } @@ -118,16 +118,22 @@ class Task extends \Espo\Core\SelectManagers\Base if (empty($result)) { return null; } - $field = $item['field']; + $attribute = null; + if (!empty($item['field'])) { // for backward compatibility + $attribute = $item['field']; + } + if (!empty($item['attribute'])) { + $attribute = $item['attribute']; + } - if ($field != 'dateStart' && $field != 'dateEnd') { + if ($attribute != 'dateStart' && $attribute != 'dateEnd') { return $result; } - $fieldDate = $field . 'Date'; + $attributeDate = $attribute . 'Date'; $dateItem = array( - 'field' => $fieldDate, + 'attribute' => $attributeDate, 'type' => $item['type'] ); if (!empty($item['value'])) { @@ -138,7 +144,7 @@ class Task extends \Espo\Core\SelectManagers\Base 'OR' => array( 'AND' => [ $result, - $fieldDate . '=' => null + $attributeDate . '=' => null ], $this->getWherePart($dateItem) ) diff --git a/client/res/templates/fields/date/search.tpl b/client/res/templates/fields/date/search.tpl index c177d5ba0e..d6a7681c08 100644 --- a/client/res/templates/fields/date/search.tpl +++ b/client/res/templates/fields/date/search.tpl @@ -1,6 +1,6 @@