コード例 #1
0
ファイル: Admin.php プロジェクト: bjtenao/tudu-web
    /**
     * 初始化应用环境
     */
    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, '应用初始化成功');
    }
コード例 #2
0
ファイル: Category.php プロジェクト: bjtenao/tudu-web
 /**
  * 保存考勤分类
  */
 public function saveAction()
 {
     $action = $this->_request->getPost('action');
     $post = $this->_request->getPost();
     $params = array();
     $returnData = array();
     $isSystem = false;
     /* @var $daoCategory Dao_App_Attend_Category */
     $daoCategory = Tudu_Dao_Manager::getDao('Dao_App_Attend_Category', Tudu_Dao_Manager::DB_APP);
     // 更新
     if ($action == self::ACTION_UPDATE) {
         $condition = array('categoryid' => $post['categoryid'], 'orgid' => $this->_user->orgId);
         $category = $daoCategory->getCategory($condition);
         if (null === $category) {
             return $this->_this->json(false, $this->lang['category_not_exists']);
         }
         $isSystem = $category->isSystem;
         if (!$post['categoryid']) {
             return $this->_this->json(false, $this->lang['parameter_error_cid']);
         }
     }
     if (!$isSystem && !$post['categoryname']) {
         return $this->_this->json(false, $this->lang['params_invalid_category_name']);
     }
     // 必须有流程步骤
     $members = (array) $this->_request->getPost('member');
     $count = count($members);
     if ($count <= 0) {
         return $this->_this->json(false, $this->lang['params_invalid_flow_steps']);
     }
     if (!empty($post['categoryname'])) {
         $categoryId = $action == self::ACTION_UPDATE ? $post['categoryid'] : null;
         $rs = $daoCategory->existsCategoryName($this->_user->orgId, $post['categoryname'], $categoryId);
         if ($rs) {
             return $this->_this->json(false, '已有此分类名称的考勤分类');
         }
     }
     $rs = $this->prepareSteps($post);
     if (!$rs['success']) {
         return $this->_this->json(false, $rs['message'], $rs['target']);
     }
     $flowId = empty($post['flowid']) ? Dao_App_Attend_Category::getFlowId() : $post['flowid'];
     $params['flowsteps'] = Dao_App_Attend_Category::formatData($this->formatSteps($post));
     // 更新考勤分类
     if ($action == self::ACTION_UPDATE) {
         if (!empty($post['categoryname'])) {
             $params['categoryname'] = $post['categoryname'];
         }
         $returnData['categoryid'] = $post['categoryid'];
         $ret = $daoCategory->updateCategory($post['categoryid'], $this->_user->orgId, $params);
         // 创建考勤分类
     } else {
         $params['categoryname'] = $post['categoryname'];
         $params['orgid'] = $this->_user->orgId;
         $params['categoryid'] = Dao_App_Attend_Category::getCategoryId();
         $params['createtime'] = time();
         $returnData['categoryid'] = $params['categoryid'];
         $ret = $daoCategory->createCategory($params);
     }
     if (!$ret) {
         return $this->_this->json(false, $this->lang['save_failed']);
     }
     return $this->_this->json(true, $this->lang['save_success'], $returnData);
 }