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\Error;
 16: 
 17: /**
 18:  * Element ColorPicker. Permet de choisir une couleur dans une palette
 19:  * @category Pry
 20:  * @package Form
 21:  * @subpackage Form_Element
 22:  * @version 1.5.0 
 23:  * @author Olivier ROGER <oroger.fr>   
 24:  *
 25:  */
 26: class Colorpicker extends Text
 27: {
 28: 
 29:     /**
 30:      * Constructeur. Défini la couleur de base à rouge
 31:      *
 32:      * @param string $nom
 33:      * @param Form_Form $form
 34:      */
 35:     public function __construct($nom, $form)
 36:     {
 37:         parent::__construct($nom, $form);
 38:         $this->value('#FF0000');
 39:     }
 40: 
 41:     /**
 42:      * Défini une couleur de base en RGB
 43:      *
 44:      * @param array $rgb
 45:      * @access public
 46:      * @return Form_Element_Colorpicker
 47:      */
 48:     public function setRGBColor($rgb)
 49:     {
 50:         for ($i = 0; $i < 2; $i++) {
 51:             if ($rgb[$i] < 0 || $rgb[$i] > 255)
 52:                 throw new Image_Exception('La valeur RGB est incorrecte (compris en 0 et 255');
 53:         }
 54: 
 55:         $this->value('#' . str_pad((dechex($rgb[0]) . dechex($rgb[1]) . dechex($rgb[2])), 6, "0", STR_PAD_LEFT));
 56:         return $this;
 57:     }
 58: 
 59:     /**
 60:      * Défini une couleur de base en Hexa
 61:      *
 62:      * @param string $color
 63:      * @access public
 64:      * @return Form_Element_Colorpicker
 65:      */
 66:     public function setHexaColor($color)
 67:     {
 68:         if ($color[0] == '#')
 69:             $this->value($color);
 70:         else
 71:             $this->value('#' . $color);
 72: 
 73:         return $this;
 74:     }
 75: 
 76:     /**
 77:      * Vérifie la couleur recu
 78:      *
 79:      * @param string $value
 80:      * @access public
 81:      * @return boolean
 82:      */
 83:     public function isValid($value)
 84:     {
 85:         if (parent::isValid($value))
 86:         {
 87:             if (!preg_match('`^#([0-9a-fA-F]{6})$`', $value))
 88:             {
 89:                 $this->errorMsg = Error::COLOR;
 90:                 return false;
 91:             }
 92:             return true;
 93:         }
 94:     }
 95: 
 96:     /**
 97:      * Ecrit l'objet
 98:      *
 99:      * @return unknown
100:      */
101:     public function __toString()
102:     {
103:         $field = '';
104:         $field.=parent::__toString();
105:         $this->form->javascript .='$("#' . $this->attrs['id'] . '").gccolor({
106:             onChange : function(target,color){
107:                 target.val("#"+color);
108:             }
109:         });';
110:         return $field;
111:     }
112: 
113: }
114: 
115: ?>
Pry API documentation generated by ApiGen 2.8.0