Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezexample.php
Go to the documentation of this file.
1 <?php
3 //
4 // $id$
5 // Bj�rn Reiten <br@ez.no>
6 // Created on: <15-Jun-2001 15:24:47 br>
7 //
8 // This source file is part of Exponential Basic, publishing software.
9 //
10 // Copyright (C) 1999-2001 eZ Systems. All rights reserved.
11 //
12 // This program is free software; you can redistribute it and/or
13 // modify it under the terms of the GNU General Public License
14 // as published by the Free Software Foundation; either version 2
15 // of the License, or (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, US
25 //
26
27
28 // include_once( "classes/ezdb.php" );
29 // include_once( "classes/ezdatetime.php" );
30
31 class eZExample
32 {
36 function __construct( $id=-1 )
37 {
38 if ( $id != -1 )
39 {
40 $this->ID = $id;
41 $this->get( $this->ID );
42 }
43 }
44
48 function get( $id=-1 )
49 {
50 $db =& eZDB::globalDatabase();
51 $ret = false;
52 if ( $id != -1 )
53 {
54 $db->array_query( $text_array, "SELECT * FROM eZExample_Test WHERE ID='$id'" );
55
56 if ( count( $text_array ) > 1 )
57 {
58 die( "Error: Text with the same ID was found in the database. This shouldn't happen." );
59 }
60 else if ( count( $text_array ) == 1 )
61 {
62 $this->ID =& $text_array[0][$db->fieldName("ID")];
63 $this->Text =& $text_array[0][$db->fieldName("Text")];
64 $this->Created =& $text_array[0][$db->fieldName("Created")];
65 $ret = true;
66 }
67 }
68 return $ret;
69 }
70
74 function &getAll()
75 {
76 $db =& eZDB::globalDatabase();
77
78 $return_array = array();
79 $url_array = array();
80
81 $db->array_query( $url_array, "SELECT ID FROM eZExample_Test ORDER BY Created DESC" );
82
83 for ( $i=0; $i<count($url_array); $i++ )
84 {
85 $return_array[$i] = new eZExample( $url_array[$i][$db->fieldName("ID")] );
86 }
87
88 return $return_array;
89 }
90
91
95 function store()
96 {
97 $db =& eZDB::globalDatabase();
98
99
100 $text = $db->escapeString( $this->Text );
101 $timeStamp =& (new eZDateTime())->timeStamp( true );
102
103 $db->begin();
104 $db->lock( "eZExample_Test" );
105
106 $nextID = $db->nextID( "eZExample_Test", "ID" );
107
108 if ( !isset( $this->ID ) )
109 {
110 $ret = $db->query( "INSERT INTO eZExample_Test
111 ( ID,
112 Text,
113 Created )
114 VALUES
115 ( '$nextID',
116 '$text',
117 '$timeStamp')
118 " );
119 $this->ID = $nextID;
120 }
121 else
122 {
123 $ret = $db->query( "UPDATE eZExample_Test SET
124 Text='$text'
125 WHERE ID='$this->ID'" );
126 }
127 $db->unlock();
128
129 if ( $ret == false )
130 $db->rollback();
131 else
132 $db->commit();
133
134 return $ret;
135 }
136
137
141 function delete( $id )
142 {
143 $db =& eZDB::globalDatabase();
144 if ( is_numeric( $id ) )
145 {
146 $this->ID = $id;
147 }
148
149 $db->begin();
150 $ret = $db->query( "DELETE FROM eZExample_Test WHERE ID='$this->ID'" );
151
152 if ( $ret == false )
153 $db->rollback( );
154 else
155 $db->commit( );
156
157 return $ret;
158 }
159
163 function id()
164 {
165 return $this->ID;
166 }
167
171 function text()
172 {
173 return $this->Text;
174 }
175
179 function setText( $value )
180 {
181 $this->Text = $value;
182 }
183
184 var $ID;
185 var $Text;
186 var $Created;
187 }
188 ?>
$i
$i
Definition: admin/adlist.php:91
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
eZDateTime
Definition: ezdatetime.php:55
eZExample
Definition: ezexample.php:32
eZExample\$ID
$ID
Definition: ezexample.php:184
eZExample\getAll
& getAll()
Definition: ezexample.php:74
eZExample\store
store()
Definition: ezexample.php:95
eZExample\$Text
$Text
Definition: ezexample.php:185
eZExample\id
id()
Definition: ezexample.php:163
eZExample\text
text()
Definition: ezexample.php:171
eZExample\__construct
__construct( $id=-1)
Definition: ezexample.php:36
eZExample\setText
setText( $value)
Definition: ezexample.php:179
eZExample\$Created
$Created
Definition: ezexample.php:186
$id
$id
Definition: companytypelist.php:193
$url_array
$url_array
Definition: ezaddress/admin/datasupplier.php:34
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.