Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezadcategory.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezadcategory.php 7906 2001-10-16 14:25:05Z br $
5 //
6 // Definition of eZAdCategory class
7 //
8 // Created on: <22-Nov-2000 20:32:30 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
40 // include_once( "classes/ezdb.php" );
41 // include_once( "ezad/classes/ezad.php" );
42
43 class eZAdCategory
44 {
51 function __construct( $id=-1 )
52 {
53 $this->ParentID = 0;
54
55 if ( $id != -1 )
56 {
57 $this->ID = $id;
58 $this->get( $this->ID );
59 }
60 }
61
65 function store()
66 {
67 $db =& eZDB::globalDatabase();
68
69 $db->begin( );
70
71 $name = $db->escapeString( $this->Name );
72 $description = $db->escapeString( $this->Description );
73
74 if ( !isset( $this->ID ) )
75 {
76 $db->lock( "eZAd_Category" );
77 $nextID = $db->nextID( "eZAd_Category", "ID" );
78
79 $res = $db->query( "INSERT INTO eZAd_Category
80 ( ID, Name, Description, ParentID )
81 VALUES
82 ( '$nextID',
83 '$name',
84 '$description',
85 '$this->ParentID' )" );
86
87 $this->ID = $nextID;
88 }
89 else
90 {
91 $res = $db->query( "UPDATE eZAd_Category SET
92 Name='$name',
93 Description='$description',
94 ParentID='$this->ParentID' WHERE ID='$this->ID'" );
95 }
96
97 $db->unlock();
98
99 if ( $res == false )
100 $db->rollback( );
101 else
102 $db->commit();
103
104 return true;
105 }
106
110 function delete()
111 {
112 $db =& eZDB::globalDatabase();
113
114 if ( isset( $this->ID ) )
115 {
116 $db->array_query( $ad_id_array, "SELECT AdID FROM eZAd_AdCategoryLink WHERE
117 CategoryID='$this->ID'");
118
119 if ( count( $ad_id_array ) > 0 )
120 {
121 foreach( $ad_id_array as $ad_id )
122 {
123 $link = new eZAd( $ad_id[$db->fieldName( "AdID" )] );
124 $link->delete();
125 }
126 }
127
128 $db->query( "DELETE FROM eZAd_AdCategoryLink
129 WHERE CategoryID='$this->ID'" );
130
131 $db->query( "DELETE FROM eZAd_Category WHERE ID='$this->ID'" );
132 }
133
134 return true;
135 }
136
140 function get( $id=-1 )
141 {
142 $ret = false;
143 $db =& eZDB::globalDatabase();
144
145 if ( $id != "" )
146 {
147 $db->array_query( $category_array, "SELECT * FROM eZAd_Category WHERE ID='$id'" );
148 if ( count( $category_array ) > 1 )
149 {
150 die( "Error: Category's with the same ID was found in the database. This shouldent happen." );
151 }
152 else if( count( $category_array ) == 1 )
153 {
154 $ret = true;
155 $this->ID = $category_array[0][$db->fieldName("ID")];
156 $this->Name = $category_array[0][$db->fieldName("Name")];
157 $this->Description = $category_array[0][$db->fieldName("Description")];
158 $this->ParentID = $category_array[0][$db->fieldName("ParentID")];
159 }
160 }
161
162 return $ret;
163 }
164
170 function getAll()
171 {
172 $db =& eZDB::globalDatabase();
173
174 $return_array = array();
175 $category_array = array();
176
177 $db->array_query( $category_array, "SELECT ID, Name FROM eZAd_Category ORDER BY Name" );
178
179 for ( $i=0; $i < count($category_array); $i++ )
180 {
181 $return_array[$i] = new eZAdCategory( $category_array[$i][$db->fieldName("ID")], 0 );
182 }
183
184 return $return_array;
185 }
186
192 function getByParent( $parent )
193 {
194 if ( is_a( $parent, "eZAdCategory" ) )
195 {
196 $db =& eZDB::globalDatabase();
197
198 $return_array = array();
199 $category_array = array();
200
201 $parentID = $parent->id();
202
203 $db->array_query( $category_array, "SELECT ID, Name FROM eZAd_Category
204 WHERE ParentID='$parentID'
205 ORDER BY Name" );
206
207 for ( $i=0; $i < count($category_array); $i++ )
208 {
209 $return_array[$i] = new eZAdCategory( $category_array[$i][$db->fieldName("ID")], 0 );
210 }
211
212 return $return_array;
213 }
214 else
215 {
216 return 0;
217 }
218 }
219
227 function path( $categoryID=0 )
228 {
229 if ( $categoryID == 0 )
230 {
231 $categoryID = $this->ID;
232 }
233
234 $category = new eZAdCategory( $categoryID );
235
236 $path = array();
237
238 $parent = $category->parent();
239
240 if ( $parent != 0 )
241 {
242 $path = array_merge( $path, $this->path( $parent->id() ) );
243 }
244 else
245 {
246 // array_push( $path, $category->name() );
247 }
248
249 if ( $categoryID != 0 )
250 array_push( $path, array( $category->id(), $category->name() ) );
251
252 return $path;
253 }
254
255 function getTree( $parentID=0, $level=0 )
256 {
257 $category = new eZAdCategory( $parentID );
258
259 $categoryList = $category->getByParent( $category );
260
261 $tree = array();
262 $level++;
263 foreach ( $categoryList as $category )
264 {
265 array_push( $tree, array( $returnObj = new eZAdCategory( $category->id() ), $level ) );
266
267 if ( $category != 0 )
268 {
269 $tree = array_merge( $tree, $this->getTree( $category->id(), $level ) );
270 }
271 }
272 return $tree;
273 }
274
275
279 function id()
280 {
281 return $this->ID;
282 }
283
284
288 function name( $html = true )
289 {
290 if( $this->Name != '' && $html )
291 return htmlspecialchars( $this->Name );
292 return $this->Name;
293 }
294
298 function description( $html = true )
299 {
300 if( $this->Description != '' && $html )
301 return htmlspecialchars( $this->Description );
302 return $this->Description;
303 }
304
308 function parent()
309 {
310 if ( $this->ParentID != 0 )
311 {
312 return new eZAdCategory( $this->ParentID );
313 }
314 else
315 {
316 return 0;
317 }
318 }
319
320
325 function excludeFromSearch( )
326 {
327 $ret = false;
328 if ( $this->ExcludeFromSearch == "true" )
329 {
330 $ret = true;
331 }
332
333 return $ret;
334 }
335
336
337
341 function setName( $value )
342 {
343 $this->Name = $value;
344 }
345
349 function setDescription( $value )
350 {
351 $this->Description = $value;
352 }
353
357 function setParent( $value )
358 {
359 if ( is_a( $value, "eZAdCategory" ) )
360 {
361 $this->ParentID = $value->id();
362 }
363 }
364
369 function setExcludeFromSearch( $value )
370 {
371 if ( $value == true )
372 {
373 $this->ExcludeFromSearch = "1";
374 }
375 else
376 {
377 $this->ExcludeFromSearch = "0";
378 }
379 }
380
384 function addAd( $value )
385 {
386 if ( is_a( $value, "eZAd" ) )
387 {
388 $db =& eZDB::globalDatabase();
389
390 $db->begin( );
391
392 $db->lock( "eZAd_AdCategoryLink" );
393 $nextID = $db->nextID( "eZAd_AdCategoryLink", "ID" );
394
395 $adID = $value->id();
396
397 $query = "INSERT INTO
398 eZAd_AdCategoryLink
399 ( ID, CategoryID, AdID )
400 VALUES
401 ( '$nextID',
402 '$this->ID',
403 '$adID' )";
404
405 $res = $db->query( $query );
406
407 $db->unlock();
408
409 if ( $res == false )
410 $db->rollback( );
411 else
412 $db->commit();
413 }
414 }
415
421 function &adlist( $sortMode="name",
422 $fetchUnActive=false,
423 $offset=0,
424 $limit=50 )
425 {
426 $db =& eZDB::globalDatabase();
427
428 $return_array = array();
429 $ad_array = array();
430
431 $fetchActiveSQL = "";
432 if ( $fetchUnActive == false )
433 {
434 $fetchActiveSQL = "AND eZAd_Ad.IsActive = '1'";
435 }
436
437 $orderBySQL = "Ad.Name ASC";
438
439 $db->array_query( $ad_array,
440 "SELECT Ad.ID, Ad.Name
441 FROM eZAd_Ad AS Ad, eZAd_AdCategoryLink AS ACL
442 WHERE Ad.ID=ACL.AdID AND ACL.CategoryID='$this->ID'
443 ORDER BY $orderBySQL", array( "Limit" => $limit, "Offset" => $offset ) );
444
445 foreach( $ad_array as $ad )
446 {
447 $return_array[] = new eZAd( $ad[$db->fieldName("ID")] );
448 }
449
450 return $return_array;
451 }
452
458 function &ads( $sortMode="name",
459 $fetchUnActive=false,
460 $offset=0,
461 $limit=50 )
462 {
463 $db =& eZDB::globalDatabase();
464
465 $return_array = array();
466 $ad_array = array();
467
468 $fetchActiveSQL = "";
469 if ( $fetchUnActive == false )
470 {
471 $fetchActiveSQL = "AND eZAd_Ad.IsActive = '1'";
472 }
473
474 if ( $sortMode == "name" )
475 $orderBySQL = "eZAd_Ad.Name ASC";
476 else
477 $orderBySQL = "eZAd_View.ViewOffsetCount ASC";
478
479 $db->array_query( $ad_array,
480 "SELECT eZAd_Ad.ID, eZAd_View.ViewCount, eZAd_Ad.Name
481 FROM
482 eZAd_Ad,
483 eZAd_AdCategoryLink,
484 eZAd_View
485 WHERE
486 eZAd_AdCategoryLink.AdID = eZAd_Ad.ID
487 AND eZAd_View.AdID = eZAd_Ad.ID
488 $fetchActiveSQL
489 AND eZAd_AdCategoryLink.CategoryID='$this->ID'
490 ORDER BY $orderBySQL",
491 array( "Limit" => $limit, "Offset" => $offset ) );
492
493 if ( count( $ad_array ) > 0 )
494 {
495 for ( $i=0; $i < count($ad_array); $i++ )
496 {
497 $return_array[$i] = new eZAd( $ad_array[$i][$db->fieldName("ID")] );
498 }
499 }
500
501 return $return_array;
502 }
503
504 var $ID;
505 var $Name;
506 var $ParentID;
507 var $Description;
508 var $ExcludeFromSearch;
509
510 }
511
512 ?>
$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
$level
$level
Definition: admin/message.php:106
$ad
$ad
Definition: adstatistics.php:56
eZAdCategory
Definition: ezadcategory.php:44
eZAdCategory\name
name( $html=true)
Definition: ezadcategory.php:288
eZAdCategory\setDescription
setDescription( $value)
Definition: ezadcategory.php:349
eZAdCategory\$ExcludeFromSearch
$ExcludeFromSearch
Definition: ezadcategory.php:508
eZAdCategory\$ID
$ID
Definition: ezadcategory.php:504
eZAdCategory\setName
setName( $value)
Definition: ezadcategory.php:341
eZAdCategory\$Name
$Name
Definition: ezadcategory.php:505
eZAdCategory\setParent
setParent( $value)
Definition: ezadcategory.php:357
eZAdCategory\excludeFromSearch
excludeFromSearch()
Definition: ezadcategory.php:325
eZAdCategory\setExcludeFromSearch
setExcludeFromSearch( $value)
Definition: ezadcategory.php:369
eZAdCategory\path
path( $categoryID=0)
Definition: ezadcategory.php:227
eZAdCategory\id
id()
Definition: ezadcategory.php:279
eZAdCategory\adlist
& adlist( $sortMode="name", $fetchUnActive=false, $offset=0, $limit=50)
Definition: ezadcategory.php:421
eZAdCategory\parent
parent()
Definition: ezadcategory.php:308
eZAdCategory\addAd
addAd( $value)
Definition: ezadcategory.php:384
eZAdCategory\getTree
getTree( $parentID=0, $level=0)
Definition: ezadcategory.php:255
eZAdCategory\__construct
__construct( $id=-1)
Definition: ezadcategory.php:51
eZAdCategory\ads
& ads( $sortMode="name", $fetchUnActive=false, $offset=0, $limit=50)
Definition: ezadcategory.php:458
eZAdCategory\getByParent
getByParent( $parent)
Definition: ezadcategory.php:192
eZAdCategory\getAll
getAll()
Definition: ezadcategory.php:170
eZAdCategory\description
description( $html=true)
Definition: ezadcategory.php:298
eZAdCategory\store
store()
Definition: ezadcategory.php:65
eZAdCategory\$Description
$Description
Definition: ezadcategory.php:507
eZAdCategory\$ParentID
$ParentID
Definition: ezadcategory.php:506
eZAd
Definition: ezad.php:46
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
$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
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$link
$link
Definition: ezlink/admin/attributeedit.php:49
$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
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.