示例#1
0
function findDepartAndUser($departID, $userID)
{
    $departDAO = new DepartmentDAO();
    $depart = $departDAO->getDepartmentByID($departID);
    if ($depart === null) {
        return false;
    }
    $result = array();
    $subDepart = $departDAO->getChildDepartments($depart);
    if ($subDepart !== null) {
        foreach ($subDepart as $subDep) {
            if ($subDep->getDepartmentID() === $subDep->getParentID()) {
                continue;
            }
            $node = array();
            $node["type"] = 1;
            $node["id"] = $subDep->getDepartmentID();
            $node["name"] = $subDep->getDepartmentName();
            $result[] = $node;
        }
    }
    $userDAO = new UserDAO();
    $users = $userDAO->getUsersByDepartment($depart);
    if ($users !== null) {
        foreach ($users as $user) {
            if ($user->getUserID() == $userID) {
                continue;
            }
            $node = array();
            $node["type"] = 2;
            $node["id"] = $user->getUserID();
            $node["name"] = $user->getFirstName() . " " . $user->getLastName();
            $result[] = $node;
        }
    }
    return $result;
}