Skip to content

Commit

Permalink
tweak(TB User Filter) fix toArray for json
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmhh committed Mar 13, 2024
1 parent 5ac96cc commit 70ebf7f
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions tine20/Tinebase/Model/Filter/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,16 @@ public function setValue($_value)
if (is_array($_value) && (isset($_value['accountId']) || array_key_exists('accountId', $_value))) {
$_value = $_value['accountId'];
}

if ($this->_userOperator && $this->_userOperator == 'inGroup') {
$this->_userValue = $_value;
$_value = Tinebase_Group::getInstance()->getGroupMembers($this->_userValue);
}


// transform current user
if ($_value == Tinebase_Model_User::CURRENTACCOUNT && is_object(Tinebase_Core::getUser())) {
$_value = Tinebase_Core::getUser()->getId();
$this->_userValue = Tinebase_Model_User::CURRENTACCOUNT;
}

$this->_userValue = $_value;

if ($this->_userOperator && $this->_userOperator == 'inGroup') {
$_value = Tinebase_Group::getInstance()->getGroupMembers($this->_userValue);
}

parent::setValue($_value);
Expand All @@ -97,16 +97,12 @@ public function toArray($_valueToJson = false)
if ($this->_userOperator && $this->_userOperator == 'inGroup') {
$result['operator'] = $this->_userOperator;
$result['value'] = $this->_userValue;
} else if ($this->_userValue === Tinebase_Model_User::CURRENTACCOUNT) {
} elseif ($this->_userValue === Tinebase_Model_User::CURRENTACCOUNT && !$_valueToJson) {
// switch back to CURRENTACCOUNT to make sure filter is saved and shown in client correctly
if ($_valueToJson) {
$this->_value = $result['value'];
} else {
$result['value'] = $this->_userValue;
}
$result['value'] = $this->_userValue;
}

if ($_valueToJson == true ) {
if ($_valueToJson === true ) {
if ($this->_userOperator && $this->_userOperator == 'inGroup' && $this->_userValue) {
try {
$result['value'] = Tinebase_Group::getInstance()->getGroupById($this->_userValue)->toArray();
Expand All @@ -117,18 +113,20 @@ public function toArray($_valueToJson = false)
switch ($this->_operator) {
case 'equals':
try {
$result['value'] = $result['value'] ? Tinebase_User::getInstance()->getUserById($this->_value)->toArray() : $result['value'];
if ($this->_userValue) {
$result['value'] = Tinebase_User::getInstance()->getUserById($this->_userValue)->toArray();
}
} catch (Tinebase_Exception_NotFound) {
$result['value'] = $this->_value;
$result['value'] = $this->_userValue;
}
break;
case 'in':
$result['value'] = array();
if (! is_array($this->_value)) {
if (! is_array($this->_userValue)) {
// somehow the client sent us a scalar - put this into the value array
$result['value'][] = $this->_value;
$result['value'][] = $this->_userValue;
} else {
foreach ($this->_value as $userId) {
foreach ($this->_userValue as $userId) {
try {
$result['value'][] = Tinebase_User::getInstance()->getUserById($userId)->toArray();
} catch(Tinebase_Exception_NotFound) {
Expand All @@ -141,6 +139,10 @@ public function toArray($_valueToJson = false)
break;
}
}
} else {
if ($this->_operator === 'equals' && is_array($result['value']) && count($result['value']) === 1 && isset($result['value'][0])) {
$result['value'] = $result['value'][0];
}
}
return $result;
}
Expand Down

0 comments on commit 70ebf7f

Please sign in to comment.