3 # FILE: ItemFactory.php
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2007-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
19 # ---- PUBLIC INTERFACE --------------------------------------------------
36 function ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName,
37 $ItemNameFieldName = NULL, $OrderOpsAllowed = FALSE, $SqlCondition = NULL)
39 # save item access names
40 $this->ItemClassName = $ItemClassName;
41 $this->ItemTableName = $ItemTableName;
42 $this->ItemIdFieldName = $ItemIdFieldName;
43 $this->ItemNameFieldName = $ItemNameFieldName;
45 # save flag indicating whether item type allows ordering operations
46 $this->OrderOpsAllowed = $OrderOpsAllowed;
50 $ItemTableName, $ItemIdFieldName);
54 # save database operation conditional
55 $this->SqlCondition = $SqlCondition;
57 # grab our own database handle
67 return $this->ItemClassName;
76 # if ID available in session variable
77 $SessionIndex = $this->ItemClassName.
"EditedIds";
78 if (isset($_SESSION[$SessionIndex]))
80 # look up value in session variable
81 $ItemId = $_SESSION[$SessionIndex][0];
85 # attempt to look up last temp item ID
88 # store it in session variable
89 $_SESSION[$SessionIndex] = array($ItemId);
92 # return ID (if any) to caller
102 # if edited ID array already stored for session
103 $SessionIndex = $this->ItemClassName.
"EditedIds";
104 if (isset($_SESSION[$SessionIndex]))
106 # prepend new value to array
107 array_unshift($_SESSION[$SessionIndex], $NewId);
111 # start with fresh array
112 $_SESSION[$SessionIndex] = array($NewId);
121 # if edited item IDs available in a session variable
122 $SessionIndex = $this->ItemClassName.
"EditedIds";
123 if (isset($_SESSION[$SessionIndex]))
125 # remove current item from edited item ID array
126 array_shift($_SESSION[$SessionIndex]);
128 # if no further edited items
129 if (count($_SESSION[$SessionIndex]) < 1)
131 # destroy session variable
132 unset($_SESSION[$SessionIndex]);
145 # if current edited item is temp item
147 if ($CurrentEditedItemId < 0)
149 # delete temp item from DB
150 if (method_exists($this->ItemClassName,
"Delete"))
152 $Item =
new $this->ItemClassName($CurrentEditedItemId);
157 $this->DB->Query(
"DELETE FROM ".$this->ItemTableName
158 .
" WHERE ".$this->ItemIdFieldName.
" = ".$CurrentEditedItemId);
162 # clear current edited item ID
175 # load array of stale items
176 $MinutesUntilStale = max($MinutesUntilStale, 1);
177 $this->DB->Query(
"SELECT ".$this->ItemIdFieldName.
" FROM ".$this->ItemTableName
178 .
" WHERE ".$this->ItemIdFieldName.
" < 0"
179 .
" AND DateLastModified < DATE_SUB(NOW(), "
180 .
" INTERVAL ".intval($MinutesUntilStale).
" MINUTE)"
181 .($this->SqlCondition ?
" AND ".$this->SqlCondition :
""));
182 $ItemIds = $this->DB->FetchColumn($this->ItemIdFieldName);
185 foreach ($ItemIds as $ItemId)
187 $Item =
new $this->ItemClassName($ItemId);
191 # report number of items deleted to caller
192 return count($ItemIds);
202 # retrieve ID of most recently modified temp item for this user
203 $ItemId = $this->DB->Query(
"SELECT ".$this->ItemIdFieldName
204 .
" FROM ".$this->ItemTableName
205 .
" WHERE LastModifiedById = '"
206 .$GLOBALS[
"User"]->Get(
"UserId").
"'"
207 .
" AND ".$this->ItemIdFieldName.
" < 0"
208 .($this->SqlCondition ?
" AND ".$this->SqlCondition :
"")
209 .
" ORDER BY ".$this->ItemIdFieldName.
" ASC"
211 $this->ItemIdFieldName);
213 # return item to caller (or NULL if none found)
224 # if no highest item ID found
226 if ($HighestItemId <= 0)
228 # start with item ID 1
233 # else use next ID available after highest
234 $ItemId = $HighestItemId + 1;
237 # return next ID to caller
250 # use class-wide condition if set
251 $ConditionString = ($this->SqlCondition && !$IgnoreSqlCondition)
252 ?
" WHERE ".$this->SqlCondition :
"";
254 # return highest item ID to caller
255 return $this->DB->Query(
"SELECT ".$this->ItemIdFieldName
256 .
" FROM ".$this->ItemTableName
258 .
" ORDER BY ".$this->ItemIdFieldName
260 $this->ItemIdFieldName);
269 $LowestItemId = $this->DB->Query(
"SELECT ".$this->ItemIdFieldName
270 .
" FROM ".$this->ItemTableName
271 .
" ORDER BY ".$this->ItemIdFieldName
273 $this->ItemIdFieldName);
274 if ($LowestItemId > 0)
280 $ItemId = $LowestItemId - 1;
295 # use condition if supplied
296 $ConditionString = ($Condition != NULL) ?
" WHERE ".$Condition :
"";
298 # if temp items are to be excluded
299 if (!$IncludeTempItems)
301 # if a condition was previously set
302 if (strlen($ConditionString))
304 # add in condition to exclude temp items
305 $ConditionString .=
" AND (".$this->ItemIdFieldName.
" >= 0)";
309 # use condition to exclude temp items
310 $ConditionString =
" WHERE ".$this->ItemIdFieldName.
" >= 0";
314 # add class-wide condition if set
315 if ($this->SqlCondition)
317 if (strlen($ConditionString))
319 $ConditionString .=
" AND ".$this->SqlCondition;
323 $ConditionString =
" WHERE ".$this->SqlCondition;
327 # retrieve item count
328 $Count = $this->DB->Query(
"SELECT COUNT(*) AS RecordCount"
329 .
" FROM ".$this->ItemTableName
333 # return count to caller
350 function GetItemIds($Condition = NULL, $IncludeTempItems = FALSE,
351 $SortField = NULL, $SortAscending = TRUE)
353 # if temp items are supposed to be included
354 if ($IncludeTempItems)
356 # condition is only as supplied
357 $ConditionString = ($Condition == NULL) ?
"" :
" WHERE ".$Condition;
361 # condition is non-negative IDs plus supplied condition
362 $ConditionString =
" WHERE ".$this->ItemIdFieldName.
" >= 0"
363 .(($Condition == NULL) ?
"" :
" AND ".$Condition);
366 # add class-wide condition if set
367 if ($this->SqlCondition)
369 if (strlen($ConditionString))
371 $ConditionString .=
" AND ".$this->SqlCondition;
375 $ConditionString =
" WHERE ".$this->SqlCondition;
379 # add sorting if specified
380 if ($SortField !== NULL)
382 $ConditionString .=
" ORDER BY `".addslashes($SortField).
"` "
383 .($SortAscending ?
"ASC" :
"DESC");
387 $this->DB->Query(
"SELECT ".$this->ItemIdFieldName
388 .
" FROM ".$this->ItemTableName
390 $ItemIds = $this->DB->FetchColumn($this->ItemIdFieldName);
392 # return IDs to caller
405 # set up SQL condition if supplied
406 $ConditionString = ($Condition == NULL) ?
"" :
" WHERE ".$Condition;
408 # add class-wide condition if set
409 if ($this->SqlCondition)
411 if (strlen($ConditionString))
413 $ConditionString .=
" AND ".$this->SqlCondition;
417 $ConditionString =
" WHERE ".$this->SqlCondition;
421 # return modification date for item most recently changed
422 return $this->DB->Query(
"SELECT MAX(DateLastModified) AS LastChangeDate"
423 .
" FROM ".$this->ItemTableName.$ConditionString,
435 return new $this->ItemClassName($ItemId);
447 $Condition = $IgnoreSqlCondition ?
""
448 : ($this->SqlCondition ?
" AND ".$this->SqlCondition :
"");
449 $ItemCount = $this->DB->Query(
"SELECT COUNT(*) AS ItemCount"
450 .
" FROM ".$this->ItemTableName
451 .
" WHERE ".$this->ItemIdFieldName.
" = ".intval($ItemId)
452 .$Condition,
"ItemCount");
453 return ($ItemCount > 0) ? TRUE : FALSE;
469 if ($ItemId === NULL)
471 # report error to caller
476 # load object and return to caller
477 return $this->
GetItem($ItemId);
490 # error out if this is an illegal operation for this item type
491 if ($this->ItemNameFieldName == NULL)
493 throw new Exception(
"Attempt to get item ID by name on item type"
494 .
"(".$this->ItemClassName.
") that has no name field specified.");
497 # query database for item ID
498 $Comparison = $IgnoreCase
499 ?
"LOWER(".$this->ItemNameFieldName.
") = '"
500 .addslashes(strtolower($Name)).
"'"
501 : $this->ItemNameFieldName.
" = '" .addslashes($Name).
"'";
502 $ItemId = $this->DB->Query(
"SELECT ".$this->ItemIdFieldName
503 .
" FROM ".$this->ItemTableName
504 .
" WHERE ".$Comparison
505 .($this->SqlCondition
506 ?
" AND ".$this->SqlCondition
508 $this->ItemIdFieldName);
510 # return ID or error indicator to caller
511 return ($ItemId === FALSE) ? NULL : $ItemId;
522 # error out if this is an illegal operation for this item type
523 if ($this->ItemNameFieldName == NULL)
525 throw new Exception(
"Attempt to get array of item names"
526 .
" on item type (".$this->ItemClassName.
") that has no"
527 .
" name field specified.");
530 # query database for item names
534 $Condition =
"WHERE ".$SqlCondition;
536 if ($this->SqlCondition)
538 if (strlen($Condition))
540 $Condition .=
" AND ".$this->SqlCondition;
544 $Condition =
" WHERE ".$this->SqlCondition;
547 $this->DB->Query(
"SELECT ".$this->ItemIdFieldName
548 .
", ".$this->ItemNameFieldName
549 .
" FROM ".$this->ItemTableName.
" "
551 .
" ORDER BY ".$this->ItemNameFieldName);
552 $Names = $this->DB->FetchColumn(
553 $this->ItemNameFieldName, $this->ItemIdFieldName);
555 # return item names to caller
569 foreach ($Ids as $Id)
592 $SqlCondition = NULL, $DisplaySize = 1, $SubmitOnChange = FALSE)
594 # retrieve requested fields
597 # if multiple selections are allowed
598 if ($DisplaySize > 1)
600 # begin multi-selection HTML option list
601 $Html =
"<select name=\"".htmlspecialchars($OptionListName).
"[]\""
602 .($SubmitOnChange ?
" onChange=\"submit()\"" :
"")
603 .
" multiple=\"multiple\" size=\"".$DisplaySize.
"\">\n";
607 # begin single-selection HTML option list
608 $Html =
"<select name=\"".htmlspecialchars($OptionListName).
"\""
609 .($SubmitOnChange ?
" onChange=\"submit()\"" :
"")
611 $Html .=
"<option value=\"-1\">--</option>\n";
614 # for each metadata field
615 foreach ($ItemNames as $Id => $Name)
617 # add entry for field to option list
618 $Html .=
"<option value=\"".$Id.
"\"";
619 if (($Id == $SelectedItemId)
620 || (is_array($SelectedItemId) && in_array($Id, $SelectedItemId)))
622 $Html .=
" selected";
624 $Html .=
">".htmlspecialchars($Name).
"</option>\n";
627 # end HTML option list
628 $Html .=
"</select>\n";
630 # return constructed HTML to caller
642 $Condition = $IgnoreCase
643 ?
"LOWER(".$this->ItemNameFieldName.
")"
644 .
" = '".addslashes(strtolower($Name)).
"'"
645 : $this->ItemNameFieldName.
" = '".addslashes($Name).
"'";
646 if ($this->SqlCondition)
648 $Condition .=
" AND ".$this->SqlCondition;
650 $NameCount = $this->DB->Query(
"SELECT COUNT(*) AS RecordCount FROM "
651 .$this->ItemTableName.
" WHERE ".$Condition,
"RecordCount");
652 return ($NameCount > 0) ? TRUE : FALSE;
672 $IncludeVariants = FALSE, $UseBooleanMode = TRUE, $Offset=0,
673 $IdExclusions = array(), $ValueExclusions=array())
675 # error out if this is an illegal operation for this item type
676 if ($this->ItemNameFieldName == NULL)
678 throw new Exception(
"Attempt to search for item names on item type"
679 .
"(".$this->ItemClassName.
") that has no name field specified.");
682 # return no results if empty search string passed in
683 if (!strlen(trim($SearchString))) {
return array(); }
685 # construct SQL query
687 $QueryString =
"SELECT ".$this->ItemIdFieldName.
",".$this->ItemNameFieldName
688 .
" FROM ".$this->ItemTableName.
" WHERE "
689 .$this->ConstructSqlConditionsForSearch(
690 $SearchString, $IncludeVariants, $UseBooleanMode, $IdExclusions,
694 $QueryString .=
" LIMIT ".intval($NumberOfResults).
" OFFSET "
697 # perform query and retrieve names and IDs of items found by query
698 $DB->Query($QueryString);
699 $Names =
$DB->FetchColumn($this->ItemNameFieldName, $this->ItemIdFieldName);
701 $Words = preg_split(
"/[\s]+/", trim($SearchString));
702 foreach ($Words as $Word)
704 $TgtWord = preg_replace(
"/[^a-zA-Z]/",
"", $Word);
705 if ($Word{0} ==
"-" && strlen($TgtWord) < $MinWordLen)
708 foreach ($Names as $Id => $Name)
710 if (! preg_match(
'/\b'.$TgtWord.
'/i', $Name))
712 $NewNames[$Id] = $Name;
719 # return names to caller
736 $UseBooleanMode = TRUE, $IdExclusions = array(), $ValueExclusions=array())
738 # return no results if empty search string passed in
739 if (!strlen(trim($SearchString))) {
return 0; }
741 # construct SQL query
743 $QueryString =
"SELECT COUNT(*) as ItemCount FROM "
744 .$this->ItemTableName.
" WHERE "
745 .$this->ConstructSqlConditionsForSearch(
746 $SearchString, $IncludeVariants, $UseBooleanMode, $IdExclusions,
749 # perform query and retrieve names and IDs of items found by query
750 $DB->Query($QueryString);
751 return intval(
$DB->FetchField(
"ItemCount"));
762 function AddItem($ItemName, $AdditionalValues = NULL)
764 # build initial database query for adding item
765 $Query =
"INSERT INTO ".$this->ItemTableName.
" SET `"
766 .$this->ItemNameFieldName.
"` = '".addslashes($ItemName).
"'";
768 # add any additional values to query
769 if ($AdditionalValues)
771 foreach ($AdditionalValues as $FieldName => $Value)
773 $Query .=
", `".$FieldName.
"` = '".addslashes($Value).
"'";
777 # add item to database
778 $this->DB->Query($Query);
780 # retrieve ID of new item
781 $Id = $this->DB->LastInsertId();
783 # return ID to caller
793 # delete item from database
794 $this->DB->Query(
"DELETE FROM ".$this->ItemTableName
795 .
" WHERE ".$this->ItemIdFieldName.
" = '".addslashes($ItemId).
"'");
799 # ---- order operations --------------------------------------------------
809 # condition is non-negative IDs (non-temp items) plus supplied condition
810 $NewCondition = $this->ItemIdFieldName.
" >= 0"
811 .($Condition ?
" AND ".$Condition :
"")
812 .($this->SqlCondition ?
" AND ".$this->SqlCondition :
"");
813 $this->OrderList->SqlCondition($NewCondition);
825 # error out if ordering operations are not allowed for this item type
826 if (!$this->OrderOpsAllowed)
828 throw new Exception(
"Attempt to perform order operation on item"
829 .
" type (".$this->ItemClassName.
") that does not support"
834 $this->OrderList->InsertBefore($TargetItem, $NewItem);
846 # error out if ordering operations are not allowed for this item type
847 if (!$this->OrderOpsAllowed)
849 throw new Exception(
"Attempt to perform order operation on item"
850 .
" type (".$this->ItemClassName.
") that does not support"
855 $this->OrderList->InsertAfter($TargetItem, $NewItem);
865 # error out if ordering operations are not allowed for this item type
866 if (!$this->OrderOpsAllowed)
868 throw new Exception(
"Attempt to perform order operation on item"
869 .
" type (".$this->ItemClassName.
") that does not support"
874 $this->OrderList->Prepend($Item);
884 # error out if ordering operations are not allowed for this item type
885 if (!$this->OrderOpsAllowed)
887 throw new Exception(
"Attempt to perform order operation on item"
888 .
" type (".$this->ItemClassName.
") that does not support"
893 $this->OrderList->Append($Item);
902 # error out if ordering operations are not allowed for this item type
903 if (!$this->OrderOpsAllowed)
905 throw new Exception(
"Attempt to perform order operation on item"
906 .
" type (".$this->ItemClassName.
") that does not support"
910 # retrieve list of IDs
911 return $this->OrderList->GetIds();
922 # error out if ordering operations are not allowed for this item type
923 if (!$this->OrderOpsAllowed)
925 throw new Exception(
"Attempt to perform order operation on item"
926 .
" type (".$this->ItemClassName.
") that does not support"
931 $this->OrderList->Remove($ItemId);
935 # ---- PRIVATE INTERFACE -------------------------------------------------
951 private function ConstructSqlConditionsForSearch(
952 $SearchString, $IncludeVariants = FALSE,
953 $UseBooleanMode = TRUE, $IdExclusions = array(), $ValueExclusions=array() )
957 # If the search string is valid but shorter than the minimum word length
958 # indexed by the FTS, just do a normal equality test instead of using
959 # the index. Otherwise, FTS away.
961 $MinWordLen =
$DB->Query(
962 "SHOW VARIABLES WHERE variable_name='ft_min_word_len'",
"Value");
963 if (strlen($SearchString) < $MinWordLen)
965 $QueryString .=
" ".$this->ItemNameFieldName.
"='".addslashes($SearchString).
"'";
967 else if ($UseBooleanMode)
969 # When we're in boolean mode, construct a search string to use in our
970 # query. Include quoted strings verbatim. Make sure that each
971 # non-quoted word is prefixed with either + or -, so that it is
972 # either explicitly included or explicitily excluded.
973 # Keep track of stopwords in the search query (these will not
974 # match in the boolean search because FTS indexes ignores them).
975 # Append 'REGEXP' queries to match, so that our search results
976 # pay *some* attention to stopwords.
977 $SearchString = preg_replace(
"/[)\(><]+/",
"", $SearchString);
978 $Words = preg_split(
"/[\s]+/", trim($SearchString));
979 $NewSearchString =
"";
980 $SearchedStopwords = array();
981 $InQuotedString = FALSE;
983 $StopWordList = $SqlVarObj->GetStopWords();
984 $MinWordLen = $SqlVarObj->Get(
"ft_min_word_len");
985 foreach ($Words as $Word)
987 # remove any query-specific terms, punctuation, etc.
988 $JustTheWord = preg_replace(
"/[^a-zA-Z-]/",
"", $Word);
990 # require (boolean AND) certain words
991 if ($InQuotedString == FALSE
992 && !in_array($JustTheWord, $StopWordList)
993 && strlen($JustTheWord) >= $MinWordLen
997 $NewSearchString .=
"+";
1000 if (preg_match(
"/^\"/", $Word)) { $InQuotedString = TRUE; }
1001 if (preg_match(
"/\"$/", $Word)) { $InQuotedString = FALSE; }
1002 $NewSearchString .= $Word.
" ";
1004 if (in_array($JustTheWord, $StopWordList))
1005 $SearchedStopwords []= $JustTheWord;
1008 # Build onto our query string by appending the boolean search
1010 $QueryString .=
" MATCH (".$this->ItemNameFieldName.
")"
1011 .
" AGAINST ('".addslashes(trim($NewSearchString)).
"'"
1012 .
" IN BOOLEAN MODE)";
1014 # If there were any stopwords included in the search string,
1015 # append REGEXP conditions to match those.
1016 foreach ($SearchedStopwords as $Stopword)
1018 $QueryString .=
" AND ".$this->ItemNameFieldName
1019 .
" REGEXP '".addslashes(preg_quote($Stopword)).
"'";
1024 # If we weren't in boolean mode, just include the search
1025 # string verbatim as a match condition:
1026 $QueryString .=
" MATCH (".$this->ItemNameFieldName.
")"
1027 .
" AGAINST ('".addslashes(trim($SearchString)).
"')";
1030 # add each ID exclusion
1031 foreach ($IdExclusions as $IdExclusion)
1033 $QueryString .=
" AND ".$this->ItemIdFieldName.
" != '"
1034 .addslashes($IdExclusion).
"' ";
1037 # add each value exclusion
1038 foreach ($ValueExclusions as $ValueExclusion)
1040 $QueryString .=
" AND ".$this->ItemNameFieldName.
" != '"
1041 .addslashes($ValueExclusion).
"' ";
1044 # add class-wide condition if set
1045 if ($this->SqlCondition)
1047 $QueryString .=
" AND ".$this->SqlCondition;
1050 return $QueryString;
1055 private $ItemClassName;
1056 private $ItemTableName;
1057 private $ItemIdFieldName;
1058 private $ItemNameFieldName;
1059 private $OrderOpsAllowed;
1061 private $SqlCondition;
GetHighestItemId($IgnoreSqlCondition=FALSE)
Retrieve highest item ID in use.
GetLastTempItemId()
Retrieve most recent temp item ID for currently-logged-in user.
GetItemIdsInOrder()
Retrieve list of item IDs in order.
RemoveItemFromOrder($ItemId)
Remove item from existing order.
Prepend($Item)
Add item to beginning of order.
GetItemClassName()
Get class name of items manipulated by factory.
ClearCurrentEditedItemId()
Clear currently edited item ID.
GetItemIdByName($Name, $IgnoreCase=FALSE)
Retrieve item ID by name.
SetCurrentEditedItemId($NewId)
Set ID of currently edited item.
SQL database abstraction object with smart query caching.
DeleteItem($ItemId)
Delete item.
GetItemsAsOptionList($OptionListName, $SelectedItemId=NULL, $SqlCondition=NULL, $DisplaySize=1, $SubmitOnChange=FALSE)
Retrieve items of specified type as HTML option list with item names as labels and item IDs as value ...
GetItemNames($SqlCondition=NULL)
Retrieve item names.
GetItemCount($Condition=NULL, $IncludeTempItems=FALSE)
Get count of items.
AddItem($ItemName, $AdditionalValues=NULL)
Add new item.
SearchForItemNames($SearchString, $NumberOfResults=100, $IncludeVariants=FALSE, $UseBooleanMode=TRUE, $Offset=0, $IdExclusions=array(), $ValueExclusions=array())
Retrieve items with names matching search string.
GetCurrentEditedItemId()
Get ID of currently edited item.
GetItem($ItemId)
Retrieve item by item ID.
GetItemByName($Name, $IgnoreCase=FALSE)
Retrieve item by name.
GetLatestModificationDate($Condition=NULL)
Get newest modification date (based on values in "DateLastModified" column in database table)...
GetCountForItemNames($SearchString, $IncludeVariants=FALSE, $UseBooleanMode=TRUE, $IdExclusions=array(), $ValueExclusions=array())
Retrieve count of items with names matching search string.
CleanOutStaleTempItems($MinutesUntilStale=10080)
Clear out (call the Delete() method) for any temp items more than specified number of minutes old...
ItemExists($ItemId, $IgnoreSqlCondition=FALSE)
Check that item exists with specified ID.
Class that allows permits easier access to MySQL system variables.
InsertBefore($TargetItem, $NewItem)
Insert item into order before specified item.
InsertAfter($TargetItem, $NewItem)
Insert item into order after specified item.
Persistent doubly-linked-list data structure, with its data stored in a specified database table...
GetItems($SqlCondition=NULL)
Retrieve items.
GetNextTempItemId()
Return next available temporary item ID.
Append($Item)
Add item to end of order.
SetOrderOpsCondition($Condition)
Set SQL condition (added to WHERE clause) used to select items for ordering operations.
Common factory class for item manipulation.
GetItemIds($Condition=NULL, $IncludeTempItems=FALSE, $SortField=NULL, $SortAscending=TRUE)
Return array of item IDs.
NameIsInUse($Name, $IgnoreCase=FALSE)
Check whether item name is currently in use.
ClearCurrentEditedItem()
Delete currently edited item and clear currently edited item ID.
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
GetNextItemId()
Retrieve next available (non-temp) item ID.