/** * Get the list of employees * * @param $id Employee ID (employee) * */ public function getList($id = false) { $users_gateway = Users::factory($this->getServiceLocator()); // NOTE: manager_id is not currently use, but can be use for verification/authorization purposes $manager_id = $this->params()->fromRoute('manager_id'); // select all employees $result = $users_gateway->select(array('role' => 'employee')); return $result; }
/** * Get the list of managers for my shifts * * @param $id Employee ID (Manager) * */ public function getList($id = false) { $users_gateway = Users::factory($this->getServiceLocator()); $employee_id = $this->params()->fromRoute('user_id'); $table = $users_gateway->getTable(); // select all managers who manages my shifts $result = $users_gateway->select(function ($select) use($employee_id, $id, $table) { // the shifts they manages $select->join(array('S' => 'shifts'), "{$table}.id = S.manager_id", array(), Select::JOIN_INNER); $where = new Where(); // we only want shifts I work on $where->equalTo("S.employee_id", $employee_id); // ensures that the user is a manager $where->equalTo("{$table}.role", 'manager'); if ($id !== false) { $where->equalTo("{$table}.id", $id); } $select->where($where); }); return $result; }
/** * Get the list of employees working with the given Employee ID * * @param $id Employee ID * */ public function getList($id = false) { $users_gateway = Users::factory($this->getServiceLocator()); $employee_id = $this->params()->fromRoute('user_id'); $table = $users_gateway->getTable(); // select all users who works during the same time period $result = $users_gateway->select(function ($select) use($employee_id, $id, $table) { // the shifts other employees work $select->join(array('S' => 'shifts'), "{$table}.id = S.employee_id", array(), Select::JOIN_INNER); // the shifts the current employee work $select->join(array('S2' => 'shifts'), new Expression("(S.start_time >= S2.start_time\n\t\t\t\t\t\t\t\t\t\t\tAND S.start_time < S2.end_time)\n\t\t\t\t\t\t\t\t\t\tOR (S.end_time >= S2.start_time\n\t\t\t\t\t\t\t\t\t\t\tAND S.end_time < S2.end_time)"), array(), Select::JOIN_INNER); $where = new Where(); // we do not want to know about our own shifts $where->notEqualTo("S.employee_id", $employee_id); // we want to use only our shifts as a comparison $where->equalTo('S2.employee_id', $employee_id); if ($id !== false) { $where->equalTo("{$table}.id", $id); } $select->where($where); }); return $result; }