此方法用于选择用户和目标用户之间的操作数,例如仅在两个用户之间。此方法的结果值取决于GetTotalOfPossibleActions()
动态的返回值(每个用户都有自己的编号)。
问题:将值计算从 SQL 移到 PHP 层会更好吗?
public function GetAction() {
// ...
$MaxActionCount = $this->GetTotalOfPossibleActions();
return registry::getInstance()->get('DB')->select(
'SELECT
`Action`
, `HA`.`Id` AS `ActionId`
, IF(`Count` IS NULL
, IF('.$MaxActionCount.' % 2
, IF(`HA`.`Id` = 1
, CEIL('.$MaxActionCount.' / 2)
, FLOOR('.$MaxActionCount.' / 2))
, '.$MaxActionCount.' / 2)
, GREATEST(IF('.$MaxActionCount.' % 2
, IF(`HA`.`Id` = 1
, CEIL('.$MaxActionCount.' / 2) - CONVERT(`H`.`Count`, SIGNED)
, FLOOR('.$MaxActionCount.' / 2) - CONVERT(`H`.`Count`, SIGNED))
, '.$MaxActionCount.' / 2 - `H`.`Count`), 0)
) AS `CountLeft`
FROM `Help` AS `H`
RIGHT JOIN `HelpAction` AS `HA`
ON `H`.`ActionId` = `HA`.`Id`
AND `UserId` = '.$this->UserId.'
AND `TargetUserId` = '.$this->TargetUserId.'
AND `CreatedDate` = CURDATE()'));
}