Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezlinkcategory.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezlinkcategory.php 8926 2002-01-11 09:33:44Z kaid $
5 //
6 // Definition of eZLinkCategory class
7 //
8 // Created on: <27-Jun-2001 12:41:48 br>
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
32
33 // include_once( "classes/ezdb.php" );
34 // include_once( "ezimagecatalogue/classes/ezimage.php" );
35
36 class eZLinkCategory
37 {
41 function __construct( $id=-1 )
42 {
43 if ( $id != -1 )
44 {
45 $this->ID = $id;
46 $this->ImageID = 0;
47 $this->get( $this->ID );
48 }
49 }
50
54 function store()
55 {
56 $db =& eZDB::globalDatabase();
57
58 $name = $db->escapeString( $this->Name );
59 $description = $db->escapeString( $this->Description );
60
61 $db->begin();
62
63 $db->lock( "eZLink_Category" );
64
65 $nextID = $db->nextID( "eZLink_Category", "ID" );
66 $queryText = "INSERT INTO eZLink_Category
67 (ID, Parent, Name, ImageID, Description, SectionID)
68 VALUES
69 ('$nextID',
70 '$this->Parent',
71 '$name',
72 '$this->ImageID',
73 '$description',
74 '$this->SectionID' )";
75
76 $res = $db->query( $queryText );
77
78 $db->unlock();
79
80 $this->ID = $nextID;
81
82 if ( $res == false )
83 $db->rollback( );
84 else
85 $db->commit();
86 }
87
91 function update()
92 {
93 $db =& eZDB::globalDatabase();
94
95 $name = $db->escapeString( $this->Name );
96 $description = $db->escapeString( $this->Description );
97
98 $db->begin( );
99
100 $res = $db->query( "UPDATE eZLink_Category SET
101 Name='$name',
102 Description='$description',
103 Parent='$this->Parent',
104 ImageID='$this->ImageID',
105 SectionID='$this->SectionID'
106 WHERE ID='$this->ID'" );
107
108 if ( $res == false )
109 $db->rollback( );
110 else
111 $db->commit();
112 }
113
117 static public function removeLink( $value, $categoryid = false )
118 {
119 if( is_a( $value, "eZLink" ) )
120 $linkID = $value->id();
121 else if (is_Numeric( $value ) )
122 $linkID = $value;
123 else
124 return false;
125
126 if ( !$categoryid )
127 $categoryid = 0;
128
129 $db =& eZDB::globaldatabase();
130 $db->query( "DELETE FROM eZLink_LinkCategoryLink
131 WHERE CategoryID='$categoryid' AND
132 LinkID='$linkID'" );
133 }
134
135
139 static public function addLink( $value, $categoryid = false )
140 {
141 if ( is_a( $value, "eZLink" ) )
142 $linkID = $value->id();
143 else if ( is_nummeric( $value ) )
144 $linkID = $value;
145 else
146 return false;
147
148 if ( !$categoryid )
149 $categoryid = 0;
150
151 $db =& eZDB::globalDatabase();
152
153 $db->begin();
154 $db->lock( "eZLink_LinkCategoryLink" );
155
156 $nextID = $db->nextID( "eZLink_LinkCategoryLink", "ID" );
157 $res[] = $db->query( "INSERT INTO eZLink_LinkCategoryLink
158 (ID, LinkID, CategoryID)
159 VALUES
160 ('$nextID', '$linkID', '$categoryid') ");
161 $db->unlock();
162 eZDB::finish( $res, $db );
163 }
164
168 /* function delete( $id = -1 )
169 {
170 if( $id == -1 )
171 $id = $this->ID;
172
173 // delete children, and links
174 $children = eZLinkCategory::getByParent( $id );
175 foreach( $children as $child )
176 {
177 $child->delete();
178 }
179 $links = eZLinkCategory::links( -1, -1, true, $id );
180 foreach( $links as $link )
181 {
182 $link->delete();
183 }
184 // delete self
185 $db =& eZDB::globalDatabase();
186 $db->query( "DELETE FROM eZLink_LinkCategoryLink WHERE CategoryID='$id'" );
187 $db->query( "DELETE FROM eZLink_LinkCategoryDefinition WHERE CategoryID='$id'" );
188 $db->query( "DELETE FROM eZLink_Category WHERE ID='$id'" );
189 }*/
190
194 function delete( $id = -1 )
195 {
196 if( $id == -1 )
197 $id = $this->ID;
198
199 $res = array(); // put the database results in here.
200
201 // get all children categories recursivly
202 $categories = eZLinkCategory::getByParent( $id, true, true );
203 $categories[] = $id; // add self
204
205 // get all the links
206 $links = array();
207 foreach( $categories as $category )
208 {
209 $links = array_merge( eZLinkCategory::links( -1, -1, true, $category, true ), $links );
210 }
211
212 // now lets delete all the links..
213 $db =& eZDB::globalDatabase();
214 $db->begin();
215 foreach( $links as $link )
216 {
217 $res[] = $db->query( "DELETE FROM eZLink_Hit WHERE Link='$link'" );
218 $res[] = $db->query( "DELETE FROM eZLink_Link WHERE ID='$link'" );
219 $res[] = $db->query( "DELETE FROM eZLink_TypeLink WHERE LinkID='$link'" );
220 $res[] = $db->query( "DELETE FROM eZLink_AttributeValue WHERE LinkID='$link'" );
221 $res[] = $db->query( "DELETE FROM eZLink_LinkCategoryDefinition WHERE LinkID='$link'" );
222 $res[] = $db->query( "DELETE FROM eZLink_LinkCategoryLink WHERE LinkID='$link'" );
223 }
224 // then we delete the categories
225 foreach( $categories as $category )
226 {
227 $res[] = $db->query( "DELETE FROM eZLink_Category WHERE ID='$category'" );
228 // these two should not be nesseccary but we run them anyway, so we are sure that
229 // everything is cleaned up.
230 $res[] = $db->query( "DELETE FROM eZLink_LinkCategoryLink WHERE CategoryID='$category'" );
231 $res[] = $db->query( "DELETE FROM eZLink_LinkCategoryDefinition WHERE CategoryID='$category'" );
232 }
233 eZDB::finish( $res, $db );
234 }
235
236
240 function get( $id )
241 {
242 $db =& eZDB::globalDatabase();
243 $db->array_query( $linkcategory_array, "SELECT * FROM eZLink_Category WHERE ID='$id'" );
244 if ( count( $linkcategory_array ) > 1 )
245 {
246 die( "error, more groups with the same id" );
247 }
248 else if ( count( $linkcategory_array ) == 1 )
249 {
250 $this->ID =& $linkcategory_array[0][$db->fieldName("ID")];
251 $this->Name =& $linkcategory_array[0][$db->fieldName("Name")];
252 $this->Description =& $linkcategory_array[0][$db->fieldName("Description")];
253 $this->Parent =& $linkcategory_array[0][$db->fieldName("Parent")];
254 $this->ImageID =& $linkcategory_array[0][$db->fieldName("ImageID")];
255 $this->SectionID =& $linkcategory_array[0][$db->fieldName("SectionID")];
256 }
257 }
258
262 function &path( $categoryID=0 )
263 {
264 if ( $categoryID == 0 )
265 {
266 if ( isset( $this->ID ) )
267 $categoryID = $this->ID;
268 else
269 $categoryID = false;
270 }
271
272 $category = new eZLinkCategory( $categoryID );
273
274 $path = array();
275
276 $parent = $category->parent();
277
278 if ( $parent != 0 && $parent != '' )
279 {
280 $path = array_merge( $path, $this->path( $parent ) );
281 }
282 else
283 {
284 // array_push( $path, $category->name() );
285 }
286
287 if ( $categoryID != 0 )
288 array_push( $path, array( $category->id(), $category->name() ) );
289
290 return $path;
291
292 }
293
294
299 function getByParent( $value, $idOnly = false, $recursive = false )
300 {
301 if ( is_a( $value, 'eZLinkCategory' ) )
302 $id = $value->id();
303 else
304 $id = $value;
305
306 $db =& eZDB::globalDatabase();
307 $parent_array = array();
308 $return_array = array();
309
310 $db->array_query( $parent_array, "SELECT ID FROM eZLink_Category
311 WHERE Parent='$id' ORDER BY Name" );
312
313 for( $i=0; $i<count( $parent_array ); $i++ )
314 {
315 $catID = $parent_array[$i][$db->fieldName("ID")];
316 if( $idOnly )
317 $return_array[] = $catID;
318 else
319 $return_array[] = new eZLinkCategory( $catID );
320
321 if( $recursive )
322 $return_array = array_merge( eZLinkCategory::getByParent( $catID, true, true ), $return_array );
323 }
324
325 return $return_array;
326 }
327
328
332 function &getTotalIncomingLinks()
333 {
334 $db =& eZDB::globalDatabase();
335
336 $count = 0;
337 $db->array_query( $link_count, "SELECT COUNT(ID) AS LinkCount FROM eZLink_Link WHERE Accepted='0'" );
338 $count = $link_count[0][$db->fieldName("LinkCount")];
339
340 return $count;
341 }
342
346 function &getAll()
347 {
348 $db =& eZDB::globalDatabase();
349 $parnet_array = array();
350 $return_array = array();
351
352 $db->array_query( $parent_array, "SELECT ID FROM eZLink_Category ORDER BY Name" );
353
354 for( $i=0; $i<count( $parent_array ); $i++ )
355 {
356 $return_array[$i] = new eZLinkCategory( $parent_array[$i][$db->fieldName("ID")] );
357 }
358
359 return $return_array;
360 }
361
365 function &getTree( $parentID=0, $level=0 )
366 {
367 $category = new eZLinkCategory( $parentID );
368
369 $categoryList = $category->getByParent( $category );
370
371 $tree = array();
372 $level++;
373 foreach ( $categoryList as $category )
374 {
375 array_push( $tree, array( $return_array[] = new eZLinkCategory( $category->id() ), $level ) );
376
377 if ( $category != 0 )
378 {
379 $tree = array_merge( $tree, $this->getTree( $category->id(), $level ) );
380 }
381 }
382 return $tree;
383 }
384
391 function links( $offset=0, $limit=30, $fetchUnAccepted=false, $id = -1, $idOnly = false )
392 {
393 $db =& eZDB::globalDatabase();
394
395 if( $id == -1 )
396 $id = $this->id();
397 $returnArray = array();
398
399 if ( $fetchUnAccepted )
400 $fetchUnAccepted = "";
401 else
402 $fetchUnAccepted = " AND eZLink_Link.Accepted='1' ";
403
404 $query = "SELECT eZLink_Link.ID, eZLink_Link.Name
405 FROM eZLink_LinkCategoryLink, eZLink_Link
406 WHERE
407 eZLink_Link.ID=eZLink_LinkCategoryLink.LinkID AND
408 eZLink_LinkCategoryLink.CategoryID='$id'
409 $fetchUnAccepted
410 ORDER BY eZLink_Link.Name";
411
412 if( $limit != -1 && $offset != -1 )
413 $db->array_query( $linkArray, $query ,
414 array( "Limit" => $limit, "Offset" => $offset ) );
415 else
416 $db->array_query( $linkArray, $query );
417
418 foreach( $linkArray as $link )
419 {
420 if( $idOnly )
421 $returnArray[] = $link[$db->fieldName("ID")];
422 else
423 $returnArray[] = new eZLink( $link[$db->fieldName("ID")] );
424 }
425 return $returnArray;
426 }
427
428
432 function linkCount( $fetchUnAccepted=false )
433 {
434 $db =& eZDB::globalDatabase();
435
436 if ( $fetchUnAccepted )
437 $fetchUnAccepted = "";
438 else
439 $fetchUnAccepted = " AND eZLink_Link.Accepted='1' ";
440
441 $query = "SELECT count( eZLink_Link.ID ) AS Count
442 FROM eZLink_LinkCategoryLink, eZLink_Link
443 WHERE
444 eZLink_Link.ID=eZLink_LinkCategoryLink.LinkID AND
445 eZLink_LinkCategoryLink.CategoryID='$this->ID'
446 $fetchUnAccepted";
447
448 $db->array_query( $linkArray, $query );
449
450 return $linkArray[0][$db->fieldName("Count")];
451 }
452
456 function id()
457 {
458 if ( isset( $this->ID ) )
459 return $this->ID;
460 else
461 return "";
462 }
463
467 function sectionID()
468 {
469 return $this->SectionID;
470 }
471
476 function sectionIDStatic($categoryID )
477 {
478 $db =& eZDB::globalDatabase();
479 $db->query_single( $res, "SELECT SectionID from eZLink_Category WHERE ID='$categoryID'");
480
481 $sectionID = $res[$db->fieldName("SectionID")];
482
483 if ( $sectionID > 0 )
484 return $sectionID;
485 else
486 return false;
487 }
488
492 function setName( &$value )
493 {
494 $this->Name = ( $value );
495 }
496
500 function setDescription( &$value )
501 {
502 $this->Description = ( $value );
503 }
504
508 function setParent( $value )
509 {
510 $this->Parent = ( $value );
511 }
512
516 function setSectionID( $value )
517 {
518 $this->SectionID = $value;
519 }
520
524 function name()
525 {
526 if( !is_null( $this->Name ) )
527 {
528 $this->Name = stripslashes($this->Name);
529 return htmlspecialchars( $this->Name );
530 }
531
532 return $this->Name;
533 }
534
538 function description()
539 {
540 $this->Description = stripslashes($this->Description);
541 return htmlspecialchars( $this->Description );
542 }
543
547 function parent()
548 {
549 if ( isset( $this->Parent ) )
550 return $this->Parent;
551 else
552 return "";
553 }
554
558 function setImage( $value )
559 {
560 if ( is_a( $value, "eZImage" ) )
561 {
562 $this->ImageID = $value->id();
563 }
564 elseif( is_numeric( $value ) )
565 {
566 $this->ImageID = $value;
567 }
568 }
569
573 function &image( )
574 {
575 $ret = false;
576 if ( $this->ImageID != 0 )
577 {
578 $ret = new eZImage( $this->ImageID );
579 }
580
581 return $ret;
582 }
583
587 function deleteImage()
588 {
589 $db =& eZDB::globalDatabase();
590
591 $db->array_query( $result, "SELECT ImageID FROM eZLink_Category WHERE ID='$this->ID'" );
592
593 foreach ( $result as $item )
594 {
595 $image = new eZImage( $item[$db->fieldName("ImageID")] );
596 $image->delete();
597 }
598
599 $db->query( "UPDATE eZLink_Category set ImageID='0' WHERE ID='$this->ID'" );
600 }
601
602 var $ID;
603 var $Name;
604 var $Description;
605 var $Parent;
606 var $ImageID;
607 var $SectionID;
608 }
609
610 ?>
$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\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZImage
Definition: ezimage.php:95
eZLinkCategory
Definition: ezlinkcategory.php:37
eZLinkCategory\name
name()
Definition: ezlinkcategory.php:524
eZLinkCategory\getTree
& getTree( $parentID=0, $level=0)
Definition: ezlinkcategory.php:365
eZLinkCategory\parent
parent()
Definition: ezlinkcategory.php:547
eZLinkCategory\id
id()
Definition: ezlinkcategory.php:456
eZLinkCategory\store
store()
Definition: ezlinkcategory.php:54
eZLinkCategory\addLink
static addLink( $value, $categoryid=false)
Definition: ezlinkcategory.php:139
eZLinkCategory\$Name
$Name
Definition: ezlinkcategory.php:603
eZLinkCategory\links
links( $offset=0, $limit=30, $fetchUnAccepted=false, $id=-1, $idOnly=false)
Definition: ezlinkcategory.php:391
eZLinkCategory\__construct
__construct( $id=-1)
Definition: ezlinkcategory.php:41
eZLinkCategory\$Parent
$Parent
Definition: ezlinkcategory.php:605
eZLinkCategory\description
description()
Definition: ezlinkcategory.php:538
eZLinkCategory\setSectionID
setSectionID( $value)
Definition: ezlinkcategory.php:516
eZLinkCategory\setParent
setParent( $value)
Definition: ezlinkcategory.php:508
eZLinkCategory\path
& path( $categoryID=0)
Definition: ezlinkcategory.php:262
eZLinkCategory\getByParent
getByParent( $value, $idOnly=false, $recursive=false)
Definition: ezlinkcategory.php:299
eZLinkCategory\linkCount
linkCount( $fetchUnAccepted=false)
Definition: ezlinkcategory.php:432
eZLinkCategory\sectionIDStatic
sectionIDStatic($categoryID)
Definition: ezlinkcategory.php:476
eZLinkCategory\setDescription
setDescription(&$value)
Definition: ezlinkcategory.php:500
eZLinkCategory\sectionID
sectionID()
Definition: ezlinkcategory.php:467
eZLinkCategory\getTotalIncomingLinks
& getTotalIncomingLinks()
Definition: ezlinkcategory.php:332
eZLinkCategory\image
& image()
Definition: ezlinkcategory.php:573
eZLinkCategory\$ImageID
$ImageID
Definition: ezlinkcategory.php:606
eZLinkCategory\$Description
$Description
Definition: ezlinkcategory.php:604
eZLinkCategory\deleteImage
deleteImage()
Definition: ezlinkcategory.php:587
eZLinkCategory\setName
setName(&$value)
Definition: ezlinkcategory.php:492
eZLinkCategory\setImage
setImage( $value)
Definition: ezlinkcategory.php:558
eZLinkCategory\$ID
$ID
Definition: ezlinkcategory.php:602
eZLinkCategory\$SectionID
$SectionID
Definition: ezlinkcategory.php:607
eZLinkCategory\update
update()
Definition: ezlinkcategory.php:91
eZLinkCategory\getAll
& getAll()
Definition: ezlinkcategory.php:346
eZLinkCategory\removeLink
static removeLink( $value, $categoryid=false)
Definition: ezlinkcategory.php:117
eZLink
Definition: ezlink.php:65
$item
$item
Definition: classes/admin/linklist.php:228
$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
$categories
$categories
Definition: ezarticle/admin/categoryedit.php:636
$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
$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
$image
$image
Definition: user/articlelist.php:242
$links
$links
Definition: user/linkcategorylist.php:181
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.