Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezarticletype.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezarticletype.php 6206 2001-07-19 12:19:22Z jakobn $
5 //
6 // Definition of eZArticleType 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
42 // include_once( "classes/ezdb.php" );
43 // include_once( "ezarticle/classes/ezarticleattribute.php" );
44
45 class eZArticleType
46 {
51 function __construct( $id=-1 )
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
67 $db->begin( );
68
69 $name = $db->escapeString( $this->Name );
70
71 if ( !isset( $this->ID ) )
72 {
73 $db->lock( "eZArticle_Type" );
74
75 $nextID = $db->nextID( "eZArticle_Type", "ID" );
76
77 $res = $db->query( "INSERT INTO eZArticle_Type
78 ( ID, Name )
79 VALUES
80 ( '$nextID', '$name' )" );
81
82 $this->ID = $nextID;
83 }
84 else
85 {
86 $res = $db->query( "UPDATE eZArticle_Type SET
87 Name='$name' WHERE ID='$this->ID'" );
88 }
89
90 $db->unlock();
91
92 if ( $res == false )
93 $db->rollback( );
94 else
95 $db->commit();
96
97 return true;
98 }
99
103 function get( $id=-1 )
104 {
105 $db =& eZDB::globalDatabase();
106
107 $ret = false;
108 if ( $id != -1 )
109 {
110 $db->array_query( $type_array, "SELECT * FROM eZArticle_Type WHERE ID='$id'" );
111
112 if ( count( $type_array ) > 1 )
113 {
114 die( "Error: Article type's with the same ID was found in the database. This shouldent happen." );
115 }
116 else if( count( $type_array ) == 1 )
117 {
118 $this->ID =& $type_array[0][$db->fieldName("ID")];
119 $this->Name =& $type_array[0][$db->fieldName("Name")];
120
121 $ret = true;
122 }
123 }
124 return $ret;
125 }
126
133 function &getByName( $name )
134 {
135 $db =& eZDB::globalDatabase();
136
137 $type = new eZArticleType();
138
139 $name = $db->escapeString( $name );
140
141 if ( $name != "" )
142 {
143 $db->array_query( $type_array, "SELECT * FROM eZArticle_Type WHERE Name='$name'" );
144
145 if ( count( $type_array ) == 1 )
146 {
147 $type = new eZArticleType($type_array[0][$db->fieldName("ID")]);
148 }
149 }
150
151 return $type;
152 }
153
157 function &getAll()
158 {
159 $db =& eZDB::globalDatabase();
160
161 $return_array = array();
162 $type_array = array();
163
164 $db->array_query( $type_array, "SELECT ID, Name FROM eZArticle_Type ORDER BY Name" );
165
166 for ( $i=0; $i<count($type_array); $i++ )
167 {
168 $return_array[$i] = new eZArticleType( $type_array[$i][$db->fieldName("ID")], 0 );
169 }
170
171 return $return_array;
172 }
173
177 function delete()
178 {
179 $db =& eZDB::globalDatabase();
180
181 // delete all attributes and values
182 $attributes = $this->attributes();
183 foreach ( $attributes as $attribute )
184 {
185 $attribute->delete();
186 }
187
188 $db->query( "DELETE FROM eZArticle_ArticleTypeLink WHERE TypeID='$this->ID'" );
189 $db->query( "DELETE FROM eZArticle_Type WHERE ID='$this->ID'" );
190 }
191
195 function id()
196 {
197 return $this->ID;
198 }
199
203 function name()
204 {
205 return $this->Name;
206 }
207
211 function setName( $value )
212 {
213 $this->Name = $value;
214 }
215
220 function attributes( $as_object = true )
221 {
222 $db =& eZDB::globalDatabase();
223
224 $return_array = array();
225 $attribute_array = array();
226
227 $db->array_query( $attribute_array, "SELECT ID, Placement
228 FROM eZArticle_Attribute
229 WHERE TypeID='$this->ID' ORDER BY Placement" );
230
231 for ( $i=0; $i<count($attribute_array); $i++ )
232 {
233 $attrib_id = $attribute_array[$i][$db->fieldName("ID")];
234 $return_array[$i] = $as_object ? new eZArticleAttribute( $attrib_id, false ) : $attrib_id;
235 }
236
237 return $return_array;
238 }
239
243 function attributesByArticle( $article )
244 {
245 $ret = false;
246
247 if ( is_a( $article, "eZArticle" ) )
248 {
249 $db =& eZDB::globalDatabase();
250
251 $articleID = $article->id();
252
253 $return_array = array();
254 $attribute_array = array();
255
256 $db->array_query( $attribute_array, "
257 SELECT Attribute.ID, Attr.TypeID, Attr.Placement
258 FROM
259 eZArticle_AttributeValue AS Value,
260 eZArticle_Attribute AS Attr
261 WHERE
262 Value.ArticleID='$articleID'
263 AND Value.AttributeID=Attr.ID
264 AND Attr.TypeID='$this->ID'
265 ORDER BY Attr.TypeID, Attr.Placement" );
266
267 for ( $i=0; $i < count( $attribute_array ); $i++ )
268 {
269 $return_array[$i] = new eZArticleAttribute( $attribute_array[$i][$db->fieldName("AttributeID")] );
270 }
271
272 $ret = true;
273 }
274 return $ret;
275 }
276
277 var $ID;
278 var $Name;
279 }
280
281 ?>
$i
$i
Definition: admin/adlist.php:91
$article
$article
Definition: articlelog.php:45
eZArticleAttribute
Definition: ezarticleattribute.php:49
eZArticleType
Definition: ezarticletype.php:46
eZArticleType\attributes
attributes( $as_object=true)
Definition: ezarticletype.php:220
eZArticleType\store
store()
Definition: ezarticletype.php:63
eZArticleType\$ID
$ID
Definition: ezarticletype.php:277
eZArticleType\__construct
__construct( $id=-1)
Definition: ezarticletype.php:51
eZArticleType\getByName
& getByName( $name)
Definition: ezarticletype.php:133
eZArticleType\id
id()
Definition: ezarticletype.php:195
eZArticleType\name
name()
Definition: ezarticletype.php:203
eZArticleType\getAll
& getAll()
Definition: ezarticletype.php:157
eZArticleType\attributesByArticle
attributesByArticle( $article)
Definition: ezarticletype.php:243
eZArticleType\setName
setName( $value)
Definition: ezarticletype.php:211
eZArticleType\$Name
$Name
Definition: ezarticletype.php:278
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
$type
$type
Definition: classes/admin/linkselect.php:220
$name
$name
Definition: companytypelist.php:194
$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
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+.