BMLT Root Server
Public Member Functions | Private Attributes | List of all members
c_comdef_formats Class Reference

Include the format class. More...

Public Member Functions

 __construct ($in_parent_obj, $in_array)
 Constructor. Sets the parent object. More...
 
 GetFormatsArray ()
 Accessor -Get the format object array. More...
 
 GetFormatByKeyAndLanguage ($in_format_key, $in_lang_enum=null)
 Return a reference to a single object, by format key and language. More...
 
 GetFormatBySharedIDCodeAndLanguage ($in_shared_id_bigint, $in_lang_enum=null)
 Return a reference to a single object, by shared ID and language. More...
 
 GetFormatsBySharedIDCode ($in_shared_id_bigint)
 Return all the formats that share a given shared ID code. More...
 
 GetFormatsByLanguage ($in_lang_enum=null)
 Return all the formats that share a given language. More...
 
 GetFormatsByString ($in_string, $in_lang_enum=null)
 Return all the formats that contain the given string. More...
 
 SetParentObj ($in_parent_obj)
 Set the parent object of this instance. More...
 
 GetParentObj ()
 Return a reference to the parent object of this instance. More...
 

Private Attributes

 $_local_id_parent_obj = null
 This is the parent (container) object that holds this instance. More...
 
 $_local_copy_of_array = null
 

Detailed Description

Include the format class.

A Class for Aggregating Format Codes

This class acts as an array aggregator for c_comdef_format objects. It is a class unto itself, because we want to have a couple of additional filtering options (like the ability to get a bunch of formats that share a _shared_id_bigint code).

The formats are kept in a simple two-dimensional array:

$_local_copy_of_array = array[$lang_enum][$shared_id_bigint]

The combination of shared ID and language needs to be unique. This is how we match formats to languages. The same shared ID is used throughout the system, and we use the localization to return its key and description in the appropriate language.

Definition at line 50 of file c_comdef_formats.class.php.

Constructor & Destructor Documentation

__construct (   $in_parent_obj,
  $in_array 
)

Constructor. Sets the parent object.

Definition at line 66 of file c_comdef_formats.class.php.

69  {
70  $this->SetParentObj($in_parent_obj);
71  $this->_local_copy_of_array = $in_array;
72  }
SetParentObj($in_parent_obj)
Set the parent object of this instance.

Member Function Documentation

GetFormatByKeyAndLanguage (   $in_format_key,
  $in_lang_enum = null 
)

Return a reference to a single object, by format key and language.

You do not need to provide a language, in which case, the server's local language is used.

Returns
A reference to the single selected object.

If no language is given, we use the server's native language.

Parameters
$in_format_keyThis is the shared ID code.
$in_lang_enumThis is the code for the desired language. If not given, the server localization will be used.

Definition at line 96 of file c_comdef_formats.class.php.

References c_comdef_server\GetServer().

99  {
100  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
101  /// If no language is given, we use the server's native language.
102  if (null == $in_lang_enum) {
103  $in_lang_enum = $this->GetParentObj()->GetLocalLang();
104  }
105 
106  if (!$in_lang_enum) {
107  $in_lang_enum = c_comdef_server::GetServer()->GetLocalLang();
108  }
109 
110  // Should never happen.
111  if (!$in_lang_enum) {
112  $in_lang_enum = "en";
113  }
114 
115  if (isset($this->_local_copy_of_array[$in_lang_enum]) && is_array($this->_local_copy_of_array[$in_lang_enum]) && count($this->_local_copy_of_array[$in_lang_enum])) {
116  foreach ($this->_local_copy_of_array[$in_lang_enum] as &$format) {
117  if ($in_format_key == $format->GetKey()) {
118  return $format;
119  };
120  }
121  }
122 
123  return null;
124  }
GetParentObj()
Return a reference to the parent object of this instance.
GetFormatBySharedIDCodeAndLanguage (   $in_shared_id_bigint,
  $in_lang_enum = null 
)

Return a reference to a single object, by shared ID and language.

You do not need to provide a language, in which case, the server's local language is used.

Returns
A reference to the single selected object.

If no language is given, we use the server's native language.

Parameters
$in_shared_id_bigintThis is the shared ID code.
$in_lang_enumThis is the code for the desired language. If not given, the server localization will be used.

Definition at line 136 of file c_comdef_formats.class.php.

References c_comdef_server\GetServer().

139  {
140  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
141  /// If no language is given, we use the server's native language.
142  if (null == $in_lang_enum) {
143  $in_lang_enum = $this->GetParentObj()->GetLocalLang();
144  }
145 
146  if (!$in_lang_enum) {
147  $in_lang_enum = c_comdef_server::GetServer()->GetLocalLang();
148  }
149 
150  // Should never happen.
151  if (!$in_lang_enum) {
152  $in_lang_enum = "en";
153  }
154 
155  if (isset($this->_local_copy_of_array[$in_lang_enum][$in_shared_id_bigint])) {
156  return $this->_local_copy_of_array[$in_lang_enum][$in_shared_id_bigint];
157  }
158  }
GetParentObj()
Return a reference to the parent object of this instance.
GetFormatsArray ( )

Accessor -Get the format object array.

Returns
a reference to an array of c_comdef_format objects.

Definition at line 80 of file c_comdef_formats.class.php.

81  {
82  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
84  }
GetFormatsByLanguage (   $in_lang_enum = null)

Return all the formats that share a given language.

You do not need to provide a language, in which case, the server's local language is used.

Returns
A simple array of references to the objects for the formats in the given language. Null if no formats fit the language.

If no language is given, we use the server's native language.

