/** * Constructor * * @param array $record */ public function __construct(array $record) { $this->ruleId = $record['ruleid']; $this->week = $this->_toInt($record['week']); $this->status = $this->_toBoolean($record['status']); $this->checkinTime = explode(':', Dao_App_Attend_Schedule::formatTime($record['checkintime'])); $this->checkoutTime = explode(':', Dao_App_Attend_Schedule::formatTime($record['checkouttime'])); parent::__construct(); }
/** * Constructor * * @param array $record */ public function __construct(array $record) { $this->orgId = $record['orgid']; $this->uniqueId = $record['uniqueid']; $this->scheduleId = $record['scheduleid']; $this->name = $record['name']; $this->isSystem = $this->_toBoolean($record['issystem']); $this->bgcolor = isset($record['bgcolor']) ? $record['bgcolor'] : null; $this->ruleId = isset($record['ruleid']) ? $record['ruleid'] : null; $this->week = isset($record['week']) ? $this->_toInt($record['week']) : null; $this->checkinTime = Dao_App_Attend_Schedule::formatTime($record['checkintime']); $this->checkoutTime = Dao_App_Attend_Schedule::formatTime($record['checkouttime']); $this->lateStandard = $this->_toInt($record['latestandard']); $this->lateCheckin = $this->_toInt($record['latecheckin']); $this->leaveCheckout = $this->_toInt($record['leavecheckout']); $this->status = isset($record['status']) ? $this->_toBoolean($record['status']) : null; $this->createTime = $this->_toTimestamp($record['createtime']); if (null !== $record['checkouttime'] && null !== $record['checkintime']) { $workTime = (int) $record['checkouttime'] - (int) $record['checkintime']; } else { $workTime = 0; } $this->workTime = Dao_App_Attend_Schedule::formatTime($workTime, true); parent::__construct(); }
/** * 初始化应用环境 */ public function initAction() { $daoApp = Tudu_Dao_Manager::getDao('Dao_App_App_App', Tudu_Dao_Manager::DB_APP); $app = $daoApp->getApp(array('orgid' => $this->_user->orgId, 'appid' => $this->_appId)); if ($app->status != 0) { return $this->json(true, '应用初始化成功'); } $ts = time(); // 创建考勤版块 $daoBoard = Tudu_Dao_Manager::getDao('Dao_Td_Board_Board', Tudu_Dao_Manager::DB_TS); $attendBoard = $daoBoard->existsBoard($this->_user->orgId, '^app-attend'); if (!$attendBoard) { $daoBoard->createBoard(array('orgid' => $this->_user->orgId, 'boardid' => '^app-attend', 'boardname' => 'attend', 'type' => 'system', 'status' => 1)); // 创建考勤版块的考勤分类 /* @var $daoClass Dao_Td_Tudu_Class */ $daoClass = Tudu_Dao_Manager::getDao('Dao_Td_Tudu_Class', Tudu_Dao_Manager::DB_TS); $classes = $daoClass->getClassesByBoardId($this->_user->orgId, '^app-attend')->toArray('classid'); if (empty($classes) || empty($classes['^attend'])) { $daoClass->createClass(array('orgid' => $this->_user->orgId, 'boardid' => '^app-attend', 'classid' => '^attend', 'classname' => '考勤')); } } // 考勤分类 $daoCategory = Tudu_Dao_Manager::getDao('Dao_App_Attend_Category', Tudu_Dao_Manager::DB_APP); foreach ($this->_defaultCategories as $id => $item) { // 默认考勤分类的审批流程 $flowId = Dao_App_Attend_Category::getFlowId(); $stepId = Dao_App_Attend_Category::getStepId(); $steps = <<<STEPS <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE flow PUBLIC "-//TUDU//DTD FLOW//ZH-CN" "http://www.tudu.com/dtd/tudu-flow.dtd"> <flow id="{$flowId}"><steps><step id="{$stepId}"><type>0</type><users><![CDATA[^upper]]></users><next>^end</next></step></steps></flow> STEPS; /*$steps = array(array( 'stepid' => $stepId, 'type' => 0, 'next' => '^end', 'sections' => '^upper' ));*/ $daoCategory->createCategory(array('categoryid' => $id, 'orgid' => $this->_user->orgId, 'categoryname' => $item['name'], 'flowsteps' => $steps, 'issystem' => 1, 'status' => 1, 'isshow' => 1, 'createtime' => $ts)); } // 创建默认排班规则 // 默认 $daoSchedule = Tudu_Dao_Manager::getDao('Dao_App_Attend_Schedule', Tudu_Dao_Manager::DB_APP); $daoSchedule->createSchedule(array('orgid' => $this->_user->orgId, 'scheduleid' => '^default', 'name' => '默认班', 'uniqueid' => '^system', 'issystem' => 1, 'bgcolor' => '#800000', 'createtime' => $ts)); for ($i = 0; $i < 7; $i++) { $isExists = $daoSchedule->existsRule($this->_user->orgId, '^default', $i); if ($isExists) { continue; } $status = $i != 0 && $i != 6 ? 1 : 0; $daoSchedule->createScheduleRule(array('orgid' => $this->_user->orgId, 'scheduleid' => '^default', 'ruleid' => Dao_App_Attend_Schedule::getRuleId(), 'createtime' => $ts, 'week' => $i, 'status' => $status, 'checkintime' => 32400, 'checkouttime' => 64800, 'latestandard' => 0, 'leavestandard' => 0)); } // 免签 $daoSchedule->createSchedule(array('orgid' => $this->_user->orgId, 'scheduleid' => '^exemption', 'name' => '免签班', 'uniqueid' => '^system', 'issystem' => 1, 'bgcolor' => '#DC143C', 'createtime' => $ts)); $daoSchedule->createScheduleRule(array('orgid' => $this->_user->orgId, 'scheduleid' => '^exemption', 'ruleid' => '^exemptionrule', 'createtime' => $ts, 'latestandard' => 0, 'leavestandard' => 0)); $daoApp->updateApp($this->_user->orgId, $this->_appId, array('status' => 2)); return $this->json(true, '应用初始化成功'); }
/** * Constructor * * @param array $record */ public function __construct(array $record) { $this->orgId = $record['orgid']; $this->uniqueId = $record['uniqueid']; $this->scheduleId = $record['scheduleid']; $this->name = $record['name']; $this->planId = $record['planid']; $this->type = $record['type']; $this->value = $record['value']; $this->cycleNum = $record['cyclenum']; $this->checkinTime = Dao_App_Attend_Schedule::formatTime($record['checkintime']); $this->checkoutTime = Dao_App_Attend_Schedule::formatTime($record['checkouttime']); $this->lateStandard = isset($record['latestandard']) ? $this->_toInt($record['latestandard']) : null; $this->lateCheckin = isset($record['latecheckin']) ? $this->_toInt($record['latecheckin']) : null; $this->leaveStandard = isset($record['leavestandard']) ? $this->_toInt($record['leavestandard']) : null; $this->leaveCheckout = isset($record['leavecheckout']) ? $this->_toInt($record['leavecheckout']) : null; $this->status = isset($record['status']) ? $this->_toBoolean($record['status']) : null; $this->startTime = isset($record['starttime']) ? $this->_toTimestamp($record['starttime']) : null; $this->endTime = isset($record['endtime']) ? $this->_toTimestamp($record['endtime']) : null; parent::__construct(); }
/** * 保存排班方案 */ public function saveAction() { $action = $this->_request->getPost('action'); $post = $this->_request->getPost(); /* @var $daoSchedule Dao_App_Attend_Schedule */ $daoSchedule = Tudu_Dao_Manager::getDao('Dao_App_Attend_Schedule', Tudu_Dao_Manager::DB_APP); if ($action == 'update') { if (empty($post['scheduleid'])) { return $this->_this->json(false, $this->lang['parameter_error_sid']); } if (!empty($post['bgcolor'])) { $existsColor = $daoSchedule->existsBgcolor($this->_user->orgId, $post['bgcolor'], $post['scheduleid']); if ($existsColor) { return $this->_this->json(false, '您提交的颜色不能与其他方案颜色重复'); } } // 默认排班方案 if ($post['scheduleid'] == '^default') { // 清除排班方案规则状态 $daoSchedule->clearAllStatus($this->_user->orgId, $post['scheduleid']); $members = (array) $this->_request->getPost('member'); foreach ($members as $member) { $week = $post['week-' . $member]; $ruleParams = array(); $ruleParams['status'] = !empty($post['status-' . $member]) ? 1 : 0; $ruleParams['latestandard'] = !empty($post['latestandard']) ? $post['latestandard'] : 0; $ruleParams['latecheckin'] = !empty($post['latecheckin']) ? $post['latecheckin'] : null; $ruleParams['leavecheckout'] = !empty($post['leavecheckout']) ? $post['leavecheckout'] : null; // 判断记录是否存在 if (!$daoSchedule->existsRule($this->_user->orgId, $post['scheduleid'], $week)) { $params = array('orgid' => $this->_user->orgId, 'scheduleid' => $post['scheduleid'], 'ruleid' => Dao_App_Attend_Schedule::getRuleId(), 'week' => $post['week-' . $member], 'checkintime' => $this->formatTime($post['checkintime-hour-' . $member] . ':' . $post['checkintime-min-' . $member]), 'checkouttime' => $this->formatTime($post['checkouttime-hour-' . $member] . ':' . $post['checkouttime-min-' . $member]), 'createtime' => time()); $ruleId = $daoSchedule->createScheduleRule(array_merge($params, $ruleParams)); if (!$ruleId) { return $this->_this->json(false, $this->lang['save_failed']); } // 更新 } else { $ruleId = $post['ruleid-' . $member]; $ruleParams['checkintime'] = $this->formatTime($post['checkintime-hour-' . $member] . ':' . $post['checkintime-min-' . $member]); $ruleParams['checkouttime'] = $this->formatTime($post['checkouttime-hour-' . $member] . ':' . $post['checkouttime-min-' . $member]); $ret = $daoSchedule->updateScheduleRule($this->_user->orgId, $post['scheduleid'], $ruleId, $ruleParams); if (!$ret) { return $this->_this->json(false, $this->lang['save_failed']); } } } if (!empty($post['bgcolor'])) { $ret = $daoSchedule->updateSchedule($this->_user->orgId, $post['scheduleid'], array('bgcolor' => $post['bgcolor'])); if (!$ret) { return $this->_this->json(false, $this->lang['save_failed']); } } // 自定义排班方案 } else { if (empty($post['ruleid'])) { return $this->_this->json(false, $this->lang['parameter_error_ruleid']); } $condition = array('orgid' => $this->_user->orgId, 'scheduleid' => $post['scheduleid']); $schedule = $daoSchedule->getSchedule($condition); // 方案不存在 if (null === $schedule) { return $this->_this->json(false, $this->lang['schedule_plan_not_exists']); } $params = array(); if (!empty($post['name'])) { $params['name'] = $post['name']; } if (!empty($post['bgcolor'])) { $params['bgcolor'] = $post['bgcolor']; } if (!empty($params)) { $ret = $daoSchedule->updateSchedule($this->_user->orgId, $post['scheduleid'], $params); if (!$ret) { return $this->_this->json(false, $this->lang['save_failed']); } } $ruleParams = array(); $ruleParams['latestandard'] = $this->isNotEmpty('late-standard', $post) ? $post['late-standard'] : null; if ($ruleParams['latestandard'] === null && $this->isNotEmpty('checkin-hour', $post)) { $ruleParams['latestandard'] = 0; } $ruleParams['latecheckin'] = $this->isNotEmpty('late-checkin', $post) ? $post['late-checkin'] : null; $ruleParams['leavecheckout'] = $this->isNotEmpty('leave-checkout', $post) ? $post['leave-checkout'] : null; $ruleParams['checkintime'] = $this->isNotEmpty('checkin-hour', $post) ? $this->formatTime($post['checkin-hour'] . ':' . $post['checkin-min']) : null; $ruleParams['checkouttime'] = $this->isNotEmpty('checkout-hour', $post) ? $this->formatTime($post['checkout-hour'] . ':' . $post['checkout-min']) : null; $ret = $daoSchedule->updateScheduleRule($this->_user->orgId, $post['scheduleid'], $post['ruleid'], $ruleParams); if (!$ret) { return $this->_this->json(false, $this->lang['save_failed']); } } // 创建排班方案 } else { $ruleParams = array(); $ruleParams['latestandard'] = $this->isNotEmpty('late-standard', $post) ? $post['late-standard'] : null; if ($ruleParams['latestandard'] === null && $this->isNotEmpty('checkin-hour', $post)) { $ruleParams['latestandard'] = 0; } $ruleParams['latecheckin'] = $this->isNotEmpty('late-checkin', $post) ? $post['late-checkin'] : null; $ruleParams['leavecheckout'] = $this->isNotEmpty('leave-checkout', $post) ? $post['leave-checkout'] : null; $ruleParams['checkintime'] = $this->isNotEmpty('checkin-hour', $post) ? $this->formatTime($post['checkin-hour'] . ':' . $post['checkin-min']) : null; $ruleParams['checkouttime'] = $this->isNotEmpty('checkout-hour', $post) ? $this->formatTime($post['checkout-hour'] . ':' . $post['checkout-min']) : null; if (!empty($post['scheduleid'])) { $params = array('name' => $post['name'], 'createtime' => time()); if (!empty($post['bgcolor'])) { $existsColor = $daoSchedule->existsBgcolor($this->_user->orgId, $post['bgcolor'], $post['scheduleid']); if ($existsColor) { return $this->_this->json(false, '您提交的颜色不能与其他方案颜色重复'); } $params['bgcolor'] = $post['bgcolor']; } $ret = $daoSchedule->updateSchedule($this->_user->orgId, $post['scheduleid'], $params); if (!$ret) { return $this->_this->json(false, $this->lang['save_failed']); } $ret = $daoSchedule->updateScheduleRule($this->_user->orgId, $post['scheduleid'], $post['ruleid'], $ruleParams); if (!$ret) { return $this->_this->json(false, $this->lang['save_failed']); } } else { $count = count($this->_bgColors); if ($daoSchedule->countSchedule($this->_user->orgId) >= $count) { return $this->_this->json(false, sprintf('最多能创建 %s 个排班方案', $count)); } if (!empty($post['bgcolor'])) { $existsColor = $daoSchedule->existsBgcolor($this->_user->orgId, $post['bgcolor']); if ($existsColor) { return $this->_this->json(false, '您提交的颜色不能与其他方案颜色重复'); } } $params = array('scheduleid' => Dao_App_Attend_Schedule::getScheduleId(), 'orgid' => $this->_user->orgId, 'uniqueid' => $this->_user->uniqueId, 'name' => $post['name'], 'createtime' => time()); if (!empty($post['bgcolor'])) { $params['bgcolor'] = $post['bgcolor']; } $scheduleId = $daoSchedule->createSchedule($params); if (!$scheduleId) { return $this->_this->json(false, $this->lang['save_failed']); } $ruleParams['orgid'] = $this->_user->orgId; $ruleParams['scheduleid'] = $scheduleId; $ruleParams['ruleid'] = Dao_App_Attend_Schedule::getRuleId(); $ruleParams['createtime'] = time(); $ruleId = $daoSchedule->createScheduleRule($ruleParams); if (!$ruleId) { return $this->_this->json(false, $this->lang['save_failed']); } } } return $this->_this->json(true, $this->lang['save_success']); }