]> git.llucax.com Git - mecon/meconlib.git/commitdiff
Se agrega por primera vez el componente caritas
authorMartín Marrese <marrese@gmail.com>
Tue, 29 Jul 2003 20:37:37 +0000 (20:37 +0000)
committerMartín Marrese <marrese@gmail.com>
Tue, 29 Jul 2003 20:37:37 +0000 (20:37 +0000)
lib/MECON/HTML/QuickForm/caritas.php [new file with mode: 0644]

diff --git a/lib/MECON/HTML/QuickForm/caritas.php b/lib/MECON/HTML/QuickForm/caritas.php
new file mode 100644 (file)
index 0000000..9979b21
--- /dev/null
@@ -0,0 +1,282 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4: */
+// +----------------------------------------------------------------------+
+// | PHP Version 4                                                        |
+// +----------------------------------------------------------------------+
+// | Copyright (c) 1997-2003 The PHP Group                                |
+// +----------------------------------------------------------------------+
+// | This source file is subject to version 2.0 of the PHP license,       |
+// | that is bundled with this package in the file LICENSE, and is        |
+// | available at through the world-wide-web at                           |
+// | http://www.php.net/license/2_02.txt.                                 |
+// | If you did not receive a copy of the PHP license and are unable to   |
+// | obtain it through the world-wide-web, please send a note to          |
+// | license@php.net so we can mail you a copy immediately.               |
+// +----------------------------------------------------------------------+
+// | Authors: Adam Daniel <adaniel1@eesus.jnj.com>                        |
+// |          Bertrand Mansion <bmansion@mamasam.com>                     |
+// +----------------------------------------------------------------------+
+//
+// $Id$
+
+require_once('HTML/QuickForm/element.php');
+require_once('HTML/QuickForm/radio.php');
+require_once('MECON/defaults.php');
+require_once('HTML/Image.php');
+/**
+ * Class to dynamically create HTML Select elements from a date
+ *
+ * @author       Bertrand Mansion <bmansion@mamasam.com>
+ * @access       public
+ */
+class HTML_QuickForm_caritas extends HTML_QuickForm_element
+{   
+    // {{{ properties
+
+    /**
+     * Contains the select objects
+     * @var       array
+     * @access    private
+     */
+    var $radios = array();
+    
+    /**
+     * Default values of the SELECTs
+     * @var       array
+     * @access    private
+     */
+    var $_selectedCarita = null;
+    
+    var $_numRows = 5;
+
+
+    /**
+     * Frozen flag tells if element is frozen or not
+     * @var       bool
+     * @access    private
+     */
+    var $_flagFrozen = false;
+
+// +X2C Operation 533
+    /**
+     * Lista archivos devolviendo un array apropiado para un SELECT.
+     *
+     * @param  string $dir Directorio donde estan las imagenes.
+     * @param  string $prepend Prefijo del archivo.
+     * @param  string $append Postfijo del archivo.
+     *
+     * @return array
+     */
+    function listarArchivos($dir = '.', $prepend = '', $append = '') // ~X2C
+    {
+        $lista = array();
+        $d = dir($dir);
+        while (($file = $d->read()) !== false) {
+            if (preg_match("/$prepend(.*)$append/", $file, $m)) {
+                $lista[] = $file;
+            }
+        }
+        return $lista;
+    }
+    // -X2C
+    // }}}
+    // {{{ constructor
+
+    /**
+     * Class constructor
+     * 
+     * @param     string    $elementName    (optional)Input field name attribute
+     * @param     string    $value          (optional)Input field value
+     * @param     mixed     $attributes     (optional)Either a typical HTML attribute string 
+     *                                      or an associative array. Date format is passed along the attributes.
+     * @access    public
+     * @return    void
+     */
+     
+    function HTML_QuickForm_caritas($elementName=null, $elementLabel=null, $options=array(), $attributes=null)
+    {
+        HTML_QuickForm_element::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
+        $this->_persistantFreeze = true;
+        $this->_type = 'caritas';
+        $this->_setDefaults($options);
+    } //end constructor
+
+    // }}}
+    // {{{ _setDefaults()
+
+    /**
+     * sets the defaults options
+     * Current options are:
+     * - format
+     * - minYear
+     * - maxYear
+     * - language
+     * 
+     * @param     array    $options    array of options
+     * @access    private
+     * @return    void
+     */
+    function _setDefaults($options)
+    {
+     /*   if (isset($options['format'])) {
+            $this->setFormat($options['format']);
+        }
+        if (isset($options['language'])) {
+            $this->setLanguage($options['language']);
+        }
+        if (isset($options['minYear'])) {
+            $this->setMinYear($options['minYear']);
+        }
+        if (isset($options['maxYear'])) {
+            $this->setMaxYear($options['maxYear']);
+        }
+      */
+    } // end func _setDefaults
+
+    // }}}
+    // {{{ setName()
+
+    /**
+     * Sets the input field name
+     * @param     string    $name   Input field name attribute
+     * @access    public
+     * @return    void
+     */
+    function setName($name)
+    {
+        $this->name = $name;
+    } //end func setName
+
+    // }}}
+    // {{{ getName()
+
+    /**
+     * Returns the element name
+     * @access    public
+     * @return    string
+     */
+    function getName()
+    {
+        return $this->name;
+    } //end func getName
+
+
+    // {{{ _createSelects()
+
+    /**
+     * Creates the select objects
+     * @access    public
+     * @return    void
+     */
+    function _createRadios()
+    {
+        $this->caritas= array();
+        $elementName = $this->name;
+        $dir = MECON_DIR_FS_IMG.'/caritas';
+        $cant=5;
+        $i=1;
+        foreach ($this->listarArchivos($dir,'','.gif') as $nombre)
+        {
+            $this->radios[$nombre] = &new HTML_QuickForm_radio($elementName, '', '', $nombre, $this->getAttributes());
+        }
+    } // end func _createSelects
+
+    // }}}
+    // {{{ _createNumericOptionList()
+
+    // {{{ setSelectedCarita()
+
+    /**
+     * Sets the selected carita
+     * @param     mixed     an associative array corresponding to the format you chose
+     *                      for your date or an unix epoch timestamp
+     * @access    public
+     * @return    void
+     */
+    function setSelectedCarita($value)
+    {
+       $this->_selectedCarita = $value;
+    } // end func setSelectedDate
+
+    // }}}
+    // {{{ toHtml()
+
+    /**
+     * Returns the SELECT in HTML
+     * @access    public
+     * @return    string
+     * @throws    
+ */    
+    function toHtml()
+    {
+        $this->_createRadios();
+        $strHtml = '';
+        $i = 1;
+        foreach ($this->radios as $nombre => $element) {
+            if (@$this->_selectedCarita == $nombre) {
+                $element->setChecked(true);
+            }
+            if ($this->_flagFrozen) {
+                if (is_string($element)) {
+                    $strHtml .= str_replace(' ', '&nbsp;', $element);
+                } else {
+                    $strHtml .= $element->getFrozenHtml();
+                }
+            } else {
+                if (is_string($element)) {
+                    $strHtml .= str_replace(' ', '&nbsp;', $element);
+                } else {
+                    $strHtml .= $element->toHtml();
+                }
+            }
+            $imagen =& new HTML_Image(MECON_DIR_IMG."/caritas/$nombre");
+            $strHtml .= '&nbsp;' . $imagen->toHtml() . '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
+            if (!($i++ % $this->_numRows))
+                $strHtml .=  '<br>';
+        }
+        return $strHtml;
+    } // end func toHtml
+
+    // }}}
+    // {{{ onQuickFormEvent()
+
+    /**
+     * Called by HTML_QuickForm whenever form event is made on this element
+     *
+     * @param     string    $event  Name of event
+     * @param     mixed     $arg    event arguments
+     * @param     object    $caller calling object
+     * @since     1.0
+     * @access    public
+     * @return    void
+     * @throws    
+     */
+    function onQuickFormEvent($event, $arg, &$caller)
+    {
+        switch ($event) {
+            case 'updateValue':
+                // constant values override both default and submitted ones
+                // default values are overriden by submitted
+                $value = $this->_findValue($caller->_constantValues);
+                if (null === $value) {
+                    $value = $this->_findValue($caller->_submitValues);
+                    if (null === $value) {
+                        $value = $this->_findValue($caller->_defaultValues);
+                    }
+                }
+                if (null !== $value) {
+                    $this->setSelectedCarita($value);
+                }
+                break;
+            case 'setGroupValue':
+                $this->setSelectedCarita($arg);
+                break;
+            default:
+                parent::onQuickFormEvent($event, $arg, $caller);
+        }
+        return true;
+    } // end func onQuickFormEvent
+
+    // }}}
+} // end class HTML_QuickForm_date
+?>