BMLT Root Server
base_templates.inc.php
Go to the documentation of this file.
1 <?php
2 /***********************************************************************/
3 /** \file base_templates.inc.php
4  \brief The base templates for all our classes. This implements the
5  i_comdef_searchable and i_comdef_db_stored interfaces and the
6  t_local_id_class, t_comdef_local_type and t_comdef_world_type abstract classes.
7 
8  This file contains a number of abstract and utility classes, as well
9  as a couple of interfaces.
10 */
11 
12 defined('BMLT_EXEC') or die('Cannot Execute Directly'); // Makes sure that this file is in the correct context.
13 
14 //require_once ( dirname ( __FILE__ )."/../../config/comdef-config.inc.php" );
15 require_once(dirname(__FILE__)."/comdef_utilityclasses.inc.php");
16 
17 /*******************************************************************/
18 /** \interface i_comdef_searchable
19  \brief This interface describes some functions that should allow a derived class to be searched.
20 */
21 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
22 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
24 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
25 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
26 {
27  /// Add a single search criteria to the object's next search.
28  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
29  public function AddSearchCriteria($in_criteria_element_mixed);
30  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
31 
32  /// Execute a search, using the previously added criteria.
33  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
34  public function ExecuteSearch();
35  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
36 }
37 
38 /*******************************************************************/
39 /** \interface i_comdef_has_parent
40  \brief Simply declares an interface for having a "container" object.
41 */
42 // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
43 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
44 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
46 // phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses
47 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
48 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
49 {
50  /// Set the parent object of this instance.
51  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
52  public function SetParentObj(
53  $in_parent_obj ///< A reference to the parent object.
54  );
55  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
56 
57  /// Return a reference to the parent object of this instance.
58  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
59  public function GetParentObj();
60  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
61 }
62 
63 /*******************************************************************/
64 /** \interface i_comdef_db_stored
65  \brief Interface for entities that store themselves in the database.
66 */
67 // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
68 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
69 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
71 // phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses
72 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
73 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
74 {
75  /// This causes the object to update the database to its current state.
76  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
77  public function UpdateToDB();
78  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
79 
80  /// Deletes the instance from the database.
81  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
82  public function DeleteFromDB();
83  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
84 
85  /// This overwrites the current state of the object from state stored in the database.
86  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
87  public function RestoreFromDB();
88  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
89  /// Returns a storable serialization of the object, as a string.
90 }
91 
92 /*******************************************************************/
93 /** \interface i_comdef_serialized
94  \brief Interface for entities that can be rendered into serialized form.
95 */
96 // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
97 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
98 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
100 // phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses
101 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
102 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
103 {
104  /// This returns a string, containing the serialized object state.
105  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
106  public function SerializeObject();
107  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
108 
109  /// This takes the serialized data, and instantiates a new object from it.
110  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
111  public static function UnserializeObject(
112  $in_parent, ///< The parent object.
113  $serialized ///< A string containing the serialized data.
114  );
115  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
116 }
117 
118 /*******************************************************************/
119 /** \interface i_comdef_auth
120  \brief Interface for entities that authenticate users.
121 */
122 // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
123 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
124 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
125 interface i_comdef_auth
126 // phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses
127 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
128 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
129 {
130  /// \brief Test to see if a user is allowed to edit an instance (change the data).
131  /// \returns true, if the user is allowed to edit, false, otherwise.
132  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
133  public function UserCanEdit( $in_user_object = null ///< A reference to a c_comdef_user object, for the user to be validated. If null, or not supplied, the server current user is tested.
134  );
135  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
136 }
137 
138 /*******************************************************************/
139 /** \brief This class allows us to assign a unique ID to each of its derived instances.
140 
141  We keep a static array of instantiated subclasses. When a new instance
142  is created, the array is consulted to assign a new ID. When
143 */
144 // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
145 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
146 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
147 abstract class t_local_id_class implements i_comdef_has_parent
148 // phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses
149 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
150 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
151 {
152  /// This is the parent (container) object that holds this instance.
153  private $_local_id_parent_obj = null;
154 
155  /*******************************************************************/
156  /** \brief Sets the object's "parent" (Container) object, as a reference.
157  */
158  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
159  public function SetParentObj(
160  $in_parent_obj ///< A reference to the parent object.
161  ) {
162  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
163  global $_COMDEF_DEBUG;
164 
165  /// We check for recursion here. We go up to a hundred levels deep (should never get close to that).
166  $next_obj = $in_parent_obj;
167  if (true == $_COMDEF_DEBUG) {
168  echo "[t_local_id_class::SetParentObj] Starting Parent Object:<pre>";
169  var_dump($next_obj);
170  echo "</pre><br/>";
171  }
172  $count = 100; /// Prevent looping forever, in case a recursed object is presented.
173 
174  while ($count-- && is_object($next_obj)) {
175  if ($next_obj === $this) {
176  throw ( new Exception("(t_local_id_class::SetParentObj) Recursion!") );
177  }
178 
179  if (is_object($next_obj) && method_exists($next_obj, 'GetParentObj')) {
180  $next_obj = $next_obj->GetParentObj();
181  if (true == $_COMDEF_DEBUG) {
182  echo "[t_local_id_class::SetParentObj] Next Parent Object:<pre>";
183  var_dump($next_obj);
184  echo "</pre><br/>";
185  }
186  } else {
187  $next_obj = $in_parent_obj;
188  break;
189  }
190  }
191 
192  if (!$count) {
193  throw ( new Exception("(t_local_id_class::SetParentObj) Recursion Count Exceeded!") );
194  }
195 
196  if (true == $_COMDEF_DEBUG) {
197  echo "[t_local_id_class::SetParentObj] Ending Parent Object:<pre>";
198  var_dump($next_obj);
199  echo "</pre><br/>";
200  }
201 
202  if (is_object($in_parent_obj)) {
203  $this->_local_id_parent_obj = null;
204  $this->_local_id_parent_obj = $in_parent_obj;
205  } elseif (null == $in_parent_obj) {
206  $this->_local_id_parent_obj = null;
207  }
208  }
209 
210  /*******************************************************************/
211  /** \brief Returns a reference to the object's container.
212 
213  \returns A reference to the object's parent object.
214  */
215  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
216  public function GetParentObj()
217  {
218  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
219  return $this->_local_id_parent_obj;
220  }
221 }
222 
223 /*******************************************************************/
224 /** \brief Allows us to specify a language to the instance (example: English or French)
225 
226  This class also allows us to specify a name for the instance, as a string, as
227  well as a description.
228 */
229 // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
230 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
231 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
232 abstract class t_comdef_local_type extends t_local_id_class
233 {
234  // phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses
235  // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
236  // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
237  private $_local_type_lang_enum = null;
238  private $_local_type_name_string = null;
239  private $_local_type_desc_string = null;
240 
241  /*******************************************************************/
242  /** \brief Sets the language.
243  */
244  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
245  public function SetLocalLang(
246  $in_lang_enum = null // An enum, indicating the language. Defaults to Global Language, as a last resport, English ("en")
247  ) {
248  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
250 
251  /// This is the server language.
252  if (null == $in_lang_enum) {
253  $in_lang_enum = $comdef_global_language;
254  }
255 
256  /// Should never be necessary.
257  if (null == $in_lang_enum) {
258  $in_lang_enum = "en";
259  }
260 
261  $this->_local_type_lang_enum = null;
262  $this->_local_type_lang_enum = $in_lang_enum;
263  }
264 
265  /*******************************************************************/
266  /** \brief Returns a reference to the local language setting.
267 
268  \returns A reference to the _local_type_lang_enum data member
269  */
270  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
271  public function GetLocalLang()
272  {
273  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
274  return $this->_local_type_lang_enum;
275  }
276 
277  /*******************************************************************/
278  /** \brief Accessor -Sets the _local_type_name_string data member.
279  */
280  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
281  public function SetLocalName(
282  $in_name_string ///< The name of this object, as a string.
283  ) {
284  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
285  $this->_local_type_name_string = null;
286  $this->_local_type_name_string = $in_name_string;
287  }
288 
289  /*******************************************************************/
290  /** \brief Accessor -Returns a reference to the _local_type_name_string data member.
291 
292  \returns A reference to the _local_type_name_string data member.
293  */
294  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
295  public function GetLocalName()
296  {
297  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
298  return $this->_local_type_name_string;
299  }
300 
301  /*******************************************************************/
302  /** \brief Accessor -Sets the _local_type_desc_string data member.
303  */
304  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
305  public function SetLocalDescription(
306  $in_description_string ///< The description as a string up to 4000 characters long.
307  ) {
308  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
309  $this->_local_type_desc_string = null;
310  $this->_local_type_desc_string = $in_description_string;
311  }
312 
313  /*******************************************************************/
314  /** \brief Accessor -Returns a reference to the _local_type_desc_string data member.
315 
316  \returns A reference to the _local_type_desc_string data member.
317  */
318  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
319  public function GetLocalDescription()
320  {
321  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
322  return $this->_local_type_desc_string;
323  }
324 }
325 
326 /*******************************************************************/
327 /** \brief A very simple class that allows whatever format NAWS will use as an ID to be assigned to the object.
328 */
329 // phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses
330 // phpcs:disable PSR1.Classes.ClassDeclaration.MissingNamespace
331 // phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
333 // phpcs:enable PSR1.Classes.ClassDeclaration.MultipleClasses
334 // phpcs:enable PSR1.Classes.ClassDeclaration.MissingNamespace
335 // phpcs:enable Squiz.Classes.ValidClassName.NotCamelCaps
336 {
337  /// This is where the ID is stored.
338  private $_world_type_worldid_mixed = null;
339 
340  /*******************************************************************/
341  /** \brief Accessor -Sets the _world_type_worldid_mixed data member.
342  */
343  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
344  public function SetWorldID(
345  $in_worldid_mixed ///< The World (NAWS) ID, as a reference.
346  ) {
347  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
348  $this->_world_type_worldid_mixed = null;
349  $this->_world_type_worldid_mixed = $in_worldid_mixed;
350  }
351 
352  /*******************************************************************/
353  /** \brief Accessor -Returns a reference to the _world_type_worldid_mixed data member.
354 
355  \returns A reference to the _world_type_worldid_mixed data member.
356  */
357  // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
358  public function GetWorldID()
359  {
360  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
361  return $this->_world_type_worldid_mixed;
362  }
363 }
This interface describes some functions that should allow a derived class to be searched.
GetLocalDescription()
Accessor -Returns a reference to the _local_type_desc_string data member.
SetLocalName($in_name_string)
Accessor -Sets the _local_type_name_string data member.
SetParentObj($in_parent_obj)
Sets the object&#39;s "parent" (Container) object, as a reference.
GetParentObj()
Return a reference to the parent object of this instance.
GetLocalLang()
Returns a reference to the local language setting.
GetLocalName()
Accessor -Returns a reference to the _local_type_name_string data member.
GetParentObj()
Returns a reference to the object&#39;s container.
global $comdef_global_language
The local server language enum (Will default to English)
SetLocalDescription($in_description_string)
Accessor -Sets the _local_type_desc_string data member.
Allows us to specify a language to the instance (example: English or French)
This class allows us to assign a unique ID to each of its derived instances.
A very simple class that allows whatever format NAWS will use as an ID to be assigned to the object...
Simply declares an interface for having a "container" object.
Interface for entities that can be rendered into serialized form.
SetWorldID($in_worldid_mixed)
Accessor -Sets the _world_type_worldid_mixed data member.
Interface for entities that store themselves in the database.
defined('BMLT_EXEC') or define('BMLT_EXEC'
Definition: index.php:3
global $_COMDEF_DEBUG
This flag, when set to true, will cause extra debug information to be output.
SetParentObj($in_parent_obj)
Set the parent object of this instance.
Interface for entities that authenticate users.
SetLocalLang($in_lang_enum=null)
Sets the language.
GetWorldID()
Accessor -Returns a reference to the _world_type_worldid_mixed data member.