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
17 # ---- PUBLIC INTERFACE --------------------------------------------------
18
25 public function __construct($OwnerId = NULL)
26 {
27 # set up item factory base class
28 parent::__construct("Folder", "Folders", "FolderId", "FolderName", TRUE);
29
30 # set up filtering to only folders by specified owner (if given)
31 if ($OwnerId !== NULL)
32 {
33 $this->OwnerId = intval($OwnerId);
34 $this->SetOrderOpsCondition("OwnerId = ".$this->OwnerId);
35 }
36 }
37
45 public function CreateFolder($ItemType, $FolderName = NULL, $OwnerId = NULL)
46 {
47 # retrieve numerical item type
48 $ItemTypeId = ($ItemType === Folder::MIXEDCONTENT)
49 ? $ItemType : Folder::GetItemTypeId($ItemType);
50
51 # use default owner if available and none specified
52 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
53 { $OwnerId = $this->OwnerId; }
54
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) : ""));
60
61 # retrieve ID of new folder
62 $Id = $this->DB->LastInsertId();
63
64 # create new folder object and return it to caller
65 return new Folder($Id);
66 }
67
75 public function CreateMixedFolder($FolderName = NULL, $OwnerId = NULL)
76 {
77 # create new mixed-content folder and return it to caller
78 return $this->CreateFolder(Folder::MIXEDCONTENT, $FolderName, $OwnerId);
79 }
80
85 public function GetFolderCount()
86 {
87 return $this->GetItemCount(isset($this->OwnerId)
88 ? "OwnerId = ".intval($this->OwnerId) : NULL);
89 }
90
100 public function GetFolderByNormalizedName($NormalizedName, $OwnerId = NULL)
101 {
102 # use default owner if available and none specified
103 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
104 { $OwnerId = $this->OwnerId; }
105
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",
111 "FolderId");
112
113 # if folder found with specified name and owner
114 if ($FolderId !== FALSE && !is_null($FolderId))
115 {
116 # create folder object and return it to caller
117 return new Folder($FolderId);
118 }
119 else
120 {
121 # return NULL to caller to indicate folder not found
122 return NULL;
123 }
124 }
125
134 public function GetFoldersContainingItem($Item, $ItemType, $OwnerId = NULL,
135 $SharedFoldersOnly = FALSE)
136 {
137 # assume we won't find any folders
138 $Folders = array();
139
140 # retrieve item ID
141 $ItemId = is_object($Item) ? $Item->Id() : $Item;
142
143 # retrieve numerical item type
144 $ItemTypeId = ($ItemType === Folder::MIXEDCONTENT)
145 ? $ItemType : Folder::GetItemTypeId($ItemType);
146
147 # use default owner if available and none specified
148 if (($OwnerId === NULL) & ($this->OwnerId !== NULL))
149 { $OwnerId = $this->OwnerId; }
150
151 # query database for IDs of all folders that contain item
152 $this->DB->Query("
153 SELECT DISTINCT FolderItemInts.FolderId
154 FROM FolderItemInts
155 LEFT JOIN Folders
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");
163
164 # create array of folders from folder IDs
165 foreach ($FolderIds as $Id)
166 {
167 $Folders[$Id] = new Folder($Id);
168 }
169
170 # return folders (if any) to caller
171 return $Folders;
172 }
173
190 public function GetFolders($ItemType = NULL, $OwnerId = NULL, $Name = NULL,
191 $Offset = 0, $Count = NULL)
192 {
193 # retrieve numerical item type
194 $ItemTypeId = ($ItemType === Folder::MIXEDCONTENT)
195 ? $ItemType : Folder::GetItemTypeId($ItemType);
196
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))
200 {
201 $Condition .= ($Condition ? " AND " : "")."OwnerId = "
202 .intval(($OwnerId !== NULL) ? $OwnerId : $this->OwnerId);
203 }
204 if ($Name !== NULL)
205 {
206 $Condition .= ($Condition ? " AND " : "")."FolderName = '"
207 .addslashes($Name)."'";
208 }
209 $FolderIds = $this->GetItemIds($Condition, FALSE, "FolderId");
210
211 # pare down list to requested range
212 if ($Offset || $Count)
213 {
214 $FolderIds = $Count ? array_slice($FolderIds, $Offset, $Count)
215 : array_slice($FolderIds, $Offset);
216 }
217
218 # create array of folders based on IDs
219 $Folders = array();
220 foreach ($FolderIds as $FolderId)
221 {
222 $Folders[$FolderId] = new Folder($FolderId);
223 }
224
225 # return folders (if any) to caller
226 return $Folders;
227 }
228
229
230 # ---- PRIVATE INTERFACE -------------------------------------------------
231
232 private $OwnerId;
233 }
FolderFactory\__construct
__construct($OwnerId=NULL)
Constructor for FolderFactory.
Definition: FolderFactory.php:25
Folder\MIXEDCONTENT
const MIXEDCONTENT
Definition: Folder.php:461
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:190
ItemFactory\GetItemCount
GetItemCount($Condition=NULL, $IncludeTempItems=FALSE)
Get count of items.
Definition: ItemFactory.php:176
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
Folder\GetItemTypeId
static GetItemTypeId($TypeName)
Definition: Folder.php:470
FolderFactory\CreateMixedFolder
CreateMixedFolder($FolderName=NULL, $OwnerId=NULL)
Create new folder that can contain multiple types of items.
Definition: FolderFactory.php:75
FolderFactory\CreateFolder
CreateFolder($ItemType, $FolderName=NULL, $OwnerId=NULL)
Create new folder that will contain only one type of item.
Definition: FolderFactory.php:45
FolderFactory\GetFolderByNormalizedName
GetFolderByNormalizedName($NormalizedName, $OwnerId=NULL)
Retrieve folder with specified normalized name (as generated by Folder::NormalizeFolderName() method)...
Definition: FolderFactory.php:100
ItemFactory\SetOrderOpsCondition
SetOrderOpsCondition($Condition)
Set SQL condition (added to WHERE clause) used to select items for ordering operations.
Definition: ItemFactory.php:677
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:233
FolderFactory\GetFolderCount
GetFolderCount()
Get total number of folders currently existing.
Definition: FolderFactory.php:85
FolderFactory\GetFoldersContainingItem
GetFoldersContainingItem($Item, $ItemType, $OwnerId=NULL, $SharedFoldersOnly=FALSE)
Retrieve folders containing specified item.
Definition: FolderFactory.php:134