Ejemplo n.º 1
0
 /**
  * @abstract    获取部门树数据
  * @param       number  $parentId  上级部门ID
  * @return      array   $dept
  */
 public function getTree($parentId)
 {
     $dept = array();
     $data = array();
     $return = array();
     $dept = new Hra_Model_Dept();
     $parentId = str_replace("D", "", str_replace("E", "", $parentId));
     $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_dbprefix . 'employee_dept'), array("id", "parentid", "text" => "name"))->where("t1.active = 1 and parentid = " . $parentId)->order(array('t1.name'));
     $data = $this->fetchAll($sql)->toArray();
     // 判断是否包含子部门
     for ($i = 0; $i < count($data); $i++) {
         $data[$i]['checked'] = false;
         if ($dept->fetchAll("parentId = " . $data[$i]['id'])->count() > 0) {
             $data[$i]['leaf'] = false;
             $data[$i]['children'] = $this->getTree($data[$i]['id'], false);
         } else {
             $data[$i]['leaf'] = true;
         }
         $data[$i]['id'] = "D" . $data[$i]['id'];
     }
     // 格式化根数据格式
     if ($parentId == 0) {
         $dept = array('id' => "D0", 'parentId' => 0, 'text' => '总公司', 'leaf' => false, 'checked' => false, 'expanded' => true, 'children' => $data);
     } else {
         $dept = $data;
     }
     return $dept;
 }
Ejemplo n.º 2
0
 /**
  * 获取通讯录列表信息
  * @param int $parentid 部门ID
  * @param string $root
  * @return multitype:
  */
 public function getContactList($key = null, $dept_id = 0, $root = true)
 {
     $list = array();
     $data = array();
     if ($key) {
         $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name))->joinLeft(array('t2' => $this->_dbprefix . 'employee_post'), "t2.id = t1.post_id", array('post' => 'name'))->joinLeft(array('t3' => $this->_dbprefix . 'user'), "t3.employee_id = t1.id", array('user_id' => 'id'))->joinLeft(array('t4' => $this->_dbprefix . 'employee_dept'), "t1.dept_id = t4.id", array('dept' => 'name'))->where("t1.active = 1 and (t1.ename like '%" . $key . "%' or t1.cname like '%" . $key . "%' or t1.number like '%" . $key . "%')")->order("CONVERT( t1.cname USING gbk )");
         $employeeData = $this->fetchAll($sql)->toArray();
         foreach ($employeeData as $e) {
             array_push($data, array('id' => null, 'parentId' => null, 'dept_id' => null, 'user_id' => $e['user_id'], 'employee_id' => $e['id'], 'text' => '[' . $e['number'] . '] ' . $e['cname'], 'post' => $e['post'], 'dept' => $e['dept'], 'cname' => $e['cname'], 'ename' => $e['ename'], 'email' => $e['email'], 'tel' => $e['tel'], 'official_qq' => $e['official_qq'], 'work_place' => $e['work_place'], 'short_num' => $e['short_num'], 'tel' => $e['msn'], 'ext' => $e['ext'], 'state' => 1, 'iconCls' => 'icon-hra-employee', 'checked' => false, 'qtitle' => '个人信息', 'qalign' => 'bl-tl', 'qtip' => '<p><b>中文名:</b>' . $e['cname'] . '</p><p><b>英文名:</b>' . $e['ename'] . '</p><p><b>部门:</b>' . $e['dept'] . '</p><p><b>职位:</b>' . $e['post'] . '</p><p><b>邮箱:</b>' . $e['email'] . '</p><p><b>手机号:</b>' . $e['tel'] . '</p><p><b>分机号:</b>' . $e['ext'] . '</p>', 'leaf' => true));
         }
     } else {
         // 查找当前部门的所有下级部门
         $dept = new Hra_Model_Dept();
         $deptData = $dept->fetchAll("active = 1 and parentid = " . $dept_id)->toArray();
         foreach ($deptData as $d) {
             // 递归获取当前部门所有下级部门信息
             $dTemp = array('id' => $d['id'], 'parentId' => $dept_id, 'dept_id' => null, 'user_id' => null, 'employee_id' => null, 'text' => $d['name'], 'post' => null, 'dept' => null, 'cname' => null, 'ename' => null, 'email' => null, 'tel' => null, 'official_qq' => null, 'short_num' => null, 'msn' => null, 'ext' => null, 'state' => 1, 'iconCls' => 'icon-hra-dept', 'checked' => false, 'qtitle' => null, 'qtip' => null, 'leaf' => true);
             // 如果有下级部门,递归获取下级部门信息
             if ($dept->fetchAll("active = 1 and parentid = " . $d['id'])->count() > 0 || $this->fetchAll("dept_id = " . $d['id'])->count() > 0) {
                 $dTemp['children'] = $this->getContactList(null, $d['id'], false);
                 $dTemp['leaf'] = false;
             }
             // 如果有成员,获取成员信息
             array_push($data, $dTemp);
         }
         $employee = new Hra_Model_Employee();
         // 获取当前部门下员工信息
         $sql = $this->select()->setIntegrityCheck(false)->from(array('t1' => $this->_name))->joinLeft(array('t2' => $this->_dbprefix . 'employee_post'), "t2.id = t1.post_id", array('post' => 'name'))->joinLeft(array('t3' => $this->_dbprefix . 'user'), "t3.employee_id = t1.id", array('user_id' => 'id'))->joinLeft(array('t4' => $this->_dbprefix . 'employee_dept'), "t1.dept_id = t4.id", array('dept' => 'name'))->where("t1.active = 1 and t1.dept_id = " . $dept_id)->order("CONVERT( t1.cname USING gbk )");
         $employeeData = $this->fetchAll($sql)->toArray();
         foreach ($employeeData as $e) {
             array_push($data, array('id' => null, 'parentId' => $dept_id, 'dept_id' => $dept_id, 'user_id' => $e['user_id'], 'employee_id' => $e['id'], 'text' => '[' . $e['number'] . '] ' . $e['cname'], 'post' => $e['post'], 'dept' => $e['dept'], 'cname' => $e['cname'], 'ename' => $e['ename'], 'email' => $e['email'], 'tel' => $e['tel'], 'official_qq' => $e['official_qq'], 'short_num' => $e['short_num'], 'msn' => $e['msn'], 'ext' => $e['ext'], 'state' => 1, 'iconCls' => 'icon-hra-employee', 'checked' => false, 'qtitle' => '个人信息', 'qtip' => '<p><b>中文名:</b>' . $e['cname'] . '</p><p><b>英文名:</b>' . $e['ename'] . '</p><p><b>职位:</b>' . $e['post'] . '</p><p><b>邮箱:</b>' . $e['email'] . '</p><p><b>手机号:</b>' . $e['tel'] . '</p><p><b>分机号:</b>' . $e['ext'] . '</p>', 'leaf' => true));
         }
     }
     // 格式化根数据格式
     if ($root) {
         $list = array('id' => null, 'parentId' => null, 'dept_id' => null, 'user_id' => null, 'employee_id' => null, 'text' => 'Root', 'post' => null, 'dept' => null, 'cname' => null, 'ename' => null, 'email' => null, 'tel' => null, 'official_qq' => null, 'short_num' => null, 'msn' => null, 'ext' => null, 'state' => 1, 'iconCls' => 'icon-hra-dept', 'leaf' => false, 'checked' => false, 'qtitle' => null, 'qtip' => null, 'children' => $data);
     } else {
         $list = $data;
     }
     return $list;
 }