CWIS Developer Documentation

- Home
- Main Page
- Classes
- Files

- File List
- File Members

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
14 class ClassificationFactory extends ItemFactory {
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)),
73 ApplicationFramework::PRIORITY_BACKGROUND,
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 # mark all search elements as required
105 $SearchString = preg_replace("%\S+%", "+\$0", $SearchString);
106
107 $QueryString =
108 "SELECT ClassificationId, ClassificationName FROM Classifications "
109 ."WHERE FieldId=".$this->FieldId
110 ." AND LastAssigned IS NOT NULL"
111 ." AND MATCH(ClassificationName) AGAINST ('".addslashes(trim($SearchString))."' IN BOOLEAN MODE)"
112 ." ".$IdExclusionSql
113 ." ".$ValueExclusionSql
114 ." ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
115
116 $this->DB->Query($QueryString);
117
118 $Names = $this->DB->FetchColumn("ClassificationName", "ClassificationId");
119
120 return $Names;
121 }
122
129 public static function RecalculateResourceCount($Id)
130 {
131 $Classification = new Classification($Id);
132
133 # only recalculate the counts if the classification is valid
134 if ($Classification->Status() == Classification::CLASSSTAT_OK)
135 {
136 $Classification->RecalcResourceCount();
137 }
138 }
139
140 # ---- PRIVATE INTERFACE -------------------------------------------------
141
142 private $FieldId;
143 }
ClassificationFactory\RecalculateResourceCount
static RecalculateResourceCount($Id)
Callback to recalculate the resource count for a single classification by its ID. ...
Definition: ClassificationFactory.php:129
Database
SQL database abstraction object with smart query caching.
Definition: Axis--Database.php:22
ClassificationFactory\GetChildIds
GetChildIds($ClassId)
Get IDs of all children of specified classification.
Definition: ClassificationFactory.php:36
ClassificationFactory\FindMatchingRecentlyUsedValues
FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5, $IdExclusions=array(), $ValueExclusions=array())
Retrieve recently used items matching a search string.
Definition: ClassificationFactory.php:87
PHP
PHP
Definition: OAIClient.php:39
ItemFactory\$DB
$DB
Definition: ItemFactory.php:1053
ClassificationFactory\RecalculateAllResourceCounts
RecalculateAllResourceCounts()
Queue tasks to recalculate resource counts for all classifications.
Definition: ClassificationFactory.php:64
ClassificationFactory\ClassificationFactory
ClassificationFactory($FieldId=NULL)
Class constructor.
Definition: ClassificationFactory.php:22
Classification\CLASSSTAT_OK
const CLASSSTAT_OK
Status code indicating operation completed successfully.
Definition: Classification.php:18
ItemFactory
Common factory class for item manipulation.
Definition: ItemFactory.php:17
ClassificationFactory
Factory for producing and manipulating Classification objects.
Definition: ClassificationFactory.php:14
Classification
Metadata type representing hierarchical ("Tree") controlled vocabulary values.
Definition: Classification.php:13
ItemFactory\GetItemIds
GetItemIds($Condition=NULL, $IncludeTempItems=FALSE, $SortField=NULL, $SortAscending=TRUE)
Return array of item IDs.
Definition: ItemFactory.php:350
ItemFactory\ItemFactory
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
Definition: ItemFactory.php:36
ApplicationFramework\PRIORITY_BACKGROUND
const PRIORITY_BACKGROUND
Lowest priority.
Definition: ApplicationFramework.php:1772