CWIS Developer Documentation
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 
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  $QueryString =
76  "SELECT ControlledNameId, ControlledName FROM ControlledNames "
77  ."WHERE FieldId=".$this->FieldId
78  ." AND MATCH(ControlledName) AGAINST ('".addslashes(trim($SearchString))."' IN BOOLEAN MODE)"
79  ." ".$IdExclusionSql
80  ." ".$ValueExclusionSql
81  ." ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
82 
83  $this->DB->Query($QueryString);
84 
85  $Names = $this->DB->FetchColumn("ControlledName", "ControlledNameId");
86 
87  return $Names;
88  }
89 
90  # ---- PRIVATE INTERFACE -------------------------------------------------
91 
92  private $FieldId;
93 }
__construct($FieldId=NULL)
Constructor for ControlledNameFactory class.
PHP
Definition: OAIClient.php:39
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.
Definition: ItemFactory.php:17
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.
Definition: ItemFactory.php:36