Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezarticleattribute.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezarticleattribute.php 6471 2001-08-16 13:57:05Z jhe $
5 //
6 // Definition of eZArticleAttribute class
7 //
8 // Created on: <01-Jun-2001 13:43:02 pkej>
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
29
32
45 // include_once( "classes/ezdb.php" );
46 // include_once( "ezarticle/classes/ezarticletype.php" );
47
48 class eZArticleAttribute
49 {
54 function __construct( $id=-1 )
55 {
56 if ( $id != -1 )
57 {
58 $this->ID = $id;
59 $this->get( $this->ID );
60 }
61 }
62
66 function store()
67 {
68 $db =& eZDB::globalDatabase();
69
70 $db->begin( );
71
72 $name = $db->escapeString( $this->Name );
73
74 if ( !isset( $this->ID ) )
75 {
76
77 $db->lock( "eZArticle_Attribute" );
78
79 $nextID = $db->nextID( "eZArticle_Attribute", "ID" );
80 $timeStamp =& (new eZDateTime())->timeStamp( true );
81
82 $db->array_query( $attribute_array, "SELECT Placement FROM eZArticle_Attribute" );
83
84 if ( count ( $attribute_array ) > 0 )
85 {
86 $place = max( $attribute_array );
87 $place = $place[$db->fieldName("Placement")];
88 $place++;
89 }
90
91 $res = $db->query( "INSERT INTO eZArticle_Attribute
92 ( ID, Name, TypeID, Placement, Created )
93 VALUES
94 ( '$nextID',
95 '$name',
96 '$this->TypeID',
97 '$place',
98 '$timeStamp' )" );
99 $db->unlock();
100 $this->ID = $nextID;
101 }
102 else
103 {
104 $res = $db->query( "UPDATE eZArticle_Attribute SET
105 Name='$name',
106 TypeID='$this->TypeID' WHERE ID='$this->ID'" );
107 }
108
109
110 if ( $res == false )
111 $db->rollback( );
112 else
113 $db->commit();
114
115 return true;
116 }
117
121 function get( $id=-1 )
122 {
123 $db =& eZDB::globalDatabase();
124
125 if ( $id != -1 )
126 {
127 $db->array_query( $attribute_array, "SELECT * FROM eZArticle_Attribute WHERE ID='$id'" );
128
129 if ( count( $attribute_array ) > 1 )
130 {
131 die( "Error: Article attribute's with the same ID was found in the database. This shouldent happen." );
132 }
133 else if( count( $attribute_array ) == 1 )
134 {
135 $this->ID =& $attribute_array[0][$db->fieldName("ID")];
136 $this->Name =& $attribute_array[0][$db->fieldName("Name")];
137 $this->TypeID =& $attribute_array[0][$db->fieldName("TypeID")];
138 $this->Placement =& $attribute_array[0][$db->fieldName("Placement")];
139 }
140 }
141 }
142
146 function &getAll()
147 {
148 $db =& eZDB::globalDatabase();
149
150 $return_array = array();
151 $attribute_array = array();
152
153 $db->array_query( $attribute_array, "SELECT ID FROM eZArticle_Attribute ORDER BY Created" );
154
155 for ( $i=0; $i<count($attribute_array); $i++ )
156 {
157 $return_array[$i] = new eZArticleAttribute( $attribute_array[$i][$db->fieldName("ID")] );
158 }
159
160 return $return_array;
161 }
162
169 function getByName( $name )
170 {
171 $db =& eZDB::globalDatabase();
172
173 $topic = new eZArticleAttribute();
174
175 $name = $db->escapeString( $name );
176
177 if ( $name != "" )
178 {
179 $db->array_query( $author_array, "SELECT * FROM eZArticle_Attribute WHERE Name='$name'" );
180
181 if( count( $author_array ) == 1 )
182 {
183 $topic = new eZArticleAttribute( $author_array[0][$db->fieldName("ID")] );
184 }
185 }
186
187 return $topic;
188 }
189
190
194 function delete()
195 {
196 $db =& eZDB::globalDatabase();
197
198 $db->query( "DELETE FROM eZArticle_AttributeValue WHERE AttributeID='$this->ID'" );
199 $db->query( "DELETE FROM eZArticle_Attribute WHERE ID='$this->ID'" );
200 }
201
205 function id()
206 {
207 return $this->ID;
208 }
209
213 function name()
214 {
215 return $this->Name;
216 }
217
221 function type()
222 {
223 $type = new eZArticleType( $this->TypeID );
224
225 return $type;
226 }
227
228
232 function setName( $value )
233 {
234 $this->Name = $value;
235 }
236
240 function setType( $type )
241 {
242 if ( is_a( $type, "eZArticleType" ) )
243 {
244 $this->TypeID = $type->id();
245 }
246 }
247
248
252 function setValue( $article, $value )
253 {
254 if ( is_a( $article, "eZArticle" ) )
255 {
256 $db =& eZDB::globalDatabase();
257
258 $db->begin( );
259
260 $articleID = $article->id();
261
262 // check if the attribute is already set, if so update
263 $db->array_query( $value_array,
264 "SELECT ID FROM eZArticle_AttributeValue WHERE ArticleID='$articleID' AND AttributeID='$this->ID'" );
265
266 $value = $db->escapeString( $value );
267
268 if ( count( $value_array ) > 0 )
269 {
270 $valueID = $value_array[0][$db->fieldName("ID")];
271
272
273 $res = $db->query( "UPDATE eZArticle_AttributeValue SET
274 Value='$value'
275 WHERE ID='$valueID'" );
276 }
277 else
278 {
279
280 $db->lock( "eZArticle_AttributeValue" );
281
282 $nextID = $db->nextID( "eZArticle_AttributeValue", "ID" );
283
284 $res = $db->query( "INSERT INTO eZArticle_AttributeValue
285 ( ID, ArticleID, AttributeID, Value )
286 VALUES
287 ( '$nextID',
288 '$articleID',
289 '$this->ID',
290 '$value' )" );
291 }
292
293 $db->unlock();
294
295 if ( $res == false )
296 $db->rollback( );
297 else
298 $db->commit();
299
300 }
301 }
302
306 function value( $article )
307 {
308 $ret = "";
309 if ( is_a( $article, "eZArticle" ) )
310 {
311 $db =& eZDB::globalDatabase();
312
313 $articleID = $article->id();
314
315 // check if the attribute is already set, if so update
316 $db->array_query( $value_array,
317 "SELECT Value FROM eZArticle_AttributeValue WHERE ArticleID='$articleID'
318 AND AttributeID='$this->ID'" );
319
320 if ( count( $value_array ) > 0 )
321 {
322 $ret = $value_array[0][$db->fieldName("Value")];
323 }
324 }
325 return $ret;
326 }
327
331 function moveUp()
332 {
333 $db =& eZDB::globalDatabase();
334
335 $query = "SELECT ID, Placement FROM eZArticle_Attribute
336 WHERE Placement<'$this->Placement' AND TypeID = '$this->TypeID' ORDER BY Placement DESC LIMIT 1";
337
338 $db->query_single( $qry, $query );
339
340 if ( !is_string( $qry ) )
341 {
342 $listorder = $qry[$db->fieldName("Placement")];
343 $listid = $qry[$db->fieldName("ID")];
344 }
345
346 $db->query_single( $qry, "SELECT min( Placement ) as Min FROM eZArticle_Attribute
347 WHERE TypeID = '$this->TypeID' ORDER BY Placement" );
348 $min = $qry[$db->fieldName("Min")];
349
350
351 if( $min == $this->Placement )
352 {
353 $db->query_single( $qry, "SELECT max( Placement ) as Max FROM eZArticle_Attribute
354 WHERE TypeID = '$this->TypeID' ORDER BY Placement ASC" );
355
356 $max = $qry[$db->fieldName("Max")];
357
358 $db->query_single( $qry, "SELECT ID, Placement FROM eZArticle_Attribute
359 WHERE Placement = '$max' AND TypeID = '$this->TypeID' ORDER BY Placement ASC" );
360
361 $listorder = $qry[$db->fieldName("Placement")];
362 $listid = $qry[$db->fieldName("ID")];
363 }
364
365 $db->query( "UPDATE eZArticle_Attribute SET Placement='$listorder' WHERE ID='$this->ID'" );
366 $db->query( "UPDATE eZArticle_Attribute SET Placement='$this->Placement' WHERE ID='$listid'" );
367 }
368
372 function moveDown()
373 {
374 $db =& eZDB::globalDatabase();
375
376 $db->query_single( $qry, "SELECT ID, Placement FROM eZArticle_Attribute
377 WHERE Placement>'$this->Placement' AND TypeID = '$this->TypeID' ORDER BY Placement ASC" );
378 $listorder = $qry[$db->fieldName("Placement")];
379 $listid = $qry[$db->fieldName("ID")];
380
381 $db->query_single( $qry, "SELECT max( Placement ) as Max FROM eZArticle_Attribute
382 WHERE TypeID = '$this->TypeID' ORDER BY Placement ASC" );
383 $max = $qry[$db->fieldName("Max")];
384
385
386 if( $max == $this->Placement )
387 {
388 $db->query_single( $qry, "SELECT min( Placement ) as Min FROM eZArticle_Attribute
389 WHERE TypeID = '$this->TypeID' ORDER BY Placement ASC" );
390
391 $min = $qry[$db->fieldName("Min")];
392
393 $db->query_single( $qry, "SELECT ID, Placement FROM eZArticle_Attribute
394 WHERE Placement = '$min' AND TypeID = '$this->TypeID' ORDER BY Placement ASC" );
395
396 $listorder = $qry[$db->fieldName("Placement")];
397 $listid = $qry[$db->fieldName("ID")];
398 }
399
400 $db->query( "UPDATE eZArticle_Attribute SET Placement='$listorder' WHERE ID='$this->ID'" );
401 $db->query( "UPDATE eZArticle_Attribute SET Placement='$this->Placement' WHERE ID='$listid'" );
402 }
403
404
405 var $ID;
406 var $TypeID;
407 var $Name;
408 var $Placement;
409 }
410
411 ?>
$i
$i
Definition: admin/adlist.php:91
$topic
foreach( $authorArray as $author) $topic
Definition: admin/articleedit.php:852
$article
$article
Definition: articlelog.php:45
eZArticleAttribute
Definition: ezarticleattribute.php:49
eZArticleAttribute\$Name
$Name
Definition: ezarticleattribute.php:407
eZArticleAttribute\setName
setName( $value)
Definition: ezarticleattribute.php:232
eZArticleAttribute\name
name()
Definition: ezarticleattribute.php:213
eZArticleAttribute\$ID
$ID
Definition: ezarticleattribute.php:405
eZArticleAttribute\store
store()
Definition: ezarticleattribute.php:66
eZArticleAttribute\setValue
setValue( $article, $value)
Definition: ezarticleattribute.php:252
eZArticleAttribute\type
type()
Definition: ezarticleattribute.php:221
eZArticleAttribute\getByName
getByName( $name)
Definition: ezarticleattribute.php:169
eZArticleAttribute\moveDown
moveDown()
Definition: ezarticleattribute.php:372
eZArticleAttribute\getAll
& getAll()
Definition: ezarticleattribute.php:146
eZArticleAttribute\moveUp
moveUp()
Definition: ezarticleattribute.php:331
eZArticleAttribute\id
id()
Definition: ezarticleattribute.php:205
eZArticleAttribute\__construct
__construct( $id=-1)
Definition: ezarticleattribute.php:54
eZArticleAttribute\setType
setType( $type)
Definition: ezarticleattribute.php:240
eZArticleAttribute\$TypeID
$TypeID
Definition: ezarticleattribute.php:406
eZArticleAttribute\$Placement
$Placement
Definition: ezarticleattribute.php:408
eZArticleAttribute\value
value( $article)
Definition: ezarticleattribute.php:306
eZArticleType
Definition: ezarticletype.php:46
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
$type
$type
Definition: classes/admin/linkselect.php:220
$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
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
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
$articleID
if( $Action=="New") $articleID
Definition: user/articleedit.php:269
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.