Parameters
$in_lang_enumThis is the code for the desired language. If not given, the server localization will be used.

Definition at line 194 of file c_comdef_formats.class.php.

References $ret.

196  {
197  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
198  $ret = null;
199 
200  /// If no language is given, we use the server's native language.
201  if (null == $in_lang_enum) {
202  $in_lang_enum = $this->GetParentObj()->GetLocalLang();
203  }
204 
205  if (isset($this->_local_copy_of_array) && is_array($this->_local_copy_of_array) && isset($this->_local_copy_of_array[$in_lang_enum]) && is_array($this->_local_copy_of_array)) {
206  $ret = $this->_local_copy_of_array[$in_lang_enum];
207  }
208 
209  return $ret;
210  }
$ret
Definition: contact.php:226
GetParentObj()
Return a reference to the parent object of this instance.
GetFormatsBySharedIDCode (   $in_shared_id_bigint)

Return all the formats that share a given shared ID code.

Returns
A simple array of references to the objects for the formats in all languages for the given shared ID. Null if no formats fit the language.
Parameters
$in_shared_id_bigintThis is the shared ID code.

Definition at line 167 of file c_comdef_formats.class.php.

References $ret.

169  {
170  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
171  $ret = null;
172 
173  foreach ($this->_local_copy_of_array as $lang) {
174  foreach ($lang as $id) {
175  if ($id->GetSharedID() == $in_shared_id_bigint) {
176  $ret[$id->GetLocalLang()] = $id;
177  }
178  }
179  }
180 
181  return $ret;
182  }
$ret
Definition: contact.php:226
GetFormatsByString (   $in_string,
  $in_lang_enum = null 
)

Return all the formats that contain the given string.

If the language is English or Spanish, this does a metaphone search of all all the strings in the "en" or "es" formats. If it is any other language, then a simple string search is performed.

Returns
A simple array of references to the objects for the formats in all languages for the given string. Null if no formats fit.

If no language is given, we use the server's native language.

We force the search to happen in lowercase. This is a very basic search.

If we will use metaphone, we convert our search criteria to metaphone keys.

We will look in each of the text fields for our string.

Parameters
$in_stringThis is the string to search for.
$in_lang_enumThis is the code for the desired language. If not given, the server localization will be used.

Definition at line 223 of file c_comdef_formats.class.php.

References $ret, and SplitIntoMetaphone().

226  {
227  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
228  $ret = null;
229 
230  /// If no language is given, we use the server's native language.
231  if (null == $in_lang_enum) {
232  $in_lang_enum = $this->GetParentObj()->GetLocalLang();
233  }
234 
235  /// We force the search to happen in lowercase. This is a very basic search.
236  $in_string = strtolower($in_string);
237 
238  /// If we will use metaphone, we convert our search criteria to metaphone keys.
239  $in_string_comp = SplitIntoMetaphone($in_string, $in_lang_enum);
240 
241  $count = 0;
242  $iterating_target = $this->GetFormatsByLanguage($in_lang_enum);
243  foreach ($iterating_target as $id) {
244  $found = false;
245 
246  /// We will look in each of the text fields for our string.
247  $string = $id->GetKey();
248 
249  $comp = SplitIntoMetaphone($string, $in_lang_enum);
250 
251  foreach ($in_string_comp as $test) {
252  if (array_search($test, $comp)) {
253  $found = true;
254  break;
255  }
256  }
257 
258  if (!$found) {
259  $string = $id->GetLocalName();
260 
261  $comp = SplitIntoMetaphone($string, $in_lang_enum);
262 
263  foreach ($in_string_comp as $test) {
264  if (array_search($test, $comp)) {
265  $found = true;
266  break;
267  }
268  }
269  }
270 
271  if (!$found) {
272  $string = $id->GetLocalDescription();
273 
274  $comp = SplitIntoMetaphone($string, $in_lang_enum);
275 
276  foreach ($in_string_comp as $test) {
277  if (array_search($test, $comp)) {
278  $found = true;
279  break;
280  }
281  }
282  }
283 
284  if ($found) {
285  $ret[$count++] = $id;
286  }
287  }
288 
289  return $ret;
290  }
$ret
Definition: contact.php:226
GetFormatsByLanguage($in_lang_enum=null)
Return all the formats that share a given language.
GetParentObj()
Return a reference to the parent object of this instance.
SplitIntoMetaphone($in_string, $in_lang_enum=null, $in_literal=false)
Converts a string into an array of metaphone entities.
GetParentObj ( )

Return a reference to the parent object of this instance.

Returns
a reference to the parent instance of the object.

Implements i_comdef_has_parent.

Definition at line 310 of file c_comdef_formats.class.php.

311  {
312  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
314  }
$_local_id_parent_obj
This is the parent (container) object that holds this instance.
SetParentObj (   $in_parent_obj)

Set the parent object of this instance.

Parameters
$in_parent_objA reference to the parent object.

Implements i_comdef_has_parent.

Definition at line 296 of file c_comdef_formats.class.php.

298  {
299  // phpcs:enable PSR1.Methods.CamelCapsMethodName.NotCamelCaps
300  $this->_local_id_parent_obj = null;
301  $this->_local_id_parent_obj = $in_parent_obj;
302  }

Member Data Documentation

$_local_copy_of_array = null
private

We keep a local copy of the simple array, because we can instantly access it, as opposed to having to instantiate iterators.

Definition at line 61 of file c_comdef_formats.class.php.

$_local_id_parent_obj = null
private

This is the parent (container) object that holds this instance.

Definition at line 55 of file c_comdef_formats.class.php.


The documentation for this class was generated from the following file: