2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
* Helper_HelioviewerEvents Class Definition
10
* @author Jeff Stys <jeffrey.stys@nasa.gov>
11
* @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
12
* @link http://launchpad.net/helioviewer.org
16
* A simple class to represent one or more Helioviewer event FRMs in a request.
19
* @package Helioviewer
20
* @author Jeff Stys <jeffrey.stys@nasa.gov>
21
* @license http://www.mozilla.org/MPL/MPL-1.1.html Mozilla Public License 1.1
22
* @link http://launchpad.net/helioviewer.org
24
class Helper_HelioviewerEvents {
26
private $_events = array();
27
private $_eventString;
31
* Creates a new HelioviewerEvents instance
33
* @param string $eventString Event string format:
34
* [event_type,frm_name,visibility]
38
public function __construct($eventString) {
39
$this->_eventString = $eventString;
41
if ( $this->_eventString == '' ) {
45
$eventStringArray = explode("],[", substr($eventString, 1, -1));
47
// Process individual events in string
48
foreach ($eventStringArray as $singleEventString) {
49
$event = $this->_decodeSingleEventString($singleEventString);
50
array_push($this->_events, $event);
53
// Store a tree representation of the events for generating
54
// human-readable strings
55
$this->_createEventTree();
57
// Check to make sure at least one valid event was specified
58
if (sizeOf($this->_events) === 0) {
60
"No valid and visible events specified for request.", 20);
65
* Returns the number of events in the collection
67
* @return int Number of events in request
69
public function length() {
70
return sizeOf($this->_events);
74
* Returns the events as an array of associative arrays
76
* @return array An array of hashes representing the requested events
78
public function toArray() {
79
return $this->_events;
83
* Returns a string representation of the request events suitable for use in queries
85
* @return string String representation of the request events for use API queries
87
public function serialize() {
88
return $this->_eventString;
92
* Creates a tree representation of the events
96
private function _createEventTree() {
99
foreach ($this->_events as $event) {
100
$event_type = $event['event_type'];
101
$frm_name = $event['frm_name'];
102
if ( !isset($tree[$event_type]) ) {
103
$tree[$event_type] = array();
105
if ( !isset($tree[$event_type][$frm_name]) ) {
106
$tree[$event_type][] = $frm_name;
110
$this->_eventTree = $tree;
114
* Takes a single event string and converts it to a more convenient
115
* associative array. filling in any missing details as neccessary
117
* @param string $eventString A single event represented as a string in
118
* the following format:
119
* [event_type, frm_name, visible]
121
* @return array Associative array representation of the event
123
private function _decodeSingleEventString ($eventString) {
125
// Break up string into individual components
126
$eventArray = explode(",", $eventString);
128
list($event_type, $frm_name, $visible) = $eventArray;
130
// Associative array form
132
"event_type" => $event_type,
133
"frm_name" => $frm_name,
134
"visible" => ( $visible == 1 || strtolower($visible) == 'true' ) ? true : false
b'\\ No newline at end of file'