protected function fetchFilterPresets()
{
global $DB;
$arActiveStatuses = [
MetaStatus::UNSEEN,
MetaStatus::EXPIRED,
Status::NEW,
Status::PENDING,
Status::IN_PROGRESS,
];
if ( ! $this->bGroupMode )
{
// Init list with predefined presets
$arPresets = array(
self::ROOT_PRESET => array(
'Name' => '/',
'Parent' => null, // This preset doesn't have parent
'Condition' => null // This preset doesn't have condition
),
self::STD_PRESET_ACTIVE_MY_TASKS => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ACTIVE_MY_TASKS'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'MEMBER' => $this->userId,
'::SUBFILTER-1' => array(
'::LOGIC' => 'OR',
'STATUS' => $arActiveStatuses,
'::SUBFILTER-1' => array(
'::LOGIC' => 'AND',
'CREATED_BY' => $this->userId,
'STATUS' => [Status::DECLINED, Status::SUPPOSEDLY_COMPLETED]
)
)
)
),
'SQL: select count' =>
"SELECT COUNT(TT.ID) AS CNT
FROM (
SELECT T.ID
FROM b_tasks T
INNER JOIN b_tasks_member TM on TM.TASK_ID = T.ID
WHERE T.CREATED_BY = $this->userId
AND T.RESPONSIBLE_ID != $this->userId
AND TM.USER_ID = $this->userId
AND T.STATUS != 4
AND T.STATUS != 5
UNION
SELECT T.ID
FROM b_tasks T
INNER JOIN b_tasks_member TM on TM.TASK_ID = T.ID
WHERE T.RESPONSIBLE_ID = $this->userId
AND TM.USER_ID = $this->userId
AND T.STATUS != 4
AND T.STATUS != 5
UNION
SELECT T.ID
FROM b_tasks T
WHERE T.CREATED_BY = $this->userId
AND (T.STATUS = 4 OR T.STATUS = 5)
) AS TT
"
),
self::STD_PRESET_ACTIVE_I_AM_DOER => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ACTIVE_I_AM_DOER'),
'Parent' => self::STD_PRESET_ACTIVE_MY_TASKS, // 'My tasks' is the parent of this filter preset
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'DOER' => $this->userId,
'::SUBFILTER-1' => array(
'::LOGIC' => 'OR',
'STATUS' => $arActiveStatuses,
'::SUBFILTER-1' => [
'::LOGIC' => 'AND',
'CREATED_BY' => $this->userId,
'STATUS' => Status::DECLINED,
],
)
)
)
),
self::STD_PRESET_ACTIVE_I_AM_RESPONSIBLE => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ACTIVE_I_AM_RESPONSIBLE'),
'Parent' => self::STD_PRESET_ACTIVE_I_AM_DOER, // 'I_AM_DOER' is the parent of this filter preset
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'RESPONSIBLE_ID' => $this->userId,
'::SUBFILTER-1' => array(
'::LOGIC' => 'OR',
'STATUS' => $arActiveStatuses,
'::SUBFILTER-1' => [
'::LOGIC' => 'AND',
'CREATED_BY' => $this->userId,
'STATUS' => Status::DECLINED,
],
)
)
)
),
self::STD_PRESET_ACTIVE_I_AM_ACCOMPLICE => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ACTIVE_I_AM_ACCOMPLICE'),
'Parent' => self::STD_PRESET_ACTIVE_I_AM_DOER, // 'I_AM_DOER' is the parent of this filter preset
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'ACCOMPLICE' => $this->userId,
'::SUBFILTER-1' => array(
'::LOGIC' => 'OR',
'STATUS' => $arActiveStatuses,
'::SUBFILTER-1' => [
'::LOGIC' => 'AND',
'CREATED_BY' => $this->userId,
'STATUS' => Status::DECLINED,
],
)
)
)
),
self::STD_PRESET_ACTIVE_I_AM_ORIGINATOR => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ACTIVE_I_AM_ORIGINATOR'),
'Parent' => self::STD_PRESET_ACTIVE_MY_TASKS, // 'My tasks' is the parent of this filter preset
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'CREATED_BY' => $this->userId,
'::SUBFILTER-1' => array(
'::LOGIC' => 'OR',
'STATUS' => $arActiveStatuses,
'::SUBFILTER-1' => [
'::LOGIC' => 'AND',
'CREATED_BY' => $this->userId,
'STATUS' => [Status::DECLINED, Status::SUPPOSEDLY_COMPLETED],
],
)
)
)
),
self::STD_PRESET_ACTIVE_I_AM_AUDITOR => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ACTIVE_I_AM_AUDITOR'),
'Parent' => self::STD_PRESET_ACTIVE_MY_TASKS, // 'My tasks' is the parent of this filter preset
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'AUDITOR' => $this->userId,
'::SUBFILTER-1' => array(
'::LOGIC' => 'OR',
'STATUS' => $arActiveStatuses,
'::SUBFILTER-1' => [
'::LOGIC' => 'AND',
'CREATED_BY' => $this->userId,
'STATUS' => Status::DECLINED,
],
)
)
)
),
self::STD_PRESET_EXPIRED => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_EXPIRED'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'MEMBER' => $this->userId,
'STATUS' => MetaStatus::EXPIRED,
)
)
),
self::STD_PRESET_EXPIRED_SOON => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_EXPIRED_SOON'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'MEMBER' => $this->userId,
'STATUS' => MetaStatus::EXPIRED_SOON,
)
)
),
self::STD_PRESET_DEFERRED_MY_TASKS => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_DEFERRED_MY_TASKS'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'MEMBER' => $this->userId,
'STATUS' => Status::DEFERRED
)
)
),
self::STD_PRESET_COMPLETED_MY_TASKS => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_COMPLETED_MY_TASKS'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'MEMBER' => $this->userId,
'STATUS' => [
Status::SUPPOSEDLY_COMPLETED,
Status::COMPLETED,
],
)
)
),
self::STD_PRESET_ALL_MY_TASKS => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ALL_MY_TASKS'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'MEMBER' => $this->userId
)
)
)
);
}
else
{
// Init list with predefined presets
$arPresets = array(
self::ROOT_PRESET => array(
'Name' => '/',
'Parent' => null, // This preset doesn't have parent
'Condition' => null // This preset doesn't have condition
),
self::STD_PRESET_ACTIVE_MY_TASKS => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ACTIVE_GROUP_TASKS'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'::SUBFILTER-1' => array(
'::LOGIC' => 'OR',
'STATUS' => $arActiveStatuses,
'::SUBFILTER-1' => [
'::LOGIC' => 'AND',
'CREATED_BY' => $this->userId,
'STATUS' => Status::DECLINED,
],
)
)
)
),
self::STD_PRESET_EXPIRED => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_EXPIRED'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'MEMBER' => $this->userId,
'STATUS' => MetaStatus::EXPIRED,
)
)
),
self::STD_PRESET_EXPIRED_SOON => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_EXPIRED_SOON'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'MEMBER' => $this->userId,
'STATUS' => MetaStatus::EXPIRED_SOON,
)
)
),
self::STD_PRESET_DEFERRED_MY_TASKS => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_DEFERRED_MY_TASKS'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'STATUS' => Status::DEFERRED
)
)
),
self::STD_PRESET_COMPLETED_MY_TASKS => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_COMPLETED_MY_TASKS'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND',
'STATUS' => [
Status::SUPPOSEDLY_COMPLETED,
Status::COMPLETED,
],
)
)
),
self::STD_PRESET_ALL_MY_TASKS => array(
'Name' => GetMessage('TASKS_FILTER_PRESET_STD_PRESET_ALL_MY_TASKS'),
'Parent' => self::ROOT_PRESET,
'Condition' => serialize(
array(
'::LOGIC' => 'AND'
)
)
)
);
}
$arPresets[self::SPEC_PRESET_FAVORITE_TASKS] = array(
'Name' => GetMessage('TASKS_FILTER_PRESET_SPEC_PRESET_FAVORITE_TASKS'),
// commented out to prevent from figuring in tree list
//'Parent' => self::ROOT_PRESET,
'Code' => 'FAVORITE',
'Condition' => serialize(
array_merge(
array(
'::LOGIC' => 'AND',
'=FAVORITE' => 'Y',
),
(
! $this->bGroupMode
?
array('MEMBER' => $this->userId)
:
array()
)
)
)
);
$arPresetsFromDb = array();
$bNeedFetchFromDatabase = true;
$cacheDir = $obCache = null;
if (defined('BX_COMP_MANAGED_CACHE'))
{
$obCache = new CPHPCache();
$lifeTime = CTasksTools::CACHE_TTL_UNLIM;
$cacheDir = '/tasks/filter_presets/' . ($this->loggedInUserId % 300);
$cacheId = 'tasks_filters_presets_' . $this->loggedInUserId;
if ($obCache->InitCache($lifeTime, $cacheId, $cacheDir))
{
$arPresetsFromDb = $obCache->GetVars();
$bNeedFetchFromDatabase = false;
}
}
if ($bNeedFetchFromDatabase)
{
$dbRes = $DB->query(
"SELECT ID, NAME, PARENT, SERIALIZED_FILTER
FROM b_tasks_filters
WHERE USER_ID = " . (int) $this->loggedInUserId . "
ORDER BY NAME, ID"
);
if ($dbRes)
{
while ($arData = $dbRes->fetch())
{
$arPresetsFromDb[(int)$arData['ID']] = array(
'Name' => $arData['NAME'],
'Parent' => (int) $arData['PARENT'],
'Condition' => $arData['SERIALIZED_FILTER']
);
}
}
else
CTaskAssert::log('DB error', CTaskAssert::ELL_ERROR, true);
if (defined('BX_COMP_MANAGED_CACHE') && $obCache->StartDataCache())
{
global $CACHE_MANAGER;
$CACHE_MANAGER->StartTagCache($cacheDir);
$CACHE_MANAGER->RegisterTag('tasks_filters_presets_' . $this->loggedInUserId);
$CACHE_MANAGER->EndTagCache();
$obCache->EndDataCache($arPresetsFromDb);
}
}
// Merge with predefined presets list
foreach ($arPresetsFromDb as $presetId => $presetData)
$arPresets[$presetId] = $presetData;
return ($arPresets);
}