/** * Construct * * @param array $record */ public function __construct(array $record) { $this->categoryId = $record['categoryid']; $this->orgId = $record['orgid']; $this->categoryName = $record['categoryname']; $this->flowSteps = Dao_App_Attend_Category::formatSteps($record['flowsteps']); $this->status = $this->_toInt($record['status']); $this->isSystem = $this->_toBoolean($record['issystem']); $this->createTime = $this->_toTimestamp($record['createtime']); 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, '应用初始化成功'); }
/** * 处理审批步骤 * * @param array $post * @return array */ public function formatSteps($post) { $steps = array(); $members = (array) $post['member']; foreach ($members as $member) { // 步骤ID $steps[$post['order-' . $member]]['id'] = !empty($post['id-' . $member]) ? $post['id-' . $member] : Dao_App_Attend_Category::getStepId(); // 存在分支 if (isset($post['branch-' . $member])) { $stepBranches = array(); $branches = (array) $post['branch-' . $member]; foreach ($branches as $branch) { $type = (int) $post['type-' . $member . '-' . $branch]; if ($type == 0) { $users = '^upper'; } elseif ($type == 1) { $users = '^uppers'; } elseif ($type == 2) { $users = $this->_parseStepSection($post['users-' . $member . '-' . $branch]); } $stepBranches[] = array('type' => $type, 'sections' => $users, 'start' => $post['start-' . $member . '-' . $branch], 'end' => $post['end-' . $member . '-' . $branch]); } $steps[$post['order-' . $member]]['branches'] = $stepBranches; // 没有分支 } else { $type = (int) $post['type-' . $member]; if ($type == 0) { $users = '^upper'; } elseif ($type == 1) { $users = '^uppers'; } elseif ($type == 2) { $users = $this->_parseStepSection($post['users-' . $member]); } $steps[$post['order-' . $member]]['type'] = $type; $steps[$post['order-' . $member]]['sections'] = $users; } } // 排序 ksort($steps); // 处理下一步关系 foreach ($steps as $key => $step) { if (isset($steps[$key + 1]['id'])) { $next = $steps[$key + 1]['id']; } else { $next = '^end'; } $steps[$key]['next'] = $next; } return $steps; }