Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Curriculum-Request
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tim Steiner
Curriculum-Request
Commits
360f8f52
Commit
360f8f52
authored
16 years ago
by
Tim Steiner
Browse files
Options
Downloads
Patches
Plain Diff
Throw an exception when a user tries to use an invalid subject code.
parent
e20e8fa8
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
application/modules/courses/models/CourseModel.php
+40
-0
40 additions, 0 deletions
application/modules/courses/models/CourseModel.php
with
40 additions
and
0 deletions
application/modules/courses/models/CourseModel.php
+
40
−
0
View file @
360f8f52
...
...
@@ -1527,6 +1527,10 @@ class Courses_CourseModel extends Unl_Model
public
function
setCourseCode
(
$subject
,
$courseNumber
,
$courseLetter
=
null
)
{
if
(
!
self
::
isSubjectValid
(
$subject
))
{
throw
new
Zend_Exception
(
'The subject code '
.
$subject
.
' is invalid.'
);
}
$homeIndex
=
null
;
foreach
(
$this
->
_data
[
'crosslistings'
]
as
$index
=>
$crosslisting
)
{
if
(
$crosslisting
[
'type'
]
==
'home listing'
)
{
...
...
@@ -1631,6 +1635,10 @@ class Courses_CourseModel extends Unl_Model
public
function
addCrosslisting
(
$type
,
$subject
,
$courseNumber
,
$courseLetter
)
{
if
(
!
self
::
isSubjectValid
(
$subject
))
{
throw
new
Zend_Exception
(
'The subject code '
.
$subject
.
' is invalid.'
);
}
$lowestId
=
min
(
array_keys
(
$this
->
_data
[
'crosslistings'
]));
if
(
!
(
$lowestId
<
0
))
{
$lowestId
=
0
;
...
...
@@ -1648,6 +1656,10 @@ class Courses_CourseModel extends Unl_Model
public
function
editCrosslisting
(
$id
,
$type
,
$subject
,
$courseNumber
,
$courseLetter
)
{
if
(
!
self
::
isSubjectValid
(
$subject
))
{
throw
new
Zend_Exception
(
'The subject code '
.
$subject
.
' is invalid.'
);
}
if
(
!
$this
->
_data
[
'crosslistings'
][
$id
])
{
throw
new
Exception
(
'Attempt to edit a non-existant crosslisting'
);
}
...
...
@@ -2149,5 +2161,33 @@ class Courses_CourseModel extends Unl_Model
}
return
true
;
}
static
$_subjectList
;
static
protected
function
_loadSubjectList
()
{
if
(
self
::
$_subjectList
)
{
return
self
::
$_subjectList
;
}
$db
=
Zend_Registry
::
get
(
'db'
);
$select
=
new
Zend_Db_Select
(
$db
);
$select
->
from
(
'creqSubjects'
,
array
(
'name'
));
$records
=
$select
->
query
()
->
fetchAll
();
self
::
$_subjectList
=
array
();
foreach
(
$records
as
$record
)
{
self
::
$_subjectList
[]
=
$record
[
'name'
];
}
return
self
::
$_subjectList
;
}
static
public
function
isSubjectValid
(
$subject
)
{
self
::
_loadSubjectList
();
return
in_array
(
$subject
,
self
::
$_subjectList
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment