public function WsData::getData in Web Service Data 7
Retrieve the value for the given data key.
This function retrieves data from the structured array in $this->data using $key as a key. $key should be a string, with the character ':' delimiting the parts of the key. I.E. The key something:someplace with retrive $this->data['something']['someplace'] N.B. This function can be overridden to work with whatever the ->parse function is implemented to return.
Parameters
string $key [optional]: Data key to load
string $lang [optional]: Language key
Return value
mixed|boolean Returns the requested data, FALSE otherwise.
1 method overrides WsData::getData()
- SampleProcessor::getData in modules/
wsconfig/ wsconfig.api.php - WsData provides a default getData implementation. This function must return a properly structured field array (including language, array of values, field names, etc...).
File
- ./
wsdata.module, line 171 - Main module for wsconfig
Class
- WsData
- Class definition for Web Service data parser
Code
public function getData($key = NULL, $lang = NULL) {
$return_data = FALSE;
if (is_array($this->data)) {
// Paths to load data from
$paths = array();
// Split the logic based on whether we have translated data
// - Return all the data for a given language
// - Return a key of data for a given language
// - Return a key of data for all languages
// First, see if we want a specific language
if ($this->languages) {
if (!is_null($lang) and array_key_exists($lang, $this->data)) {
$paths[$lang] = !empty($key) ? $lang . ':' . $key : $lang;
}
else {
foreach ($this->languages as $lang) {
$paths[$lang] = !empty($key) ? $lang . ':' . $key : $lang;
}
}
}
else {
if (!empty($key)) {
$paths[$key] = $key;
}
}
// Get the raw data
$return_data = $this->data;
// Simplest case, return all data.
if (empty($paths)) {
return $return_data;
}
// Second simplest case, one specific value
if (!empty($paths[$key])) {
$location = explode(':', $paths[$key]);
foreach ($location as $l) {
if (isset($return_data[$l])) {
$return_data = $return_data[$l];
}
else {
$return_data = FALSE;
}
}
return $return_data;
}
// Third case, one specific value in a given language
if (!empty($paths[$lang]) and count($paths) == 1) {
$location = explode(':', $path[$lang]);
foreach ($location as $l) {
if (isset($return_data[$l])) {
$return_data = $return_data[$l];
}
else {
$return_data = FALSE;
}
}
// Language specific data is always keyed by the language
$return_data[$lang] = $return_data;
return $return_data;
}
// Lastly, the complicated case. Keyed value for all languages
if ($this->languages and count($paths) > 1) {
$keyed_data = array();
foreach ($paths as $p => $path) {
// Reset return data
$return_data = $this->data;
$location = explode(':', $path);
foreach ($location as $l) {
if (isset($return_data[$l])) {
$return_data = $return_data[$l];
}
else {
$return_data = FALSE;
}
}
$keyed_data[$p] = $return_data;
}
// Finally, put the keyed data back into the return data.
return $keyed_data;
}
}
return $return_data;
}