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
17 # ---- PUBLIC INTERFACE --------------------------------------------------
18
23 public function __construct($FieldId = NULL)
24 {
25 # set up item factory base class
26 parent::__construct("Classification", "Classifications",
27 "ClassificationId", "ClassificationName", FALSE,
28 ($FieldId ? "FieldId = ".intval($FieldId) : NULL));
29 $this->FieldId = (!is_null($FieldId)) ? intval($FieldId) : NULL;
30 }
31
37 public function GetChildIds($ClassId)
38 {
39 static $DB;
40
41 # retrieve IDs of all children
42 if (!isset($DB)) { $DB = new Database(); }
43 $DB->Query("SELECT ClassificationId FROM Classifications"
44 ." WHERE ParentId = ".intval($ClassId));
45 $ChildIds = $DB->FetchColumn("ClassificationId");
46
47 # for each child
48 $Ids = $ChildIds;
49 foreach ($Ids as $Id)
50 {
51 # retrieve IDs of any children of child
52 $ChildChildIds = $this->GetChildIds($Id);
53
54 # add retrieved IDs to child ID list
55 $ChildIds = array_merge($ChildIds, $ChildChildIds);
56 }
57
58 # return child ID list to caller
59 return $ChildIds;
60 }
61
65 public function RecalculateAllResourceCounts()
66 {
67 # queue a task to recalculate the resource counts for each
68 # classification
69 foreach ($this->GetItemIds() as $Id)
70 {
71 $GLOBALS["AF"]->QueueUniqueTask(
72 array(__CLASS__, "RecalculateResourceCount"),
73 array(intval($Id)),
74 ApplicationFramework::PRIORITY_BACKGROUND,
75 "Recalculate the resource counts for a classification");
76 }
77 }
78
88 public function FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5,
89 $IdExclusions=array(), $ValueExclusions=array() )
90 {
91 # return no results if empty search string passed in
92 if (!strlen(trim($SearchString))) { return array(); }
93
94 $IdExclusionSql = (count($IdExclusions) >0) ?
95 "AND ClassificationId NOT IN ("
96 . implode(',', array_map('intval', $IdExclusions) ) . ")" :
97 "" ;
98
99 $ValueExclusionSql = (count($ValueExclusions) > 0)
100 ? "AND ClassificationName NOT IN ("
101 .implode(',', array_map(
102 function($v){ return "'".addslashes($v)."'"; },
103 $ValueExclusions) ).")"
104 : "";
105
106 # mark all search elements as required
107 $SearchString = preg_replace("%\S+%", "+\$0", $SearchString);
108
109 $QueryString =
110 "SELECT ClassificationId, ClassificationName"
111 ." FROM Classifications "
112 ."WHERE FieldId=".$this->FieldId
113 ." AND LastAssigned IS NOT NULL"
114 ." AND MATCH(ClassificationName) AGAINST ('"
115 .addslashes(trim($SearchString))."' IN BOOLEAN MODE)"
116 ." ".$IdExclusionSql
117 ." ".$ValueExclusionSql
118 ." ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
119
120 $this->DB->Query($QueryString);
121
122 $Names = $this->DB->FetchColumn("ClassificationName", "ClassificationId");
123
124 return $Names;
125
126 }
133 public static function RecalculateResourceCount($Id)
134 {
135 $Classification = new Classification($Id);
136
137 # only recalculate the counts if the classification is valid
138 if ($Classification->Status() == Classification::CLASSSTAT_OK)
139 {
140 $Classification->RecalcResourceCount();
141 }
142 }
143
144 # ---- PRIVATE INTERFACE -------------------------------------------------
145
146 private $FieldId;
147 }
ClassificationFactory\RecalculateResourceCount
static RecalculateResourceCount($Id)
Callback to recalculate the resource count for a single classification by its ID. ...
Definition: ClassificationFactory.php:133
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
ClassificationFactory\GetChildIds
GetChildIds($ClassId)
Get IDs of all children of specified classification.
Definition: ClassificationFactory.php:37
ClassificationFactory\__construct
__construct($FieldId=NULL)
Class constructor.
Definition: ClassificationFactory.php:23
ClassificationFactory\FindMatchingRecentlyUsedValues
FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5, $IdExclusions=array(), $ValueExclusions=array())
Retrieve recently used items matching a search string.
Definition: ClassificationFactory.php:88
ItemFactory\$DB
$DB
Definition: ItemFactory.php:927
PHP
PHP
Definition: RSSClient--Test.php:12
ClassificationFactory\RecalculateAllResourceCounts
RecalculateAllResourceCounts()
Queue tasks to recalculate resource counts for all classifications.
Definition: ClassificationFactory.php:65
Classification\CLASSSTAT_OK
const CLASSSTAT_OK
Status code indicating operation completed successfully.
Definition: Classification.php:19
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:233