本文整理汇总了PHP中Term::isValidTerm方法的典型用法代码示例。如果您正苦于以下问题:PHP Term::isValidTerm方法的具体用法?PHP Term::isValidTerm怎么用?PHP Term::isValidTerm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Term
的用法示例。
在下文中一共展示了Term::isValidTerm方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute(CommandContext $context)
{
if (!UserStatus::isAdmin() || !Current_User::allow('hms', 'edit_terms')) {
PHPWS_Core::initModClass('hms', 'exception/PermissionException.php');
throw new PermissionException('You do not have permission to edit terms.');
}
$successCmd = CommandFactory::getCommand('ShowEditTerm');
$errorCmd = CommandFactory::getCommand('ShowCreateTerm');
$year = $context->get('year_drop');
$sem = $context->get('term_drop');
if (!isset($year) || is_null($year) || empty($year)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a year.');
$errorCmd->redirect();
}
if (!isset($sem) || is_null($sem) || empty($sem)) {
NQ::simple('hms', hms\NotificationView::ERROR, 'You must provide a semester.');
$errorCmd->redirect();
}
// Check to see if the specified term already exists
if (!Term::isValidTerm($year . $sem)) {
$term = new Term(NULL);
$term->setTerm($year . $sem);
$term->setBannerQueue(1);
try {
$term->save();
} catch (DatabaseException $e) {
NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error saving the term. Please try again or contact ESS.');
$errorCmd->redirect();
}
} else {
$term = new Term($year . $sem);
// The term already exists, make sure there are no halls for this term
$db = new PHPWS_DB('hms_residence_hall');
$db->addWhere('term', $term->getTerm());
$num = $db->count();
if (!is_null($num) && $num > 0) {
NQ::simple('hms', hms\NotificationView::ERROR, 'One or more halls already exist for this term, so nothing can be copied.');
$errorCmd->redirect();
}
}
$text = Term::toString($term->getTerm());
$copy = $context->get('copy_pick');
$copyAssignments = false;
$copyRoles = false;
// If you want to copy roles and/or assignments
// you must also copy the hall structure.
if (isset($copy['struct'])) {
// Copy hall structure
if (isset($copy['assign'])) {
// Copy assignments.
$copyAssignments = true;
}
if (isset($copy['role'])) {
// Copy roles.
$copyRoles = true;
}
} else {
// either $copy == 'nothing', or the view didn't specify... either way, we're done
NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully.");
$successCmd->redirect();
}
# Figure out which term we're copying from, if there isn't one then use the "current" term.
$fromTerm = $context->get('from_term');
if (is_null($fromTerm)) {
$fromTerm = Term::getCurrentTerm();
}
PHPWS_Core::initModClass('hms', 'HMS_Residence_Hall.php');
PHPWS_Core::initModClass('hms', 'HousingApplication.php');
$db = new PHPWS_DB();
try {
$db->query('BEGIN');
# Get the halls from the current term
$halls = HMS_Residence_Hall::get_halls($fromTerm);
set_time_limit(36000);
foreach ($halls as $hall) {
$hall->copy($term->getTerm(), $copyAssignments, $copyRoles);
}
$db->query('COMMIT');
} catch (Exception $e) {
$db->query('ROLLBACK');
PHPWS_Error::log(print_r($e, true), 'hms');
NQ::simple('hms', hms\NotificationView::ERROR, 'There was an error copying the hall structure and/or assignments. The term was created, but nothing was copied.');
$errorCmd->redirect();
}
if ($copyAssignments) {
NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully. The hall structure and assignments were copied successfully.");
} else {
NQ::simple('hms', hms\NotificationView::SUCCESS, "{$text} term created successfully and hall structure copied successfully.");
}
Term::setSelectedTerm($term->getTerm());
$successCmd->redirect();
}
示例2: execute
public function execute(CommandContext $context)
{
$currentTerm = Term::getCurrentTerm();
$username = UserStatus::getUsername();
# Create a contact form command, redirect to it in case of error.
$contactCmd = CommandFactory::getCommand('ShowContactForm');
//TODO add try catch blocks here for StudentNotFound exception
$student = StudentFactory::getStudentByUsername($username, $currentTerm);
$applicationTerm = $student->getApplicationTerm();
// In case this is a new freshmen, they'll likely have no student type in the "current" term.
// So, instead, we need to lookup the student in their application term.
if ($applicationTerm > $currentTerm) {
$student = StudentFactory::getStudentByUsername($username, $applicationTerm);
}
$studentType = $student->getType();
$studentClass = $student->getClass();
$dob = $student->getDob();
# Check for banner errors in any of these calls
if (empty($applicationTerm) || empty($studentType) || empty($studentClass) || empty($dob) || is_null($dob)) {
# TODO: HMS_Mail here
PHPWS_Error::log('Initial banner lookup failed', 'hms', 'show_welcome_screen', "username: " . UserStatus::getUsername());
$badDataCmd = CommandFactory::getCommand('ShowBadBannerData');
$badDataCmd->redirect();
}
# Recreate the student object using the student's application term
$student = StudentFactory::getStudentByUsername($username, $applicationTerm);
# Check for an assignment in the current term. So far, this only matters for type 'Z' (readmit) students
$assignment = HMS_Assignment::checkForAssignment($username, $currentTerm);
/******************************************
* Sort returning students (lottery) from *
* freshmen (first-time application) *
******************************************/
# Check application term for past or future
if ($applicationTerm <= $currentTerm || $studentType == TYPE_READMIT && $assignment === TRUE) {
/**************
* Continuing *
**************/
# Application term is in the past
/*
* There's an exception above for type 'Z' (readmit) students.
* Their application terms will be in the past. They're considered continuing if they're
* already assigned. Otherwise, (not assigned) they're considered freshmen
*/
# Redirect to the returning student menu
$cmd = CommandFactory::getCommand('ShowReturningStudentMenu');
$cmd->redirect();
} else {
if ($applicationTerm > $currentTerm || $studentType == TYPE_READMIT) {
/**
* Exception for type 'Z' (readmit) students.
* Their application term is in the past, but they should be treated as freshmen/transfer
*/
/**
* This is somehwat of a hack for type 'Z' (readmit) students.
* This code sets the student's application term to the term after the current term, since type Z students.
* This makes *everything* else work right.
*/
if ($studentType == TYPE_READMIT) {
$applicationTerm = Term::getNextTerm(Term::getCurrentTerm());
//TODO find a way around this, because this doesn't work
$_SESSION['application_term'] = $application_term;
}
/*********************
* Incoming Freshmen *
*********************/
# Application term is in the future
# Check the student type, must be freshmen, transfer, readmit, or non-degree
/** Commenting this out since we have freshmen students with future application terms with student types of 'C'
if(!$student->isInternational() && $studentType != TYPE_FRESHMEN && $studentType != TYPE_TRANSFER && $studentType != TYPE_RETURNING && $studentType != TYPE_READMIT && $studentType != TYPE_NONDEGREE){
# No idea what's going on here, send to a contact page
$contactCmd->redirect();
}
*/
# Make sure the user's application term exists in hms_term,
# otherwise give a "too early" message
if (!Term::isValidTerm($applicationTerm)) {
PHPWS_Core::initModClass('hms', 'WelcomeScreenViewInvalidTerm.php');
$view = new WelcomeScreenViewInvalidTerm($applicationTerm, $contactCmd);
$context->setContent($view->show());
return;
}
# Make sure the student doesn't already have an assignment on file for the current term
if (HMS_Assignment::checkForAssignment($username, $currentTerm)) {
# No idea what's going on here, send to a contact page
$contactCmd->redirect();
}
# Check to see if the user has an application on file already for every required term
# If so, forward to main menu
$requiredTerms = HousingApplication::checkAppliedForAllRequiredTerms($student);
if (count($requiredTerms) > 0) {
# Student is missing a required application, so redirect to the application form for that term
$appCmd = CommandFactory::getCommand('ShowHousingApplicationWelcome');
$appCmd->setTerm($requiredTerms[0]);
$appCmd->redirect();
} else {
$menuCmd = CommandFactory::getCommand('ShowFreshmenMainMenu');
$menuCmd->redirect();
}
}
}
//.........这里部分代码省略.........