Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezvirtualfolder.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezvirtualfolder.php 9140 2002-02-04 17:42:03Z jhe $
5 //
6 // Definition of eZVirtualFolder class
7 //
8 // Created on: <11-Dec-2000 15:24:35 bf>
9 //
10 // This source file is part of Exponential Basic, publishing software.
11 //
12 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
13 //
14 // This program is free software; you can redistribute it and/or
15 // modify it under the terms of the GNU General Public License
16 // as published by the Free Software Foundation; either version 2
17 // of the License, or (at your option) any later version.
18 //
19 // This program is distributed in the hope that it will be useful,
20 // but WITHOUT ANY WARRANTY; without even the implied warranty of
21 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 // GNU General Public License for more details.
23 //
24 // You should have received a copy of the GNU General Public License
25 // along with this program; if not, write to the Free Software
26 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
27 //
28
31
38 // include_once( "classes/ezdb.php" );
39 // include_once( "ezuser/classes/ezusergroup.php" );
40 // include_once( "ezuser/classes/ezobjectpermission.php" );
41
42 class eZVirtualFolder
43 {
50 function __construct( $id=-1 )
51 {
52 $this->ExcludeFromSearch = false;
53 $this->UserID = 0;
54 $this->SectionID = 0;
55 $this->ParentID = 0;
56
57 if ( $id != -1 )
58 {
59 $this->ID = $id;
60 $this->get( $this->ID );
61 }
62 }
63
67 function store()
68 {
69 $db =& eZDB::globalDatabase();
70 $db->begin();
71 $name = $db->escapeString( $this->Name );
72 $description = $db->escapeString( $this->Description );
73 if ( !isset( $this->ID ) )
74 {
75 $db->lock( "eZFileManager_Folder" );
76 $nextID = $db->nextID( "eZFileManager_Folder", "ID" );
77 $result = $db->query( "INSERT INTO eZFileManager_Folder
78 (ID, Name, Description, UserID, SectionID, ParentID)
79 VALUES ('$nextID',
80 '$name',
81 '$description',
82 '$this->UserID',
83 '$this->SectionID',
84 '$this->ParentID')" );
85 $db->unlock();
86 $this->ID = $nextID;
87 }
88 else
89 {
90 $result = $db->query( "UPDATE eZFileManager_Folder SET
91 Name='$name',
92 Description='$description',
93 UserID='$this->UserID',
94 SectionID='$this->SectionID',
95 ParentID='$this->ParentID'
96 WHERE ID='$this->ID'" );
97
98 }
99
100
101 if ( $result == false )
102 $db->rollback( );
103 else
104 $db->commit();
105 }
106
107 function getByName( $dir, $parent = 0, $create = false, $readgroup = -1, $writegroup = -1 )
108 {
109 unset( $folder_array );
110 $dirlist = split( "/", $dir );
111 if ( $dirlist[0] == "" )
112 array_shift( $dirlist );
113 $db =& eZDB::globalDatabase();
114 if ( count( $dirlist ) == 1 )
115 {
116 $db->array_query( $folder_array, "SELECT * FROM eZFileManager_Folder WHERE ParentID='$parent' AND Name='" . $dirlist[0] . "'" );
117 if ( count( $folder_array ) == 0 )
118 {
119 if ( $create )
120 {
121 $folder = new eZVirtualFolder();
122 $folder->setName( $dirlist[0] );
123 $folder->setParent( $parent );
124 $folder->store();
125 $group = new eZUserGroup( $readgroup );
126 eZObjectPermission::setPermission( $group, $folder->id(), "filemanager_folder", "r" );
127 $group = new eZUserGroup( $writegroup );
128 eZObjectPermission::setPermission( $group, $folder->id(), "filemanager_folder", "w" );
129
130 return $folder->ID();
131 }
132 else
133 {
134 return false;
135 }
136 }
137 else
138 {
139 return $folder_array[0][$db->fieldName( "ID" )];
140 }
141 }
142 else
143 {
144 for ( $i = 0; $i < count( $dirlist ); $i++ )
145 {
146 $parent = eZVirtualFolder::getByName( $dirlist[$i], $parent, $create, $readgroup, $writegroup );
147 if ( !$parent )
148 return false;
149 }
150 return $parent;
151 }
152 }
153
158 function delete( $catID = -1 )
159 {
160 $db =& eZDB::globalDatabase();
161 if ( $catID == -1 )
162 $catID = $this->ID;
163
164 $category = new eZVirtualFolder( $catID );
165
166 $categoryList = $category->getByParent( $category );
167 $db->begin();
168
169 foreach ( $categoryList as $category )
170 {
171 $this->delete( $category->id() );
172 }
173
174 foreach ( $this->files( "time", -1, -1) as $file )
175 {
176 $file->delete();
177 }
178
179 $res[] = $db->query( "DELETE FROM eZFileManager_Folder WHERE ID='$catID'" );
180 $res[] = $db->query( "DELETE FROM eZFileManager_FileFolderLink WHERE FolderID='$catID'" );
181 $res[] = $db->query( "DELETE FROM eZFileManager_FolderPermission WHERE ObjectID='$catID'" );
182 eZDB::finish( $res, $db );
183 }
184
188 function get( $id = -1 )
189 {
190 $db =& eZDB::globalDatabase();
191
192 if ( $id != "" )
193 {
194 $db->array_query( $category_array, "SELECT * FROM eZFileManager_Folder WHERE ID='$id'" );
195 if ( count( $category_array ) > 1 )
196 {
197 die( "Error: Category's with the same ID was found in the database. This shouldent happen." );
198 }
199 else if ( count( $category_array ) == 1 )
200 {
201 $this->ID =& $category_array[0][$db->fieldName( "ID" )];
202 $this->Name =& $category_array[0][$db->fieldName( "Name" )];
203 $this->Description =& $category_array[0][$db->fieldName( "Description" )];
204 $this->ParentID =& $category_array[0][$db->fieldName( "ParentID" )];
205 $this->UserID =& $category_array[0][$db->fieldName( "UserID" )];
206 $this->SectionID =& $category_array[0][$db->fieldName( "SectionID" )];
207 }
208 }
209 }
210
216 function &getAll()
217 {
218 $db =& eZDB::globalDatabase();
219
220 $return_array = array();
221 $category_array = array();
222
223 $db->array_query( $category_array, "SELECT ID, Name FROM eZFileManager_Folder ORDER BY Name" );
224
225 for ( $i = 0; $i < count( $category_array ); $i++ )
226 {
227 $return_array[$i] = new eZVirtualFolder( $category_array[$i][$db->fieldName( "ID" )], 0 );
228 }
229
230 return $return_array;
231 }
232
241 function &getByParent( $parent )
242 {
243 if ( is_a( $parent, "eZVirtualFolder" ) )
244 {
245 $db =& eZDB::globalDatabase();
246
247 $return_array = array();
248 $category_array = array();
249
250 $parentID = $parent->id();
251
252 $db->array_query( $category_array, "SELECT ID, Name FROM eZFileManager_Folder
253 WHERE ParentID='$parentID'
254 ORDER BY Name" );
255
256 for ( $i = 0; $i < count( $category_array ); $i++ )
257 {
258 $return_array[$i] = new eZVirtualFolder( $category_array[$i][$db->fieldName( "ID" )], 0 );
259 }
260 return $return_array;
261 }
262 else
263 {
264 return array();
265 }
266 }
267
275 function &path( $categoryID=0 )
276 {
277 if ( $categoryID == 0 )
278 {
279 $categoryID = $this->ID;
280 }
281
282 $category = new eZVirtualFolder( $categoryID );
283
284 $path = array();
285
286 $parent = $category->parent();
287
288 if ( $parent != 0 )
289 {
290 $path = array_merge( $path, $this->path( $parent->id() ) );
291 }
292 else
293 {
294 // array_push( $path, $category->name() );
295 }
296
297 if ( $categoryID != 0 )
298 array_push( $path, array( $category->id(), $category->name() ) );
299
300 return $path;
301 }
302
303 function &getIDByParent( $name, $parent = 0 )
304 {
305 if ( is_a( $parent, "eZVirtualFolder" ) )
306 $parentID = $parent->ID();
307 else if ( is_numeric( $parent ) )
308 $parentID = $parent;
309 else
310 return false;
311
312 $db =& eZDB::globalDatabase();
313 $res[] = $db->array_query( $return_array, "SELECT ID FROM eZFileManager_Folder WHERE Name='$name' AND ParentID='$parentID'" );
314 if ( count( $return_array ) == 1 )
315 {
316 return $return_array[0][ $db->fieldName( "ID" ) ];
317 }
318 else
319 {
320 return false;
321 }
322 }
323
324 function &getTree( $parentID = 0, $level = 0 )
325 {
326 $user =& eZUser::currentUser();
327
328 $category = new eZVirtualFolder( $parentID );
329
330 $categoryList = $category->getByParent( $category );
331
332 $tree = array();
333 $level++;
334 foreach ( $categoryList as $category )
335 {
336 array_push( $tree, array( $return_array[] = new eZVirtualFolder( $category->id() ), $level ) );
337
338 if ( $category != 0 )
339 {
340 $tree = array_merge( $tree, $this->getTree( $category->id(), $level ) );
341 }
342
343 }
344
345 return $tree;
346 }
347
348
352 function id()
353 {
354 return $this->ID;
355 }
356
357
361 function &name( $html = true )
362 {
363 $this->Name = stripslashes($this->Name);
364 if ( $html )
365 return htmlspecialchars( $this->Name );
366 else
367 return $this->Name;
368 }
369
373 function &description( $html = false )
374 {
375 $this->Description = stripslashes($this->Description);
376 if ( $html )
377 return htmlspecialchars( $this->Description );
378 else
379 return $this->Description;
380 }
381
385 function &parent()
386 {
387 if ( $this->ParentID != 0 )
388 {
389 return new eZVirtualFolder( $this->ParentID );
390 }
391 else
392 {
393 return 0;
394 }
395 }
396
400 function &user( $asObject = true )
401 {
402
403 if ( $this->UserID != 0 && $asObject )
404 {
405 $ret = new eZUser( $this->UserID );
406 }
407 else
408 {
409 $ret = $this->UserID;
410 }
411
412 return $ret;
413 }
414
421 static public function isOwner( $user, $folderID )
422 {
423 if ( !is_a( $user, "eZUser" ) )
424 return false;
425
426 $db =& eZDB::globalDatabase();
427 $db->query_single( $res, "SELECT UserID from eZFileManager_Folder WHERE ID='$folderID'");
428 $userID = $res[$db->fieldName( "UserID" )];
429 if ( $userID == $user->id() )
430 return true;
431
432 return false;
433 }
434
435
439 function setName( $value )
440 {
441 $this->Name = $value;
442 }
443
447 function setSectionID( $value )
448 {
449 $this->SectionID = $value;
450 }
451
452
456 function setDescription( $value )
457 {
458 $this->Description = $value;
459 }
460
464 function setParent( $value )
465 {
466 if ( is_a( $value, "eZVirtualFolder" ) )
467 {
468 $this->ParentID = $value->id();
469 }
470 else if ( is_numeric( $value ) )
471 {
472 $this->ParentID = $value;
473 }
474 }
475
480 function setExcludeFromSearch( $value )
481 {
482 if ( $value == true )
483 {
484 $this->ExcludeFromSearch = "true";
485 }
486 else
487 {
488 $this->ExcludeFromSearch = "false";
489 }
490 }
491
492
496 function setUser( &$user )
497 {
498 if ( is_a( $user, "eZUser" ) )
499 {
500 $userID = $user->id();
501
502 $this->UserID = $userID;
503 }
504 }
505
509 function sectionID( )
510 {
511 return $this->SectionID;
512 }
513
514
518 function addFile( &$value )
519 {
520 if ( is_a( $value, "eZVirtualFile" ) )
521 {
522 $db =& eZDB::globalDatabase();
523 $db->begin();
524 $db->lock( "eZFileManager_FileFolderLink" );
525 $nextID = $db->nextID( "eZFileManager_FileFolderLink", "ID" );
526
527 $fileID = $value->id();
528
529 $query = "INSERT INTO eZFileManager_FileFolderLink
530 ( ID, FolderID, FileID )
531 VALUES ( '$nextID',
532 '$this->ID',
533 '$fileID'
534 )";
535
536 $result = $db->query( $query );
537
538 $db->unlock();
539
540 if ( $result == false )
541 $db->rollback( );
542 else
543 $db->commit();
544 }
545 }
546
551 function &files( $sortMode="time",
552 $offset=0,
553 $limit=50 )
554 {
555 $db =& eZDB::globalDatabase();
556
557 $return_array = array();
558 $article_array = array();
559
560 $db->array_query( $file_array, "
561 SELECT eZFileManager_File.ID AS FileID, eZFileManager_File.OriginalFileName
562 FROM eZFileManager_File, eZFileManager_Folder, eZFileManager_FileFolderLink
563 WHERE
564 eZFileManager_FileFolderLink.FileID = eZFileManager_File.ID
565 AND
566 eZFileManager_Folder.ID = eZFileManager_FileFolderLink.FolderID
567 AND
568 eZFileManager_Folder.ID='$this->ID'
569 GROUP BY eZFileManager_File.ID, eZFileManager_File.OriginalFileName ORDER BY eZFileManager_File.OriginalFileName",
570 array( "Limit" => $limit,
571 "Offset" => $offset ) );
572
573 for ( $i = 0; $i < count( $file_array ); $i++ )
574 {
575 $return_array[$i] = new eZVirtualFile( $file_array[$i][$db->fieldName( "FileID" )], false );
576 }
577
578 return $return_array;
579 }
580
581 function countFiles()
582 {
583 $db =& eZDB::globalDatabase();
584 $file_array = array();
585
586 $db->array_query( $file_array, "SELECT count( eZFileManager_File.ID )
587 FROM eZFileManager_File, eZFileManager_FileFolderLink,
588 eZFileManager_Folder
589 WHERE
590 eZFileManager_FileFolderLink.FileID = eZFileManager_File.ID
591 AND
592 eZFileManager_FileFolderLink.FolderID='$this->ID'
593 AND
594 eZFileManager_Folder.ID='$this->ID'" );
595 return $file_array[0][0];
596 }
597
601 function hasFile( $file )
602 {
603 $db =& eZDB::globalDatabase();
604 $db->array_query( $file_array, "SELECT ID FROM eZFileManager_File
605 WHERE OriginalFileName='" . $file . "'" );
606 $ret = false;
607 foreach ( $file_array as $singlefile )
608 {
609 $db->array_query( $folder_array, "SELECT ID FROM eZFileManager_FileFolderLink
610 WHERE FolderID='" . $this->ID .
611 "' AND FileID='" .
612 $singlefile[$db->fieldName( "ID" )] .
613 "'" );
614 if ( count( $folder_array ) > 0 )
615 $ret = true;
616 }
617 return $ret;
618 }
619
624 static public function sectionIDStatic($folderID )
625 {
626 $db =& eZDB::globalDatabase();
627 $res = array();
628
629 $db->query_single( $res, "SELECT SectionID from eZFileManager_Folder WHERE ID='$folderID'");
630
631 if( is_array( $res ) && count( $res ) > 0 )
632 $sectionID = $res[$db->fieldName("SectionID")];
633 else
634 $sectionID = 0;
635
636 if ( $sectionID > 0 )
637 return $sectionID;
638 else
639 return false;
640 }
641
642 var $ID;
643 var $Name;
644 var $ParentID;
645 var $Description;
646 var $UserID;
647 var $SectionID;
648 var $ExcludeFromSearch;
649 }
650
651 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
$categoryList
foreach( $pathArray as $path) $categoryList
Definition: admin/adlist.php:86
$group
$group
Definition: admin/articleedit.php:799
$level
$level
Definition: admin/message.php:106
$userID
else $userID
Definition: appointmentedit.php:121
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZObjectPermission\setPermission
static setPermission( $group, $objectID, $moduleTable, $permission)
Definition: ezobjectpermission.php:236
eZUserGroup
Definition: ezusergroup.php:66
eZUser
Definition: ezuser.php:76
eZUser\currentUser
static & currentUser()
Definition: ezuser.php:896
eZVirtualFile
Definition: ezvirtualfile.php:42
eZVirtualFolder
Definition: ezvirtualfolder.php:43
eZVirtualFolder\$Description
$Description
Definition: ezvirtualfolder.php:645
eZVirtualFolder\setSectionID
setSectionID( $value)
Definition: ezvirtualfolder.php:447
eZVirtualFolder\__construct
__construct( $id=-1)
Definition: ezvirtualfolder.php:50
eZVirtualFolder\countFiles
countFiles()
Definition: ezvirtualfolder.php:581
eZVirtualFolder\$ExcludeFromSearch
$ExcludeFromSearch
Definition: ezvirtualfolder.php:648
eZVirtualFolder\getIDByParent
& getIDByParent( $name, $parent=0)
Definition: ezvirtualfolder.php:303
eZVirtualFolder\description
& description( $html=false)
Definition: ezvirtualfolder.php:373
eZVirtualFolder\path
& path( $categoryID=0)
Definition: ezvirtualfolder.php:275
eZVirtualFolder\setExcludeFromSearch
setExcludeFromSearch( $value)
Definition: ezvirtualfolder.php:480
eZVirtualFolder\files
& files( $sortMode="time", $offset=0, $limit=50)
Definition: ezvirtualfolder.php:551
eZVirtualFolder\sectionID
sectionID()
Definition: ezvirtualfolder.php:509
eZVirtualFolder\addFile
addFile(&$value)
Definition: ezvirtualfolder.php:518
eZVirtualFolder\setParent
setParent( $value)
Definition: ezvirtualfolder.php:464
eZVirtualFolder\store
store()
Definition: ezvirtualfolder.php:67
eZVirtualFolder\setName
setName( $value)
Definition: ezvirtualfolder.php:439
eZVirtualFolder\name
& name( $html=true)
Definition: ezvirtualfolder.php:361
eZVirtualFolder\getTree
& getTree( $parentID=0, $level=0)
Definition: ezvirtualfolder.php:324
eZVirtualFolder\setUser
setUser(&$user)
Definition: ezvirtualfolder.php:496
eZVirtualFolder\parent
& parent()
Definition: ezvirtualfolder.php:385
eZVirtualFolder\id
id()
Definition: ezvirtualfolder.php:352
eZVirtualFolder\$ID
$ID
Definition: ezvirtualfolder.php:642
eZVirtualFolder\$SectionID
$SectionID
Definition: ezvirtualfolder.php:647
eZVirtualFolder\getByName
getByName( $dir, $parent=0, $create=false, $readgroup=-1, $writegroup=-1)
Definition: ezvirtualfolder.php:107
eZVirtualFolder\getByParent
& getByParent( $parent)
Definition: ezvirtualfolder.php:241
eZVirtualFolder\hasFile
hasFile( $file)
Definition: ezvirtualfolder.php:601
eZVirtualFolder\getAll
& getAll()
Definition: ezvirtualfolder.php:216
eZVirtualFolder\user
& user( $asObject=true)
Definition: ezvirtualfolder.php:400
eZVirtualFolder\$Name
$Name
Definition: ezvirtualfolder.php:643
eZVirtualFolder\$UserID
$UserID
Definition: ezvirtualfolder.php:646
eZVirtualFolder\sectionIDStatic
static sectionIDStatic($folderID)
Definition: ezvirtualfolder.php:624
eZVirtualFolder\isOwner
static isOwner( $user, $folderID)
Definition: ezvirtualfolder.php:421
eZVirtualFolder\setDescription
setDescription( $value)
Definition: ezvirtualfolder.php:456
eZVirtualFolder\$ParentID
$ParentID
Definition: ezvirtualfolder.php:644
$result
$result
Definition: companysearch.php:94
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$query
if(isset( $Year) &&!is_numeric( $Year)||isset( $Month) &&!is_numeric( $Month)) $query
Definition: entryexitpages.php:65
$tree
$tree
Definition: ezad/admin/categoryedit.php:172
$db
$db
Definition: ezarticle/user/authorlist.php:53
$folder
if(!isset( $FolderID)) $folder
Definition: ezfilemanager/admin/browse.php:74
$file
$file
Definition: ezfilemanager/user/filedownload.php:35
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$dir
$dir
Definition: ezsitemanager/admin/filelist.php:87
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$categoryID
else $categoryID
Definition: productview.php:66
Name
if($user) if(isset( $next) && $next)<?=isset($all_fields_error) &&$all_fields_error ?><?=isset($password_error) &&$password_error ?></p ><? endif;?>< form method="post">< table border="0" cellspacing="2" cellpadding="2" class="boxtext" style="font-size=13;">< tr >< td style="color:<?= isset( $error['first_name'] ) ?> First Name
Definition: step1.php:127
$category_array
$category_array
Definition: todoedit.php:604
$user
$user
Definition: user/adlist.php:39
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.