本文整理汇总了PHP中CommandContext::setDefault方法的典型用法代码示例。如果您正苦于以下问题:PHP CommandContext::setDefault方法的具体用法?PHP CommandContext::setDefault怎么用?PHP CommandContext::setDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CommandContext
的用法示例。
在下文中一共展示了CommandContext::setDefault方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @see Command::execute()
*/
public function execute(CommandContext $context)
{
if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'hall_attributes')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to edit halls.');
}
// Make sure a hall ID was set
$hallId = $context->get('hallId');
if (is_null($hallId)) {
throw new InvalidArgumentException('Missing hall ID.');
}
$viewCmd = CommandFactory::getCommand('EditResidenceHallView');
$viewCmd->setHallId($hallId);
PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
// Create the hall object given the hall id
$hall = new HMS_Residence_Hall($hallId);
if (!$hall) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid hall.');
$viewCmd->redirect();
}
if ($context->get('tab') == 'settings') {
// Compare the hall's gender and the gender the user selected
// If they're not equal, call 'can_change_gender' public function
if ($hall->gender_type != $_REQUEST['gender_type']) {
if (!$hall->can_change_gender($_REQUEST['gender_type'])) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Incompatible gender detected. No changes were made.');
$viewCmd->redirect();
}
}
// Grab all the input from the form and save the hall
$hall->hall_name = $context->get('hall_name');
$hall->gender_type = $context->get('gender_type');
// Set the defaults for the check boxes
$context->setDefault('air_conditioned', 0);
$context->setDefault('is_online', 0);
$context->setDefault('meal_plan_required', 0);
$context->setDefault('assignment_notifications', 0);
$hall->air_conditioned = $context->get('air_conditioned');
$hall->is_online = $context->get('is_online');
$hall->meal_plan_required = $context->get('meal_plan_required');
$hall->assignment_notifications = $context->get('assignment_notifications');
$hall->setPackageDeskId($context->get('package_desk'));
} else {
if ($context->get('tab') == 'images') {
$hall->exterior_image_id = $context->get('exterior_image_id');
$hall->other_image_id = $context->get('other_image_id');
$hall->map_image_id = $context->get('map_image_id');
$hall->room_plan_image_id = $context->get('room_plan_image_id');
}
}
$result = $hall->save();
if (!$result || PHPWS_Error::logIfError($result)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'There was a problem saving the Residence Hall. No changes were made.');
$viewCmd->redirect();
}
NQ::simple('hms', hms\NotificationView::SUCCESS, 'The Residence hall was updated successfully.');
$viewCmd->redirect();
}
示例2: execute
public function execute(CommandContext $context)
{
if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'floor_attributes')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to edit floors.');
}
PHPWS_Core::initModClass('hms', 'HMS_Floor.php');
$floorId = $context->get('floorId');
$viewCmd = CommandFactory::getCommand('EditFloorView');
$viewCmd->setFloorId($floorId);
// Create the floor object gien the floor id
$floor = new HMS_Floor($floorId);
if (!$floor) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Invalid floor.');
$viewCmd->redirect();
}
if ($context->get('tab') == 'settings') {
// Compare the floor's gender and the gender the user selected
// If they're not equal, call 'can_change_gender' public function
if ($floor->gender_type != $context->get('gender_type')) {
if (!$floor->can_change_gender($context->get('gender_type'))) {
NQ::simple('hms', hms\NotificationView::ERROR, 'Incompatible gender detected. No changes were made.');
$viewCmd->redirect();
}
}
// Grab all the input from the form and save the floor
$floor->gender_type = $context->get('gender_type');
$context->setDefault('is_online', 0);
$floor->is_online = $context->get('is_online');
if ($context->get('f_movein_time') == 0) {
$floor->f_movein_time_id = NULL;
} else {
$floor->f_movein_time_id = $context->get('f_movein_time');
}
if ($context->get('t_movein_time') == 0) {
$floor->t_movein_time_id = NULL;
} else {
$floor->t_movein_time_id = $context->get('t_movein_time');
}
if ($context->get('rt_movein_time') == 0) {
$floor->rt_movein_time_id = NULL;
} else {
$floor->rt_movein_time_id = $context->get('rt_movein_time');
}
if ($context->get('floor_rlc_id') == 0) {
$floor->rlc_id = NULL;
} else {
$floor->rlc_id = $context->get('floor_rlc_id');
}
} else {
if ($context->get('tab') == 'images') {
$floor->floor_plan_image_id = $context->get('floor_plan_image_id');
}
}
try {
$floor->save();
} catch (DatabaseException $e) {
NQ::simple('hms', hms\NotificationView::ERROR, 'There was a problem saving the floor data. No changes were made.');
$viewCmd->redirect();
}
NQ::simple('hms', hms\NotificationView::SUCCESS, 'The floor was updated successfully.');
$viewCmd->redirect();
}