CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Qualifier.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: Qualifier.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2012-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
10 class Qualifier
11 {
12
13 # ---- PUBLIC INTERFACE --------------------------------------------------
14
18 const STATUS_OK = 0;
19
23 const STATUS_DOES_NOT_EXIST = 1;
24
30 public function __construct($QualifierId = NULL)
31 {
32 $this->DB = new Database();
33
34 # assume the qualifier operations will be successful
35 $this->Status = self::STATUS_OK;
36
37 # no ID given
38 if (func_num_args() == 0)
39 {
40 # determine next qualifier ID
41 $HighestId = $this->DB->Query("
42 SELECT QualifierId FROM Qualifiers
43 ORDER BY QualifierId DESC
44 LIMIT 1",
45 "QualifierId");
46 $this->Id = $HighestId > 0 ? $HighestId + 1 : 1;
47
48 # add record to database with that ID
49 $this->DB->Query("
50 INSERT INTO Qualifiers
51 SET QualifierId = ".addslashes($this->Id));
52 }
53
54 # if ID supplied
55 else if (!is_null($QualifierId))
56 {
57 $this->Id = intval($QualifierId);
58
59 # attempt to load qualifier info from database
60 $this->DB->Query("
61 SELECT * FROM Qualifiers
62 WHERE QualifierId = '".addslashes($this->Id)."'");
63
64 # if the qualifier was found
65 if ($this->DB->NumRowsSelected() > 0)
66 {
67 # set attributes to values returned by database
68 $this->DBFields = $this->DB->FetchRow();
69 }
70
71 # the qualifier was not found
72 else
73 {
74 $this->Status = self::STATUS_DOES_NOT_EXIST;
75 }
76 }
77
78 # null given
79 else
80 {
81 $this->Status = self::STATUS_DOES_NOT_EXIST;
82 }
83 }
84
89 public function Status()
90 {
91 return $this->Status;
92 }
93
98 public function Delete()
99 {
100 # do not try deleting a qualifier with a bad status
101 if ($this->Status != self::STATUS_OK)
102 {
103 return;
104 }
105
106 # delete record from database
107 $this->DB->Query("
108 DELETE FROM Qualifiers
109 WHERE QualifierId = ".addslashes($this->Id));
110
111 # update status
112 $this->Status = self::STATUS_DOES_NOT_EXIST;
113 }
114
119 public function Id()
120 {
121 return $this->Id;
122 }
123
129 public function Name($NewValue=DB_NOVALUE)
130 {
131 return $this->UpdateValue("QualifierName", $NewValue);
132 }
133
139 public function NSpace($NewValue=DB_NOVALUE)
140 {
141 return $this->UpdateValue("QualifierNamespace", $NewValue);
142 }
143
149 public function Url($NewValue=DB_NOVALUE)
150 {
151 return $this->UpdateValue("QualifierUrl", $NewValue);
152 }
153
154 # ---- PRIVATE INTERFACE -------------------------------------------------
155
160 protected $Id;
161
166 protected $Status;
167
172 protected $DB;
173
178 protected $DBFields;
179
186 protected function UpdateValue($FieldName, $NewValue)
187 {
188 return $this->DB->UpdateValue(
189 "Qualifiers",
190 $FieldName,
191 $NewValue,
192 "QualifierId = '".addslashes($this->Id)."'",
193 $this->DBFields);
194 }
195 }
Qualifier\$DBFields
$DBFields
Cached qualifier data from the database.
Definition: Qualifier.php:178
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
Qualifier\Url
Url($NewValue=DB_NOVALUE)
Get or set the qualifier URL.
Definition: Qualifier.php:149
Qualifier\Status
Status()
Get the status of this qualifier.
Definition: Qualifier.php:89
Qualifier\UpdateValue
UpdateValue($FieldName, $NewValue)
Convenience method to supply parameters to Database::UpdateValue().
Definition: Qualifier.php:186
Qualifier
Definition: Qualifier.php:10
PHP
PHP
Definition: RSSClient--Test.php:12
DB_NOVALUE
const DB_NOVALUE
Definition: Database.php:1706
Qualifier\Id
Id()
Get the qualifier ID.
Definition: Qualifier.php:119
Qualifier\$DB
$DB
The database object.
Definition: Qualifier.php:172
Qualifier\$Id
$Id
The ID of the qualifier.
Definition: Qualifier.php:160
Qualifier\Name
Name($NewValue=DB_NOVALUE)
Get or set the qualifier name.
Definition: Qualifier.php:129
Qualifier\Delete
Delete()
Delete the qualifier if in a valid state.
Definition: Qualifier.php:98
Qualifier\__construct
__construct($QualifierId=NULL)
Load the qualifier with the given ID or create a new qualifier if no ID is given. ...
Definition: Qualifier.php:30
Qualifier\NSpace
NSpace($NewValue=DB_NOVALUE)
Get or set the qualifier namespace.
Definition: Qualifier.php:139
Qualifier\$Status
$Status
The status code of the qualifier.
Definition: Qualifier.php:166
Qualifier\STATUS_DOES_NOT_EXIST
const STATUS_DOES_NOT_EXIST
Status code used for a non-existent qualifier.
Definition: Qualifier.php:23
Qualifier\STATUS_OK
const STATUS_OK
Status code used for an okay, valid qualifier.
Definition: Qualifier.php:18