Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F391108
body.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
body.php
View Options
<?php
/**
* Geo body class.
*
* Zed. The immensity of stars. The HyperShip. The people.
*
* (c) 2010, Dereckson, some rights reserved.
* Released under BSD license.
*
* A 3D grid of objects
*
* 0.1 2010-01-27 21:51 Autogenerated by Pluton Scaffolding
*
* @package Zed
* @subpackage Geo
* @author Sébastien Santoro aka Dereckson <dereckson@espace-win.org>
* @copyright 2010 Sébastien Santoro aka Dereckson
* @license http://www.opensource.org/licenses/bsd-license.php BSD
* @version 0.1
* @link http://scherzo.dereckson.be/doc/zed
* @link http://zed.dereckson.be/
* @filesource
*/
/**
* Geo body class
*/
class
GeoBody
{
public
$code
;
public
$name
;
public
$hypership
;
public
$asteroid
;
public
$moon
;
public
$planet
;
public
$star
;
public
$orbital
;
public
$hidden
;
public
$location
;
public
$description
;
public
$lastError
;
/**
* Initializes a new instance
*
* @param int $code the primary key
*/
function
__construct
(
$code
=
null
)
{
if
(
$code
)
{
$this
->
code
=
$code
;
$this
->
load_from_database
();
}
}
/**
* Loads the object body (ie fill the properties) from the $_POST array
*
* @param bool $readBoolean if false, don't read any form item matching a boolean field to avoid to set it to false if there are absent from a form.
*/
function
load_from_form
(
$readBoolean
=
true
)
{
if
(
array_key_exists
(
'name'
,
$_POST
))
{
$this
->
name
=
$_POST
[
'name'
];
}
if
(
$readBoolean
)
{
if
(
array_key_exists
(
'hypership'
,
$_POST
))
{
$this
->
hypership
=
$_POST
[
'hypership'
];
}
if
(
array_key_exists
(
'star'
,
$_POST
))
{
$this
->
start
=
$_POST
[
'star'
];
}
if
(
array_key_exists
(
'asteroid'
,
$_POST
))
{
$this
->
hypership
=
$_POST
[
'asteroid'
];
}
if
(
array_key_exists
(
'moon'
,
$_POST
))
{
$this
->
start
=
$_POST
[
'moon'
];
}
if
(
array_key_exists
(
'planet'
,
$_POST
))
{
$this
->
start
=
$_POST
[
'planet'
];
}
if
(
array_key_exists
(
'orbital'
,
$_POST
))
{
$this
->
start
=
$_POST
[
'orbital'
];
}
if
(
array_key_exists
(
'hidden'
,
$_POST
))
{
$this
->
start
=
$_POST
[
'hidden'
];
}
}
if
(
array_key_exists
(
'location'
,
$_POST
))
{
$this
->
location
=
$_POST
[
'location'
];
}
if
(
array_key_exists
(
'description'
,
$_POST
))
{
$this
->
description
=
$_POST
[
'description'
];
}
}
/**
* Loads the object body (ie fill the properties) from the database
*/
function
load_from_database
()
{
global
$db
;
$sql
=
"SELECT * FROM "
.
TABLE_BODIES
.
" WHERE body_code = '"
.
$this
->
code
.
"'"
;
if
(
!(
$result
=
$db
->
query
(
$sql
))
)
{
message_die
(
SQL_ERROR
,
"Unable to query geo_bodies"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
}
if
(!
$row
=
$db
->
fetchRow
(
$result
))
{
$this
->
lastError
=
"body unknown: "
.
$this
->
code
;
return
false
;
}
$this
->
name
=
$row
[
'body_name'
];
$this
->
location
=
$row
[
'body_location'
];
$this
->
description
=
$row
[
'body_description'
];
if
(
$row
[
'body_status'
])
{
$flags
=
explode
(
','
,
$row
[
'body_status'
]);
foreach
(
$flags
as
$flag
)
{
$this
->
$flag
=
true
;
}
}
return
true
;
}
/**
* Gets the status field
*
* @return string the status field value (e.g. "asteroid,hidden")
*/
function
getStatus
()
{
$flags
=
[
'hypership'
,
'asteroid'
,
'moon'
,
'planet'
,
'star'
,
'orbital'
,
'hidden'
];
foreach
(
$flags
as
$flag
)
{
if
(
$this
->
$flag
)
{
$status
[]
=
$flag
;
}
}
return
implode
(
','
,
$status
);
}
/**
* Gets the kind of place the body is (e.g. asteroid)
*
* @return string the kind of place
*/
function
kind
()
{
//If a location can be described by 2 flags, order the relevant flags list
//by priority, as it'll return the first triggered.
//e.g. a moon converted in hypership will be "hypership" and not "moon".
$relevantFlags
=
[
'hypership'
,
'asteroid'
,
'moon'
,
'planet'
,
'star'
,
'orbital'
];
foreach
(
$relevantFlags
as
$flag
)
{
if
(
$this
->
$flag
)
{
return
$flag
;
}
}
return
""
;
}
/**
* Gets the name of the body, as a string representation of the object
*
* @return string the name of the body
*/
function
__toString
()
{
return
$this
->
name
;
}
/**
* Saves to database
*/
function
save_to_database
()
{
global
$db
;
$code
=
$this
->
code
?
"'"
.
$db
->
escape
(
$this
->
code
)
.
"'"
:
'NULL'
;
$name
=
$db
->
escape
(
$this
->
name
);
$status
=
getStatus
();
$location
=
$db
->
escape
(
$this
->
location
);
$description
=
$db
->
escape
(
$this
->
description
);
//Updates or inserts
$sql
=
"REPLACE INTO "
.
TABLE_BODIES
.
" (`body_code`, `body_name`, `body_status`, `body_location`, `body_description`) VALUES ($code, '$name', '$status', '$location', '$description')"
;
if
(!
$db
->
query
(
$sql
))
{
message_die
(
SQL_ERROR
,
"Unable to save"
,
''
,
__LINE__
,
__FILE__
,
$sql
);
}
if
(!
$code
)
{
//Gets new record code value
$this
->
code
=
$db
->
nextId
();
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Feb 22, 20:21 (20 h, 52 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
22825
Default Alt Text
body.php (5 KB)
Attached To
rZED Zed
Event Timeline
Log In to Comment