CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- 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 /*
78 * Retrieve recently used items matching a search string.
79 * @param string $SearchString String to match
80 * @param int $NumberOfResults Number of results to return. (OPTIONAL,
81 * defaults to 5)
82 * @param array $IdExclusions List of IDs of items to exclude.
83 * @param array $ValueExclusions List of names of items to exclude.
84 * @return array List of item names, with item IDs for index.
85 */
86 function FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5,
87 $IdExclusions=array(), $ValueExclusions=array() )
88 {
89 # return no results if empty search string passed in
90 if (!strlen(trim($SearchString))) { return array(); }
91
92 $IdExclusionSql = (count($IdExclusions) >0) ?
93 "AND ClassificationId NOT IN ("
94 . implode(',', array_map('intval', $IdExclusions) ) . ")" :
95 "" ;
96
97 $ValueExclusionSql = (count($ValueExclusions)>0)?
98 "AND ClassificationName NOT IN ("
99 .implode(',', array_map(
100 function($v){ return "'".addslashes($v)."'"; }, $ValueExclusions) ).")" :
101 "";
102
103 # mark all search elements as required
104 $SearchString = preg_replace("%\S+%", "+\$0", $SearchString);
105
106 $QueryString =
107 "SELECT ClassificationId, ClassificationName FROM Classifications "
108 ."WHERE FieldId=".$this->FieldId
109 ." AND LastAssigned IS NOT NULL"
110 ." AND MATCH(ClassificationName) AGAINST ('".addslashes(trim($SearchString))."' IN BOOLEAN MODE)"
111 ." ".$IdExclusionSql
112 ." ".$ValueExclusionSql
113 ." ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
114
115 $this->DB->Query($QueryString);
116
117 $Names = $this->DB->FetchColumn("ClassificationName", "ClassificationId");
118
119 return $Names;
120
121 }
128 public static function RecalculateResourceCount($Id)
129 {
130 $Classification = new Classification($Id);
131
132 # only recalculate the counts if the classification is valid
133 if ($Classification->Status() == Classification::CLASSSTAT_OK)
134 {
135 $Classification->RecalcResourceCount();
136 }
137 }
138
139 # ---- PRIVATE INTERFACE -------------------------------------------------
140
141 private $FieldId;
142 }
ClassificationFactory\RecalculateResourceCount
static RecalculateResourceCount($Id)
Callback to recalculate the resource count for a single classification by its ID. ...
Definition: ClassificationFactory.php:128
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())
Definition: ClassificationFactory.php:86
ItemFactory\$DB
$DB
Definition: ItemFactory.php:1053
PHP
PHP
Definition: RSSClient--Test.php:12
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