示例#1
0
function loadDepartments($cid, $id)
{
    // subdepartments
    $departments = array();
    if ($id == -1) {
        $request = "SELECT * FROM department WHERE cid = {$cid} AND did IS NULL";
    } else {
        $request = "SELECT * FROM department WHERE cid = {$cid} and did = {$id}";
    }
    $result = mysql_query($request);
    $count = mysql_num_rows($result);
    while ($row = mysql_fetch_object($result)) {
        $department = new Department();
        $department->setId($row->id);
        $department->setName($row->name);
        $department->setDepartments(loadDepartments($cid, $row->id));
        $employees = loadEmployees($cid, $row->id);
        $department->setEmployees($employees);
        $inconsistent = containsManager($employees);
        if ($inconsistent == true) {
            $department->setInconsistent(true);
            $department->setMessage("No Manager!");
        }
        $departments[] = $department;
    }
    return $departments;
}
示例#2
0
function loadDepartment($jsonObject)
{
    $id = $jsonObject->id;
    // name
    $request = "SELECT * FROM department WHERE id = {$id}";
    $result = mysql_query($request);
    $row = mysql_fetch_object($result);
    $name = $row->name;
    // departments
    $departments = array();
    $request = "SELECT * FROM department WHERE did = {$id}";
    $result = mysql_query($request);
    $count = mysql_num_rows($result);
    while ($row = mysql_fetch_object($result)) {
        $departments[] = $row->name;
    }
    // employees
    $employees = array();
    $request = "SELECT * FROM employee WHERE did = {$id}";
    $result = mysql_query($request);
    $count = mysql_num_rows($result);
    while ($row = mysql_fetch_object($result)) {
        if ($row->manager == true) {
            $manager = $row->name;
        } else {
            $employees[] = $row->name;
        }
    }
    // total
    $total = totalDepartment($id);
    // create department object
    $department = new Department();
    $department->setDepartments($departments);
    $department->setEmployees($employees);
    $department->setManager($manager);
    $department->setName($name);
    $department->setTotal($total);
    // return department object
    return $department;
}
示例#3
0
function loadDepartment($id)
{
    // name
    $request = "SELECT * FROM department WHERE id = " . $id;
    $result = mysql_query($request);
    $row = mysql_fetch_object($result);
    $name = $row->name;
    $parent = $row->did;
    // departments
    $unselectable = unselectable($id);
    $departments = array();
    $request = "SELECT * FROM department WHERE id NOT IN (" . $unselectable . ")";
    $result = mysql_query($request);
    while ($row = mysql_fetch_object($result)) {
        $department["id"] = $row->id;
        $department["name"] = $row->name;
        if ($row->id == $parent) {
            $department["parent"] = true;
        } else {
            $department["parent"] = false;
        }
        $departments[] = $department;
    }
    // employees
    $employees = array();
    $request = "SELECT * FROM employee";
    $result = mysql_query($request);
    while ($row = mysql_fetch_object($result)) {
        $employee = array();
        $employee["id"] = $row->id;
        $employee["name"] = $row->name;
        if ($row->manager == true && $row->did == $id) {
            $employee["manager"] = true;
        } else {
            $employee["manager"] = false;
        }
        $employees[] = $employee;
    }
    // total
    $total = totalDepartment($id);
    // create department object
    $department = new Department();
    $department->setId($id);
    $department->setDepartments($departments);
    $department->setEmployees($employees);
    $department->setName($name);
    $department->setTotal($total);
    // return department object
    return $department;
}