Пример #1
0
 /**
  * Construct
  * 
  * @param array $record
  */
 public function __construct(array $record)
 {
     $this->orgId = $record['orgid'];
     $this->deptId = $record['deptid'];
     $this->deptName = $record['deptname'];
     $this->parentId = !empty($record['parentid']) ? $record['parentid'] : null;
     $this->orderNum = $record['ordernum'];
     $this->moderators = Dao_Md_Department_Department::formatModerator($record['moderators']);
     $this->firstNode = isset($record['firstnode']) && $record['firstnode'] ? true : false;
     $this->lastNode = isset($record['lastnode']) && $record['lastnode'] ? true : false;
     $this->depth = isset($record['depth']) ? $this->_toInt($record['depth']) : null;
     $this->prefix = !empty($record['prefix']) ? $record['prefix'] : null;
     $this->path = isset($record['path']) ? $record['path'] : array();
     parent::__construct();
 }
Пример #2
0
 /**
  * 获取用户可见的部门
  *
  * @param string $orgId
  * @param string $userId
  * @return boolean
  */
 public function getCastDepartments($orgId, $userId)
 {
     if (!$orgId || !$userId) {
         return new Oray_Dao_Recordset();
     }
     $orgId = $this->_db->quote($orgId);
     $userId = $this->_db->quote($userId);
     $table = 'md_department AS D ' . "LEFT JOIN md_cast_disable_dept AS UD ON UD.org_id = D.org_id AND UD.dept_id = D.dept_id AND UD.owner_id = {$userId}";
     $columns = 'D.org_id AS orgid, D.dept_id AS deptid, dept_name AS deptname, parent_dept_id AS parentid, ' . 'moderators, order_num as ordernum';
     $where = array();
     //$where[] = 'UD.org_id = ' . $this->_db->quote($orgId);
     //$where[] = 'UD.owner_id = ' . $this->_db->quote($userId);
     $where[] = "D.org_id = {$orgId}";
     $where[] = "UD.dept_id IS NULL";
     $where = implode(' AND ', $where);
     // ORDER
     $order = 'ORDER BY D.org_id, D.parent_dept_id, D.order_num DESC';
     $sql = "SELECT {$columns} FROM {$table} WHERE {$where} {$order}";
     $_records = $this->_db->fetchAll($sql);
     if (!$_records) {
         return new Oray_Dao_Recordset();
     }
     if (!class_exists('Dao_Md_Department_Department')) {
         require_once 'Dao/Md/Department/Department.php';
     }
     $records = array();
     $records = Dao_Md_Department_Department::sortRecords($_records);
     $records = Dao_Md_Department_Department::formatRecords($records);
     return new Oray_Dao_Recordset($records, 'Dao_Md_Department_Record_Department');
 }
Пример #3
0
 /**
  * 获取构架配置可见的部门
  *
  * @param string $orgId
  * @param string $castId
  * @return boolean
  */
 public function getCastDepartments($orgId, $castId)
 {
     if (!$orgId || !$castId) {
         return new Oray_Dao_Recordset();
     }
     $table = 'v_cast_department';
     $columns = 'org_id AS orgid, dept_id AS deptid, dept_name AS deptname, parent_dept_id AS parentid, order_num as ordernum, moderators';
     $where = array();
     $where[] = 'org_id = ' . $this->_db->quote($orgId);
     $where[] = 'cast_id = ' . $this->_db->quote($castId);
     $where = implode(' AND ', $where);
     // ORDER
     $order = 'ORDER BY org_id, parent_dept_id, order_num DESC';
     $sql = "SELECT {$columns} FROM {$table} WHERE {$where} {$order}";
     $_records = $this->_db->fetchAll($sql);
     if (!$_records) {
         return new Oray_Dao_Recordset();
     }
     if (!class_exists('Dao_Md_Department_Department')) {
         require_once 'Dao/Md/Department/Department.php';
     }
     $records = array();
     $records = Dao_Md_Department_Department::sortRecords($_records);
     $records = Dao_Md_Department_Department::formatRecords($records);
     return new Oray_Dao_Recordset($records, 'Dao_Md_Department_Record_Department');
 }
Пример #4
0
 /**
  * 创建部门
  */
 public function createDept(array &$params)
 {
     if ($params['deptid'] == '^new') {
         $isImport = !empty($params['import']) ? true : false;
         // 部门名称
         if (!$isImport && empty($params['deptname'])) {
             return $this->json(false, '请输入新部门名称');
         }
         /* @var $daoDepartment Dao_Md_Department_Department */
         $daoDepartment = Tudu_Dao_Manager::getDao('Dao_Md_Department_Department', Tudu_Dao_Manager::DB_MD);
         $departments = $daoDepartment->getDepartments(array('orgid' => $params['orgid']))->toArray('deptid');
         $parentId = '^root';
         $deptPath = array();
         if (!empty($params['deptparentid'])) {
             $parentId = $params['deptparentid'];
             // 父级部门不存在
             if (!isset($departments[$parentId])) {
                 if ($isImport) {
                     $params['exist-parentid'] = true;
                     return;
                 } else {
                     return $this->json(false, '新建部门的父级部门不存在或已被删除');
                 }
             }
             $deptPath = array_merge($departments[$parentId]['path'], array($parentId));
         }
         $deptId = Dao_Md_Department_Department::getDeptId();
         $deptId = $daoDepartment->createDepartment(array('orgid' => $params['orgid'], 'deptname' => $params['deptname'], 'deptid' => $deptId, 'parentid' => $parentId, 'ordernum' => $daoDepartment->getMaxOrderNum($params['orgid'], $parentId) + 1));
         if (!$deptId) {
             if ($isImport) {
                 return;
             } else {
                 return $this->json(false, '所属部门创建失败');
             }
         }
         $this->_createLog(Dao_Md_Log_Oplog::MODULE_DEPT, Dao_Md_Log_Oplog::OPERATION_CREATE, null, implode(':', array($params['orgid'], $deptId)), array('deptname' => $params['deptname']));
         // 插入消息队列
         $options = $this->_bootstrap->getOption('httpsqs');
         $httpsqs = new Oray_Httpsqs($options['host'], $options['port'], $options['charset'], $options['name']);
         $data = implode(' ', array(Dao_Md_Log_Oplog::MODULE_DEPT, Dao_Md_Log_Oplog::OPERATION_CREATE, null, implode(':', array($params['orgid'], $deptId))));
         $httpsqs->put($data);
         $params['deptid'] = $deptId;
         unset($params['deptname']);
         unset($params['deptparentid']);
     }
 }