/** * 格式化周期任务参数 * * @param array $params * @param string $suffix * @return array */ public function formatParams($params, $suffix = '') { $cycle = array(); if (!empty($params['cycleid' . $suffix])) { $cycle['cycleid'] = $params['cycleid' . $suffix]; } else { $cycle['cycleid'] = Dao_Td_Tudu_Cycle::getCycleId(); } $cycle['mode'] = $params['mode' . $suffix]; $cycle['endtype'] = $params['endtype' . $suffix]; $cycle['displaydate'] = $params['displaydate' . $suffix]; // 重复范围 if ($cycle['endtype'] == Dao_Td_Tudu_Cycle::END_TYPE_COUNT) { $cycle['endcount'] = (int) $params['endcount' . $suffix]; } elseif ($cycle['endtype'] == Dao_Td_Tudu_Cycle::END_TYPE_DATE) { $cycle['enddate'] = @strtotime($params['enddate' . $suffix]); } else { $cycle['endtype'] = Dao_Td_Tudu_Cycle::END_TYPE_NONE; } if ($cycle['displaydate'] == 1 && empty($params['starttime' . $suffix])) { $params['starttime'] = time(); } $cycle['type'] = (int) $params['type' . '-' . $cycle['mode'] . $suffix]; $prefix = $cycle['mode' . $suffix] . '-' . $cycle['type' . $suffix] . '-'; $cycle['day'] = isset($params[$prefix . 'day' . $suffix]) ? (int) $params[$prefix . 'day' . $suffix] : 0; $cycle['week'] = isset($params[$prefix . 'week' . $suffix]) ? (int) $params[$prefix . 'week' . $suffix] : 0; $cycle['month'] = isset($params[$prefix . 'month' . $suffix]) ? (int) $params[$prefix . 'month' . $suffix] : 0; $cycle['iskeepattach'] = !empty($params['iskeepattach' . $suffix]) ? 1 : 0; if (isset($params[$prefix . 'weeks'])) { $cycle['weeks'] = implode(',', $params[$prefix . 'weeks' . $suffix]); } if (isset($params[$prefix . 'at'])) { $cycle['at'] = (int) $params[$prefix . 'at' . $suffix]; } if (isset($params[$prefix . 'what'])) { $cycle['what'] = $params[$prefix . 'what' . $suffix]; } if (!empty($params['starttime' . $suffix]) && !empty($params['endtime' . $suffix])) { $cycle['period'] = Oray_Function::dateDiff('d', strtotime($params['starttime' . $suffix]), strtotime($params['endtime' . $suffix])); } return $cycle; }
/** * 更新图度 * * @param string $tuduId * @param array $params * @return boolean */ public function updateTudu($tuduId, array $params) { if (!empty($params['vote'])) { $params['special'] = Dao_Td_Tudu_Tudu::SPECIAL_VOTE; $params['vote']['tuduid'] = $tuduId; } // 处理周期任务 if (!empty($params['cycle'])) { $params['special'] = Dao_Td_Tudu_Tudu::SPECIAL_CYCLE; $daoCycle = new Dao_Td_Tudu_Cycle($this->_db); $cycleId = isset($params['cycle']['cycleid']) ? $params['cycle']['cycleid'] : null; if (!$cycleId) { $cycleId = Dao_Td_Tudu_Cycle::getCycleId(); $params['cycle']['cycleid'] = $cycleId; if (!$daoCycle->createCycle($params['cycle'])) { return false; } } else { $daoCycle->updateCycle($cycleId, $params['cycle']); } $params['cycleid'] = $cycleId; } if (!empty($params['meeting'])) { $params['meeting']['tuduid'] = $tuduId; $this->updateMeeting($params['meeting']); } if (!$this->_tuduDao->updateTudu($tuduId, $params)) { return false; } if (!empty($params['vote'])) { $params['vote']['tuduid'] = $tuduId; $this->updateVote($params['vote']); } return true; }
/** * * @param array $params * @param string $suffix */ private function _getCycleParams(array $params, $suffix = '') { $keys = array('cycleid' => array('type' => 'string'), 'mode' => array('type' => 'string'), 'endtype' => array('type' => 'int'), 'displaydate' => array('type' => 'boolean'), 'starttime' => array('type' => 'date'), 'keepattach' => array('type' => 'boolean'), 'type' => array('type' => 'int', 'key' => 'type-%mode'), 'day' => array('type' => 'int', 'key' => '%mode-%type-day'), 'week' => array('type' => 'int', 'key' => '%mode-%type-week'), 'month' => array('type' => 'int', 'key' => '%mode-%type-month')); $ret = array('mode' => 'day', 'type' => 1); foreach ($keys as $col => $item) { $key = isset($item['key']) ? str_replace(array('%mode', '%type'), array($ret['mode'], $ret['type']), $item['key']) : $col . $suffix; $val = isset($params[$key]) ? $params[$key] : null; switch ($item['type']) { case 'int': $ret[$col] = (int) $val; break; case 'date': $ret[$col] = is_numeric($val) ? (int) $val : strtotime($val); break; case 'boolean': $ret[$col] = (bool) $val; break; case 'string': default: $ret[$col] = trim($val); break; } } if (Dao_Td_Tudu_Cycle::END_TYPE_COUNT == $params['endtype']) { $ret['endcount'] = !empty($params['endcount' . $suffix]) ? $params['endcount' . $suffix] : 1; } if (Dao_Td_Tudu_Cycle::END_TYPE_DATE == $params['endtype']) { $ret['enddate'] = !empty($params['enddate' . $suffix]) ? $params['enddate' . $suffix] : strtotime(date('Y-m-d')); } if (empty($ret['cycleid'])) { $ret['cycleid'] = Dao_Td_Tudu_Cycle::getCycleId(); } $prefix = $ret['mode'] . '-' . $ret['type'] . '-'; if (isset($params[$prefix . 'weeks'])) { $ret['weeks'] = implode(',', $params[$prefix . 'weeks' . $suffix]); } if (isset($params[$prefix . 'at'])) { $ret['at'] = (int) $params[$prefix . 'at' . $suffix]; } if (isset($params[$prefix . 'what'])) { $ret['what'] = $params[$prefix . 'what' . $suffix]; } if (!empty($params['starttime' . $suffix]) && !empty($params['endtime' . $suffix])) { $ret['period'] = Oray_Function::dateDiff('d', strtotime($params['starttime' . $suffix]), strtotime($params['endtime' . $suffix])); } return $ret; }