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"),
73 ApplicationFramework::PRIORITY_BACKGROUND,
74 "Recalculate the resource counts for a classification");
87 $IdExclusions=array(), $ValueExclusions=array() )
89 # return no results if empty search string passed in
90 if (!strlen(trim($SearchString))) {
return array(); }
92 $IdExclusionSql = (count($IdExclusions) >0) ?
93 "AND ClassificationId NOT IN ("
94 . implode(
',', array_map(
'intval', $IdExclusions) ) .
")" :
97 $ValueExclusionSql = (count($ValueExclusions)>0)?
98 "AND ClassificationName NOT IN ("
99 .implode(
',', array_map(
100 function($v){
return "'".addslashes($v).
"'"; }, $ValueExclusions) ).
")" :
103 # mark all search elements as required
104 $SearchString = preg_replace(
"%\S+%",
"+\$0", $SearchString);
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)"
112 .
" ".$ValueExclusionSql
113 .
" ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
115 $this->DB->Query($QueryString);
117 $Names = $this->DB->FetchColumn(
"ClassificationName",
"ClassificationId");
132 # only recalculate the counts if the classification is valid
135 $Classification->RecalcResourceCount();
139 # ---- 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())
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.