Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezmediaattribute.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezmediaattribute.php 8138 2001-11-01 08:31:40Z ce $
5 //
6 // Definition of eZMediaAttribute 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
31
45 // include_once( "classes/ezdb.php" );
46 // include_once( "ezmediacatalogue/classes/ezmediatype.php" );
47
48 class eZMediaAttribute
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 $db->lock( "eZMediaCatalogue_Attribute" );
72
73 if ( !isset( $this->ID ) )
74 {
75 $db->array_query( $attribute_array, "SELECT Placement FROM eZMediaCatalogue_Attribute" );
76
77 if ( count ( $attribute_array ) > 0 )
78 {
79 $place = max( $attribute_array );
80 $place = $place["Placement"];
81 $place++;
82 }
83
84 $timeStamp =& (new eZDateTime())->timeStamp( true );
85
86 $this->ID = $db->nextID( "eZMediaCatalogue_Attribute", "ID" );
87 $res = $db->query( "INSERT INTO eZMediaCatalogue_Attribute
88 (ID,
89 Name,
90 DefaultValue,
91 TypeID,
92 Placement,
93 Unit,
94 Created)
95 VALUES
96 ('$this->ID',
97 '$this->Name',
98 '$this->DefaultValue',
99 '$this->TypeID',
100 '$place',
101 '$this->Unit',
102 '$timeStamp')" );
103
104 }
105 else
106 {
107 $res = $db->query( "UPDATE eZMediaCatalogue_Attribute SET
108 Name='$this->Name',
109 DefaultValue='$this->DefaultValue',
110 Created=Created,
111 Unit='$this->Unit',
112 TypeID='$this->TypeID' WHERE ID='$this->ID'" );
113
114 }
115
116 $db->unlock();
117
118 if ( $res == false )
119 $db->rollback( );
120 else
121 $db->commit();
122
123 return true;
124 }
125
129 function get( $id = -1 )
130 {
131 $db =& eZDB::globalDatabase();
132
133 if ( $id != -1 )
134 {
135 $db->array_query( $attribute_array, "SELECT * FROM eZMediaCatalogue_Attribute WHERE ID='$id'" );
136
137 if ( count( $attribute_array ) > 1 )
138 {
139 die( "Error: Media attribute's with the same ID was found in the database. This shouldent happen." );
140 }
141 else if( count( $attribute_array ) == 1 )
142 {
143 $this->ID =& $attribute_array[0][ $db->fieldName( "ID" ) ];
144 $this->Name =& $attribute_array[0][ $db->fieldName( "Name" ) ];
145 $this->DefaultValue =& $attribute_array[0][ $db->fieldName( "DefaultValue" ) ];
146 $this->TypeID =& $attribute_array[0][ $db->fieldName( "TypeID" ) ];
147 $this->Placement =& $attribute_array[0][ $db->fieldName( "Placement" ) ];
148 $this->Unit =& $attribute_array[0][ $db->fieldName( "Unit" ) ];
149 }
150 }
151 }
152
156 function &getAll()
157 {
158 $db =& eZDB::globalDatabase();
159
160 $return_array = array();
161 $attribute_array = array();
162
163 $db->array_query( $attribute_array, "SELECT ID FROM eZMediaCatalogue_Attribute ORDER BY Created" );
164
165 for ( $i = 0; $i < count( $attribute_array ); $i++ )
166 {
167 $return_array[$i] = new eZMediaAttribute( $attribute_array[$i][ $db->fieldName( "ID" ) ], 0 );
168 }
169
170 return $return_array;
171 }
172
176 function delete()
177 {
178 $db =& eZDB::globalDatabase();
179
180 $db->begin();
181 $res[] = $db->query( "DELETE FROM eZMediaCatalogue_AttributeValue WHERE AttributeID='$this->ID'" );
182 $res[] = $db->query( "DELETE FROM eZMediaCatalogue_Attribute WHERE ID='$this->ID'" );
183 if ( in_array( false, $res ) )
184 $db->rollback();
185 else
186 $db->commit();
187 }
188
192 function id()
193 {
194 return $this->ID;
195 }
196
200 function &name()
201 {
202 $this->Name = stripslashes($this->Name);
203 return $this->Name;
204 }
205
209 function &defaultValue()
210 {
211 return $this->DefaultValue;
212 }
213
217 function &unit()
218 {
219 return $this->Unit;
220 }
221
225 function &type()
226 {
227 $type = new eZMediaType( $this->TypeID );
228 return $type;
229 }
230
231
235 function setName( $value )
236 {
237 $this->Name = $value;
238 }
239
243 function setDefaultValue( &$value )
244 {
245 $this->DefaultValue = $value;
246 }
247
251 function setUnit( &$value )
252 {
253 $this->Unit = $value;
254 }
255
259 function setType( &$type )
260 {
261 if ( is_a( $type, "eZMediaType" ) )
262 {
263 $this->TypeID = $type->id();
264 }
265 }
266
270 function setValue( &$media, &$value )
271 {
272 $db =& eZDB::globalDatabase();
273
274 if ( is_a( $media, "eZMedia" ) )
275 {
276 $mediaID = $media->id();
277
278 // check if the attribute is already set, if so update
279 $db->array_query( $value_array,
280 "SELECT ID FROM eZMediaCatalogue_AttributeValue WHERE MediaID='$mediaID' AND AttributeID='$this->ID'" );
281
282 $db->begin();
283
284 if ( count( $value_array ) > 0 )
285 {
286 $valueID = $value_array[0]["ID"];
287
288 $res = $db->query( "UPDATE eZMediaCatalogue_AttributeValue SET
289 Value='$value'
290 WHERE ID='$valueID'" );
291 }
292 else
293 {
294 $db->lock( "eZMediaCatalogue_AttributeValue" );
295 $nextID = $db->nextID( "eZMediaCatalogue_AttributeValue", "ID" );
296
297 $res = $db->query( "INSERT INTO eZMediaCatalogue_AttributeValue
298 (ID, MediaID, AttributeID, Value)
299 VALUES
300 ('$nextID','$mediaID','$this->ID','$value')" );
301 $db->unlock();
302 }
303 if ( $res == false )
304 $db->rollback( );
305 else
306 $db->commit();
307
308 }
309 }
310
314 function &value( &$media )
315 {
316 $db =& eZDB::globalDatabase();
317 $ret = "";
318 if ( is_a( $media, "eZMedia" ) )
319 {
320 $mediaID = $media->id();
321
322 // check if the attribute is already set, if so update
323 $db->array_query( $value_array,
324 "SELECT Value FROM eZMediaCatalogue_AttributeValue WHERE MediaID='$mediaID'
325 AND AttributeID='$this->ID'" );
326
327 if ( count( $value_array ) > 0 )
328 {
329 $ret = $value_array[0][ $db->fieldName( "Value" ) ];
330 }
331 }
332 return $ret;
333 }
334
338 function moveUp()
339 {
340 $db =& eZDB::globalDatabase();
341 $db->query_single( $qry, "SELECT ID, Placement FROM eZMediaCatalogue_Attribute
342 WHERE Placement<'$this->Placement' ORDER BY Placement DESC",
343 array( "Limit" => 1 ) );
344 $listorder = $qry[ $db->fieldName( "Placement" ) ];
345 $listid = $qry[ $db->fieldName( "ID" ) ];
346 $db->begin();
347 $db->lock( "eZMediaCatalogue_Attribute" );
348 $res[] = $db->query( "UPDATE eZMediaCatalogue_Attribute SET Placement='$listorder' WHERE ID='$this->ID'" );
349 $res[] = $db->query( "UPDATE eZMediaCatalogue_Attribute SET Placement='$this->Placement' WHERE ID='$listid'" );
350 $db->unlock();
351
352 if ( in_array( false, $res ) )
353 $db->rollback();
354 else
355 $db->commit();
356 }
357
361 function moveDown()
362 {
363 $db =& eZDB::globalDatabase();
364 $db->query_single( $qry, "SELECT ID, Placement FROM eZMediaCatalogue_Attribute
365 WHERE Placement>'$this->Placement' ORDER BY Placement ASC",
366 array( "Limit" => 1 ) );
367 $listorder = $qry[ $db->fieldName( "Placement" ) ];
368 $listid = $qry[ $db->fieldName( "ID" ) ];
369 $db->begin();
370 $db->lock( "eZMediaCatalogue_Attribute" );
371 $res[] = $db->query( "UPDATE eZMediaCatalogue_Attribute SET Placement='$listorder' WHERE ID='$this->ID'" );
372 $res[] = $db->query( "UPDATE eZMediaCatalogue_Attribute SET Placement='$this->Placement' WHERE ID='$listid'" );
373 $db->unlock();
374 if ( in_array( false, $res ) )
375 $db->rollback();
376 else
377 $db->commit();
378 }
379
380 var $ID;
381 var $TypeID;
382 var $Name;
383 var $Placement;
384 var $Unit;
385 var $DefaultValue;
386
387 }
388
389 ?>
$i
$i
Definition: admin/adlist.php:91
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZMediaAttribute
Definition: ezmediaattribute.php:49
eZMediaAttribute\setName
setName( $value)
Definition: ezmediaattribute.php:235
eZMediaAttribute\unit
& unit()
Definition: ezmediaattribute.php:217
eZMediaAttribute\setDefaultValue
setDefaultValue(&$value)
Definition: ezmediaattribute.php:243
eZMediaAttribute\setValue
setValue(&$media, &$value)
Definition: ezmediaattribute.php:270
eZMediaAttribute\setUnit
setUnit(&$value)
Definition: ezmediaattribute.php:251
eZMediaAttribute\moveDown
moveDown()
Definition: ezmediaattribute.php:361
eZMediaAttribute\store
store()
Definition: ezmediaattribute.php:66
eZMediaAttribute\$DefaultValue
$DefaultValue
Definition: ezmediaattribute.php:385
eZMediaAttribute\defaultValue
& defaultValue()
Definition: ezmediaattribute.php:209
eZMediaAttribute\moveUp
moveUp()
Definition: ezmediaattribute.php:338
eZMediaAttribute\name
& name()
Definition: ezmediaattribute.php:200
eZMediaAttribute\$Placement
$Placement
Definition: ezmediaattribute.php:383
eZMediaAttribute\$TypeID
$TypeID
Definition: ezmediaattribute.php:381
eZMediaAttribute\id
id()
Definition: ezmediaattribute.php:192
eZMediaAttribute\__construct
__construct( $id=-1)
Definition: ezmediaattribute.php:54
eZMediaAttribute\getAll
& getAll()
Definition: ezmediaattribute.php:156
eZMediaAttribute\$ID
$ID
Definition: ezmediaattribute.php:380
eZMediaAttribute\$Name
$Name
Definition: ezmediaattribute.php:382
eZMediaAttribute\setType
setType(&$type)
Definition: ezmediaattribute.php:259
eZMediaAttribute\type
& type()
Definition: ezmediaattribute.php:225
eZMediaAttribute\$Unit
$Unit
Definition: ezmediaattribute.php:384
eZMediaAttribute\value
& value(&$media)
Definition: ezmediaattribute.php:314
eZMediaType
Definition: ezmediatype.php:33
$type
$type
Definition: classes/admin/linkselect.php:220
$id
$id
Definition: companytypelist.php:193
$media
if(isset( $AddMedia)) $media
Definition: ezarticle/admin/medialist.php:76
$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
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.