3 # FILE: ClassificationFactory.php
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/
16 # ---- PUBLIC INTERFACE --------------------------------------------------
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;
40 # retrieve IDs of all children
42 $DB->Query(
"SELECT ClassificationId FROM Classifications"
43 .
" WHERE ParentId = ".intval($ClassId));
44 $ChildIds =
$DB->FetchColumn(
"ClassificationId");
50 # retrieve IDs of any children of child
53 # add retrieved IDs to child ID list
54 $ChildIds = array_merge($ChildIds, $ChildChildIds);
57 # return child ID list to caller
66 # queue a task to recalculate the resource counts for each
70 $GLOBALS[
"AF"]->QueueUniqueTask(
71 array(__CLASS__,
"RecalculateResourceCount"),
74 "Recalculate the resource counts for a classification");
88 $IdExclusions=array(), $ValueExclusions=array() )
90 # return no results if empty search string passed in
91 if (!strlen(trim($SearchString))) {
return array(); }
93 $IdExclusionSql = (count($IdExclusions)>0) ?
94 "AND ClassificationId NOT IN ("
95 .implode(
',',array_map(
'intval',$IdExclusions)).
")" :
98 $ValueExclusionSql = (count($ValueExclusions)>0)?
99 "AND ClassificationName NOT IN ("
100 .implode(
',', array_map(
101 function($v){
return "'".addslashes($v).
"'"; }, $ValueExclusions) ).
")" :
105 "SELECT ClassificationId, ClassificationName FROM Classifications "
106 .
"WHERE FieldId=".$this->FieldId
107 .
" AND MATCH(ClassificationName) AGAINST ('".addslashes(trim($SearchString)).
"' IN BOOLEAN MODE)"
109 .
" ".$ValueExclusionSql
110 .
" ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
112 $this->DB->Query($QueryString);
114 $Names = $this->DB->FetchColumn(
"ClassificationName",
"ClassificationId");
129 # only recalculate the counts if the classification is valid
132 $Classification->RecalcResourceCount();
136 # ---- PRIVATE INTERFACE -------------------------------------------------
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.
FindMatchingRecentlyUsedValues($SearchString, $NumberOfResults=5, $IdExclusions=array(), $ValueExclusions=array())
Retrieve recently used items matching a search string.
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.
Factory for producing and manipulating Classification objects.
Metadata type representing hierarchical ("Tree") 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.
const PRIORITY_BACKGROUND
Lowest priority.