Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

eztipcategory.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: eztipcategory.php,v 1.27 2001/10/16 14:25:05 br Exp $
5 //
6 // Definition of eZTipCategory 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( "eztip/classes/eztip.php" );
42
43 class eZTipCategory
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
72 $name = $db->escapeString( $this->Name );
73 $description = $db->escapeString( $this->Description );
74 $isPublished = $db->escapeString( $this->IsPublished );
75
76 if ( !isset( $this->ID ) )
77 {
78 $db->lock( "eZTip_Category" );
79 $nextID = $db->nextID( "eZTip_Category", "ID" );
80
81 $res = $db->query( "INSERT INTO eZTip_Category
82 ( ID, Name, Description, ParentID, SectionID, IsPublished, LocationID )
83 VALUES
84 ( '$nextID',
85 '$name',
86 '$description',
87 '$this->ParentID',
88 '$this->SectionArray',
89 '$isPublished',
90 '$this->LocationID'
91 )" );
92
93 $this->ID = $nextID;
94 }
95 else
96 {
97 $res = $db->query( "UPDATE eZTip_Category SET
98 Name='$name',
99 Description='$description',
100 ParentID='$this->ParentID',
101 SectionID='$this->SectionArray',
102 IsPublished='$isPublished',
103 LocationID='$this->LocationID'
104 WHERE ID='$this->ID'" );
105 }
106
107 $db->unlock();
108
109 if ( $res == false )
110 $db->rollback( );
111 else
112 $db->commit();
113
114
115 return true;
116 }
117
121 function delete()
122 {
123 $db =& eZDB::globalDatabase();
124
125 if ( isset( $this->ID ) )
126 {
127 $db->array_query( $tip_id_array, "SELECT TipID FROM eZTip_TipCategoryLink WHERE
128 CategoryID='$this->ID'");
129
130 if ( count( $tip_id_array ) > 0 )
131 {
132 foreach( $tip_id_array as $tip_id )
133 {
134 $link = new eZTip( $tip_id[$db->fieldName( "TipID" )] );
135 $link->delete();
136 }
137 }
138
139 $db->query( "DELETE FROM eZTip_TipCategoryLink
140 WHERE CategoryID='$this->ID'" );
141
142 $db->query( "DELETE FROM eZTip_Category WHERE ID='$this->ID'" );
143 }
144
145 return true;
146 }
147
151 function get( $id=-1 )
152 {
153 $ret = false;
154 $db =& eZDB::globalDatabase();
155
156 if ( $id != "" )
157 {
158 $db->array_query( $category_array, "SELECT * FROM eZTip_Category WHERE ID='$id'" );
159 if ( count( $category_array ) > 1 )
160 {
161 die( "Error: Category's with the same ID was found in the database. This shouldent happen." );
162 }
163 else if( count( $category_array ) == 1 )
164 {
165 $ret = true;
166 $this->ID = $category_array[0][$db->fieldName("ID")];
167 $this->Name = $category_array[0][$db->fieldName("Name")];
168 $this->Description = $category_array[0][$db->fieldName("Description")];
169 $this->ParentID = $category_array[0][$db->fieldName("ParentID")];
170 $this->SectionID = $category_array[0][$db->fieldName("SectionID")];
171 $this->IsPublished = $category_array[0][$db->fieldName("IsPublished")];
172 $this->LocationID = $category_array[0][$db->fieldName("LocationID")];
173 }
174 }
175
176 return $ret;
177 }
178
184 function getAll()
185 {
186 $db =& eZDB::globalDatabase();
187
188 $return_array = array();
189 $category_array = array();
190
191 $db->array_query( $category_array, "SELECT ID, Name FROM eZTip_Category ORDER BY Name" );
192
193 for ( $i=0; $i < count($category_array); $i++ )
194 {
195 $return_array[$i] = new eZTipCategory( $category_array[$i][$db->fieldName("ID")], 0 );
196 }
197
198 return $return_array;
199 }
200
206 function getByParent( $parent )
207 {
208 if ( get_class( $parent ) == "eZTipCategory" )
209 {
210 $db =& eZDB::globalDatabase();
211
212 $return_array = array();
213 $category_array = array();
214
215 $parentID = $parent->id();
216
217 $db->array_query( $category_array, "SELECT ID, Name FROM eZTip_Category
218 WHERE ParentID='$parentID'
219 ORDER BY Name" );
220
221 for ( $i=0; $i < count($category_array); $i++ )
222 {
223 $return_array[$i] = new eZTipCategory( $category_array[$i][$db->fieldName("ID")], 0 );
224 }
225
226 return $return_array;
227 }
228 else
229 {
230 return array();
231 }
232 }
233
241 function path( $categoryID=0 )
242 {
243 if ( $categoryID == 0 )
244 {
245 $categoryID = $this->ID;
246 }
247
248 $category = new eZTipCategory( $categoryID );
249
250 $path = array();
251
252 $parent = $category->parent();
253
254 if ( $parent != 0 )
255 {
256 $path = array_merge( $path, $this->path( $parent->id() ) );
257 }
258 else
259 {
260 // array_push( $path, $category->name() );
261 }
262
263 if ( $categoryID != 0 )
264 array_push( $path, array( $category->id(), $category->name() ) );
265
266 return $path;
267 }
268
269 function getTree( $parentID=0, $level=0 )
270 {
271 $category = new eZTipCategory( $parentID );
272
273 $categoryList = $category->getByParent( $category );
274
275 $tree = array();
276 $level++;
277 foreach ( $categoryList as $category )
278 {
279 array_push( $tree, array( $returnObj = new eZTipCategory( $category->id() ), $level ) );
280
281 if ( $category != 0 )
282 {
283 $tree = array_merge( $tree, $this->getTree( $category->id(), $level ) );
284 }
285 }
286 return $tree;
287 }
288
289
293 function id()
294 {
295 return $this->ID;
296 }
297
298
302 function name( $html = true )
303 {
304 if( $html && $this->Name != "" )
305 return htmlspecialchars( $this->Name );
306 return $this->Name;
307 }
308
312 function description( $html = true )
313 {
314 if( $html && $this->Description != "" )
315 return htmlspecialchars( $this->Description );
316 return $this->Description;
317 }
318
322 function parent()
323 {
324 if ( $this->ParentID != 0 )
325 {
326 return new eZTipCategory( $this->ParentID );
327 }
328 else
329 {
330 return 0;
331 }
332 }
333
334
338 function ispublished( )
339 {
340 $ret = false;
341 if ( $this->IsPublished == "1" )
342 {
343 $ret = true;
344 }
345
346 return $ret;
347 }
351 function locationID( )
352 {
353 return $this->LocationID;
354 }
358 function setName( $value )
359 {
360 $this->Name = $value;
361 }
362
366 function setDescription( $value )
367 {
368 $this->Description = $value;
369 }
370
374 function setParent( $value )
375 {
376 $this->ParentID = $value;
377 }
378
382 function setLocationID( $value )
383 {
384 $this->LocationID = $value;
385 }
386
391 function setIsPublished( $value )
392 {
393 if ( $value == true )
394 {
395 $this->IsPublished = "1";
396 }
397 else
398 {
399 $this->IsPublished = "0";
400 }
401 }
402
403 function setSectionArray( $value )
404 {
405 $ret = ",";
406 if ( isset( $value ) )
407 {
408 if ( $value[0] == "0" )
409 {
410 $ret="0";
411 }
412 else
413 {
414 foreach ( $value as $section )
415 {
416 $ret .= "$section,";
417 }
418 // $ret = substr("$ret", 0, -1);
419 }
420 }
421 $this->SectionArray = $ret;
422 }
423
427 function getSectionArray()
428 {
429 $ret = Array();
430
431 $this->get();
432 $temp = $this->SectionID;
433
434 if ( !is_null( $temp ) )
435 {
436 $ret = explode( "," , $temp);
437 }
438
439 return $ret;
440 }
441
445 function addTip( $value )
446 {
447 if ( get_class( $value ) == "eZTip" )
448 {
449 $db =& eZDB::globalDatabase();
450
451 $db->begin( );
452
453 $db->lock( "eZTip_TipCategoryLink" );
454 $nextID = $db->nextID( "eZTip_TipCategoryLink", "ID" );
455
456 $tipID = $value->id();
457
458 $query = "INSERT INTO
459 eZTip_TipCategoryLink
460 ( ID, CategoryID, TipID )
461 VALUES
462 ( '$nextID',
463 '$this->ID',
464 '$tipID' )";
465
466 $res = $db->query( $query );
467
468 $db->unlock();
469
470 if ( $res == false )
471 $db->rollback( );
472 else
473 $db->commit();
474 }
475 }
476
482 function &tiplist( $sortMode="name",
483 $fetchUnActive=false,
484 $offset=0,
485 $limit=50 )
486 {
487 $db =& eZDB::globalDatabase();
488
489 $return_array = array();
490 $tip_array = array();
491
492 $fetchActiveSQL = "";
493 if ( $fetchUnActive == false )
494 {
495 $fetchActiveSQL = "AND eZTip_Tip.IsActive = '1'";
496 }
497
498 $orderBySQL = "Tip.Name ASC";
499
500 $db->array_query( $tip_array,
501 "SELECT Tip.ID, Tip.Name
502 FROM eZTip_Tip AS Tip, eZTip_TipCategoryLink AS ACL
503 WHERE Tip.ID=ACL.TipID AND ACL.CategoryID='$this->ID'
504 ORDER BY $orderBySQL", array( "Limit" => $limit, "Offset" => $offset ) );
505
506 foreach( $tip_array as $tip )
507 {
508 $return_array[] = new eZTip( $tip[$db->fieldName("ID")] );
509 }
510
511 return $return_array;
512 }
513
519 function &tips( $sortMode="name",
520 $fetchUnActive=false,
521 $offset=0,
522 $limit=50,
523 $tipLocationID=0 )
524 {
525 global $GlobalSectionID;
526 $db =& eZDB::globalDatabase();
527
528 // section selector
529 $section = new eZSection();
530 $sectionID = $section->ID;
531
532 $return_array = array();
533 $tip_array = array();
534
535 $fetchActiveSQL = "";
536 if ( $fetchUnActive == false )
537 {
538 $fetchActiveSQL = "AND eZTip_Tip.IsActive = '1'";
539 }
540 if ( $sortMode == "name" )
541 $orderBySQL = "eZTip_Tip.Name ASC";
542 else
543 $orderBySQL = "eZTip_View.ViewOffsetCount ASC";
544
545 $sectionCheckSQL = "AND (eZTip_Category.SectionID LIKE '%,$GlobalSectionID,%' OR eZTip_Category.SectionID = '0')";
546 $locationCheckSQL = "AND (eZTip_Category.LocationID LIKE $tipLocationID)";
547
548 $db->array_query( $tip_array,
549 "SELECT eZTip_Tip.ID, eZTip_View.ViewCount, eZTip_Tip.Name
550 FROM
551 eZTip_Tip,
552 eZTip_TipCategoryLink,
553 eZTip_View,
554 eZTip_Category
555 WHERE
556 eZTip_TipCategoryLink.TipID = eZTip_Tip.ID
557 AND eZTip_TipCategoryLink.CategoryID = eZTip_Category.ID
558 AND eZTip_View.TipID = eZTip_Tip.ID
559 AND eZTip_Category.IsPublished = 1
560 $sectionCheckSQL
561 $fetchActiveSQL
562 $locationCheckSQL
563 ORDER BY $orderBySQL",
564 array( "Limit" => $limit, "Offset" => $offset ) );
565
566
567 if ( count( $tip_array ) > 0 )
568 {
569 for ( $i=0; $i < count($tip_array); $i++ )
570 {
571 $return_array[$i] = new eZTip( $tip_array[$i][$db->fieldName("ID")] );
572 }
573 }
574 return $return_array;
575 }
576
577 var $ID;
578 var $Name;
579 var $ParentID;
580 var $Description;
581 var $IsPublished;
582 var $SectionID;
583 // corrected $tipLOcationID
584 var $tipLocationID;
585 var $LocationID;
586 var $SectionArray; // used to store the section array as a string
587 }
588
589 ?>
$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
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZSection
Definition: ezsection.php:45
eZTipCategory
Definition: eztipcategory.php:44
eZTipCategory\tips
& tips( $sortMode="name", $fetchUnActive=false, $offset=0, $limit=50, $tipLocationID=0)
Definition: eztipcategory.php:519
eZTipCategory\setParent
setParent( $value)
Definition: eztipcategory.php:374
eZTipCategory\store
store()
Definition: eztipcategory.php:65
eZTipCategory\description
description( $html=true)
Definition: eztipcategory.php:312
eZTipCategory\getByParent
getByParent( $parent)
Definition: eztipcategory.php:206
eZTipCategory\ispublished
ispublished()
Definition: eztipcategory.php:338
eZTipCategory\setDescription
setDescription( $value)
Definition: eztipcategory.php:366
eZTipCategory\$IsPublished
$IsPublished
Definition: eztipcategory.php:581
eZTipCategory\$SectionArray
$SectionArray
Definition: eztipcategory.php:586
eZTipCategory\$ParentID
$ParentID
Definition: eztipcategory.php:579
eZTipCategory\addTip
addTip( $value)
Definition: eztipcategory.php:445
eZTipCategory\getTree
getTree( $parentID=0, $level=0)
Definition: eztipcategory.php:269
eZTipCategory\$ID
$ID
Definition: eztipcategory.php:577
eZTipCategory\setIsPublished
setIsPublished( $value)
Definition: eztipcategory.php:391
eZTipCategory\name
name( $html=true)
Definition: eztipcategory.php:302
eZTipCategory\$LocationID
$LocationID
Definition: eztipcategory.php:585
eZTipCategory\id
id()
Definition: eztipcategory.php:293
eZTipCategory\$tipLocationID
$tipLocationID
Definition: eztipcategory.php:584
eZTipCategory\__construct
__construct( $id=-1)
Definition: eztipcategory.php:51
eZTipCategory\getSectionArray
getSectionArray()
Definition: eztipcategory.php:427
eZTipCategory\path
path( $categoryID=0)
Definition: eztipcategory.php:241
eZTipCategory\$SectionID
$SectionID
Definition: eztipcategory.php:582
eZTipCategory\setSectionArray
setSectionArray( $value)
Definition: eztipcategory.php:403
eZTipCategory\tiplist
& tiplist( $sortMode="name", $fetchUnActive=false, $offset=0, $limit=50)
Definition: eztipcategory.php:482
eZTipCategory\getAll
getAll()
Definition: eztipcategory.php:184
eZTipCategory\$Description
$Description
Definition: eztipcategory.php:580
eZTipCategory\$Name
$Name
Definition: eztipcategory.php:578
eZTipCategory\locationID
locationID()
Definition: eztipcategory.php:351
eZTipCategory\parent
parent()
Definition: eztipcategory.php:322
eZTipCategory\setName
setName( $value)
Definition: eztipcategory.php:358
eZTipCategory\setLocationID
setLocationID( $value)
Definition: eztipcategory.php:382
eZTip
Definition: eztip.php:46
$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
$GlobalSectionID
$GlobalSectionID
Definition: ezad/user/datasupplier.php:28
$db
$db
Definition: ezarticle/user/authorlist.php:53
$limit
$limit
Definition: ezimagecatalogue/admin/imagelist.php:312
$section
$section
Definition: ezimagecatalogue/user/categoryedit.php:393
$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
$tip
$tip
Definition: tipstatistics.php:57
$category_array
$category_array
Definition: todoedit.php:604
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.