Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

ezcompanytype.php
Go to the documentation of this file.
1 <?php
3 //
4 // $Id: ezcompanytype.php 6970 2001-09-05 11:57:07Z jhe $
5 //
6 // Definition of eZCompanyType class
7 //
8 // Created on: <09-Nov-2000 14:52:40 ce>
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( "ezcontact/classes/ezcompany.php" );
47
48 class eZCompanyType
49 {
53 function __construct( $id = -1 )
54 {
55 $this->ImageID = 0;
56
57 if ( $id != -1 )
58 {
59 $this->ID = $id;
60 $this->get( $this->ID );
61 }
62 }
63
67 function store()
68 {
69 $db =& eZDB::globalDatabase();
70 $db->begin();
71
72 $ret = false;
73 $name = $db->escapeString( $this->Name );
74 $description = $db->escapeString( $this->Description );
75 if ( !isset( $this->ID ) )
76 {
77 $db->lock( "eZContact_CompanyType" );
78 $this->ID = $db->nextID( "eZContact_CompanyType", "ID" );
79 $res[] = $db->query( "INSERT INTO eZContact_CompanyType
80 (ID, Name, Description, ImageID, ParentID)
81 VALUES
82 ('$this->ID',
83 '$name',
84 '$description',
85 '$this->ImageID',
86 '$this->ParentID')" );
87 $db->unlock();
88 $ret = true;
89 }
90 else
91 {
92 $res[] = $db->query( "UPDATE eZContact_CompanyType set Name='$name', Description='$description', ImageID='$this->ImageID', ParentID='$this->ParentID' WHERE ID='$this->ID'" );
93
94 $ret = true;
95 }
96 eZDB::finish( $res, $db );
97 return $ret;
98 }
99
100
101 /*
102 Delets the company type from the database.
103 */
104 function delete()
105 {
106 $sub_categories =& eZCompanyType::getByParentID( $this->ID );
107 foreach ( $sub_categories as $category )
108 {
109 $category->delete();
110 }
111 $top_category = new eZCompanyType( 0 );
112 $companies =& eZCompany::getByCategory( $this->ID );
113 foreach ( $companies as $company )
114 {
115 $company->removeCategories();
116 $top_category->addCompany( $company );
117 }
118 $db =& eZDB::globalDatabase();
119 $db->begin();
120 $res[] = $db->query( "DELETE FROM eZContact_CompanyType WHERE ID='$this->ID'" );
121 eZDB::finish( $res, $db );
122 }
123
124 /*
125 Fetches a company type with the ID == $id
126 */
127 function get( $id )
128 {
129 $db =& eZDB::globalDatabase();
130 if ( $id != "" )
131 {
132 $db->array_query( $company_type_array, "SELECT * FROM eZContact_CompanyType WHERE ID='$id'" );
133
134 if ( count( $company_type_array ) > 1 )
135 {
136 die( "Error: More than one company type with the same ID found. Major problem, clean up the table eZContact_CompanyType. " );
137 }
138 else if ( count( $company_type_array ) == 1 )
139 {
140 $this->ID = $company_type_array[ 0 ][ $db->fieldName( "ID" ) ];
141 $this->Name = $company_type_array[ 0 ][ $db->fieldName( "Name" ) ];
142 $this->Description = $company_type_array[ 0 ][ $db->fieldName( "Description" ) ];
143 $this->ParentID = $company_type_array[ 0 ][ $db->fieldName( "ParentID" ) ];
144 $this->ImageID = $company_type_array[ 0 ][ $db->fieldName( "ImageID" ) ];
145 }
146 }
147 }
148
152 static public function getAll( $OrderBy = "ID", $LimitStart = "None", $LimitBy = "None" )
153 {
154 $db =& eZDB::globalDatabase();
155
156 switch ( strtolower( $OrderBy ) )
157 {
158 case "description":
159 case "desc":
160 $OrderBy = "ORDER BY Description";
161 break;
162 case "name":
163 $OrderBy = "ORDER BY Name";
164 break;
165 case "parentid":
166 case "pid":
167 $OrderBy = "ORDER BY ParentID";
168 break;
169 case "id":
170 case "typeid":
171 $OrderBy = "ORDER BY ID";
172 break;
173 default:
174 $OrderBy = "ORDER BY ID";
175 break;
176 }
177
178 if ( is_numeric( $LimitStart ) )
179 {
180 $LimitArray = array( "Offset" => $LimitStart );
181
182 if ( is_numeric( $LimitBy ) )
183 {
184 $LimitArray =& array_merge( $LimitArray, array( "Limit" => $LimitBy ) );
185 }
186 }
187 else
188 {
189 $LimitArray = array();
190 }
191
192 $company_type_array = array();
193 $return_array = array();
194
195
196 $db->array_query( $company_type_array, "SELECT ID FROM eZContact_CompanyType $OrderBy", $LimitClause );
197
198 foreach ( $company_type_array as $companyTypeItem )
199 {
200 $return_array[] = new eZCompanyType( $companyTypeItem[ $db->fieldName( "ID" ) ] );
201 }
202 return $return_array;
203 }
204
208 static public function &getByParentID( $parent = 0, $OrderBy = "ID", $LimitStart = "None", $LimitBy = "None" )
209 {
210 $db =& eZDB::globalDatabase();
211 $LimitArray = false;
212
213 if ( is_a( $parent, "eZCompanyType" ) )
214 {
215 $id = $parent->id();
216 }
217 else
218 {
219 $id = $parent;
220 }
221
222 switch ( strtolower( $OrderBy ) )
223 {
224 case "description":
225 case "desc":
226 $OrderBy = "ORDER BY Description";
227 break;
228 case "name":
229 $OrderBy = "ORDER BY Name";
230 break;
231 case "parentid":
232 case "pid":
233 $OrderBy = "ORDER BY ParentID";
234 break;
235 case "id":
236 case "typeid":
237 $OrderBy = "ORDER BY ID";
238 break;
239 default:
240 $OrderBy = "ORDER BY ID";
241 break;
242 }
243
244 if ( is_numeric( $LimitStart ) )
245 {
246 $LimitArray = array( "Offset" => $LimitStart );
247
248 if ( is_numeric( $LimitBy ) )
249 {
250 $LimitArray =& array_merge( $LimitArray, array( "Limit" => $LimitBy ) );
251 }
252 else
253 $LimitArray =& array_merge( $LimitArray, array( "Limit" => -1 ) );
254 }
255 else
256 {
257 $LimitClause = "";
258 }
259
260 $company_type_array = array();
261 $return_array = array();
262
263 $db->array_query( $company_type_array, "SELECT ID FROM eZContact_CompanyType WHERE ParentID='$id' $OrderBy", $LimitArray );
264
265 foreach ( $company_type_array as $companyTypeItem )
266 {
267 $return_array[] = new eZCompanyType( $companyTypeItem[ $db->fieldName( "ID" ) ] );
268 }
269 return $return_array;
270 }
271
275 static public function hasChildren( &$childrenCount, $id = "this" )
276 {
277 $ret = false;
278
279 if ( $id == "this" )
280 {
281 $id = $this->ID;
282 }
283
284 if ( is_numeric( $id ) )
285 {
286 $db =& eZDB::globalDatabase();
287
288 $company_type_array = array();
289 $db->array_query( $company_type_array, "SELECT ParentID FROM eZContact_CompanyType WHERE ParentID='$id'" );
290 $childrenCount = count( $company_type_array );
291
292 if ( $childrenCount != 0 )
293 {
294 $ret = true;
295 }
296 }
297
298 return $ret;
299 }
300
304 static public function path( $categoryID = 0 )
305 {
306 if ( $categoryID == 0 )
307 {
308 $categoryID = false;
309 }
310
311 $category = new eZCompanyType( $categoryID );
312
313 $path = array();
314
315 $parent = $category->parentID();
316
317 if ( $parent != 0 )
318 {
319 $path = array_merge( $path, eZCompanyType::path( $parent ) );
320 }
321
322 if ( $categoryID != 0 )
323 array_push( $path, array( $category->id(), $category->name() ) );
324
325 return $path;
326 }
327
328 static public function &getTree( $parentID=0, $level=0, $add_top = false, $name = false )
329 {
330 if ( $add_top )
331 {
332 $tree = array();
333 $level++;
334 $category = new eZCompanyType();
335 $category->ID = 0;
336 $category->setName( $name );
337 array_push( $tree, array( $category, $level ) );
338 $tree = array_merge( $tree, eZCompanyType::getTree( 0, $level ) );
339 }
340 else
341 {
342 $categoryList =& eZCompanyType::getByParentID( $parentID );
343
344 $tree = array();
345 $level++;
346 foreach ( $categoryList as $category )
347 {
348 array_push( $tree, array( $category , $level ) );
349
350 if ( $category != 0 )
351 {
352 $tree = array_merge( $tree, eZCompanyType::getTree( $category->id(), $level ) );
353 }
354 }
355
356 }
357 return $tree;
358 }
359
365 function addCompany( $company )
366 {
367 $ret = false;
368
369 if ( get_class( $company ) )
370 {
371 $db =& eZDB::globalDatabase();
372 $db->begin();
373 $companyID = $company->id();
374 $res[] = $db->query( "INSERT INTO eZContact_CompanyTypeDict
375 (CompanyID, CompanyTypeID)
376 VALUES
377 ('$companyID', '$this->ID')" );
378 eZDB::finish( $res, $db );
379 $ret = true;
380 }
381 return $ret;
382 }
383
387 function setImageID( $value )
388 {
389 if ( is_a( $value, "eZImage" ) )
390 {
391 $this->ImageID = $value->id();
392 }
393 else if ( is_numeric( $value ) )
394 {
395 $this->ImageID = $value;
396 }
397 }
398
399
403 function setName( $value )
404 {
405 $this->Name = $value;
406 }
410 function setDescription( $value )
411 {
412 $this->Description = $value;
413 }
414
418 function setParentID( $value )
419 {
420 $this->ParentID = $value;
421 }
422
423
427 function id()
428 {
429 return $this->ID;
430 }
431
435 function name( )
436 {
437 return $this->Name;
438 }
439
443 function description( )
444 {
445 return $this->Description;
446 }
447
451 function parentID( )
452 {
453 return $this->ParentID;
454 }
455
456
460 function imageID( )
461 {
462 return $this->ImageID;
463 }
464
465 var $ID;
466 var $ParentID;
467 var $Name;
468 var $Description;
469 var $ImageID;
470 }
471
472 ?>
$category
if( $Action=="Edit") $category
Definition: adedit.php:378
$categoryList
foreach( $pathArray as $path) $categoryList
Definition: admin/adlist.php:86
$companies
else $companies
Definition: admin/consultationlist.php:221
$level
$level
Definition: admin/message.php:106
$Description
$Description
Definition: articlelistrss.php:38
eZCompany\getByCategory
& getByCategory( $categoryID, $offset=0, $limit=-1, $order="name")
Definition: ezcompany.php:277
eZDB\finish
static finish(&$resultArray, &$db)
Definition: ezdb.php:204
eZDB\globalDatabase
static & globalDatabase()
Definition: ezdb.php:134
$company
if(!is_numeric( $Year)) if(!is_numeric( $Month)) if(!is_numeric( $Day)) $company
Definition: companystats.php:72
$name
$name
Definition: companytypelist.php:194
$ImageID
$ImageID
Definition: companytypelist.php:201
$id
$id
Definition: companytypelist.php:193
$tree
$tree
Definition: ezad/admin/categoryedit.php:172
$db
$db
Definition: ezarticle/user/authorlist.php:53
$ret
$ret
Definition: ezsitemanager/admin/filelist.php:88
$res
$res
Definition: ezstats/admin/cron.php:45
$ParentID
$ParentID
Definition: eztrade/admin/categorylist.php:171
$Name
$Name
Definition: polledit.php:250
$categoryID
else $categoryID
Definition: productview.php:66
$OrderBy
$OrderBy
Definition: reciverpopup.php:21
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+.