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  }
29 
35  function GetChildIds($ClassId)
36  {
37  static $DB;
38 
39  # retrieve IDs of all children
40  if (!isset($DB)) { $DB = new Database(); }
41  $DB->Query("SELECT ClassificationId FROM Classifications"
42  ." WHERE ParentId = ".intval($ClassId));
43  $ChildIds = $DB->FetchColumn("ClassificationId");
44 
45  # for each child
46  $Ids = $ChildIds;
47  foreach ($Ids as $Id)
48  {
49  # retrieve IDs of any children of child
50  $ChildChildIds = $this->GetChildIds($Id);
51 
52  # add retrieved IDs to child ID list
53  $ChildIds = array_merge($ChildIds, $ChildChildIds);
54  }
55 
56  # return child ID list to caller
57  return $ChildIds;
58  }
59 
63  public function RecalculateAllResourceCounts()
64  {
65  # queue a task to recalculate the resource counts for each
66  # classification
67  foreach ($this->GetItemIds() as $Id)
68  {
69  $GLOBALS["AF"]->QueueUniqueTask(
70  array(__CLASS__, "RecalculateResourceCount"),
71  array(intval($Id)),
73  "Recalculate the resource counts for a classification");
74  }
75  }
76 
83  public static function RecalculateResourceCount($Id)
84  {
85  $Classification = new Classification($Id);
86 
87  # only recalculate the counts if the classification is valid
88  if ($Classification->Status() == Classification::CLASSSTAT_OK)
89  {
90  $Classification->RecalcResourceCount();
91  }
92  }
93 
94  # ---- PRIVATE INTERFACE -------------------------------------------------
95 
96 }
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.
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 (&quot;Tree&quot;) 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.