Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

eznewscategory.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: eznewscategory.php 6224 2001-07-20 11:21:41Z jakobn $
5 //
6 // Definition of eZNewsCategory class
7 //
8 // Created on: <18-Oct-2000 14:05:56 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
39 // include_once( "classes/ezdb.php" );
40
41 class eZNewsCategory
42 {
49 function __construct( $id=-1 )
50 {
51 $this->ParentID = 0;
52
53 if ( $id != -1 )
54 {
55 $this->ID = $id;
56 $this->get( $this->ID );
57 }
58 }
59
63 function store()
64 {
65 $db =& eZDB::globalDatabase();
66 $db->begin();
67
68 $name = $db->escapeString( $this->Name );
69 $description = $db->escapeString( $this->Description );
70
71 if ( !isset( $this->ID ) )
72 {
73 $db->lock( "eZNewsFeed_Category" );
74 $nextID = $db->nextID( "eZNewsFeed_Category", "ID" );
75 $ret[] = $db->query( "INSERT INTO eZNewsFeed_Category
76 ( ID,
77 Name,
78 Description,
79 ParentID )
80 VALUES
81 ( '$nextID',
82 '$name',
83 '$description',
84 '$this->ParentID' )" );
85 $this->ID = $nextID;
86 }
87 else
88 {
89 $ret[] = $db->query( "UPDATE eZNewsFeed_Category SET
90 Name='$name',
91 Description='$description',
92 ParentID='$this->ParentID' WHERE ID='$this->ID'" );
93 }
94
95 eZDB::finish( $ret, $db );
96
97 return $ret;
98 }
99
104 function delete()
105 {
106 $db =& eZDB::globalDatabase();
107 $db->begin();
108
109 if ( isset( $this->ID ) )
110 {
111 $res[] = $db->query( "DELETE FROM eZNewsFeed_NewsCategoryLink WHERE CategoryID='$this->ID'" );
112
113 $res[] = $db->query( "DELETE FROM eZNewsFeed_Category WHERE ID='$this->ID'" );
114 }
115
116 eZDB::finish( $res, $db );
117
118 return in_array( false, $res );
119 }
120
124 function get( $id=-1 )
125 {
126 $db =& eZDB::globalDatabase();
127
128 if ( $id != "" )
129 {
130 $db->array_query( $category_array, "SELECT * FROM eZNewsFeed_Category WHERE ID='$id'" );
131 if ( count( $category_array ) > 1 )
132 {
133 die( "Error: Category's with the same ID was found in the database. This shouldent happen." );
134 }
135 else if( count( $category_array ) == 1 )
136 {
137 $this->ID = $category_array[0][$db->fieldName("ID")];
138 $this->Name = $category_array[0][$db->fieldName("Name")];
139 $this->Description = $category_array[0][$db->fieldName("Description")];
140 $this->ParentID = $category_array[0][$db->fieldName("ParentID")];
141 }
142 }
143 }
144
150 function getAll()
151 {
152 $db =& eZDB::globalDatabase();
153
154 $return_array = array();
155 $category_array = array();
156
157 $db->array_query( $category_array, "SELECT ID FROM eZNewsFeed_Category ORDER BY Name" );
158
159 for ( $i=0; $i<count($category_array); $i++ )
160 {
161 $return_array[$i] = new eZNewsCategory( $category_array[$i][$db->fieldName("ID")], 0 );
162 }
163
164 return $return_array;
165 }
166
174 function getByParent( $parent, $showAll=false, $sortby="name" )
175 {
176 if ( is_a( $parent, "eZNewsCategory" ) )
177 {
178 $db =& eZDB::globalDatabase();
179
180 $return_array = array();
181 $category_array = array();
182
183 $parentID = $parent->id();
184
185 if ( $showAll == true )
186 {
187 $db->array_query( $category_array, "SELECT ID, Name FROM eZNewsFeed_Category
188 WHERE ParentID='$parentID'
189 ORDER BY Name" );
190 }
191 else
192 {
193 $db->array_query( $category_array, "SELECT ID, Name FROM eZNewsFeed_Category
194 WHERE ParentID='$parentID'
195 ORDER BY Name" );
196 }
197
198
199 for ( $i=0; $i<count($category_array); $i++ )
200 {
201 $return_array[$i] = new eZNewsCategory( $category_array[$i][$db->fieldName("ID")], 0 );
202 }
203
204 return $return_array;
205 }
206 else
207 {
208 return 0;
209 }
210 }
211
219 function path( $categoryID=0 )
220 {
221 if ( $categoryID == 0 )
222 {
223 $categoryID = $this->ID;
224 }
225
226 $category = new eZNewsCategory( $categoryID );
227
228 $path = array();
229
230 $parent = $category->parent();
231
232 if ( $parent != 0 )
233 {
234 $path = array_merge( $path, $this->path( $parent->id() ) );
235 }
236 else
237 {
238 // array_push( $path, $category->name() );
239 }
240
241 if ( $categoryID != 0 )
242 {
243 array_push( $path, array( $category->id(), $category->name() ) );
244 }
245
246 return $path;
247 }
248
249
253 function id()
254 {
255 return $this->ID;
256 }
257
258
262 function name()
263 {
264 return $this->Name;
265 }
266
270 function description()
271 {
272 return $this->Description;
273 }
274
278 function parent()
279 {
280 if ( $this->ParentID != 0 )
281 {
282 return new eZNewsCategory( $this->ParentID );
283 }
284 else
285 {
286 return 0;
287 }
288 }
289
290
294 function setName( $value )
295 {
296 $this->Name = $value;
297 }
298
302 function setDescription( $value )
303 {
304 $this->Description = $value;
305 }
306
310 function setParent( $value )
311 {
312 if ( is_a( $value, "eZNewsCategory" ) )
313 {
314 $this->ParentID = $value->id();
315 }
316 }
317
321 function addNews( $value )
322 {
323 if ( is_a( $value, "eZNews" ) )
324 {
325 $db =& eZDB::globalDatabase();
326 $db->begin();
327 $newsID = $value->id();
328 $db->lock( "eZNewsFeed_NewsCategoryLink" );
329 $nextID = $db->nextID( "eZNewsFeed_NewsCategoryLink" );
330 $ret[] = $db->query( "INSERT INTO eZNewsFeed_NewsCategoryLink
331 ( ID,
332 CategoryID,
333 NewsID )
334 VALUES
335 ( '$nextID',
336 '$this->ID',
337 '$newsID' )" );
338
339 eZDB::finish( $ret, $db );
340 }
341 }
342
354 function &newsList( $sortMode="time",
355 $fetchNonPublished="no",
356 $offset=0,
357 $limit=50 )
358 {
359
360 $db =& eZDB::globalDatabase();
361
362 $OrderBy = "eZNewsFeed_News.PublishingDate DESC";
363 switch( $sortMode )
364 {
365 case "alpha" :
366 {
367 $OrderBy = "eZNewsFeed_Name.Name ASC";
368 }
369 break;
370 }
371
372 $return_array = array();
373 $news_array = array();
374
375
376 if ( $fetchNonPublished == "yes" )
377 {
378 $db->array_query( $news_array, "
379 SELECT eZNewsFeed_News.ID AS NewsID, eZNewsFeed_News.Name, eZNewsFeed_Category.ID, eZNewsFeed_Category.Name
380 FROM eZNewsFeed_News, eZNewsFeed_Category, eZNewsFeed_NewsCategoryLink
381 WHERE
382 eZNewsFeed_NewsCategoryLink.NewsID = eZNewsFeed_News.ID
383 AND
384 eZNewsFeed_Category.ID = eZNewsFeed_NewsCategoryLink.CategoryID
385 AND
386 eZNewsFeed_Category.ID='$this->ID'
387 ORDER BY $OrderBy", array( "Limit" => $limit, "Offset" => $offset ) );
388 }
389
390 if ( $fetchNonPublished == "no" )
391 {
392 $db->array_query( $news_array, "
393 SELECT eZNewsFeed_News.ID AS NewsID, eZNewsFeed_News.Name, eZNewsFeed_Category.ID, eZNewsFeed_Category.Name
394 FROM eZNewsFeed_News, eZNewsFeed_Category, eZNewsFeed_NewsCategoryLink
395 WHERE
396 eZNewsFeed_NewsCategoryLink.NewsID = eZNewsFeed_News.ID
397 AND
398 eZNewsFeed_News.IsPublished = '1'
399 AND
400 eZNewsFeed_Category.ID = eZNewsFeed_NewsCategoryLink.CategoryID
401 AND
402 eZNewsFeed_Category.ID='$this->ID'
403 ORDER BY $OrderBy", array( "Limit" => $limit, "Offset" => $offset ) );
404 }
405
406 if ( $fetchNonPublished == "only" )
407 {
408 $db->array_query( $news_array, "
409 SELECT eZNewsFeed_News.ID AS NewsID, eZNewsFeed_News.Name, eZNewsFeed_Category.ID, eZNewsFeed_Category.Name
410 FROM eZNewsFeed_News, eZNewsFeed_Category, eZNewsFeed_NewsCategoryLink
411 WHERE
412 eZNewsFeed_NewsCategoryLink.NewsID = eZNewsFeed_News.ID
413 AND
414 eZNewsFeed_News.IsPublished = '0'
415 AND
416 eZNewsFeed_Category.ID = eZNewsFeed_NewsCategoryLink.CategoryID
417 AND
418 eZNewsFeed_Category.ID='$this->ID'
419 ORDER BY $OrderBy", array( "Limit" => $limit, "Offset" => $offset ) );
420 }
421
422 for ( $i=0; $i<count($news_array); $i++ )
423 {
424 $return_array[$i] = new eZNews( $news_array[$i][$db->fieldName("NewsID")], false );
425 }
426 return $return_array;
427 }
428
429
442 function &newsListCount( $sortMode="time",
443 $fetchNonPublished="no" )
444 {
445
446 $db =& eZDB::globalDatabase();
447
448 $return_array = array();
449 $news_array = array();
450
451
452 if ( $fetchNonPublished == "yes" )
453 {
454 $db->array_query( $news_array, "
455 SELECT count( eZNewsFeed_News.ID ) AS Count
456 FROM eZNewsFeed_News, eZNewsFeed_Category, eZNewsFeed_NewsCategoryLink
457 WHERE
458 eZNewsFeed_NewsCategoryLink.NewsID = eZNewsFeed_News.ID
459 AND
460 eZNewsFeed_Category.ID = eZNewsFeed_NewsCategoryLink.CategoryID
461 AND
462 eZNewsFeed_Category.ID='$this->ID'" );
463 }
464
465 if ( $fetchNonPublished == "no" )
466 {
467 $db->array_query( $news_array, "
468 SELECT count( eZNewsFeed_News.ID ) AS Count
469 FROM eZNewsFeed_News, eZNewsFeed_Category, eZNewsFeed_NewsCategoryLink
470 WHERE
471 eZNewsFeed_NewsCategoryLink.NewsID = eZNewsFeed_News.ID
472 AND
473 eZNewsFeed_News.IsPublished = '1'
474 AND
475 eZNewsFeed_Category.ID = eZNewsFeed_NewsCategoryLink.CategoryID
476 AND
477 eZNewsFeed_Category.ID='$this->ID'" );
478 }
479
480 if ( $fetchNonPublished == "only" )
481 {
482 $db->array_query( $news_array, "
483 SELECT count( eZNewsFeed_News.ID ) AS Count
484 FROM eZNewsFeed_News, eZNewsFeed_Category, eZNewsFeed_NewsCategoryLink
485 WHERE
486 eZNewsFeed_NewsCategoryLink.NewsID = eZNewsFeed_News.ID
487 AND
488 eZNewsFeed_News.IsPublished = '0'
489 AND
490 eZNewsFeed_Category.ID = eZNewsFeed_NewsCategoryLink.CategoryID
491 AND
492 eZNewsFeed_Category.ID='$this->ID'
493 " );
494 }
495
496
497 return $news_array[0][$db->fieldName("Count")];
498 }
499
500
501 var $ID;
502 var $ParentID;
503 var $Name;
504 var $Description;
505 }
506
507 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$i
$i
Definition: admin/adlist.php:91
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZNewsCategory
Definition: eznewscategory.php:42
eZNewsCategory\id
id()
Definition: eznewscategory.php:253
eZNewsCategory\setName
setName( $value)
Definition: eznewscategory.php:294
eZNewsCategory\$Name
$Name
Definition: eznewscategory.php:503
eZNewsCategory\store
store()
Definition: eznewscategory.php:63
eZNewsCategory\description
description()
Definition: eznewscategory.php:270
eZNewsCategory\getAll
getAll()
Definition: eznewscategory.php:150
eZNewsCategory\path
path( $categoryID=0)
Definition: eznewscategory.php:219
eZNewsCategory\setParent
setParent( $value)
Definition: eznewscategory.php:310
eZNewsCategory\newsListCount
& newsListCount( $sortMode="time", $fetchNonPublished="no")
Definition: eznewscategory.php:442
eZNewsCategory\addNews
addNews( $value)
Definition: eznewscategory.php:321
eZNewsCategory\name
name()
Definition: eznewscategory.php:262
eZNewsCategory\setDescription
setDescription( $value)
Definition: eznewscategory.php:302
eZNewsCategory\parent
parent()
Definition: eznewscategory.php:278
eZNewsCategory\$Description
$Description
Definition: eznewscategory.php:504
eZNewsCategory\$ParentID
$ParentID
Definition: eznewscategory.php:502
eZNewsCategory\getByParent
getByParent( $parent, $showAll=false, $sortby="name")
Definition: eznewscategory.php:174
eZNewsCategory\newsList
& newsList( $sortMode="time", $fetchNonPublished="no", $offset=0, $limit=50)
Definition: eznewscategory.php:354
eZNewsCategory\__construct
__construct( $id=-1)
Definition: eznewscategory.php:49
eZNewsCategory\$ID
$ID
Definition: eznewscategory.php:501
eZNews
Definition: eznews.php:63
$name
$name
Definition: companytypelist.php:194
$id
$id
Definition: companytypelist.php:193
$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
$categoryID
else $categoryID
Definition: productview.php:66
$OrderBy
$OrderBy
Definition: reciverpopup.php:21
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+.