/** * Lists bookings. * * @param int userid * @param int $start * @param int $end * @param array typeIds Optional. An array with IDs of the booking types to * limit the results to. Default is NULL. * @param bool $showDeleted Optional. Default is FALSE. * @param string orderby Order by key (start*, end, username, flexitime, overtime, denied) * @param string ordermode Order mode ("asc" or "desc"; default: desc) * @return array An array of booking items */ public function do_list_bookings($userId, $start, $end, array $typeIds = null, $showDeleted = false, $ordermode = null, $orderBy = null) { $user = $this->requireUser(); $query = $this->createBookingQuery($user)->join('Transaction.UserRelatedByUserId')->join('UserRelatedByUserId.Domain')->join('Domain.Account'); if ((string) $userId !== '') { $employee = $this->findUserById($userId); if ($employee === null) { throw new Exception('Employee with ID ' . $userId . ' could not be found.'); } $query->add(TransactionPeer::USER_ID, $employee->getId()); } if ((string) $start !== '') { $query->add(TransactionPeer::END, $start, Criteria::GREATER_EQUAL); } if ((string) $end !== '') { $query->add(TransactionPeer::START, $end, Criteria::LESS_EQUAL); } if (!empty($typeIds)) { $query->filterByBookingTypeId($typeIds, Criteria::IN); } if (!$showDeleted) { $query->add(TransactionPeer::DELETED, 0, Criteria::EQUAL); } if ($ordermode == 'asc') { $sortMethod = 'addAscendingOrderByColumn'; } else { $ordermode = 'desc'; $sortMethod = 'addDescendingOrderByColumn'; } switch ($orderBy) { case 'User': $query->orderBy('Account.Name', $ordermode); $query->orderBy('Account.Identifier', $ordermode); $query->orderBy('UserRelatedByUserId.Name', $ordermode); $query->orderBy('Transaction.Start', $ordermode); $query->orderBy('Transaction.End', $ordermode); break; case 'End': $query->orderBy('Transaction.End', $ordermode); $query->orderBy('Transaction.Start', $ordermode); $query->orderBy('Account.Name', $ordermode); $query->orderBy('Account.Identifier', $ordermode); $query->orderBy('UserRelatedByUserId.Name', $ordermode); break; case 'Start': default: $query->orderBy('Transaction.Start', $ordermode); $query->orderBy('Transaction.End', $ordermode); $query->orderBy('Account.Name', $ordermode); $query->orderBy('Account.Identifier', $ordermode); $query->orderBy('UserRelatedByUserId.Name', $ordermode); break; } $query->orderById($ordermode); $result = array(); foreach ($query->find() as $booking) { $result[] = EntityArray::from($booking); } return $result; }
/** * Returns the user details * * @param string|int $id The user ID or full login name * @param bool $allowPeerUsers Optional. If TRUE and the method was called * by a plugin, users from the same company account but not managed by * the authenticated user can be returned as well. If FALSE, only * subordinate users will be returned. Default is FALSE. * @return array An associative array of user properties. */ public function do_details($id = null, $allowPeerUsers = false) { $user = $this->requireUser(); /* @var $user User */ if ((string) $id !== '') { // Check if it is a plugin execution $user = (PluginIXml::inPlugin() and $allowPeerUsers) ? $this->getPeerUser($user->getAccountId(), $id) : $user->getSubordinate($id); } return EntityArray::from($user) + array('Properties' => $user->getProperties()); }
/** * Removes a clocking entry * * @param int $id The clocking ID */ public function do_remove($id) { $con = Propel::getConnection(); if (!$con->beginTransaction()) { throw new Exception('Could not start transaction.'); } try { $authUser = $this->requireUser($con); $clocking = $this->getClockingById($id, $con); if ($clocking->getBooked()) { throw new Exception('Cannot remove clocking entry #' . $id . ' because it already has bookings. Please remove the transactions instead.'); } if (!$clocking->isOpen() and !$authUser->isAdmin()) { $account = $authUser->getAccount($con); if ($account === null) { throw new Exception('Could not get account of user #' . $authUser->getId() . ' "' . $authUser->getFQN($con) . '".'); } $type = $clocking->getClockingType($con); if ($type === null) { throw new Exception('Could not get clocking type with ID #' . $clocking->getTypeId() . '.'); } $this->validateTimeLimits($account, $authUser, $clocking, $con); } $clockingUser = $clocking->getUserRelatedByUserId($con); if ($clockingUser === null) { throw new Exception('Could not determine clocking\'s assigned user #' . $clocking->getUserId() . '.'); } PluginPeer::fireEvent($clockingUser, 'clocking', 'remove', EntityArray::from($clocking, $con), $con); $clocking->setDeleted(1)->save($con); } catch (Exception $e) { $con->rollBack(); throw $e; } if (!$con->commit()) { throw new Exception('Could not commit transaction.'); } return true; }