Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezlinkattribute.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezlinkattribute.php 6220 2001-07-20 11:15:21Z jakobn $
5 //
6 // Definition of eZLinkAttribute class
7 //
8 // Created on: <29-Jun-2001 11:09:22 jhe>
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 // include_once( "classes/ezdb.php" );
30 // include_once( "ezlink/classes/ezlinktype.php" );
31
32 class eZLinkAttribute
33 {
38 function __construct( $id=-1 )
39 {
40 if ( $id != -1 )
41 {
42 $this->ID = $id;
43 $this->get( $this->ID );
44 }
45 }
46
50 function store()
51 {
52 $db =& eZDB::globalDatabase();
53
54 $db->begin();
55 $db->lock( "eZLink_Attribute" );
56
57 if ( !isset( $this->ID ) )
58 {
59 $db->array_query( $attribute_array, "SELECT Placement FROM eZLink_Attribute" );
60
61 if ( count ( $attribute_array ) > 0 )
62 {
63 $place = max( $attribute_array );
64 $place = $place["Placement"];
65 $place++;
66 }
67
68 $timeStamp =& (new eZDateTime())->timeStamp( true );
69
70 $this->ID = $db->nextID( "eZLink_Attribute", "ID" );
71 $res = $db->query( "INSERT INTO eZLink_Attribute
72 (ID,
73 Name,
74 TypeID,
75 Placement,
76 Unit,
77 Created)
78 VALUES
79 ('$this->ID',
80 '$this->Name',
81 '$this->TypeID',
82 '$place',
83 '$this->Unit',
84 '$timeStamp')" );
85
86 }
87 else
88 {
89 $res = $db->query( "UPDATE eZLink_Attribute SET
90 Name='$this->Name',
91 Created=Created,
92 Unit='$this->Unit',
93 TypeID='$this->TypeID' WHERE ID='$this->ID'" );
94
95 }
96
97 $db->unlock();
98
99 if ( $res == false )
100 $db->rollback( );
101 else
102 $db->commit();
103
104 return true;
105 }
106
110 function get( $id = -1 )
111 {
112 $db =& eZDB::globalDatabase();
113
114 if ( $id != -1 )
115 {
116 $db->array_query( $attribute_array, "SELECT * FROM eZLink_Attribute WHERE ID='$id'" );
117
118 if ( count( $attribute_array ) > 1 )
119 {
120 die( "Error: Link attribute's with the same ID was found in the database. This shouldent happen." );
121 }
122 else if( count( $attribute_array ) == 1 )
123 {
124 $this->ID =& $attribute_array[0][ $db->fieldName( "ID" ) ];
125 $this->Name =& $attribute_array[0][ $db->fieldName( "Name" ) ];
126 $this->TypeID =& $attribute_array[0][ $db->fieldName( "TypeID" ) ];
127 $this->Placement =& $attribute_array[0][ $db->fieldName( "Placement" ) ];
128 $this->Unit =& $attribute_array[0][ $db->fieldName( "Unit" ) ];
129 }
130 }
131 }
132
136 function &getAll()
137 {
138 $db =& eZDB::globalDatabase();
139
140 $return_array = array();
141 $attribute_array = array();
142
143 $db->array_query( $attribute_array, "SELECT ID FROM eZLink_Attribute ORDER BY Created" );
144
145 for ( $i = 0; $i < count( $attribute_array ); $i++ )
146 {
147 $return_array[$i] = new eZLinkAttribute( $attribute_array[$i][ $db->fieldName( "ID" ) ], 0 );
148 }
149
150 return $return_array;
151 }
152
156 function delete()
157 {
158 $db =& eZDB::globalDatabase();
159
160 $db->begin();
161 $res[] = $db->query( "DELETE FROM eZLink_AttributeValue WHERE AttributeID='$this->ID'" );
162 $res[] = $db->query( "DELETE FROM eZLink_Attribute WHERE ID='$this->ID'" );
163 if ( in_array( false, $res ) )
164 $db->rollback();
165 else
166 $db->commit();
167 }
168
172 function id()
173 {
174 return $this->ID;
175 }
176
180 function name()
181 {
182 return $this->Name;
183 }
184
188 function unit()
189 {
190 return $this->Unit;
191 }
192
196 function type()
197 {
198 $type = new eZLinkType( $this->TypeID );
199 return $type;
200 }
201
202
206 function setName( $value )
207 {
208 $this->Name = $value;
209 }
210
214 function setUnit( $value )
215 {
216 $this->Unit = $value;
217 }
218
222 function setType( $type )
223 {
224 if ( is_a( $type, "eZLinkType" ) )
225 {
226 $this->TypeID = $type->id();
227 }
228 }
229
233 function setValue( $link, $value )
234 {
235 $db =& eZDB::globalDatabase();
236
237 if ( is_a( $link, "eZLink" ) )
238 {
239 $linkID = $link->id();
240
241 // check if the attribute is already set, if so update
242 $db->array_query( $value_array,
243 "SELECT ID FROM eZLink_AttributeValue WHERE LinkID='$linkID' AND AttributeID='$this->ID'" );
244
245 $db->begin();
246
247 if ( count( $value_array ) > 0 )
248 {
249 $valueID = $value_array[0]["ID"];
250
251 $res = $db->query( "UPDATE eZLink_AttributeValue SET
252 Value='$value'
253 WHERE ID='$valueID'" );
254 }
255 else
256 {
257 $db->lock( "eZLink_AttributeValue" );
258 $nextID = $db->nextID( "eZLink_AttributeValue", "ID" );
259
260 $res = $db->query( "INSERT INTO eZLink_AttributeValue
261 (ID, LinkID, AttributeID, Value)
262 VALUES
263 ('$nextID','$linkID','$this->ID','$value')" );
264 $db->unlock();
265 }
266 if ( $res == false )
267 $db->rollback( );
268 else
269 $db->commit();
270
271 }
272 }
273
277 function value( $link )
278 {
279 $db =& eZDB::globalDatabase();
280 $ret = "";
281 if ( is_a( $link, "eZLink" ) )
282 {
283 $linkID = $link->id();
284
285 // check if the attribute is already set, if so update
286 $db->array_query( $value_array,
287 "SELECT Value FROM eZLink_AttributeValue WHERE LinkID='$linkID'
288 AND AttributeID='$this->ID'" );
289
290 if ( count( $value_array ) > 0 )
291 {
292 $ret = $value_array[0][ $db->fieldName( "Value" ) ];
293 }
294 }
295 return $ret;
296 }
297
301 function moveUp()
302 {
303 $db =& eZDB::globalDatabase();
304 $db->query_single( $qry, "SELECT ID, Placement FROM eZLink_Attribute
305 WHERE Placement<'$this->Placement' ORDER BY Placement DESC",
306 array( "Limit" => 1 ) );
307 $listorder = $qry[ $db->fieldName( "Placement" ) ];
308 $listid = $qry[ $db->fieldName( "ID" ) ];
309 $db->begin();
310 $db->lock( "eZLink_Attribute" );
311 $res[] = $db->query( "UPDATE eZLink_Attribute SET Placement='$listorder' WHERE ID='$this->ID'" );
312 $res[] = $db->query( "UPDATE eZLink_Attribute SET Placement='$this->Placement' WHERE ID='$listid'" );
313 $db->unlock();
314
315 if ( in_array( false, $res ) )
316 $db->rollback();
317 else
318 $db->commit();
319 }
320
324 function moveDown()
325 {
326 $db =& eZDB::globalDatabase();
327 $db->query_single( $qry, "SELECT ID, Placement FROM eZLink_Attribute
328 WHERE Placement>'$this->Placement' ORDER BY Placement ASC",
329 array( "Limit" => 1 ) );
330 $listorder = $qry[ $db->fieldName( "Placement" ) ];
331 $listid = $qry[ $db->fieldName( "ID" ) ];
332 $db->begin();
333 $db->lock( "eZLink_Attribute" );
334 $res[] = $db->query( "UPDATE eZLink_Attribute SET Placement='$listorder' WHERE ID='$this->ID'" );
335 $res[] = $db->query( "UPDATE eZLink_Attribute SET Placement='$this->Placement' WHERE ID='$listid'" );
336 $db->unlock();
337 if ( in_array( false, $res ) )
338 $db->rollback();
339 else
340 $db->commit();
341 }
342
343 var $ID;
344 var $TypeID;
345 var $Name;
346 var $Placement;
347 var $Unit;
348
349 }
350
351 ?>
$i
$i
Definition: admin/adlist.php:91
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZLinkAttribute
Definition: ezlinkattribute.php:33
eZLinkAttribute\$Unit
$Unit
Definition: ezlinkattribute.php:347
eZLinkAttribute\moveUp
moveUp()
Definition: ezlinkattribute.php:301
eZLinkAttribute\$TypeID
$TypeID
Definition: ezlinkattribute.php:344
eZLinkAttribute\id
id()
Definition: ezlinkattribute.php:172
eZLinkAttribute\value
value( $link)
Definition: ezlinkattribute.php:277
eZLinkAttribute\getAll
& getAll()
Definition: ezlinkattribute.php:136
eZLinkAttribute\setName
setName( $value)
Definition: ezlinkattribute.php:206
eZLinkAttribute\setType
setType( $type)
Definition: ezlinkattribute.php:222
eZLinkAttribute\unit
unit()
Definition: ezlinkattribute.php:188
eZLinkAttribute\store
store()
Definition: ezlinkattribute.php:50
eZLinkAttribute\moveDown
moveDown()
Definition: ezlinkattribute.php:324
eZLinkAttribute\$ID
$ID
Definition: ezlinkattribute.php:343
eZLinkAttribute\__construct
__construct( $id=-1)
Definition: ezlinkattribute.php:38
eZLinkAttribute\name
name()
Definition: ezlinkattribute.php:180
eZLinkAttribute\$Placement
$Placement
Definition: ezlinkattribute.php:346
eZLinkAttribute\type
type()
Definition: ezlinkattribute.php:196
eZLinkAttribute\setValue
setValue( $link, $value)
Definition: ezlinkattribute.php:233
eZLinkAttribute\setUnit
setUnit( $value)
Definition: ezlinkattribute.php:214
eZLinkAttribute\$Name
$Name
Definition: ezlinkattribute.php:345
eZLinkType
Definition: ezlinktype.php:33
$type
$type
Definition: classes/admin/linkselect.php:220
$id
$id
Definition: companytypelist.php:193
$db
$db
Definition: ezarticle/user/authorlist.php:53
$link
$link
Definition: ezlink/admin/attributeedit.php:49
$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
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.