本文整理汇总了PHP中CommandContext类的典型用法代码示例。如果您正苦于以下问题:PHP CommandContext类的具体用法?PHP CommandContext怎么用?PHP CommandContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CommandContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getApplicationFromSession
public static function getApplicationFromSession(array $sessionData, $term, Student $student, $applicationType)
{
$context = new CommandContext();
$context->clearParams();
$context->setParams($sessionData);
return ContextApplicationFactory::getApplicationFromContext($context, $term, $student, $applicationType);
}
示例2: execute
public function execute(CommandContext $context)
{
PHPWS_Core::initModClass('hms', 'HMS_Lottery.php');
$requestId = $context->get('requestId');
$errorCmd = CommandFactory::getCommand('LotteryShowDenyRoommateRequest');
$errorCmd->setRequestId($requestId);
# Confirm the captcha
PHPWS_Core::initCoreClass('Captcha.php');
$captcha = Captcha::verify(TRUE);
if ($captcha === FALSE) {
NQ::simple('hms', hms\NotificationView::ERROR, 'The words you entered were incorrect. Please try again.');
$errorCmd->redirect();
}
# Get the roommate request
$request = HMS_Lottery::get_lottery_roommate_invite_by_id($context->get('requestId'));
# Make sure that the logged in user is the same as the confirming the request
if (UserStatus::getUsername() != $request['asu_username']) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid roommate request. You can not confirm that roommate request.');
$errorCmd->redirect();
}
# Deny the roommate requst
try {
HMS_Lottery::denyRoommateRequest($requestId);
} catch (Exception $e) {
NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error denying the roommate request. Please contact University Housing.');
$errorCmd->redirect();
}
# Log that it happened
PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
HMS_Activity_Log::log_activity(UserStatus::getUsername(), ACTIVITY_LOTTERY_ROOMMATE_DENIED, UserStatus::getUsername(), 'Captcha words: ' . $captcha);
# Success
NQ::simple('hms', hms\NotificationView::SUCCESS, 'The roommate request was successfully declined.');
$successCmd = CommandFactory::getCommand('ShowStudentMenu');
$successCmd->redirect();
}
示例3: execute
public function execute(CommandContext $context)
{
$id = $context->get('roommateId');
if (is_null($id)) {
throw new InvalidArgumentException('Must set roommateId');
}
PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
$roommate = new HMS_Roommate($id);
if ($roommate->id = 0) {
throw new InvalidArgumentException('Invalid roommateId ' . $id);
}
$username = UserStatus::getUsername();
if ($username != $roommate->requestor && $username != $roommate->requestee) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}");
}
PHPWS_Core::initCoreClass('Captcha.php');
// get other roommate
$other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term);
$form = new PHPWS_Form();
$cmd = CommandFactory::getCommand('RoommateBreak');
$cmd->setRoommateId($id);
$cmd->initForm($form);
$form->addTplTag('CAPTCHA_IMAGE', Captcha::get());
$form->addTplTag('NAME', $other->getFullName());
$form->addSubmit('Confirm');
$form->addCssClass('submit', 'btn btn-danger');
$context->setContent(PHPWS_Template::process($form->getTemplate(), 'hms', 'student/roommate_break_confirm.tpl'));
}
示例4: execute
public function execute(CommandContext $context)
{
// Check permissions
if (!Current_User::allow('hms', 'checkin')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to checkin students.');
}
$term = Term::getSelectedTerm();
$bannerId = $context->get('bannerId');
$hallId = $context->get('hallId');
$errorCmd = CommandFactory::getCommand('ShowCheckinStart');
if (!isset($bannerId) || is_null($bannerId) || $bannerId == '') {
NQ::simple('hms', hms\NotificationView::ERROR, 'Missing Banner ID.');
$errorCmd->redirect();
}
if (!isset($hallId)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Missing residence hall ID.');
$errorCmd->redirect();
}
// Check the Banner ID
if (preg_match("/[\\d]{9}/", $bannerId) == false) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Imporperly formatted Banner ID.');
$errorCmd->redirect();
}
// Try to lookup the student in Banner
try {
$student = StudentFactory::getStudentByBannerId($bannerId, $term);
} catch (StudentNotFoundException $e) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Could not locate a student with that Banner ID.');
$errorCmd->redirect();
}
// Make sure the student is assigned in the current term
$assignment = HMS_Assignment::getAssignmentByBannerId($bannerId, $term);
if (!isset($assignment) || is_null($assignment)) {
NQ::simple('hms', hms\NotificationView::ERROR, $student->getName() . ' is not assigned for ' . Term::toString($term) . '. Please contact the University Housing Assignments Office at 828-262-6111.');
$errorCmd->redirect();
}
// Make sure the student's assignment matches the hall the user selected
$bed = $assignment->get_parent();
$room = $bed->get_parent();
$floor = $room->get_parent();
$hall = $floor->get_parent();
if ($hallId != $hall->getId()) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Wrong hall! ' . $student->getName() . ' is assigned to ' . $assignment->where_am_i());
$errorCmd->redirect();
}
// Load any existing check-in
$checkin = CheckinFactory::getLastCheckinByBannerId($bannerId, $term);
// If there is a checkin for the same bed, and the difference between the current time and the checkin time is
// greater than 48 hours, then show an error.
if (!is_null($checkin)) {
$checkoutDate = $checkin->getCheckoutDate();
if ($checkin->getBedId() == $bed->getId() && !isset($checkoutDate) && time() - $checkin->getCheckinDate() > Checkin::CHECKIN_TIMEOUT) {
NQ::simple('hms', hms\NotificationView::ERROR, $student->getName() . ' has already checked in to ' . $assignment->where_am_i());
$errorCmd->redirect();
}
}
$view = new CheckinFormView($student, $assignment, $hall, $floor, $room, $checkin);
$context->setContent($view->show());
}
示例5: execute
public function execute(CommandContext $context)
{
$id = $context->get('roommateId');
if (is_null($id)) {
throw new InvalidArgumentException('Must set roommateId');
}
PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
$roommate = new HMS_Roommate($id);
if ($roommate->id == 0) {
throw new InvalidArgumentException('Invalid roommateId ' . $id);
}
$username = UserStatus::getUsername();
if ($username != $roommate->requestor) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException("{$username} tried to break roommate pairing {$roommate->id}");
}
$roommate->delete();
$other = StudentFactory::getStudentByUsername($roommate->get_other_guy($username), $roommate->term);
HMS_Activity_Log::log_activity($other->getUsername(), ACTIVITY_STUDENT_CANCELLED_ROOMMATE_REQUEST, $username, "{$username} cancelled roommate request");
HMS_Activity_Log::log_activity($username, ACTIVITY_STUDENT_CANCELLED_ROOMMATE_REQUEST, $other->getUsername(), "{$username} cancelled roommate request");
// Email both parties
PHPWS_Core::initModClass('hms', 'HMS_Email.php');
HMS_Email::send_cancel_emails($roommate);
$name = $other->getFullName();
NQ::Simple('hms', hms\NotificationView::SUCCESS, "You have cancelled your roommate request for {$name}.");
$cmd = CommandFactory::getCommand('ShowStudentMenu');
$cmd->redirect();
}
示例6: execute
public function execute(CommandContext $context)
{
$resultCmd = CommandFactory::getCommand('ShowSendRlcInvites');
$respondByDate = $context->get('respond_by_date');
$respondByTime = $context->get('time');
if (!isset($respondByDate) || $respondByDate == '') {
NQ::simple('hms', hms\NotificationView::ERROR, 'Please choose a \'respond by\' date.');
$resultCmd->redirect();
}
$dateParts = explode('/', $respondByDate);
$respondByTimestamp = mktime($respondByTime, null, null, $dateParts[0], $dateParts[1], $dateParts[2]);
$term = Term::getSelectedTerm();
$studentType = $context->get('type');
if (!isset($studentType)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Please choose a student type.');
$resultCmd->redirect();
}
PHPWS_Core::initModClass('hms', 'RlcAssignmentFactory.php');
PHPWS_Core::initModClass('hms', 'RlcAssignmentInvitedState.php');
$assignments = RlcAssignmentFactory::getAssignmentsByTermStateType($term, 'new', $studentType);
if (sizeof($assignments) == 0) {
NQ::simple('hms', hms\NotificationView::WARNING, 'No invites needed to be sent.');
$resultCmd->redirect();
}
foreach ($assignments as $assign) {
$assign->changeState(new RlcAssignmentInvitedState($assign, $respondByTimestamp));
}
NQ::simple('hms', hms\NotificationView::SUCCESS, 'Learning community invites sent.');
$resultCmd->redirect();
}
示例7: execute
public function execute(CommandContext $context)
{
$id = $context->get('roommateId');
if (is_null($id)) {
throw new InvalidArgumentException('Must set roommateId');
}
PHPWS_Core::initModClass('hms', 'HMS_Roommate.php');
$roommate = new HMS_Roommate($id);
if ($roommate->id == 0) {
throw new InvalidArgumentException('Invalid roommateId ' . $id);
}
$username = UserStatus::getUsername();
if ($username != $roommate->requestee) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException("{$username} tried to display confirmation screen for pairing {$roommate->id}");
}
$tpl = array();
$acceptCmd = CommandFactory::getCommand('ShowRoommateConfirmAccept');
$acceptCmd->setRoommateId($roommate->id);
$tpl['ACCEPT'] = $acceptCmd->getURI();
$rejectCmd = CommandFactory::getCommand('RoommateReject');
$rejectCmd->setRoommateId($roommate->id);
$tpl['DECLINE'] = $rejectCmd->getURI();
$cancelCmd = CommandFactory::getCommand('ShowStudentMenu');
$tpl['CANCEL'] = $cancelCmd->getURI();
$requestor = StudentFactory::getStudentByUsername($roommate->requestor, $roommate->term);
$tpl['REQUESTOR_NAME'] = $requestor->getFullName();
$context->setContent(PHPWS_Template::process($tpl, 'hms', 'student/roommate_accept_reject_screen.tpl'));
}
示例8: execute
public function execute(CommandContext $context)
{
if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'bed_structure')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to remove a bed.');
}
PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
$viewCmd = CommandFactory::getCommand('EditRoomView');
$viewCmd->setRoomId($context->get('roomId'));
$bedId = $context->get('bedId');
$roomId = $context->get('roomId');
if (!isset($roomId)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Missing room ID.');
$viewCmd->redirect();
}
if (!isset($bedId)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Missing bed ID.');
$viewCmd->redirect();
}
# Try to delete the bed
try {
HMS_Bed::deleteBed($bedId);
} catch (Exception $e) {
NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error deleting the bed: ' . $e->getMessage());
$viewCmd->redirect();
}
NQ::simple('hms', hms\NotificationView::SUCCESS, 'Bed successfully deleted.');
$viewCmd->redirect();
}
示例9: execute
public function execute(CommandContext $context)
{
if (!Current_User::allow('hms', 'room_structure')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to add a room.');
}
PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
PHPWS_Core::initModClass('hms', 'HMS_Floor.php');
PHPWS_Core::initModClass('hms', 'HMS_Bed.php');
PHPWS_Core::initModClass('hms', 'HMS_Assignment.php');
PHPWS_Core::initModClass('hms', 'HMS_Util.php');
PHPWS_Core::initModClass('hms', 'AddRoomView.php');
$floor_id = $context->get('floor');
$tpl = array();
# Setup the title and color of the title bar
$tpl['TITLE'] = 'Add Room';
# Check to make sure we have a floor and hall.
$floor = new HMS_Floor($floor_id);
if (!$floor) {
$tpl['ERROR_MSG'] = 'There was an error getting the floor object. Please contact ESS.';
return PHPWS_Template::process($tpl, 'hms', 'admin/add_room.tpl');
}
$hall = $floor->get_parent();
if (!$hall) {
$tpl['ERROR_MSG'] = 'There was an error getting the hall object. Please contact ESS.';
return PHPWS_Template::process($tpl, 'hms', 'admin/add_room.tpl');
}
# Check Permissions
if (!Current_User::allow('hms', 'room_structure')) {
HMS_Floor::show_edit_floor($floor_id, NULL, 'You do not have permission to add rooms.');
}
$view = new AddRoomView($floor);
$context->setContent($view->show());
}
示例10: execute
public function execute(CommandContext $context)
{
if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'assign_by_floor')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to assign students by floor.');
}
$username = $context->get('username');
$banner_id = (int) $context->get('banner_id');
$reason = $context->get('reason');
$meal_plan = $context->get('meal_plan');
$bed_id = $context->get('bed_id');
$term = Term::getSelectedTerm();
try {
if ($banner_id) {
$student = StudentFactory::getStudentByBannerID($banner_id, Term::getSelectedTerm());
} elseif (!empty($username)) {
$student = StudentFactory::getStudentByUsername($username, Term::getSelectedTerm());
} else {
$context->setContent(json_encode(array('status' => 'failure', 'message' => 'Did not receive Banner ID or user name.')));
return;
}
try {
HMS_Assignment::assignStudent($student, $term, null, $bed_id, $meal_plan, null, null, $reason);
} catch (AssignmentException $e) {
$context->setContent(json_encode(array('status' => 'failure', 'message' => $e->getMessage())));
return;
}
$message = $student->first_name . ' ' . $student->last_name;
$context->setContent(json_encode(array('status' => 'success', 'message' => $message, 'student' => $student)));
} catch (\StudentNotFoundException $e) {
$context->setContent(json_encode(array('status' => 'failure', 'message' => $e->getMessage())));
}
}
示例11: execute
public function execute(CommandContext $context)
{
if (!Current_User::allow('hms', 'edit_role_members')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to edit role members.');
}
$username = $context->get('username');
$role_id = $context->get('role');
$classname = $context->get('class');
$instance = $context->get('instance');
if (is_null($username) || is_null($role_id)) {
echo json_encode(false);
exit;
}
$role = new HMS_Role();
$role->id = $role_id;
if ($role->load()) {
try {
$role->addUser($username, $classname, $instance);
echo json_encode('true');
exit;
} catch (Exception $e) {
echo json_encode($e->getMessage());
exit;
}
}
}
示例12: execute
/**
* (non-PHPdoc)
* @see Command::execute()
*/
public function execute(CommandContext $context)
{
PHPWS_Core::initModClass('hms', 'StudentFactory.php');
PHPWS_Core::initModClass('hms', 'HousingApplicationFactory.php');
$term = $context->get('term');
if (!isset($term)) {
throw new InvalidArgumentException('Missing term.');
}
$user = UserStatus::getUsername();
$student = StudentFactory::getStudentByUsername($user, $term);
// Load the student's application. Should be a lottery application.
$application = HousingApplicationFactory::getAppByStudent($student, $term);
// If there isn't a valid application in the DB, then we have a problem.
if (!isset($application) || !$application instanceof LotteryApplication) {
throw new InvalidArgumentException('Null application object.');
}
// Check to make sure the date isn't already set
$time = $application->getWaitingListDate();
if (isset($time)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'You have already applied for the waiting list.');
$cmd = CommandFactory::getCommand('ShowStudentMenu');
$cmd->redirect();
}
// Set the date
$application->setWaitingListDate(time());
// Save the application again
$application->save();
// Log it to the activity log
HMS_Activity_Log::log_activity($student->getUsername(), ACTIVITY_REAPP_WAITINGLIST_APPLY, UserStatus::getUsername());
// Success command
$cmd = CommandFactory::getCommand('ShowStudentMenu');
$cmd->redirect();
}
示例13: execute
public function execute(CommandContext $context)
{
if (!Current_User::allow('hms', 'room_view')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to view rooms.');
}
// Check for a hall ID
$roomId = $context->get('room');
if (!isset($roomId)) {
throw new InvalidArgumentException('Missing room ID.');
}
// Load the room
$room = new HMS_Room($roomId);
if ($room->term != Term::getSelectedTerm()) {
$roomCmd = CommandFactory::getCommand('SelectRoom');
$roomCmd->setTitle('Edit a Room');
$roomCmd->setOnSelectCmd(CommandFactory::getCommand('EditRoomView'));
$roomCmd->redirect();
}
// Load the floor/hall
$floor = $room->get_parent();
$hall = $floor->get_parent();
// Load the room damages and damage types
$damageTypes = DamageTypeFactory::getDamageTypeAssoc();
$roomView = new RoomView($hall, $floor, $room, $damageTypes);
$context->setContent($roomView->show());
}
示例14: execute
public function execute(CommandContext $context)
{
if (!Current_User::allow('hms', 'approve_rlc_applications')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to approve RLC applications.');
}
PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
PHPWS_Core::initModClass('hms', 'StudentFactory.php');
# Foreach rlc assignment made
# $app_id is the 'id' column in the 'learning_community_applications' table, tells which student we're assigning
# $rlc_id is the 'id' column in the 'learning_communitites' table, and refers to the RLC selected for the student
foreach ($_REQUEST['final_rlc'] as $app_id => $rlc_id) {
if ($rlc_id <= 0) {
continue;
}
$app = HMS_RLC_Application::getApplicationById($app_id);
$student = StudentFactory::getStudentByUsername($app->username, $app->term);
# Insert a new assignment in the 'learning_community_assignment' table
$assign = new HMS_RLC_Assignment();
$assign->rlc_id = $rlc_id;
$assign->gender = $student->getGender();
$assign->assigned_by = UserStatus::getUsername();
$assign->application_id = $app->id;
$assign->state = 'new';
$assign->save();
# Log the assignment
PHPWS_Core::initModClass('hms', 'HMS_Activity_Log.php');
HMS_Activity_Log::log_activity($app->username, ACTIVITY_ASSIGN_TO_RLC, UserStatus::getUsername(), "New Assignment");
}
// Show a success message
NQ::simple('hms', hms\NotificationView::SUCCESS, 'Successfully assigned RLC applicant(s).');
$context->goBack();
}
示例15: execute
public function execute(CommandContext $context)
{
if (!Current_User::allow('hms', 'approve_rlc_applications')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to approve/deny RLC applications.');
}
PHPWS_Core::initModClass('hms', 'HMS_RLC_Assignment.php');
PHPWS_Core::initModClass('hms', 'HMS_RLC_Application.php');
// Remove assignment
$assignment = HMS_RLC_Assignment::getAssignmentById($context->get('assignId'));
$rlcName = $assignment->getRlcName();
$rlcApp = $assignment->getApplication();
if (!is_null($assignment)) {
$assignment->delete();
} else {
NQ::simple('hms', hms\NotificationView::ERROR, 'Could not find an RLC assignment with that id.');
}
HMS_Activity_Log::log_activity($rlcApp->getUsername(), ACTIVITY_RLC_UNASSIGN, Current_User::getUsername(), "Removed from {$rlcName}");
NQ::simple('hms', hms\NotificationView::SUCCESS, 'Removed from RLC');
// Deny application
$rlcApp->denied = 1;
$rlcApp->save();
NQ::simple('hms', hms\NotificationView::SUCCESS, 'RLC Application denied');
HMS_Activity_Log::log_activity($rlcApp->getUsername(), ACTIVITY_DENIED_RLC_APPLICATION, Current_User::getUsername(), 'RLC Application Denied');
$context->goBack();
}