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
16 # ---- PUBLIC INTERFACE --------------------------------------------------
17
22 public function __construct($FieldId = NULL)
23 {
24 # save field ID for our later use
25 $this->FieldId = $FieldId;
26
27 # set up item factory base class
28 parent::__construct("ControlledName", "ControlledNames",
29 "ControlledNameId", "ControlledName", FALSE,
30 ($FieldId ? "FieldId = ".intval($FieldId) : NULL));
31 }
32
38 public function GetUsageCount()
39 {
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",
46 "ResourceCount");
47 }
48
49
59 public function FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5,
60 $IdExclusions=array(), $ValueExclusions=array() )
61 {
62 # return no results if empty search string passed in
63 if (!strlen(trim($SearchString))) { return array(); }
64
65 $IdExclusionSql = (count($IdExclusions)>0)
66 ? "AND ControlledNameId NOT IN ("
67 .implode(',', array_map('intval', $IdExclusions)).")"
68 : "";
69
70 $ValueExclusionSql = (count($ValueExclusions)>0)
71 ? "AND ControlledName NOT IN ("
72 .implode(',', array_map(
73 function($v){ return "'".addslashes($v)."'"; },
74 $ValueExclusions) ).")"
75 : "";
76
77 # mark all search elements as required
78 $SearchString = preg_replace("%\S+%", "+\$0", $SearchString);
79
80 $QueryString =
81 "SELECT ControlledNameId, ControlledName FROM ControlledNames "
82 ."WHERE FieldId=".$this->FieldId
83 ." AND LastAssigned IS NOT NULL"
84 ." AND MATCH(ControlledName) AGAINST ('"
85 .addslashes(trim($SearchString))."' IN BOOLEAN MODE)"
86 ." ".$IdExclusionSql
87 ." ".$ValueExclusionSql
88 ." ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
89
90 $this->DB->Query($QueryString);
91
92 $Names = $this->DB->FetchColumn("ControlledName", "ControlledNameId");
93
94 return $Names;
95 }
96
97 # ---- PRIVATE INTERFACE -------------------------------------------------
98
99 private $FieldId;
100 }
ControlledNameFactory\__construct
__construct($FieldId=NULL)
Constructor for ControlledNameFactory class.
Definition: ControlledNameFactory.php:22
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:38
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:59