Пример #1
0
 function display($tpl = null)
 {
     // Get data from the model
     require_once JPATH_COMPONENT . '/models/ajaxvote.php';
     $model = new AcepollsModelAjaxvote();
     $vote = $model->getVoted();
     $data = $model->getData();
     $total = $model->getTotal();
     $poll_id = JRequest::getInt('id', 0, 'post');
     // create root node
     $xml = new JXMLElement('<poll></poll>');
     $xml->addAttribute('id', $poll_id);
     //get total votes
     $sum = 0;
     foreach ($data as $row) {
         $sum += $row->votes;
     }
     $number_voters = 0;
     $options =& $xml->addChild('options');
     for ($i = 0; $i < $total; $i++) {
         $option =& $options->addChild('option');
         $option->addAttribute('id', $data[$i]->id);
         $option->addAttribute('percentage', self::_toPercent($data[$i]->votes, $sum));
         $option->addAttribute('color', $data[$i]->color);
         $option->addChild('text', $data[$i]->text);
         $number_voters += $data[$i]->votes;
     }
     $xml->addChild('voters', $number_voters);
     $this->assign('xml', $xml->asFormattedXML());
     $this->setLayout('raw');
     parent::display($tpl);
 }
Пример #2
0
 public function getField($type, $attributes = array(), $field_value = '')
 {
     static $types = null;
     $defaults = array('name' => '', 'id' => '');
     if (!$types) {
         jimport('joomla.form.helper');
         $types = array();
     }
     if (!in_array($type, $types)) {
         JFormHelper::loadFieldClass($type);
     }
     try {
         $attributes = array_merge($defaults, $attributes);
         $xml = new JXMLElement('<?xml version="1.0" encoding="utf-8"?><field />');
         foreach ($attributes as $key => $value) {
             if ('_options' == $key) {
                 foreach ($value as $_opt_value) {
                     $xml->addChild('option', $_opt_value->text)->addAttribute('value', $_opt_value->value);
                 }
                 continue;
             }
             $xml->addAttribute($key, $value);
         }
         $class = 'JFormField' . $type;
         $field = new $class();
         $field->setup($xml, $field_value);
         return $field;
     } catch (Exception $e) {
         return false;
     }
 }
 public function getCategories($config = array('showlist_id' => 0))
 {
     $objJSNImages = JSNISFactory::getObj('classes.jsn_is_images');
     $syncAlbum = $objJSNImages->getSyncAlbumsByShowlistID($config['showlist_id']);
     $syncAlbum = count($syncAlbum) > 0 ? $syncAlbum : array();
     $path = JPath::clean(JPATH_ROOT . DS . $this->_folder);
     if (!is_dir($path)) {
         return false;
     }
     $xmlObj = new JXMLElement('<node></node>');
     $xmlObj->addAttribute('label', 'images');
     $xmlObj->addAttribute('data', 'images');
     $xmlObj->addAttribute('type', 'root');
     $this->drawTree($xmlObj, $path, $syncAlbum);
     return $xmlObj->asFormattedXML();
 }
Пример #4
0
 /**
  * Method to attach a JForm object to the field.
  *
  * @param   object  &$element  The JXmlElement object representing the <field /> tag for the form field object.
  * @param   mixed   $value     The form field value to validate.
  * @param   string  $group     The field name group control value. This acts as as an array container for the field.
  *                             For example if the field has name="foo" and the group value is set to "bar" then the
  *                             full field name would end up being "bar[foo]".
  *
  * @return  boolean  True on success.
  *
  * @since   11.1
  */
 public function setup(&$element, $value, $group = null)
 {
     // Make sure there is a valid JFormField XML element.
     if (!$element instanceof JXMLElement || (string) $element->getName() != 'field') {
         return false;
     }
     // Reset the input and label values.
     $this->input = null;
     $this->label = null;
     // Set the XML element object.
     $this->element = $element;
     // Get some important attributes from the form field element.
     $class = (string) $element['class'];
     $id = (string) $element['id'];
     $multiple = (string) $element['multiple'];
     $name = (string) $element['name'];
     $required = (string) $element['required'];
     // Set the required and validation options.
     $this->required = $required == 'true' || $required == 'required' || $required == '1';
     $this->validate = (string) $element['validate'];
     // Add the required class if the field is required.
     if ($this->required) {
         if ($class) {
             if (strpos($class, 'required') === false) {
                 $this->element['class'] = $class . ' required';
             }
         } else {
             $this->element->addAttribute('class', 'required');
         }
     }
     // Set the multiple values option.
     $this->multiple = $multiple == 'true' || $multiple == 'multiple';
     // Allow for field classes to force the multiple values option.
     if (isset($this->forceMultiple)) {
         $this->multiple = (bool) $this->forceMultiple;
     }
     // Set the field description text.
     $this->description = (string) $element['description'];
     // Set the visibility.
     $this->hidden = (string) $element['type'] == 'hidden' || (string) $element['hidden'] == 'true';
     // Determine whether to translate the field label and/or description.
     $this->translateLabel = !((string) $this->element['translate_label'] == 'false' || (string) $this->element['translate_label'] == '0');
     $this->translateDescription = !((string) $this->element['translate_description'] == 'false' || (string) $this->element['translate_description'] == '0');
     // Set the group of the field.
     $this->group = $group;
     // Set the field name and id.
     $this->fieldname = $this->getFieldName($name);
     $this->name = $this->getName($this->fieldname);
     $this->id = $this->getId($id, $this->fieldname);
     // Set the field default value.
     $this->value = $value;
     // Set the CSS class of field label
     $this->labelClass = (string) $element['labelclass'];
     return true;
 }
Пример #5
0
 /**
  * $type, $domId, $value, $options = array(), $formName = null, $disabled = false
  */
 public static function element()
 {
     list($type, $domId, $value, $options) = func_get_args();
     $options = (array) $options;
     // Load the JFormField object for the field.
     JFormHelper::addFieldPath(JPATH_COMPONENT_ADMINISTRATOR . DS . 'models' . DS . 'fields');
     $field = JFormHelper::loadFieldType($type, true);
     // If the object could not be loaded, get a text field object.
     if ($field === false) {
         throw new Exception('Cannot load field type ' . $type);
     }
     $element = new JXMLElement('<field></field>');
     $element->addAttribute('id', $domId);
     if (!empty($options)) {
         foreach ($options as $name => $val) {
             $element->addAttribute($name, $val);
         }
     }
     if (!$field->setup($element, $value, null)) {
         throw new Exception('Cannot setup field ' . $type);
     }
     return $field->input;
 }