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 LastAssigned IS NOT NULL"
113 .(($this->FieldId !== NULL) ? " AND FieldId = "
114 .intval($this->FieldId) : "")
115 ." AND MATCH(ClassificationName) AGAINST ('"
116 .addslashes(trim($SearchString))."' IN BOOLEAN MODE)"
117 ." ".$IdExclusionSql
118 ." ".$ValueExclusionSql
119 ." ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
120
121 $this->DB->Query($QueryString);
122
123 $Names = $this->DB->FetchColumn("ClassificationName", "ClassificationId");
124
125 return $Names;
126
127 }
134 public static function RecalculateResourceCount($Id)
135 {
136 # only recalculate the counts if the classification appears valid
137 try
138 {
139 $Classification = new Classification($Id);
140 }
141 catch (Exception $e)
142 {
143 return;
144 }
145
146 $Classification->RecalcResourceCount();
147 }
148
149 # ---- PRIVATE INTERFACE -------------------------------------------------
150
151 private $FieldId;
152 }
ClassificationFactory\RecalculateResourceCount
static RecalculateResourceCount($Id)
Callback to recalculate the resource count for a single classification by its ID. ...
Definition: ClassificationFactory.php:134
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
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