/**
  * Generates an HTML radio list.
  *
  * @param array An array of objects
  * @param string The value of the HTML name attribute
  * @param string Additional HTML attributes for the <select> tag
  * @param mixed The key that is selected
  * @param string The name of the object variable for the option value
  * @param string The name of the object variable for the option text
  * @return string HTML for the select list
  */
 public static function radiolist($data, $name, $attribs = null, $optKey = 'value', $optText = 'text', $selected = null, $idtag = false, $translate = false)
 {
     reset($data);
     $html = '';
     if (is_array($attribs)) {
         $attribs = GantryArrayHelper::toString($attribs);
     }
     $id_text = $idtag ? $idtag : $name;
     foreach ($data as $ind => $obj) {
         $k = $obj->{$optKey};
         $t = $translate ? JText::_($obj->{$optText}) : $obj->{$optText};
         $id = isset($obj->id) ? $obj->id : null;
         $extra = '';
         $extra .= $id ? ' id="' . $obj->id . '"' : '';
         if (is_array($selected)) {
             foreach ($selected as $val) {
                 $k2 = is_object($val) ? $val->{$optKey} : $val;
                 if ($k == $k2) {
                     $extra .= ' selected="selected"';
                     break;
                 }
             }
         } else {
             $extra .= (string) $k == (string) $selected ? ' checked="checked"' : '';
         }
         $html .= "\n\t" . '<input type="radio" name="' . $name . '"' . ' id="' . $id_text . $k . '" value="' . $k . '"' . ' ' . $extra . ' ' . $attribs . '/>' . "\n\t" . '<label for="' . $id_text . $k . '" id="' . $id_text . $k . '-lbl" class="radiobtn_' . strtolower($obj->{$optText}) . '">' . $t . '</label>';
     }
     $html .= "\n";
     return $html;
 }
 /**
  * Method to recursively bind data to a parent object.
  *
  * @param	object	$parent	The parent object on which to attach the data values.
  * @param	mixed	$data	An array or object of data to bind to the parent object.
  *
  * @return	void
  * @since	1.6
  */
 protected function bindData(&$parent, $data)
 {
     // Ensure the input data is an array.
     if (is_object($data)) {
         $data = get_object_vars($data);
     } else {
         $data = (array) $data;
     }
     foreach ($data as $k => $v) {
         if (is_array($v) && GantryArrayHelper::isAssociative($v) || is_object($v)) {
             $parent->{$k} = new stdClass();
             $this->bindData($parent->{$k}, $v);
         } else {
             $parent->{$k} = $v;
         }
     }
 }
 /**
  * Method to apply an input filter to a value based on field data.
  *
  * @param	string	$element	The XML element object representation of the form field.
  * @param	mixed	$value		The value to filter for the field.
  *
  * @return	mixed	The filtered value.
  * @since	1.6
  */
 protected function filterField($element, $value)
 {
     gantry_import('core.utilities.gantryfilterinput');
     // Make sure there is a valid GantrySimpleXMLElement.
     if (!$element instanceof GantrySimpleXMLElement) {
         return false;
     }
     // Get the field filter type.
     $filter = (string) $element['filter'];
     // Process the input value based on the filter.
     $return = null;
     switch (strtoupper($filter)) {
         // Access Control Rules.
         case 'RULES':
             $return = array();
             foreach ((array) $value as $action => $ids) {
                 // Build the rules array.
                 $return[$action] = array();
                 foreach ($ids as $id => $p) {
                     if ($p !== '') {
                         $return[$action][$id] = $p == '1' || $p == 'true' ? true : false;
                     }
                 }
             }
             break;
             // Do nothing, thus leaving the return value as null.
         // Do nothing, thus leaving the return value as null.
         case 'UNSET':
             break;
             // No Filter.
         // No Filter.
         case 'RAW':
             $return = $value;
             break;
             // Filter the input as an array of integers.
         // Filter the input as an array of integers.
         case 'INT_ARRAY':
             // Make sure the input is an array.
             if (is_object($value)) {
                 $value = get_object_vars($value);
             }
             $value = is_array($value) ? $value : array($value);
             GantryArrayHelper::toInteger($value);
             $return = $value;
             break;
             // Filter safe HTML.
         // Filter safe HTML.
         case 'SAFEHTML':
             $return = GantryFilterInput::getInstance(null, null, 1, 1)->clean($value, 'string');
             break;
             // Convert a date to UTC based on the server timezone offset.
         // Convert a date to UTC based on the server timezone offset.
         case 'SERVER_UTC':
             if (intval($value) > 0) {
                 // Get the server timezone setting.
                 $offset = JFactory::getConfig()->get('offset');
                 // Return a MySQL formatted datetime string in UTC.
                 $return = JFactory::getDate($value, $offset)->toMySQL();
             } else {
                 $return = '';
             }
             break;
             // Convert a date to UTC based on the user timezone offset.
         // Convert a date to UTC based on the user timezone offset.
         case 'USER_UTC':
             if (intval($value) > 0) {
                 // Get the user timezone setting defaulting to the server timezone setting.
                 $offset = JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset'));
                 // Return a MySQL formatted datetime string in UTC.
                 $return = JFactory::getDate($value, $offset)->toMySQL();
             } else {
                 $return = '';
             }
             break;
         default:
             // Check for a callback filter.
             if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) {
                 $return = call_user_func(explode('::', $filter), $value);
             } else {
                 if (function_exists($filter)) {
                     $return = call_user_func($filter, $value);
                 } else {
                     $return = GantryFilterInput::getInstance()->clean($value, $filter);
                 }
             }
             break;
     }
     return $return;
 }
 /**
  * Utility function to map an object to an array
  *
  * @static
  * @param	object	The source object
  * @param	boolean	True to recurve through multi-level objects
  * @param	string	An optional regular expression to match on field names
  * @return	array	The array mapped from the given object
  * @since	1.5
  */
 static function fromObject($p_obj, $recurse = true, $regex = null)
 {
     $result = null;
     if (is_object($p_obj)) {
         $result = array();
         foreach (get_object_vars($p_obj) as $k => $v) {
             if ($regex) {
                 if (!preg_match($regex, $k)) {
                     continue;
                 }
             }
             if (is_object($v)) {
                 if ($recurse) {
                     $result[$k] = GantryArrayHelper::fromObject($v, $recurse, $regex);
                 }
             } else {
                 $result[$k] = $v;
             }
         }
     }
     return $result;
 }