3 # FILE: ControlledName.php 5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2001-2016 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 17 # ---- PUBLIC INTERFACE -------------------------------------------------- 29 public static function Create($Term, $FieldId)
33 # check if this controlledname is already present 34 $DB->Query(
"SELECT * FROM ControlledNames".
35 " WHERE ControlledName = '".addslashes($Term).
36 "' AND FieldId = ".intval($FieldId));
37 if ($Row =
$DB->FetchRow())
39 $NameId = $Row[
"ControlledNameId"];
43 # add new controlled name 44 $DB->Query(
"INSERT INTO ControlledNames ".
45 "(FieldId, ControlledName) VALUES (".
46 intval($FieldId).
", '".addslashes($Term).
"')");
48 $NameId =
$DB->LastInsertId();
50 # instantiate new controlledname and return 68 $DB->Query(
"SELECT * FROM ControlledNames".
69 " WHERE ControlledName = '".addslashes($Term).
70 "' AND FieldId = ".intval($FieldId));
71 return $DB->NumRowsSelected();
82 return $this->
UpdateValue(
"ControlledName", $NewValue);
96 # unset any variant name attached if asked 97 if ($NewValue === FALSE)
99 $this->DB->Query(
"DELETE FROM VariantNames WHERE " 100 .
"ControlledNameId = ".$this->
Id);
101 $this->VNCache = NULL;
106 $this->VNCache = $NewValue;
108 # try to load variant name and update cache 109 $this->DB->Query(
"SELECT VariantName FROM VariantNames WHERE " 110 .
"ControlledNameId = ".$this->
Id);
112 # variant name exists so do an update 113 if ($this->DB->NumRowsSelected() > 0)
115 $this->DB->Query(
"UPDATE VariantNames SET VariantName = '" 116 .addslashes($NewValue).
"' WHERE ControlledNameId = " 119 # no variant name so do an insert 122 $this->DB->Query(
"INSERT INTO VariantNames ".
123 "(VariantName, ControlledNameId) VALUES ".
124 "('".addslashes($NewValue).
"', ".$this->
Id.
")");
128 # if variant name is not cached 129 else if (!isset($this->VNCache))
131 $this->VNCache = $this->DB->Query(
"SELECT VariantName FROM VariantNames".
132 " WHERE ControlledNameId = ".$this->
Id,
"VariantName");
135 return $this->VNCache;
155 return $this->
UpdateValue(
"QualifierId", $NewValue);
165 # if new qualifier supplied 168 # set new qualifier ID 171 # use new qualifier for return value 172 $Qualifier = $NewValue;
176 # if qualifier is available 180 # create qualifier object using stored ID 183 # if ID was zero and no name available for qualifieR 184 # (needed because some controlled name records in DB 185 # have 0 instead of NULL when no controlled name assigned) 186 # (NOTE: this is problematic if there is a qualifier with an 188 if ($this->
QualifierId() == 0 && !strlen($Qualifier->Name()))
190 # return NULL to indicate no qualifier 196 # return NULL to indicate no qualifier 201 # return qualifier to caller 215 # query for the controlled name 217 SELECT ControlledNameId FROM 218 ControlledNames WHERE FieldId='".addslashes($FieldId).
"' 219 AND ControlledName='".addslashes($ControlledName).
"'");
221 # return the controlled name IDs found, if any 222 return $Database->FetchColumn(
"ControlledNameId");
231 return $this->DB->Query(
"SELECT COUNT(*) AS Count FROM ".
232 "ResourceNameInts WHERE ControlledNameId = ".$this->
Id,
"Count");
242 "SELECT ResourceId FROM ResourceNameInts " 243 .
"WHERE ControlledNameId = ".$this->
Id);
245 return $this->DB->FetchColumn(
"ResourceId");
255 # Get a list of resources associated with the new name 256 $this->DB->Query(
"SELECT ResourceId FROM ResourceNameInts " 257 .
"WHERE ControlledNameId = ".intval($NewNameId));
258 $NewNameResources = array();
259 while ($Row = $this->DB->FetchRow())
261 $NewNameResources[$Row[
"ResourceId"]]=1;
264 # Get a list of resources associated with the old name 265 $this->DB->Query(
"SELECT ResourceId FROM ResourceNameInts " 266 .
"WHERE ControlledNameId = ".intval($this->
Id));
267 $OldNameResources = array();
268 while ($Row = $this->DB->FetchRow())
270 $OldNameResources[]= $Row[
"ResourceId"];
273 # Foreach of the old name resources, check to see if it's already 274 # associated with the new name. If not, associate it. 275 foreach ($OldNameResources as $ResourceId)
277 if (!isset($NewNameResources[$ResourceId]))
279 $this->DB->Query(
"INSERT INTO ResourceNameInts " 280 .
"(ResourceId, ControlledNameId) VALUES " 281 .
"(".intval($ResourceId).
",".intval($NewNameId).
")");
285 # Clear out all the associations to the old name 286 $this->DB->Query(
"DELETE FROM ResourceNameInts WHERE ControlledNameId = " 295 $this->DB->Query(
"UPDATE ControlledNames SET LastAssigned=NOW() " 296 .
"WHERE ControlledNameId=".intval($this->
Id));
305 public function Delete($DeleteIfHasResources = FALSE)
309 if ($DeleteIfHasResources || !$this->
InUse())
311 # delete this controlled name 314 # delete associated variant name 315 $DB->Query(
"DELETE FROM VariantNames WHERE ControlledNameId=".
318 if ($DeleteIfHasResources)
320 $DB->Query(
"DELETE FROM ResourceNameInts WHERE ".
321 "ControlledNameId=".$this->
Id);
static ControlledNameExists($Term, $FieldId)
Check if there exists a controlledname with a ControlledName and FieldId same as given.
RemapTo($NewNameId)
Change all currently associated Resources to be instead associated with another ControlledName.
Name($NewValue=DB_NOVALUE)
Get or set the controlled vocabulary term.
GetAssociatedResources()
Get resourceIds associated with this ControlledName.
Delete($DeleteIfHasResources=FALSE)
Remove ControlledName (and any accompanying associations from database.
static SearchForControlledName($ControlledName, $FieldId)
Check if the given controlled name already exists for a given field ID.
static Create($Term, $FieldId)
Create a new empty ControlledName if it's not already present.
UpdateValue($ColumnName, $NewValue=DB_NOVALUE)
Convenience function to supply parameters to Database::UpdateValue().
SQL database abstraction object with smart query caching.
VariantName($NewValue=DB_NOVALUE)
Get, set, or clear any variant terms for this controlled name .
Metadata type representing non-hierarchical controlled vocabulary values.
Qualifier($NewValue=DB_NOVALUE)
Get or set the Qualifier associated with this term via object.
Common base class for persistent items store in database.
FieldId($NewValue=DB_NOVALUE)
Get or set the MetadataField associated with this term.
QualifierId($NewValue=DB_NOVALUE)
Get or set the Qualifier associated with this term via ID.
static ItemExists($Id)
Check whether an item exists with the specified ID.
InUse()
See if ControlledName is currently associated with any Resources.
UpdateLastAssigned()
Update the LastAssigned timestamp for this classification.