CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

FolderFactory.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: FolderFactory.php
4 #
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/
8 #
9
14 class FolderFactory extends ItemFactory {
15
16 # ---- PUBLIC INTERFACE --------------------------------------------------
17
24 function FolderFactory($OwnerId = NULL)
25 {
26 # set up item factory base class
27 $this->ItemFactory("Folder", "Folders", "FolderId", "FolderName", TRUE);
28
29 # set up filtering to only folders by specified owner (if given)
30 if ($OwnerId !== NULL)
31 {
32 $this->OwnerId = intval($OwnerId);
33 $this->SetOrderOpsCondition("OwnerId = ".$this->OwnerId);
34 }
35 }
36
44 function CreateFolder($ItemType, $FolderName = NULL, $OwnerId = NULL)
45 {
46 # retrieve numerical item type
47 $ItemTypeId = ($ItemType === Folder::MIXEDCONTENT)
48 ? $ItemType : Folder::GetItemTypeId($ItemType);
49
50 # use default owner if available and none specified
51 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
52 { $OwnerId = $this->OwnerId; }
53
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) : ""));
59
60 # retrieve ID of new folder
61 $Id = $this->DB->LastInsertId();
62
63 # create new folder object and return it to caller
64 return new Folder($Id);
65 }
66
74 function CreateMixedFolder($FolderName = NULL, $OwnerId = NULL)
75 {
76 # create new mixed-content folder and return it to caller
77 return $this->CreateFolder(Folder::MIXEDCONTENT, $FolderName, $OwnerId);
78 }
79
84 function GetFolderCount()
85 {
86 return $this->GetItemCount(isset($this->OwnerId)
87 ? "OwnerId = ".intval($this->OwnerId) : NULL);
88 }
89
90 /*
91 * Retrieve folder with specified normalized name (as generated by
92 * Folder::NormalizeFolderName() method).
93 * @param Normalized folder name.
94 * @param OwnerId ID of folder owner. (OPTIONAL)
95 * @return Folder object or NULL if no folder found. If multiple folders
96 * with the specified name are found, the one with the lowest folder
97 * ID is returned.
98 */
99 function GetFolderByNormalizedName($NormalizedName, $OwnerId = NULL)
100 {
101 # use default owner if available and none specified
102 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
103 { $OwnerId = $this->OwnerId; }
104
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",
110 "FolderId");
111
112 # if folder found with specified name and owner
113 if ($FolderId !== FALSE && !is_null($FolderId))
114 {
115 # create folder object and return it to caller
116 return new Folder($FolderId);
117 }
118 else
119 {
120 # return NULL to caller to indicate folder not found
121 return NULL;
122 }
123 }
124
133 function GetFoldersContainingItem($Item, $ItemType, $OwnerId = NULL, $SharedFoldersOnly = FALSE)
134 {
135 # assume we won't find any folders
136 $Folders = array();
137
138 # retrieve item ID
139 $ItemId = is_object($Item) ? $Item->Id() : $Item;
140
141 # retrieve numerical item type
142 $ItemTypeId = ($ItemType === Folder::MIXEDCONTENT)
143 ? $ItemType : Folder::GetItemTypeId($ItemType);
144
145 # use default owner if available and none specified
146 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
147 { $OwnerId = $this->OwnerId; }
148
149 # query database for IDs of all folders that contain item
150 $this->DB->Query("
151 SELECT DISTINCT FolderItemInts.FolderId
152 FROM FolderItemInts
153 LEFT JOIN Folders
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");
161
162 # create array of folders from folder IDs
163 foreach ($FolderIds as $Id)
164 {
165 $Folders[$Id] = new Folder($Id);
166 }
167
168 # return folders (if any) to caller
169 return $Folders;
170 }
171
187 function GetFolders($ItemType = NULL, $OwnerId = NULL, $Name = NULL,
188 $Offset = 0, $Count = NULL)
189 {
190 # retrieve numerical item type
191 $ItemTypeId = ($ItemType === Folder::MIXEDCONTENT)
192 ? $ItemType : Folder::GetItemTypeId($ItemType);
193
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))
197 {
198 $Condition .= ($Condition ? " AND " : "")."OwnerId = "
199 .intval(($OwnerId !== NULL) ? $OwnerId : $this->OwnerId);
200 }
201 if ($Name !== NULL)
202 {
203 $Condition .= ($Condition ? " AND " : "")."FolderName = '"
204 .addslashes($Name)."'";
205 }
206 $FolderIds = $this->GetItemIds($Condition);
207
208 # pare down list to requested range
209 if ($Offset || $Count)
210 {
211 $FolderIds = $Count ? array_slice($FolderIds, $Offset, $Count)
212 : array_slice($FolderIds, $Offset);
213 }
214
215 # create array of folders based on IDs
216 $Folders = array();
217 foreach ($FolderIds as $FolderId)
218 {
219 $Folders[$FolderId] = new Folder($FolderId);
220 }
221
222 # return folders (if any) to caller
223 return $Folders;
224 }
225
226
227 # ---- PRIVATE INTERFACE -------------------------------------------------
228
229 private $OwnerId;
230 }
Folder\MIXEDCONTENT
const MIXEDCONTENT
Definition: Folder.php:422
FolderFactory\GetFolders
GetFolders($ItemType=NULL, $OwnerId=NULL, $Name=NULL, $Offset=0, $Count=NULL)
Retrieve folders with specified name, owner, or default content type.
Definition: FolderFactory.php:187
ItemFactory\GetItemCount
GetItemCount($Condition=NULL, $IncludeTempItems=FALSE)
Get count of items.
Definition: ItemFactory.php:293
FolderFactory
Factory object for Folder class, used to retrieve and manage Folders and groups of Folders...
Definition: FolderFactory.php:14
Folder
Folder object used to create and manage groups of items.
Definition: Folder.php:17
PHP
PHP
Definition: RSSClient--Test.php:12
FolderFactory\FolderFactory
FolderFactory($OwnerId=NULL)
Constructor for FolderFactory.
Definition: FolderFactory.php:24
Folder\GetItemTypeId
static GetItemTypeId($TypeName)
Definition: Folder.php:431
FolderFactory\CreateMixedFolder
CreateMixedFolder($FolderName=NULL, $OwnerId=NULL)
Create new folder that can contain multiple types of items.
Definition: FolderFactory.php:74
FolderFactory\CreateFolder
CreateFolder($ItemType, $FolderName=NULL, $OwnerId=NULL)
Create new folder that will contain only one type of item.
Definition: FolderFactory.php:44
FolderFactory\GetFolderByNormalizedName
GetFolderByNormalizedName($NormalizedName, $OwnerId=NULL)
Definition: FolderFactory.php:99
ItemFactory\SetOrderOpsCondition
SetOrderOpsCondition($Condition)
Set SQL condition (added to WHERE clause) used to select items for ordering operations.
Definition: ItemFactory.php:807
ItemFactory
Common factory class for item manipulation.
Definition: ItemFactory.php:17
ItemFactory\GetItemIds
GetItemIds($Condition=NULL, $IncludeTempItems=FALSE, $SortField=NULL, $SortAscending=TRUE)
Return array of item IDs.
Definition: ItemFactory.php:350
ItemFactory\ItemFactory
ItemFactory($ItemClassName, $ItemTableName, $ItemIdFieldName, $ItemNameFieldName=NULL, $OrderOpsAllowed=FALSE, $SqlCondition=NULL)
Class constructor.
Definition: ItemFactory.php:36
FolderFactory\GetFolderCount
GetFolderCount()
Get total number of folders currently existing.
Definition: FolderFactory.php:84
FolderFactory\GetFoldersContainingItem
GetFoldersContainingItem($Item, $ItemType, $OwnerId=NULL, $SharedFoldersOnly=FALSE)
Retrieve folders containing specified item.
Definition: FolderFactory.php:133