Page Menu
Home
Code
Search
Configure Global Search
Log In
Files
F391621
section.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
section.php
View Options
<?php
/*
* Zed
* (c) 2010, Dereckson, some rights reserved
* Released under BSD license
*
* Story section
*/
require_once
(
'choice.php'
);
class
StorySection
{
/*
* @var string the section ID
*/
public
$id
;
/*
* @var string the section title
*/
public
$title
;
/*
* @var string the section description
*/
public
$description
;
/*
* @var string the local location
*/
public
$location_local
;
/*
* @var Array the section choices (array of StoryChoice items)
*/
public
$choices
=
array
();
/*
* @var boolean if true, it's the story start ; otherwise, false;
*/
public
$start
;
function
__construct
(
$id
)
{
$this
->
id
=
$id
;
}
/*
* Gets choice from specified guid
* @return StoryChoice the wanted choice, or null if it doesn't exist
*/
function
get_choice
(
$guid
)
{
foreach
(
$this
->
choices
as
$choice
)
{
if
(
$choice
->
guid
==
$guid
)
return
$choice
;
}
return
null
;
}
/*
* Intializes a story section from an XML document
* @param string $xml the XML document
* @return StorySection the section instance
*/
static
function
from_xml
(
$xml
)
{
//Reads attributes
$id
=
''
;
$start
=
false
;
foreach
(
$xml
->
attributes
()
as
$key
=>
$value
)
{
switch
(
$key
)
{
case
'start'
:
if
(
$value
)
$start
=
true
;
break
;
case
'id'
:
$id
=
(
string
)
$value
;
break
;
default
:
message_die
(
GENERAL_ERROR
,
"Unknown attribute: $key =
\"
$value
\"
"
,
"Story error"
);
}
}
if
(!
$id
)
{
message_die
(
GENERAL_ERROR
,
"Section without id. Please add id='' in <section> tag"
,
"Story error"
);
}
$section
=
new
StorySection
(
$id
);
$section
->
title
=
(
string
)
$xml
->
title
;
$section
->
description
=
(
string
)
$xml
->
description
;
$section
->
location_local
=
(
string
)
$xml
->
local
;
$section
->
start
=
$start
;
if
(
$xml
->
choices
)
{
foreach
(
$xml
->
choices
->
choice
as
$choice
)
{
$section
->
choices
[]
=
StoryChoice
::
from_xml
(
$choice
);
}
}
return
$section
;
}
}
?>
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, Feb 22, 20:24 (1 d, 12 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
25308
Default Alt Text
section.php (2 KB)
Attached To
rZEDHG ZedLegacy
Event Timeline
Log In to Comment