123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- class TaskPreconditionCompare
- {
- private static $instance = null;
-
-
-
- public static function getInstance(){
- if (is_null(self::$instance)) { self::$instance = new TaskPreconditionCompare();}
- return self::$instance;
- }
-
-
- private function __construct()
- {
- }
-
-
-
-
-
- public function getResult($userTaskInfo,
- $taskPreconditionInfo){
-
- if (!is_null($userTaskInfo ->baseInfo)){
- if ($this ->compare($taskPreconditionInfo ->age,
- $userTaskInfo ->baseInfo ->age))
- return true;
- if ($this ->compare($taskPreconditionInfo ->sex,
- $userTaskInfo ->baseInfo ->sex))
- return true;
- if ($this ->compare($taskPreconditionInfo ->time,
- $userTaskInfo ->baseInfo ->time))
- return true;
- if ($this ->compare($taskPreconditionInfo ->ulevel,
- $userTaskInfo ->baseInfo ->ulevel))
- return true;
- if ($this ->compare($taskPreconditionInfo ->place,
- $userTaskInfo ->baseInfo ->place))
- return true;
- if ($this ->compare($taskPreconditionInfo ->weather,
- $userTaskInfo ->baseInfo ->weather))
- return true;
-
- }
-
- if (!is_null($userTaskInfo ->taskPhysicalDataPInfo)){
- if ($this ->compare($taskPreconditionInfo ->isLikeSports,
- $userTaskInfo ->baseInfo ->isLikeSports))
- return true;
- if ($this ->compare($taskPreconditionInfo ->isHypertension,
- $userTaskInfo ->baseInfo ->isHypertension))
- return true;
- if ($this ->compare($taskPreconditionInfo ->isHeartAttack,
- $userTaskInfo ->baseInfo ->isHeartAttack))
- return true;
- if ($this ->compare($taskPreconditionInfo ->isAgile,
- $userTaskInfo ->baseInfo ->isAgile))
- return true;
- if ($this ->compare($taskPreconditionInfo ->isHardBody,
- $userTaskInfo ->baseInfo ->isHardBody))
- return true;
-
- }
- return false;
- }
-
-
-
-
- private function isTaskCondtionInfo($value)
- {
- if ($value instanceof TaskCondtionInfo)
- return true;
- return false;
- }
-
-
-
-
-
- private function compare($value1,$value2)
- {
- if (true == $this ->isTaskCondtionInfo($value1))
- {
- if (true == $this ->isEmpty($value1 ->equalValue)){
- return $value2 == $value1 ->equalValue;
- }
- if (true == $this ->isEmpty($value1 ->minValue)
- && true == $this ->isEmpty($value1 ->maxValue)){
- return ($value2 > $value1 ->minValue && $value2 <= $value1 ->maxValue);
- }
- if (true == $this ->isEmpty($value1 ->minValue)){
- return $value2 >= $value1 ->minValue;
- }
- if (true == $this ->isEmpty($value1 ->maxValue)){
- return $value2 <= $value1 ->maxValue;
- }
- }else
- {
- return $value1 == $value2;
- }
- }
-
-
-
-
- private function isEmpty($value){
- if (!is_null($value) && !empty($value)){
- return true;
- }
- return false;
- }
- }
|