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/ 17 # ---- PUBLIC INTERFACE -------------------------------------------------- 27 # set up item factory base class 28 parent::__construct(
"Folder",
"Folders",
"FolderId",
"FolderName", TRUE);
30 # set up filtering to only folders by specified owner (if given) 31 if ($OwnerId !== NULL)
33 $this->OwnerId = intval($OwnerId);
45 public function CreateFolder($ItemType, $FolderName = NULL, $OwnerId = NULL)
47 # retrieve numerical item type 51 # use default owner if available and none specified 52 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
53 { $OwnerId = $this->OwnerId; }
55 # add new folder to database 56 $this->DB->Query(
"INSERT INTO Folders SET" 57 .
" ContentType = ".$ItemTypeId
58 .($FolderName ?
", FolderName = '".addslashes($FolderName).
"'" :
"")
59 .(($OwnerId !== NULL) ?
", OwnerId = ".intval($OwnerId) :
""));
61 # retrieve ID of new folder 62 $Id = $this->DB->LastInsertId();
64 # create new folder object and return it to caller 77 # create new mixed-content folder and return it to caller 88 ?
"OwnerId = ".intval($this->OwnerId) : NULL);
102 # use default owner if available and none specified 103 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
104 { $OwnerId = $this->OwnerId; }
106 # query database for folder ID 107 $FolderId = $this->DB->Query(
"SELECT FolderId FROM Folders" 108 .
" WHERE NormalizedName = '".addslashes($NormalizedName).
"'" 109 .(($OwnerId !== NULL) ?
" AND OwnerId = ".$this->OwnerId :
"")
110 .
" ORDER BY FolderId ASC",
113 # if folder found with specified name and owner 114 if ($FolderId !== FALSE && !is_null($FolderId))
116 # create folder object and return it to caller 117 return new Folder($FolderId);
121 # return NULL to caller to indicate folder not found 135 $SharedFoldersOnly = FALSE)
137 # assume we won't find any folders 141 $ItemId = is_object($Item) ? $Item->Id() : $Item;
143 # retrieve numerical item type 147 # use default owner if available and none specified 148 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
149 { $OwnerId = $this->OwnerId; }
151 # query database for IDs of all folders that contain item 153 SELECT DISTINCT FolderItemInts.FolderId 156 ON FolderItemInts.FolderId = Folders.FolderId 157 WHERE FolderItemInts.ItemId = '".intval($ItemId).
"' 158 AND (FolderItemInts.ItemTypeId = '".intval($ItemTypeId).
"' 159 OR Folders.ContentType = '".intval($ItemTypeId).
"') 160 ".(($OwnerId !== NULL) ?
" AND Folders.OwnerId = ".intval($OwnerId) :
"").
" 161 ".(($SharedFoldersOnly) ?
" AND Folders.IsShared = 1" :
""));
162 $FolderIds = $this->DB->FetchColumn(
"FolderId");
164 # create array of folders from folder IDs 165 foreach ($FolderIds as $Id)
167 $Folders[$Id] =
new Folder($Id);
170 # return folders (if any) to caller 190 public function GetFolders($ItemType = NULL, $OwnerId = NULL, $Name = NULL,
191 $Offset = 0, $Count = NULL)
193 # retrieve numerical item type 197 # retrieve IDs of all folders that match specified parameters 198 $Condition = ($ItemTypeId !== NULL) ?
"ContentType = ".intval($ItemTypeId) : NULL;
199 if (($OwnerId !== NULL) || ($this->OwnerId !== NULL))
201 $Condition .= ($Condition ?
" AND " :
"").
"OwnerId = " 202 .intval(($OwnerId !== NULL) ? $OwnerId : $this->OwnerId);
206 $Condition .= ($Condition ?
" AND " :
"").
"FolderName = '" 207 .addslashes($Name).
"'";
209 $FolderIds = $this->
GetItemIds($Condition, FALSE,
"FolderId");
211 # pare down list to requested range 212 if ($Offset || $Count)
214 $FolderIds = $Count ? array_slice($FolderIds, $Offset, $Count)
215 : array_slice($FolderIds, $Offset);
218 # create array of folders based on IDs 220 foreach ($FolderIds as $FolderId)
222 $Folders[$FolderId] =
new Folder($FolderId);
225 # return folders (if any) to caller 230 # ---- PRIVATE INTERFACE ------------------------------------------------- __construct($OwnerId=NULL)
Constructor for FolderFactory.
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.
static GetItemTypeId($TypeName)
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)
Retrieve folder with specified normalized name (as generated by Folder::NormalizeFolderName() method)...
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.
GetFolderCount()
Get total number of folders currently existing.
GetFoldersContainingItem($Item, $ItemType, $OwnerId=NULL, $SharedFoldersOnly=FALSE)
Retrieve folders containing specified item.