Example #1
0
 /**
  * 开启一个任务
  *
  * @param int $id
  * @param int $status 开启1或是关闭0
  * @param int $order 顺序
  * @param string $title 标题
  * @return PwError|boolean
  */
 public function openTask($id, $status, $order = '', $title = '')
 {
     $task = $this->_taskDs()->get($id);
     if (!$task) {
         return new PwError('TASK:id.illegal');
     }
     $taskDm = new PwTaskDm();
     $reward = unserialize($task['reward']);
     $taskDm->setTaskId($id)->setTitle($title)->setViewOrder($order)->setIsOpen($status)->setEndTime($task['end_time'])->setIsAuto($task['is_auto'])->setIsDisplayAll($task['is_display_all'])->setUserGroups(explode(',', $task['user_groups']))->setReward($reward);
     PwTaskDmFactory::addRewardDecoration($taskDm, $reward);
     return $this->_taskDs()->updateTask($taskDm);
 }
 /**
  * 设置dm
  *
  * @return PwTaskDm
  */
 private function setDm($id)
 {
     $condition = $this->getInput('condition');
     $dm = PwTaskDmFactory::getInstance($condition['type'], $condition['child']);
     PwTaskDmFactory::addRewardDecoration($dm, $this->getInput('reward'));
     $icon = $this->saveIcon();
     $user_groups = $this->getInput('user_groups');
     $is_display_all = $this->getInput('is_display_all');
     /*如果全选用户组,则设置该用户组为-1*/
     /* @var $userGroup PwUserGroups */
     $userGroup = Wekit::load('usergroup.PwUserGroups');
     $groups = $userGroup->getAllGroups();
     if (!$user_groups || !array_diff(array_keys($groups), $user_groups)) {
         $user_groups = array(-1);
     }
     $startTime = $this->getInput('start_time');
     $endTime = $this->getInput('end_time');
     $dm->setTaskId($id)->setTitle($this->getInput('title'))->setDescription($this->getInput('description'))->setIcon($icon)->setStartTime($startTime ? Pw::str2time($startTime) : 0)->setEndTime($endTime ? Pw::str2time($endTime . ' 23:59:59') : PwTaskDm::MAXENDTIME)->setPeriod($this->getInput('period'))->setPreTask($this->getInput('pre_task'))->setUserGroups($user_groups)->setIsAuto($this->getInput('is_auto'))->setIsDisplayAll($is_display_all)->setConditions($condition);
     return $dm;
 }