CWIS Developer Documentation
ClassificationFactory.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: ClassificationFactory.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2004-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9 
15 
16  # ---- PUBLIC INTERFACE --------------------------------------------------
17 
22  function ClassificationFactory($FieldId = NULL)
23  {
24  # set up item factory base class
25  $this->ItemFactory("Classification", "Classifications",
26  "ClassificationId", "ClassificationName", FALSE,
27  ($FieldId ? "FieldId = ".intval($FieldId) : NULL));
28  $this->FieldId = (!is_null($FieldId)) ? intval($FieldId) : NULL;
29  }
30 
36  function GetChildIds($ClassId)
37  {
38  static $DB;
39 
40  # retrieve IDs of all children
41  if (!isset($DB)) { $DB = new Database(); }
42  $DB->Query("SELECT ClassificationId FROM Classifications"
43  ." WHERE ParentId = ".intval($ClassId));
44  $ChildIds = $DB->FetchColumn("ClassificationId");
45 
46  # for each child
47  $Ids = $ChildIds;
48  foreach ($Ids as $Id)
49  {
50  # retrieve IDs of any children of child
51  $ChildChildIds = $this->GetChildIds($Id);
52 
53  # add retrieved IDs to child ID list
54  $ChildIds = array_merge($ChildIds, $ChildChildIds);
55  }
56 
57  # return child ID list to caller
58  return $ChildIds;
59  }
60 
64  public function RecalculateAllResourceCounts()
65  {
66  # queue a task to recalculate the resource counts for each
67  # classification
68  foreach ($this->GetItemIds() as $Id)
69  {
70  $GLOBALS["AF"]->QueueUniqueTask(
71  array(__CLASS__, "RecalculateResourceCount"),
72  array(intval($Id)),
74  "Recalculate the resource counts for a classification");
75  }
76  }
77 
87  function FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5,
88  $IdExclusions=array(), $ValueExclusions=array() )
89  {
90  # return no results if empty search string passed in
91  if (!strlen(trim($SearchString))) { return array(); }
92 
93  $IdExclusionSql = (count($IdExclusions)>0) ?
94  "AND ClassificationId NOT IN ("
95  .implode(',',array_map('intval',$IdExclusions)).")" :
96  "";
97 
98  $ValueExclusionSql = (count($ValueExclusions)>0)?
99  "AND ClassificationName NOT IN ("
100  .implode(',', array_map(
101  function($v){ return "'".addslashes($v)."'"; }, $ValueExclusions) ).")" :
102  "";
103 
104  $QueryString =
105  "SELECT ClassificationId, ClassificationName FROM Classifications "
106  ."WHERE FieldId=".$this->FieldId
107  ." AND MATCH(ClassificationName) AGAINST ('".addslashes(trim($SearchString))."' IN BOOLEAN MODE)"
108  ." ".$IdExclusionSql
109  ." ".$ValueExclusionSql
110  ." ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
111 
112  $this->DB->Query($QueryString);
113 
114  $Names = $this->DB->FetchColumn("ClassificationName", "ClassificationId");
115 
116  return $Names;
117  }
118 
125  public static function RecalculateResourceCount($Id)
126  {
127  $Classification = new Classification($Id);
128 
129  # only recalculate the counts if the classification is valid
130  if ($Classification->Status() == Classification::CLASSSTAT_OK)
131  {
132  $Classification->RecalcResourceCount();
133  }
134  }
135 
136  # ---- PRIVATE INTERFACE -------------------------------------------------
137 
138  private $FieldId;
139 }
static RecalculateResourceCount($Id)
Callback to recalculate the resource count for a single classification by its ID. ...
SQL database abstraction object with smart query caching.
GetChildIds($ClassId)
Get IDs of all children of specified classification.
FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5, $IdExclusions=array(), $ValueExclusions=array())
Retrieve recently used items matching a search string.
PHP
Definition: OAIClient.php:39
RecalculateAllResourceCounts()
Queue tasks to recalculate resource counts for all classifications.
ClassificationFactory($FieldId=NULL)
Class constructor.
const CLASSSTAT_OK
Status code indicating operation completed successfully.
Common factory class for item manipulation.
Definition: ItemFactory.php:17
Factory for producing and manipulating Classification objects.
Metadata type representing hierarchical ("Tree") controlled vocabulary values.
GetItemIds($Condition=NULL, $IncludeTempItems=FALSE, $SortField=NULL, $SortAscending=TRUE)
Return array of item IDs.
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
Definition: ItemFactory.php:36
const PRIORITY_BACKGROUND
Lowest priority.