Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezproductattribute.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezproductattribute.php 6318 2001-07-31 11:33:12Z jhe $
5 //
6 // Definition of eZProductAttribute class
7 //
8 // Created on: <20-Dec-2000 13:43:02 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
29
32
45 // include_once( "classes/ezdb.php" );
46 // include_once( "eztrade/classes/ezproducttype.php" );
47
48 class eZProductAttribute
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 $this->Name = $db->escapeString( $this->Name );
71 $this->Unit = $db->escapeString( $this->Unit );
72
73 if ( !isset( $this->ID ) )
74 {
75
76 $db->array_query( $attribute_array, "SELECT Placement FROM eZTrade_Attribute" );
77
78 if ( count ( $attribute_array ) > 0 )
79 {
80 $place = max( $attribute_array );
81 $place = $place[$db->fieldName( "Placement" )];
82 $place++;
83 }
84 $timeStamp = (new eZDateTime())->timeStamp( true );
85 $db->lock( "eZTrade_Attribute" );
86 $nextID = $db->nextID( "eZTrade_Attribute", "ID" );
87 $res[] = $db->query( "INSERT INTO eZTrade_Attribute
88 ( ID,
89 Name,
90 TypeID,
91 AttributeType,
92 Placement,
93 Unit,
94 Created )
95 VALUES
96 ( '$nextID',
97 '$this->Name',
98 '$this->TypeID',
99 '$this->AttributeType',
100 '$place',
101 '$this->Unit',
102 '$timeStamp' )" );
103 $db->unlock();
104 $this->ID = $nextID;
105 }
106 else
107 {
108 $res[] = $db->query( "UPDATE eZTrade_Attribute SET
109 Name='$this->Name',
110 Created=Created,
111 AttributeType='$this->AttributeType',
112 Unit='$this->Unit',
113 TypeID='$this->TypeID' WHERE ID='$this->ID'" );
114 }
115
116 eZDB::finish( $res, $db );
117
118 return true;
119 }
120
124 function get( $id=-1 )
125 {
126 $db =& eZDB::globalDatabase();
127
128 if ( $id != -1 )
129 {
130 $db->array_query( $attribute_array, "SELECT * FROM eZTrade_Attribute WHERE ID='$id'" );
131
132 if ( count( $attribute_array ) > 1 )
133 {
134 die( "Error: Product attribute's with the same ID was found in the database. This shouldent happen." );
135 }
136 else if( count( $attribute_array ) == 1 )
137 {
138 $this->ID =& $attribute_array[0][$db->fieldName( "ID" )];
139 $this->Name =& $attribute_array[0][$db->fieldName( "Name" )];
140 $this->TypeID =& $attribute_array[0][$db->fieldName( "TypeID" )];
141 $this->AttributeType =& $attribute_array[0][$db->fieldName( "AttributeType" )];
142 $this->Placement =& $attribute_array[0][$db->fieldName( "Placement" )];
143 $this->Unit =& $attribute_array[0][$db->fieldName( "Unit" )];
144
145 }
146 }
147 }
148
152 function &getAll()
153 {
154 $db =& eZDB::globalDatabase();
155
156 $return_array = array();
157 $attribute_array = array();
158
159 $db->array_query( $attribute_array, "SELECT ID FROM eZTrade_Attribute ORDER BY Created" );
160
161 for ( $i=0; $i<count($attribute_array); $i++ )
162 {
163 $return_array[$i] = new eZProductAttribute( $attribute_array[$i][$db->fieldName( "ID" )], 0 );
164 }
165
166 return $return_array;
167 }
168
172 function delete()
173 {
174 $db =& eZDB::globalDatabase();
175 $db->begin();
176
177 $res[] = $db->query( "DELETE FROM eZTrade_AttributeValue WHERE AttributeID='$this->ID'" );
178 $res[] = $db->query( "DELETE FROM eZTrade_Attribute WHERE ID='$this->ID'" );
179
180 eZDB::finish( $res, $db );
181 }
182
186 function id()
187 {
188 return $this->ID;
189 }
190
194 function name()
195 {
196 return $this->Name;
197 }
198
202 function unit()
203 {
204 return $this->Unit;
205 }
206
213 function attributeType()
214 {
215 return $this->AttributeType;
216 }
217
218
222 function type()
223 {
224 $type = new eZProductType( $this->TypeID );
225 return $type;
226 }
227
228
232 function setName( $value )
233 {
234 $this->Name = $value;
235 }
236
240 function setUnit( $value )
241 {
242 $this->Unit = $value;
243 }
244
248 function setType( $type )
249 {
250 if ( is_a( $type, "eZProductType" ) )
251 {
252 $this->TypeID = $type->id();
253 }
254 }
255
262 function setAttributeType( $attributeType )
263 {
264 if ( $attributeType == 2 )
265 {
266 $db =& eZDB::globalDatabase();
267 $db->begin();
268
269 $res[] = $db->query( "DELETE FROM eZTrade_AttributeValue WHERE AttributeID='$this->ID'" );
270
271 eZDB::finish( $res, $db );
272 }
273
274 $this->AttributeType = $attributeType;
275
276 }
277
281 function setValue( $product, $value )
282 {
283 $db =& eZDB::globalDatabase();
284
285 if ( is_a( $product, "eZProduct" ) )
286 {
287 $value = $db->escapeString( $value );
288 $productID = $product->id();
289
290 // check if the attribute is already set, if so update
291 $db->array_query( $value_array,
292 "SELECT ID FROM eZTrade_AttributeValue WHERE ProductID='$productID' AND AttributeID='$this->ID'" );
293
294 if ( count( $value_array ) > 0 )
295 {
296 $valueID = $value_array[0][$db->fieldName( "ID" )];
297
298 $res = $db->query( "UPDATE eZTrade_AttributeValue SET
299 Value='$value'
300 WHERE ID='$valueID'" );
301 }
302 else
303 {
304 $db->lock( "eZTrade_AttributeValue" );
305 $nextID = $db->nextID( "eZTrade_AttributeValue", "ID" );
306 $res[] = $db->query( "INSERT INTO eZTrade_AttributeValue
307 ( ID,
308 ProductID,
309 AttributeID,
310 Value )
311 VALUES
312 ( '$nextID',
313 '$productID',
314 '$this->ID',
315 '$value' )" );
316 $db->unlock();
317 }
318 }
319 eZDB::finish( $res, $db );
320 }
321
325 function value( $product )
326 {
327 $db =& eZDB::globalDatabase();
328 $ret = "";
329 if ( is_a( $product, "eZProduct" ) )
330 {
331 $productID = $product->id();
332
333 // check if the attribute is already set, if so update
334 $db->array_query( $value_array,
335 "SELECT Value FROM eZTrade_AttributeValue WHERE ProductID='$productID'
336 AND AttributeID='$this->ID'" );
337
338 if ( count( $value_array ) > 0 )
339 {
340 $ret = $value_array[0][$db->fieldName( "Value" )];
341 }
342 }
343 return $ret;
344 }
345
349 function moveUp()
350 {
351 $db =& eZDB::globalDatabase();
352 $db->begin();
353 $db->query_single( $qry, "SELECT ID, Placement FROM eZTrade_Attribute
354 WHERE Placement<'$this->Placement' ORDER BY Placement DESC", array( "Limit" => 1, "Offset" => 0 ) );
355 $listorder = $qry[$db->fieldName( "Placement" )];
356 $listid = $qry[$db->fieldName( "ID" )];
357 $res[] = $db->query( "UPDATE eZTrade_Attribute SET Placement='$listorder' WHERE ID='$this->ID'" );
358 $res[] = $db->query( "UPDATE eZTrade_Attribute SET Placement='$this->Placement' WHERE ID='$listid'" );
359
360 eZDB::finish( $res, $db );
361 }
362
366 function moveDown()
367 {
368 $db =& eZDB::globalDatabase();
369 $db->begin();
370
371 $db->query_single( $qry, "SELECT ID, Placement FROM eZTrade_Attribute
372 WHERE Placement>'$this->Placement' ORDER BY Placement ASC", array( "Limit" => 1, "Offset" => 0 ) );
373 $listorder = $qry[$db->fieldName( "Placement" )];
374 $listid = $qry[$db->fieldName( "ID" )];
375 $res[] = $db->query( "UPDATE eZTrade_Attribute SET Placement='$listorder' WHERE ID='$this->ID'" );
376 $res[] = $db->query( "UPDATE eZTrade_Attribute SET Placement='$this->Placement' WHERE ID='$listid'" );
377
378 eZDB::finish( $res, $db );
379 }
380
381
382 var $ID;
383 var $TypeID;
384 var $Name;
385 var $AttributeType;
386 var $Placement;
387 var $Unit;
388 }
389 ?>
$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
eZDateTime
Definition: ezdatetime.php:55
eZProductAttribute
Definition: ezproductattribute.php:49
eZProductAttribute\$Placement
$Placement
Definition: ezproductattribute.php:386
eZProductAttribute\attributeType
attributeType()
Definition: ezproductattribute.php:213
eZProductAttribute\$Unit
$Unit
Definition: ezproductattribute.php:387
eZProductAttribute\value
value( $product)
Definition: ezproductattribute.php:325
eZProductAttribute\$TypeID
$TypeID
Definition: ezproductattribute.php:383
eZProductAttribute\$ID
$ID
Definition: ezproductattribute.php:382
eZProductAttribute\$Name
$Name
Definition: ezproductattribute.php:384
eZProductAttribute\setType
setType( $type)
Definition: ezproductattribute.php:248
eZProductAttribute\setName
setName( $value)
Definition: ezproductattribute.php:232
eZProductAttribute\$AttributeType
$AttributeType
Definition: ezproductattribute.php:385
eZProductAttribute\moveUp
moveUp()
Definition: ezproductattribute.php:349
eZProductAttribute\__construct
__construct( $id=-1)
Definition: ezproductattribute.php:54
eZProductAttribute\setValue
setValue( $product, $value)
Definition: ezproductattribute.php:281
eZProductAttribute\type
type()
Definition: ezproductattribute.php:222
eZProductAttribute\moveDown
moveDown()
Definition: ezproductattribute.php:366
eZProductAttribute\getAll
& getAll()
Definition: ezproductattribute.php:152
eZProductAttribute\unit
unit()
Definition: ezproductattribute.php:202
eZProductAttribute\name
name()
Definition: ezproductattribute.php:194
eZProductAttribute\store
store()
Definition: ezproductattribute.php:66
eZProductAttribute\id
id()
Definition: ezproductattribute.php:186
eZProductAttribute\setUnit
setUnit( $value)
Definition: ezproductattribute.php:240
eZProductAttribute\setAttributeType
setAttributeType( $attributeType)
Definition: ezproductattribute.php:262
eZProductType
Definition: ezproducttype.php:46
$type
$type
Definition: classes/admin/linkselect.php:220
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$product
$product
Definition: homepage.php:202
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
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.