3 # FILE: FolderFactory.php
5 # Part of the Collection Workflow Information System (CWIS)
6 # Copyright 2012-2013 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
16 # ---- PUBLIC INTERFACE --------------------------------------------------
26 # set up item factory base class
27 $this->
ItemFactory(
"Folder",
"Folders",
"FolderId",
"FolderName", TRUE);
29 # set up filtering to only folders by specified owner (if given)
30 if ($OwnerId !== NULL)
32 $this->OwnerId = intval($OwnerId);
44 function CreateFolder($ItemType, $FolderName = NULL, $OwnerId = NULL)
46 # retrieve numerical item type
48 ? $ItemType : Folder::GetItemTypeId($ItemType);
50 # use default owner if available and none specified
51 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
52 { $OwnerId = $this->OwnerId; }
54 # add new folder to database
55 $this->DB->Query(
"INSERT INTO Folders SET"
56 .
" ContentType = ".$ItemTypeId
57 .($FolderName ?
", FolderName = '".addslashes($FolderName).
"'" :
"")
58 .(($OwnerId !== NULL) ?
", OwnerId = ".intval($OwnerId) :
""));
60 # retrieve ID of new folder
61 $Id = $this->DB->LastInsertId();
63 # create new folder object and return it to caller
76 # create new mixed-content folder and return it to caller
87 ?
"OwnerId = ".intval($this->OwnerId) : NULL);
101 # use default owner if available and none specified
102 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
103 { $OwnerId = $this->OwnerId; }
105 # query database for folder ID
106 $FolderId = $this->DB->Query(
"SELECT FolderId FROM Folders"
107 .
" WHERE NormalizedName = '".addslashes($NormalizedName).
"'"
108 .(($OwnerId !== NULL) ?
" AND OwnerId = ".$this->OwnerId :
"")
109 .
" ORDER BY FolderId ASC",
112 # if folder found with specified name and owner
113 if ($FolderId !== FALSE && !is_null($FolderId))
115 # create folder object and return it to caller
116 return new Folder($FolderId);
120 # return NULL to caller to indicate folder not found
135 # assume we won't find any folders
139 $ItemId = is_object($Item) ? $Item->Id() : $Item;
141 # retrieve numerical item type
143 ? $ItemType : Folder::GetItemTypeId($ItemType);
145 # use default owner if available and none specified
146 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
147 { $OwnerId = $this->OwnerId; }
149 # query database for IDs of all folders that contain item
151 SELECT DISTINCT FolderItemInts.FolderId
154 ON FolderItemInts.FolderId = Folders.FolderId
155 WHERE FolderItemInts.ItemId = '".intval($ItemId).
"'
156 AND (FolderItemInts.ItemTypeId = '".intval($ItemTypeId).
"'
157 OR Folders.ContentType = '".intval($ItemTypeId).
"')
158 ".(($OwnerId !== NULL) ?
" AND Folders.OwnerId = ".intval($OwnerId) :
"").
"
159 ".(($SharedFoldersOnly) ?
" AND Folders.IsShared = 1" :
""));
160 $FolderIds = $this->DB->FetchColumn(
"FolderId");
162 # create array of folders from folder IDs
163 foreach ($FolderIds as $Id)
165 $Folders[$Id] =
new Folder($Id);
168 # return folders (if any) to caller
187 function GetFolders($ItemType = NULL, $OwnerId = NULL, $Name = NULL,
188 $Offset = 0, $Count = NULL)
190 # retrieve numerical item type
192 ? $ItemType : Folder::GetItemTypeId($ItemType);
194 # retrieve IDs of all folders that match specified parameters
195 $Condition = ($ItemTypeId !== NULL) ?
"ContentType = ".intval($ItemTypeId) : NULL;
196 if (($OwnerId !== NULL) || ($this->OwnerId !== NULL))
198 $Condition .= ($Condition ?
" AND " :
"").
"OwnerId = "
199 .intval(($OwnerId !== NULL) ? $OwnerId : $this->OwnerId);
203 $Condition .= ($Condition ?
" AND " :
"").
"FolderName = '"
204 .addslashes($Name).
"'";
208 # pare down list to requested range
209 if ($Offset || $Count)
211 $FolderIds = $Count ? array_slice($FolderIds, $Offset, $Count)
212 : array_slice($FolderIds, $Offset);
215 # create array of folders based on IDs
217 foreach ($FolderIds as $FolderId)
219 $Folders[$FolderId] =
new Folder($FolderId);
222 # return folders (if any) to caller
227 # ---- PRIVATE INTERFACE -------------------------------------------------
GetFolders($ItemType=NULL, $OwnerId=NULL, $Name=NULL, $Offset=0, $Count=NULL)
Retrieve folders with specified name, owner, or default content type.
GetItemCount($Condition=NULL, $IncludeTempItems=FALSE)
Get count of items.
Factory object for Folder class, used to retrieve and manage Folders and groups of Folders...
Folder object used to create and manage groups of items.
FolderFactory($OwnerId=NULL)
Constructor for FolderFactory.
CreateMixedFolder($FolderName=NULL, $OwnerId=NULL)
Create new folder that can contain multiple types of items.
CreateFolder($ItemType, $FolderName=NULL, $OwnerId=NULL)
Create new folder that will contain only one type of item.
GetFolderByNormalizedName($NormalizedName, $OwnerId=NULL)
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.
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
GetFolderCount()
Get total number of folders currently existing.
GetFoldersContainingItem($Item, $ItemType, $OwnerId=NULL, $SharedFoldersOnly=FALSE)
Retrieve folders containing specified item.