Overview

Namespaces

  • None
  • PHP
  • Pry
    • Auth
      • Interfaces
    • Config
    • Controller
    • Date
    • Db
    • Feed
      • Abstracts
      • Writers
    • File
      • Decorator
    • Form
      • Element
    • Image
    • Log
      • Writer
    • Net
      • Exception
    • Session
    • Util
    • Validate
      • Validator
    • View

Classes

  • AutoCompleter
  • Checkbox
  • Colorpicker
  • Date
  • DatePicker
  • Email
  • File
  • Hidden
  • Html
  • Ip
  • Mac
  • Multi
  • NumericStepper
  • Password
  • Radio
  • Select
  • Slider
  • Submit
  • Text
  • Textarea
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Pry Framework
  5:  *
  6:  * LICENSE
  7:  *
  8:  * This source file is subject to the new BSD license that is bundled
  9:  * with this package in the file LICENSE.txt.
 10:  * 
 11:  */
 12: 
 13: namespace Pry\Form\Element;
 14: 
 15: use Pry\Form\Input;
 16: 
 17: /**
 18:  * Elément checkbox
 19:  * 
 20:  * @category Pry
 21:  * @package Form
 22:  * @subpackage Form_Element
 23:  * @version 1.1.2 
 24:  * @author Olivier ROGER <oroger.fr>  
 25:  *
 26:  */
 27: class Checkbox extends Input
 28: {
 29: 
 30:     /**
 31:      * Case cochée
 32:      *
 33:      * @var boolean
 34:      * @access private
 35:      */
 36:     private $checked;
 37: 
 38:     /**
 39:      * Constructeur. Par défaut case non cochée
 40:      *
 41:      * @param string $nom
 42:      * @param Form_Form $form
 43:      * @access public
 44:      */
 45:     public function __construct($nom, $form)
 46:     {
 47:         parent::__construct($nom, $form);
 48:         $this->attrs['type'] = 'checkbox';
 49:         $this->checked       = false;
 50:     }
 51: 
 52:     /**
 53:      * Défini si la case est cochée ou non
 54:      *
 55:      * @param boolean $bool
 56:      * @access public
 57:      * @return Form_Element_Checkbox
 58:      */
 59:     public function checked($bool = true)
 60:     {
 61:         $this->checked = $bool;
 62:         return $this;
 63:     }
 64: 
 65:     /**
 66:      * Ecrit l'objet
 67:      *
 68:      * @access public
 69:      * @return ustring
 70:      */
 71:     public function __toString()
 72:     {
 73:         $this->cssClass();
 74:         $label = '';
 75:         $css   = '';
 76: 
 77:         if (!empty($this->label))
 78:         {
 79:             $label = "\t" . '<span class="' . $this->cssLabel . '">' . $this->label . '</span>' . "\n";
 80:             if (!empty($this->info))
 81:                 $label.="\t" . '<img src="' . $this->imgInfo . '" id="' . $this->attrs['name'] . '_tooltip" class="form_tooltip" title="' . $this->info . '" alt="" style="cursor:help;" />';
 82:             if ($this->labelNewLine)
 83:                 $label.="\t" . '<br />' . "\n";
 84:         }
 85: 
 86:         $error = '';
 87: 
 88:         if (!is_null($this->errorMsg))
 89:         {
 90:             $error = '<span class="' . $this->errorClass . '">' . $this->errorMsg . '</span><br />';
 91:         }
 92: 
 93:         //Posted value ou value par défaut
 94:         $value = $this->form->getPostedvalue($this->attrs['name']);
 95:         if (empty($value))
 96:         {
 97:             $value                  = $this->value;
 98:             if (!$this->checked)
 99:                 unset($this->attrs['checked']);
100:             else
101:                 $this->attrs['checked'] = 'checked';
102:         }
103:         elseif (!empty($value))
104:         {
105:             $this->attrs['checked'] = 'checked';
106:         }
107:         elseif ($this->value == $value || $this->checked)
108:             $this->attrs['checked'] = 'checked';
109: 
110:         $attributs = $this->attrsToString();
111: 
112:         $field = "\t" . '<input ' . $css . ' ' . $attributs . ' />' . "\n";
113: 
114:         return $field . $label . $error;
115:     }
116: 
117: }
118: 
119: ?>
Pry API documentation generated by ApiGen 2.8.0