first import
[projectpier.git] / application / helpers / pageactions.php
blob5d16f90b61472473264a8d55ddbe28654400696f
1 <?php
3 /**
4 * Return all page actions
6 * @access public
7 * @param void
8 * @return array
9 */
10 function page_actions() {
11 return PageActions::instance()->getActions();
12 } // page_actions
14 /**
15 * Add single page action
17 * You can use set of two params where first param is title and second one
18 * is URL (the default set) and you can use array of actions as first
19 * parram mapped like $title => $url
21 * @access public
22 * @param string $title
23 * @param string $url
24 * @return PageAction
26 function add_page_action() {
28 $args = func_get_args();
29 if(!is_array($args) || !count($args)) return;
31 // Array of data as first param mapped like $title => $url
32 if(is_array(array_var($args, 0))) {
34 foreach(array_var($args, 0) as $title => $url) {
35 if(!empty($title) && !empty($url)) {
36 PageActions::instance()->addAction( new PageAction($title, $url) );
37 } // if
38 } // foreach
40 // Two string params, title and URL
41 } else {
43 $title = array_var($args, 0);
44 $url = array_var($args, 1);
46 if(!empty($title) && !empty($url)) {
47 PageActions::instance()->addAction( new PageAction($title, $url) );
48 } // if
50 } // if
52 } // add_page_action
54 /**
55 * Single page action
57 * @version 1.0
58 * @http://www.projectpier.org/
60 class PageAction {
62 /**
63 * Acction title
65 * @var string
67 private $title;
69 /**
70 * Action URL
72 * @var string
74 private $url;
76 /**
77 * Construct the PageAction
79 * @access public
80 * @param void
81 * @return PageAction
83 function __construct($title, $url) {
84 $this->setTitle($title);
85 $this->setURL($url);
86 } // __construct
88 // ---------------------------------------------------
89 // Getters and setters
90 // ---------------------------------------------------
92 /**
93 * Get title
95 * @access public
96 * @param null
97 * @return string
99 function getTitle() {
100 return $this->title;
101 } // getTitle
104 * Set title value
106 * @access public
107 * @param string $value
108 * @return null
110 function setTitle($value) {
111 $this->title = $value;
112 } // setTitle
115 * Get url
117 * @access public
118 * @param null
119 * @return string
121 function getURL() {
122 return $this->url;
123 } // getURL
126 * Set url value
128 * @access public
129 * @param string $value
130 * @return null
132 function setURL($value) {
133 $this->url = $value;
134 } // setURL
136 } // PageAction
139 * Page actions container that can be accessed globaly
141 * @version 1.0
142 * @http://www.projectpier.org/
144 class PageActions {
147 * Array of PageAction objects
149 * @var array
151 private $actions = array();
154 * Return all actions that are in this container
156 * @access public
157 * @param void
158 * @return array
160 function getActions() {
161 return count($this->actions) ? $this->actions : null;
162 } // getActions
165 * Add single action
167 * @access public
168 * @param PageAction $action
169 * @return PageAction
171 function addAction(PageAction $action) {
172 $this->actions[] = $action;
173 return $action;
174 } // addAction
177 * Return single PageActions instance
179 * @access public
180 * @param void
181 * @return PageActions
183 function instance() {
184 static $instance;
186 // Check instance
187 if(!($instance instanceof PageActions)) {
188 $instance = new PageActions();
189 } // if
191 // Done!
192 return $instance;
194 } // instance
196 } // PageActions