3 # FILE: ControlledNameFactory.php
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2011-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
15 # ---- PUBLIC INTERFACE --------------------------------------------------
23 # save field ID for our later use
24 $this->FieldId = $FieldId;
26 # set up item factory base class
27 $this->
ItemFactory(
"ControlledName",
"ControlledNames",
28 "ControlledNameId",
"ControlledName", FALSE,
29 ($FieldId ?
"FieldId = ".intval($FieldId) : NULL));
39 return $this->DB->Query(
40 "SELECT COUNT(DISTINCT RNI.ResourceId) AS ResourceCount"
41 .
" FROM ResourceNameInts RNI, ControlledNames CN"
42 .
" WHERE CN.FieldId = ".intval($this->FieldId)
43 .
" AND RNI.ControlledNameId = CN.ControlledNameId"
44 .
" AND RNI.ResourceId >= 0",
59 $IdExclusions=array(), $ValueExclusions=array() )
61 # return no results if empty search string passed in
62 if (!strlen(trim($SearchString))) {
return array(); }
64 $IdExclusionSql = (count($IdExclusions)>0) ?
65 "AND ControlledNameId NOT IN ("
66 .implode(
',',array_map(
'intval',$IdExclusions)).
")" :
69 $ValueExclusionSql = (count($ValueExclusions)>0)?
70 "AND ControlledName NOT IN ("
71 .implode(
',', array_map(
72 function($v){
return "'".addslashes($v).
"'"; }, $ValueExclusions) ).
")" :
75 # mark all search elements as required
76 $SearchString = preg_replace(
"%\S+%",
"+\$0", $SearchString);
79 "SELECT ControlledNameId, ControlledName FROM ControlledNames "
80 .
"WHERE FieldId=".$this->FieldId
81 .
" AND LastAssigned IS NOT NULL"
82 .
" AND MATCH(ControlledName) AGAINST ('".addslashes(trim($SearchString)).
"' IN BOOLEAN MODE)"
84 .
" ".$ValueExclusionSql
85 .
" ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
87 $this->DB->Query($QueryString);
89 $Names = $this->DB->FetchColumn(
"ControlledName",
"ControlledNameId");
94 # ---- PRIVATE INTERFACE -------------------------------------------------
__construct($FieldId=NULL)
Constructor for ControlledNameFactory class.
Factory for manipulating ControlledName objects.
GetUsageCount()
Determine how many resources have controlled names (associated with this metadata field) assigned to ...
Common factory class for item manipulation.
FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5, $IdExclusions=array(), $ValueExclusions=array())
Retrieve recently used items matching a search string.
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.