Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmediacategory.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezmediacategory.php 8138 2001-11-01 08:31:40Z ce $
5 //
6 // Definition of eZMediaCategory class
7 //
8 // Created on: <24-Jul-2001 10:28:22 ce>
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
49 // include_once( "classes/ezdb.php" );
50 // include_once( "classes/INIFile.php" );
51
52 // include_once( "ezmediacatalogue/classes/ezmedia.php" );
53
54 class eZMediaCategory
55 {
62 function __construct( $id=-1 )
63 {
64 $this->ExcludeFromSearch = "false";
65 if ( $id != -1 )
66 {
67 $this->ID = $id;
68 $this->get( $this->ID );
69 }
70 }
71
75 function store()
76 {
77 $db =& eZDB::globalDatabase();
78
79 $db->begin( );
80
81 $name = $db->escapeString( $this->Name );
82 $description = $db->escapeString( $this->Description );
83
84 if ( $this->ID == false )
85 {
86 $db->lock( "eZMediaCatalogue_Category" );
87
88 $this->ID = $db->nextID( "eZMediaCatalogue_Category", "ID" );
89
90 $db->query( "INSERT INTO eZMediaCatalogue_Category
91 ( ID, Name, Description, UserID, ParentID ) VALUES
92 ( '$this->ID', '$name', '$description', '$this->UserID', '$this->ParentID' )" );
93 $db->unlock();
94 }
95 else
96 {
97 $db->query( "UPDATE eZMediaCatalogue_Category SET
98 Name='$name',
99 Description='$description',
100 UserID='$this->UserID',
101 ParentID='$this->ParentID' WHERE ID='$this->ID'" );
102 }
103
104
105 if ( $dbError == true )
106 $db->rollback( );
107 else
108 $db->commit();
109
110
111 return true;
112 }
113
117 function delete( $catID=-1 )
118 {
119
120 if ( $catID == -1 )
121 $catID = $this->ID;
122
123 $category = new eZMediaCategory( $catID );
124
125 $categoryList = $category->getByParent( $category );
126
127 foreach ( $categoryList as $category )
128 {
129 $this->delete( $category->id() );
130 }
131
132 foreach ( $this->media() as $media )
133 {
134 $media->delete();
135 }
136
137 $categoryID = $category->id();
138
139 $db =& eZDB::globalDatabase();
140
141 $db->begin( );
142
143 $res1 = $db->query( "DELETE FROM eZMediaCatalogue_Category WHERE ID='$categoryID'" );
144 $res2 = $db->query( "DELETE FROM eZMediaCatalogue_CategoryPermission WHERE ObjectID='$this->ID'" );
145
146 if ( ( $res1 == false) || ( $res2 == false ) )
147 $db->rollback( );
148 else
149 $db->commit();
150
151 }
152
156 function get( $id = -1 )
157 {
158 $db =& eZDB::globalDatabase();
159
160 if ( $id != "" )
161 {
162 $db->array_query( $category_array, "SELECT * FROM eZMediaCatalogue_Category WHERE ID='$id'" );
163 if ( count( $category_array ) > 1 )
164 {
165 die( "Error: Category's with the same ID was found in the database. This shouldent happen." );
166 }
167 else if( count( $category_array ) == 1 )
168 {
169 $this->ID =& $category_array[0][$db->fieldName("ID")];
170 $this->Name =& $category_array[0][$db->fieldName("Name")];
171 $this->Description =& $category_array[0][$db->fieldName("Description")];
172 $this->ParentID =& $category_array[0][$db->fieldName("ParentID")];
173 $this->UserID =& $category_array[0][$db->fieldName("UserID")];
174 }
175 }
176 }
177
183 function getAll()
184 {
185 $db =& eZDB::globalDatabase();
186
187 $return_array = array();
188 $category_array = array();
189
190 $db->array_query( $category_array, "SELECT ID, Name FROM eZMediaCatalogue_Category ORDER BY Name" );
191
192 for ( $i=0; $i<count($category_array); $i++ )
193 {
194 $return_array[$i] = new eZMediaCategory( $category_array[$i][$db->fieldName("ID")] );
195 }
196
197 return $return_array;
198 }
199
204 function &getMedia( &$user, $category=false )
205 {
206 if ( !$category )
207 $category = $this->ID;
208
209 $db =& eZDB::globalDatabase();
210
211 $return_array = array();
212 $media_array = array();
213
214 $db->array_query( $media_array, "SELECT MediaID, CategoryID FROM eZMediaCatalogue_MediaCategoryLink WHERE CategoryID='$category' ORDER BY MediaID DESC" );
215
216 for ( $i = 0; $i < count( $media_array ); $i++ )
217 {
218 $media = new eZMedia( $media_array[$i][$db->fieldName( "MediaID" )] );
219 if ( $media->hasReadPermissions( $user ) )
220 {
221 array_push( $return_array, $media );
222 }
223 }
224 return $return_array;
225 }
226
230 function countByParent( &$parent )
231 {
232 if ( is_a( $parent, "eZMediaCategory" ) )
233 {
234 $db =& eZDB::globalDatabase();
235
236 $parentID = $parent->id();
237
238 $db->query_single( $count, "SELECT count( ID ) AS Count FROM eZMediaCatalogue_Category
239 WHERE ParentID='$parentID'", "Count" );
240
241 return $count;
242 }
243 else
244 {
245 return 0;
246 }
247 }
248
257 function &getByParent( &$parent, $offset = 0, $max = -1 )
258 {
259 if ( is_a( $parent, "eZMediaCategory" ) )
260 {
261 $db =& eZDB::globalDatabase();
262
263 $return_array = array();
264 $category_array = array();
265
266 $parentID = $parent->id();
267
268 $db->array_query( $category_array, "SELECT ID, Name FROM eZMediaCatalogue_Category
269 WHERE ParentID='$parentID'
270 ORDER BY Name", array( "Limit" => $max,
271 "Offset" => $offset ) );
272
273 for ( $i=0; $i<count($category_array); $i++ )
274 {
275 $return_array[$i] = new eZMediaCategory( $category_array[$i][$db->fieldName("ID")] );
276 }
277
278 return $return_array;
279 }
280 else
281 {
282 return array();
283 }
284 }
285
292 function &getByName( &$name )
293 {
294 $db =& eZDB::globalDatabase();
295
296 $topic = new eZMediaCategory();
297
298 $name = $db->escapeString( $name );
299
300 if( $name != "" )
301 {
302 $db->array_query( $author_array, "SELECT ID, Name FROM eZMediaCatalogue_Category WHERE Name='$name'" );
303
304 if( count( $author_array ) == 1 )
305 {
306 $topic = new eZMediaCategory( $author_array[0][$db->fieldName("ID")] );
307 }
308 }
309
310 return $topic;
311 }
312
313
321 function path( $categoryID=0 )
322 {
323 if ( $categoryID == 0 )
324 {
325 $categoryID = $this->ID;
326 }
327
328 $category = new eZMediaCategory( $categoryID );
329
330 $path = array();
331
332 $parent = $category->parent();
333
334 if ( $parent != 0 )
335 {
336 $path = array_merge( $path, $this->path( $parent->id() ) );
337 }
338 else
339 {
340 // array_push( $path, $category->name() );
341 }
342
343 if ( $categoryID != 0 )
344 array_push( $path, array( $category->id(), $category->name() ) );
345
346 return $path;
347 }
348
352 function &getTree( $parentID=0, $level=0 )
353 {
354 $category = new eZMediaCategory( $parentID );
355
356 $categoryList = $category->getByParent( $category );
357
358 $tree = array();
359 $level++;
360 foreach ( $categoryList as $category )
361 {
362 array_push( $tree, array( $return_array[] = new eZMediaCategory( $category->id() ), $level ) );
363
364 if ( $category != 0 )
365 {
366 $tree = array_merge( $tree, $this->getTree( $category->id(), $level ) );
367 }
368
369 }
370
371 return $tree;
372 }
373
374
378 function id()
379 {
380 return $this->ID;
381 }
382
383
387 function &name( $html = true )
388 {
389 $this->Name = stripslashes($this->Name);
390 if( $html )
391 return htmlspecialchars( $this->Name );
392 else
393 return $this->Name;
394 }
395
399 function &description( $html = true )
400 {
401 $this->Description = stripslashes($this->Description);
402 if( $html )
403 return htmlspecialchars( $this->Description );
404 else
405 return $this->Description;
406
407 }
408
412 function &parent()
413 {
414 if ( $this->ParentID != 0 )
415 {
416 return new eZMediaCategory( $this->ParentID );
417 }
418 else
419 {
420 return 0;
421 }
422 }
423
424
428 function &user()
429 {
430 if ( $this->UserID != 0 )
431 {
432 $ret = new eZUser( $this->UserID );
433 }
434
435 return $ret;
436 }
437
444 function isOwner( &$user, &$mediacategory )
445 {
446 if( !is_a( $user, "eZUser" ) )
447 return false;
448
449 $db =& eZDB::globalDatabase();
450 $db->query_single( $res, "SELECT UserID from eZMediaCatalogue_Category WHERE ID='$mediacategory'");
451 $userID = $res[$db->fieldName("UserID")];
452 if( $userID == $user->id() )
453 return true;
454
455 return false;
456 }
457
458
462 function setName( &$value )
463 {
464 $this->Name = $value;
465 }
466
470 function setDescription( &$value )
471 {
472 $this->Description = $value;
473 }
474
478 function setParent( &$value )
479 {
480 if ( is_a( $value, "eZMediaCategory" ) )
481 {
482 $this->ParentID = $value->id();
483 }
484 }
485
489 function setUser( &$user )
490 {
491 if ( is_a( $user, "eZUser" ) )
492 {
493 $userID = $user->id();
494
495 $this->UserID = $userID;
496 }
497 }
498
504 function addMedia( &$value, $categoryid = false )
505 {
506 if ( is_a( $value, "eZMedia" ) )
507 $mediaID = $value->id();
508 else if ( is_numeric( $value ) )
509 $mediaID = $value;
510 else
511 return false;
512
513 if ( !$categoryid )
514 $categoryid = $this->ID;
515
516 $db =& eZDB::globalDatabase();
517
518 $mediaID = $value->id();
519
520 $db->begin( );
521 $db->lock( "eZMediaCatalogue_MediaCategoryLink" );
522
523 $query = "DELETE FROM eZMediaCatalogue_MediaCategoryLink WHERE
524 CategoryID='$categoryid' AND MediaID='$mediaid'";
525
526 $db->query( $query );
527
528 $nextID = $db->nextID( "eZMediaCatalogue_MediaCategoryLink", "ID" );
529
530 $query = "INSERT INTO eZMediaCatalogue_MediaCategoryLink ( ID, CategoryID, MediaID )
531 VALUES ( '$nextID', '$categoryid', '$mediaID' )";
532
533 $res = $db->query( $query );
534
535 $db->unlock();
536
537 if ( $res == false )
538 $db->rollback( );
539 else
540 $db->commit();
541 }
542
548 function removeMedia( &$value, $categoryid = false )
549 {
550 if ( is_a( $value, "eZMedia" ) )
551 $mediaID = $value->id();
552 else if ( is_numeric( $value ) )
553 $mediaID = $value;
554 else
555 return false;
556
557 if ( !$categoryid )
558 $categoryid = $this->ID;
559
560 $db =& eZDB::globalDatabase();
561 $query = "DELETE FROM eZMediaCatalogue_MediaCategoryLink
562 WHERE CategoryID='$categoryid' AND
563 MediaID='$mediaID'";
564
565 $db->begin( );
566
567 $res = $db->query( $query );
568
569 if ( $res == false )
570 $db->rollback( );
571 else
572 $db->commit();
573 }
574
575
579 function mediaCount()
580 {
581 if ( !isset($limit) || isset($limit) && $limit == 0 )
582 {
583 $ini =& eZINI::instance( 'site.ini' );
584 $limit = $ini->variable( "eZMediaCatalogueMain", "ListMediaPerPage" );
585 }
586
587 $db =& eZDB::globalDatabase();
588
589 $db->query_single( $count, "
590 SELECT count( DISTINCT eZMediaCatalogue_Media.ID ) AS Count
591 FROM eZMediaCatalogue_Media, eZMediaCatalogue_Category, eZMediaCatalogue_MediaCategoryLink
592 WHERE
593 eZMediaCatalogue_MediaCategoryLink.MediaID = eZMediaCatalogue_Media.ID
594 AND
595 eZMediaCatalogue_Category.ID = eZMediaCatalogue_MediaCategoryLink.CategoryID
596 AND
597 eZMediaCatalogue_Category.ID='$this->ID'", "Count" );
598
599 return $count;
600 }
601
605 function &media( $sortMode = "time", $offset = 0, $limit = -1 )
606 {
607 $db =& eZDB::globalDatabase();
608
609 $return_array = array();
610 $article_array = array();
611
612 $db->array_query( $file_array, "
613 SELECT eZMediaCatalogue_Media.ID AS MediaID, eZMediaCatalogue_Media.OriginalFileName
614 FROM eZMediaCatalogue_Media, eZMediaCatalogue_Category, eZMediaCatalogue_MediaCategoryLink
615 WHERE
616 eZMediaCatalogue_MediaCategoryLink.MediaID = eZMediaCatalogue_Media.ID
617 AND
618 eZMediaCatalogue_Category.ID = eZMediaCatalogue_MediaCategoryLink.CategoryID
619 AND
620 eZMediaCatalogue_Category.ID='$this->ID'
621 GROUP BY eZMediaCatalogue_Media.ID, eZMediaCatalogue_Media.OriginalFileName ORDER BY eZMediaCatalogue_Media.OriginalFileName",
622 array( "Limit" => $limit,
623 "Offset" => $offset ) );
624
625 for ( $i = 0; $i < count( $file_array ); $i++ )
626 {
627 $return_array[$i] = new eZMedia( $file_array[$i][$db->fieldName("MediaID")], false );
628 }
629
630 return $return_array;
631 }
632
633 var $ID;
634 var $Name;
635 var $ParentID;
636 var $Description;
637 var $UserID;
638 var $ExcludeFromSearch;
639 }
640
641 ?>
$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
$topic
foreach( $authorArray as $author) $topic
Definition: admin/articleedit.php:852
$level
$level
Definition: admin/message.php:106
$userID
else $userID
Definition: appointmentedit.php:121
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZMediaCategory
Definition: ezmediacategory.php:55
eZMediaCategory\getMedia
& getMedia(&$user, $category=false)
Definition: ezmediacategory.php:204
eZMediaCategory\mediaCount
mediaCount()
Definition: ezmediacategory.php:579
eZMediaCategory\media
& media( $sortMode="time", $offset=0, $limit=-1)
Definition: ezmediacategory.php:605
eZMediaCategory\description
& description( $html=true)
Definition: ezmediacategory.php:399
eZMediaCategory\getByName
& getByName(&$name)
Definition: ezmediacategory.php:292
eZMediaCategory\parent
& parent()
Definition: ezmediacategory.php:412
eZMediaCategory\name
& name( $html=true)
Definition: ezmediacategory.php:387
eZMediaCategory\path
path( $categoryID=0)
Definition: ezmediacategory.php:321
eZMediaCategory\user
& user()
Definition: ezmediacategory.php:428
eZMediaCategory\$ExcludeFromSearch
$ExcludeFromSearch
Definition: ezmediacategory.php:638
eZMediaCategory\getAll
getAll()
Definition: ezmediacategory.php:183
eZMediaCategory\getTree
& getTree( $parentID=0, $level=0)
Definition: ezmediacategory.php:352
eZMediaCategory\$Description
$Description
Definition: ezmediacategory.php:636
eZMediaCategory\setDescription
setDescription(&$value)
Definition: ezmediacategory.php:470
eZMediaCategory\id
id()
Definition: ezmediacategory.php:378
eZMediaCategory\$ParentID
$ParentID
Definition: ezmediacategory.php:635
eZMediaCategory\addMedia
addMedia(&$value, $categoryid=false)
Definition: ezmediacategory.php:504
eZMediaCategory\store
store()
Definition: ezmediacategory.php:75
eZMediaCategory\$UserID
$UserID
Definition: ezmediacategory.php:637
eZMediaCategory\setParent
setParent(&$value)
Definition: ezmediacategory.php:478
eZMediaCategory\__construct
__construct( $id=-1)
Definition: ezmediacategory.php:62
eZMediaCategory\isOwner
isOwner(&$user, &$mediacategory)
Definition: ezmediacategory.php:444
eZMediaCategory\$ID
$ID
Definition: ezmediacategory.php:633
eZMediaCategory\setName
setName(&$value)
Definition: ezmediacategory.php:462
eZMediaCategory\getByParent
& getByParent(&$parent, $offset=0, $max=-1)
Definition: ezmediacategory.php:257
eZMediaCategory\$Name
$Name
Definition: ezmediacategory.php:634
eZMediaCategory\setUser
setUser(&$user)
Definition: ezmediacategory.php:489
eZMediaCategory\countByParent
countByParent(&$parent)
Definition: ezmediacategory.php:230
eZMediaCategory\removeMedia
removeMedia(&$value, $categoryid=false)
Definition: ezmediacategory.php:548
eZMedia
Definition: ezmedia.php:65
eZUser
Definition: ezuser.php:76
$ini
$ini
Definition: classes/admin/linklist.php:64
$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
$media
if(isset( $AddMedia)) $media
Definition: ezarticle/admin/medialist.php:76
$db
$db
Definition: ezarticle/user/authorlist.php:53
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$offset
$offset
Definition: ezstats/admin/cron.php:51
$count
$count
Definition: onlinetypelist.php:108
$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+.