123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- <?php
- /// @Brief 任务前置条件比较
- ///
- class TaskPreconditionCompare
- {
- private static $instance = null; // 单例
- // @function 获取单例
- //
- // @return TaskPreconditionCompare
- public static function getInstance(){
- if (is_null(self::$instance)) { self::$instance = new TaskPreconditionCompare();}
- return self::$instance;
- }
- // @function 构造
- //
- private function __construct()
- {
- }
- // @function 获取结果
- //
- // @param userDataInfo 用户数据信息<参见UserDataInfo>
- // @param taskPreconditionInfo 任务前置条件信息<参考TaskPreconditionInfo>
- // @return boolean
- 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;
- // todo
- }
- // 任务生理数据前置条件信息比较
- 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;
- // todo
- }
- return false;
- }
- // @function 是否是任务条件信息
- //
- // @param value 值
- // @return boolean
- private function isTaskCondtionInfo($value)
- {
- if ($value instanceof TaskCondtionInfo)
- return true;
- return false;
- }
- // @function 比较
- //
- // @param value1 值1
- // @param value2 值2
- // @return boolean
- 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;
- }
- }
- // @function 是否为空
- //
- // @param value 值
- // @return boolean
- private function isEmpty($value){
- if (!is_null($value) && !empty($value)){
- return true;
- }
- return false;
- }
- }
|