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/ 17 # ---- PUBLIC INTERFACE -------------------------------------------------- 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;
41 # retrieve IDs of all children 43 $DB->Query(
"SELECT ClassificationId FROM Classifications" 44 .
" WHERE ParentId = ".intval($ClassId));
45 $ChildIds =
$DB->FetchColumn(
"ClassificationId");
51 # retrieve IDs of any children of child 54 # add retrieved IDs to child ID list 55 $ChildIds = array_merge($ChildIds, $ChildChildIds);
58 # return child ID list to caller 67 # queue a task to recalculate the resource counts for each 71 $GLOBALS[
"AF"]->QueueUniqueTask(
72 array(__CLASS__,
"RecalculateResourceCount"),
74 ApplicationFramework::PRIORITY_BACKGROUND,
75 "Recalculate the resource counts for a classification");
89 $IdExclusions=array(), $ValueExclusions=array() )
91 # return no results if empty search string passed in 92 if (!strlen(trim($SearchString))) {
return array(); }
94 $IdExclusionSql = (count($IdExclusions) >0) ?
95 "AND ClassificationId NOT IN (" 96 . implode(
',', array_map(
'intval', $IdExclusions) ) .
")" :
99 $ValueExclusionSql = (count($ValueExclusions) > 0)
100 ?
"AND ClassificationName NOT IN (" 101 .implode(
',', array_map(
102 function($v){
return "'".addslashes($v).
"'"; },
103 $ValueExclusions) ).
")" 106 # mark all search elements as required 107 $SearchString = preg_replace(
"%\S+%",
"+\$0", $SearchString);
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)" 117 .
" ".$ValueExclusionSql
118 .
" ORDER BY LastAssigned DESC LIMIT ".$NumberOfResults;
120 $this->DB->Query($QueryString);
122 $Names = $this->DB->FetchColumn(
"ClassificationName",
"ClassificationId");
137 # only recalculate the counts if the classification is valid 140 $Classification->RecalcResourceCount();
144 # ---- 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.
__construct($FieldId=NULL)
Class constructor.
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.
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.