CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

ControlledNameFactory.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: ControlledNameFactory.php
4 #
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/
8 #
9
13 class ControlledNameFactory extends ItemFactory {
14
15 # ---- PUBLIC INTERFACE --------------------------------------------------
16
21 function __construct($FieldId = NULL)
22 {
23 # save field ID for our later use
24 $this->FieldId = $FieldId;
25
26 # set up item factory base class
27 $this->ItemFactory("ControlledName", "ControlledNames",
28 "ControlledNameId", "ControlledName", FALSE,
29 ($FieldId ? "FieldId = ".intval($FieldId) : NULL));
30 }
31
37 function GetUsageCount()
38 {
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",
45 "ResourceCount");
46 }
47
48
58 function FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5,
59 $IdExclusions=array(), $ValueExclusions=array() )
60 {
61 # return no results if empty search string passed in
62 if (!strlen(trim($SearchString))) { return array(); }
63
64 $IdExclusionSql = (count($IdExclusions)>0) ?
65 "AND ControlledNameId NOT IN ("
66 .implode(',',array_map('intval',$IdExclusions)).")" :
67 "";
68
69 $ValueExclusionSql = (count($ValueExclusions)>0)?
70 "AND ControlledName NOT IN ("
71 .implode(',', array_map(
72 function($v){ return "'".addslashes($v)."'"; }, $ValueExclusions) ).")" :
73 "";
74
75 # mark all search elements as required
76 $SearchString = preg_replace("%\S+%", "+\$0", $SearchString);
77
78 $QueryString =
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)"
83 ." ".$IdExclusionSql
84 ." ".$ValueExclusionSql
85 ." ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
86
87 $this->DB->Query($QueryString);
88
89 $Names = $this->DB->FetchColumn("ControlledName", "ControlledNameId");
90
91 return $Names;
92 }
93
94 # ---- PRIVATE INTERFACE -------------------------------------------------
95
96 private $FieldId;
97 }
ControlledNameFactory\__construct
__construct($FieldId=NULL)
Constructor for ControlledNameFactory class.
Definition: ControlledNameFactory.php:21
PHP
PHP
Definition: RSSClient--Test.php:12
ControlledNameFactory
Factory for manipulating ControlledName objects.
Definition: ControlledNameFactory.php:13
ControlledNameFactory\GetUsageCount
GetUsageCount()
Determine how many resources have controlled names (associated with this metadata field) assigned to ...
Definition: ControlledNameFactory.php:37
ItemFactory
Common factory class for item manipulation.
Definition: ItemFactory.php:17
ControlledNameFactory\FindMatchingRecentlyUsedValues
FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5, $IdExclusions=array(), $ValueExclusions=array())
Retrieve recently used items matching a search string.
Definition: ControlledNameFactory.php:58
ItemFactory\ItemFactory
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
Definition: ItemFactory.php:36