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();
85 # unset any variant name attached if asked 86 if ($NewValue === FALSE)
88 $this->DB->Query(
"DELETE FROM VariantNames WHERE " 89 .
"ControlledNameId = ".$this->
Id);
90 $this->VNCache = NULL;
95 $this->VNCache = $NewValue;
97 # try to load variant name and update cache 98 $this->DB->Query(
"SELECT VariantName FROM VariantNames WHERE " 99 .
"ControlledNameId = ".$this->
Id);
101 # variant name exists so do an update 102 if ($this->DB->NumRowsSelected() > 0)
104 $this->DB->Query(
"UPDATE VariantNames SET VariantName = '" 105 .addslashes($NewValue).
"' WHERE ControlledNameId = " 108 # no variant name so do an insert 111 $this->DB->Query(
"INSERT INTO VariantNames ".
112 "(VariantName, ControlledNameId) VALUES ".
113 "('".addslashes($NewValue).
"', ".$this->
Id.
")");
117 # if variant name is not cached 118 else if (!isset($this->VNCache))
120 $this->VNCache = $this->DB->Query(
"SELECT VariantName FROM VariantNames".
121 " WHERE ControlledNameId = ".$this->
Id,
"VariantName");
124 return $this->VNCache;
144 return $this->
UpdateValue(
"QualifierId", $NewValue);
154 # if new qualifier supplied 157 # set new qualifier ID 160 # use new qualifier for return value 161 $Qualifier = $NewValue;
165 # if qualifier is available 169 # create qualifier object using stored ID 172 # if ID was zero and no name available for qualifieR 173 # (needed because some controlled name records in DB 174 # have 0 instead of NULL when no controlled name assigned) 175 # (NOTE: this is problematic if there is a qualifier with an 177 if ($this->
QualifierId() == 0 && !strlen($Qualifier->Name()))
179 # return NULL to indicate no qualifier 185 # return NULL to indicate no qualifier 190 # return qualifier to caller 204 # query for the controlled name 206 SELECT ControlledNameId FROM 207 ControlledNames WHERE FieldId='".addslashes($FieldId).
"' 208 AND ControlledName='".addslashes($ControlledName).
"'");
210 # return the controlled name IDs found, if any 211 return $Database->FetchColumn(
"ControlledNameId");
220 return $this->DB->Query(
"SELECT COUNT(*) AS Count FROM ".
221 "ResourceNameInts WHERE ControlledNameId = ".$this->
Id,
"Count");
231 "SELECT ResourceId FROM ResourceNameInts " 232 .
"WHERE ControlledNameId = ".$this->
Id);
234 return $this->DB->FetchColumn(
"ResourceId");
244 # Get a list of resources associated with the new name 245 $this->DB->Query(
"SELECT ResourceId FROM ResourceNameInts " 246 .
"WHERE ControlledNameId = ".intval($NewNameId));
247 $NewNameResources = array();
248 while ($Row = $this->DB->FetchRow())
250 $NewNameResources[$Row[
"ResourceId"]]=1;
253 # Get a list of resources associated with the old name 254 $this->DB->Query(
"SELECT ResourceId FROM ResourceNameInts " 255 .
"WHERE ControlledNameId = ".intval($this->
Id));
256 $OldNameResources = array();
257 while ($Row = $this->DB->FetchRow())
259 $OldNameResources[]= $Row[
"ResourceId"];
262 # Foreach of the old name resources, check to see if it's already 263 # associated with the new name. If not, associate it. 264 foreach ($OldNameResources as $ResourceId)
266 if (!isset($NewNameResources[$ResourceId]))
268 $this->DB->Query(
"INSERT INTO ResourceNameInts " 269 .
"(ResourceId, ControlledNameId) VALUES " 270 .
"(".intval($ResourceId).
",".intval($NewNameId).
")");
274 # Clear out all the associations to the old name 275 $this->DB->Query(
"DELETE FROM ResourceNameInts WHERE ControlledNameId = " 284 $this->DB->Query(
"UPDATE ControlledNames SET LastAssigned=NOW() " 285 .
"WHERE ControlledNameId=".intval($this->
Id));
294 public function Delete($DeleteIfHasResources = FALSE)
298 if ($DeleteIfHasResources || !$this->
InUse())
300 # delete this controlled name 303 # delete associated variant name 304 $DB->Query(
"DELETE FROM VariantNames WHERE ControlledNameId=".
307 if ($DeleteIfHasResources)
309 $DB->Query(
"DELETE FROM ResourceNameInts WHERE ".
310 "ControlledNameId=".$this->
Id);
323 parent::SetDatabaseAccessValues($ClassName);
324 self::$ItemNameColumnNames[$ClassName] =
"ControlledName";
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.
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.
static SetDatabaseAccessValues($ClassName)
Set the database access values (table name, ID column name, name column name) for specified class...
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.