CWIS Developer Documentation
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 Internet Scout Project
7 # http://scout.wisc.edu/
8 #
9 
10 class Qualifier
11 {
12 
13  # ---- PUBLIC INTERFACE --------------------------------------------------
14 
18  const STATUS_OK = 0;
19 
24 
31  public function Qualifier($QualifierId = NULL)
32  {
33  $this->DB = new Database();
34 
35  # assume the qualifier operations will be successful
36  $this->Status = self::STATUS_OK;
37 
38  # no ID given
39  if (func_num_args() == 0)
40  {
41  # determine next qualifier ID
42  $HighestId = $this->DB->Query("
43  SELECT QualifierId FROM Qualifiers
44  ORDER BY QualifierId DESC
45  LIMIT 1",
46  "QualifierId");
47  $this->Id = $HighestId > 0 ? $HighestId + 1 : 1;
48 
49  # add record to database with that ID
50  $this->DB->Query("
51  INSERT INTO Qualifiers
52  SET QualifierId = ".addslashes($this->Id));
53  }
54 
55  # if ID supplied
56  else if (!is_null($QualifierId))
57  {
58  $this->Id = intval($QualifierId);
59 
60  # attempt to load qualifier info from database
61  $this->DB->Query("
62  SELECT * FROM Qualifiers
63  WHERE QualifierId = '".addslashes($this->Id)."'");
64 
65  # if the qualifier was found
66  if ($this->DB->NumRowsSelected() > 0)
67  {
68  # set attributes to values returned by database
69  $this->DBFields = $this->DB->FetchRow();
70  }
71 
72  # the qualifier was not found
73  else
74  {
75  $this->Status = self::STATUS_DOES_NOT_EXIST;
76  }
77  }
78  }
79 
84  public function Status()
85  {
86  return $this->Status;
87  }
88 
93  public function Delete()
94  {
95  # do not try deleting a qualifier with a bad status
96  if ($this->Status != self::STATUS_OK)
97  {
98  return;
99  }
100 
101  # delete record from database
102  $this->DB->Query("
103  DELETE FROM Qualifiers
104  WHERE QualifierId = ".addslashes($this->Id));
105 
106  # update status
107  $this->Status = self::STATUS_DOES_NOT_EXIST;
108  }
109 
114  public function Id()
115  {
116  return $this->Id;
117  }
118 
124  public function Name($NewValue=DB_NOVALUE)
125  {
126  return $this->UpdateValue("QualifierName", $NewValue);
127  }
128 
134  public function NSpace($NewValue=DB_NOVALUE)
135  {
136  return $this->UpdateValue("QualifierNamespace", $NewValue);
137  }
138 
144  public function Url($NewValue=DB_NOVALUE)
145  {
146  return $this->UpdateValue("QualifierUrl", $NewValue);
147  }
148 
149  # ---- PRIVATE INTERFACE -------------------------------------------------
150 
154  protected $Id;
155 
159  protected $Status;
160 
164  protected $DB;
165 
169  protected $DBFields;
170 
177  protected function UpdateValue($FieldName, $NewValue)
178  {
179  return $this->DB->UpdateValue(
180  "Qualifiers",
181  $FieldName,
182  $NewValue,
183  "QualifierId = '".addslashes($this->Id)."'",
184  $this->DBFields);
185  }
186 
187 }