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/ 16 # ---- PUBLIC INTERFACE -------------------------------------------------- 24 # save field ID for our later use 25 $this->FieldId = $FieldId;
27 # set up item factory base class 28 parent::__construct(
"ControlledName",
"ControlledNames",
29 "ControlledNameId",
"ControlledName", FALSE,
30 ($FieldId ?
"FieldId = ".intval($FieldId) : NULL));
40 return $this->DB->Query(
41 "SELECT COUNT(DISTINCT RNI.ResourceId) AS ResourceCount" 42 .
" FROM ResourceNameInts RNI, ControlledNames CN" 43 .
" WHERE CN.FieldId = ".intval($this->FieldId)
44 .
" AND RNI.ControlledNameId = CN.ControlledNameId" 45 .
" 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).
"'"; },
73 $ValueExclusions) ).
")" 76 # mark all search elements as required 77 $SearchString = preg_replace(
"%\S+%",
"+\$0", $SearchString);
80 "SELECT ControlledNameId, ControlledName FROM ControlledNames " 81 .
"WHERE FieldId=".$this->FieldId
82 .
" AND LastAssigned IS NOT NULL" 83 .
" AND MATCH(ControlledName) AGAINST ('" 84 .addslashes(trim($SearchString)).
"' IN BOOLEAN MODE)" 86 .
" ".$ValueExclusionSql
87 .
" ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
89 $this->DB->Query($QueryString);
91 $Names = $this->DB->FetchColumn(
"ControlledName",
"ControlledNameId");
105 # escape special chars in the regex 106 $CNRegex = preg_quote($SearchString);
108 # replace * and space with wild cards 109 $CNRegex = str_replace(
"\\*",
".*.", $CNRegex);
110 $CNRegex = str_replace(
" ",
".*.", $CNRegex);
112 # add escaping for sql 113 $CNRegex = addslashes($CNRegex);
115 # construct and execute our SQL query 116 $Query =
"SELECT C.ControlledNameId AS ControlledNameId ".
117 "FROM ControlledNames AS C LEFT JOIN VariantNames AS V ON ".
118 "C.ControlledNameId = V.ControlledNameId WHERE (".
119 "ControlledName REGEXP \"".$CNRegex.
"\" OR ".
120 "VariantName REGEXP \"".$CNRegex.
"\") ".
121 "AND C.FieldId = ".$this->FieldId.
" ".
122 "ORDER BY ControlledName";
123 $this->DB->Query($Query);
125 # return the matching CNIDs 126 return $this->DB->FetchColumn(
"ControlledNameId");
129 # ---- 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 ...
ControlledNameSearch($SearchString)
Search for ControlledNames or variants that match a search string.
Common factory class for item manipulation.
FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5, $IdExclusions=array(), $ValueExclusions=array())
Retrieve recently used items matching a search string.