Advertisement
rfv123

CheckboxHistory interface

May 22nd, 2016
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.84 KB | None | 0 0
  1. <?php
  2. namespace app\system;
  3. /**
  4. * Maintain a list of checkboxes and the immidiate history
  5. *
  6. * Uses: array of  $key => $label
  7. *
  8. *   the key can be numbers or string the class works with keys    
  9. *
  10. *   e.g.  $cbxHistory = new CheckboxHistory(array('key1' => 'label 1',
  11. *                                                 'key2' => 'label 2',
  12. *                                                 'key3' => 'label 3',
  13. *                                                 ))
  14. *  
  15. * It uses a string to hold whether each checkbox in the list currently is checked or not
  16. *
  17. *  e.g.   $cbxHistory->cbxStateString()
  18. *  
  19. *         This will be stored in a hidden field $_POST and will become the $prvCheckedState
  20. *          
  21. *
  22. *
  23. *  It generates all the details to
  24. *     1) use in the checkbox HTML
  25. *          'label' is for the html checkbox label
  26. *          'value' is for the html checkbox value
  27. *            note: the value is a position in the list not a key!      
  28. *
  29. *     2) The state of the checkbox and whether is has just changed
  30. *
  31. *  e.g.  $cbxHistory->cbxDetails($key);
  32. *
  33. *        returns: array('label'       => $this->cbxLabel($key),
  34. *                       'value'       => $this->cbxValue($key),
  35. *                       'key'         => $key,
  36. *                        
  37. *                       'hasChanged'  => $this->hasChanged($key),
  38. *                       'curChecked'  => $this->curChecked($key),
  39. *                       'prvChecked'  => $this->prvChecked($key));
  40. *      
  41. *  It uses a cbxStateString to know what the previous states of the checkbox
  42. *
  43. *    e.g.  $cbxHistory->setCbxCheckedState($oldCbxCheckedState);
  44. *
  45. *          This will normally be from the html 'hidden' cbxState field
  46. *  
  47. */
  48.  
  49. interface ICheckboxHistory {
  50.  
  51.  
  52.    /**
  53.    * The label value to be used in the html
  54.    *
  55.    * @param mixed $key
  56.    *
  57.    * @return label text
  58.    */
  59.    public function cbxLabel($key);
  60.  
  61.    /**
  62.    * The value to be used for the checkbox in the html.
  63.    *
  64.    * It is actually the position of the lookup key in the list
  65.    *  
  66.    * @param mixed $key
  67.    *
  68.    * @return integer
  69.    */
  70.    public function cbxValue($key);
  71.  
  72.    /**
  73.    * The 'key' of the checkbox given the 'value' (position])
  74.    *
  75.    * It is actually the key at that position in the list
  76.    *  
  77.    * @param integer $html value of the checkbox
  78.    *
  79.    * @return mixed $key
  80.    */
  81.    public function cbxKey($value);
  82.  
  83.    /**
  84.    * This is the current state vector of all the checkboxes
  85.    *
  86.    * It is stored in a 'hidden' field on the form
  87.    *
  88.    * It is used in the  fromCbxStateString() method  
  89.    *
  90.    * @return string
  91.    */  
  92.    public function cbxStateString();
  93.  
  94.    
  95.    /**
  96.    * All the details (checkbox state) in one convenient list
  97.    *
  98.    * @param mixed $key
  99.    *
  100.    * @return array  ('label'       => cbxLabel(),
  101.    *                 'value'       => $cbxValue(),
  102.    *                 'key'         => $key,
  103.    *                 'hasChanged'  => hasChanged(),
  104.    *                 'curChecked'  => curChecked(),
  105.    *                 'prvChecked'  => prvChecked(),
  106.    *                )
  107.    */
  108.    public function cbxDetails($key);
  109.    
  110.    public function cbxDetailsByKey($key); // alias of cbxDetails
  111.  
  112.    /**
  113.    * All the details (checkbox state) in one convenient list given a checkbox value
  114.    *
  115.    *
  116.    * @param integer $position (html value of the checkbox)
  117.    *
  118.    * @return array
  119.    */
  120.    public function cbxDetailsByValue($position);
  121.  
  122.  
  123.    /**
  124.    * All the cbxDetails as an array
  125.    *
  126.    *   The key of the array is position  (cbxValue)
  127.    *
  128.    * @return array
  129.    */
  130.    public function cbxDetailsArray();
  131.  
  132.    public function getIterator();
  133.  
  134.    /**
  135.    * set the curCheckedState from an array of values ($positions)
  136.    *  
  137.    * @param array $positionList i.e. $_POST
  138.    *
  139.    * @return void
  140.    */
  141.    public function fromCheckedList(array $checkedPos);
  142.  
  143.    
  144.   /**
  145.    * This is the previous state of the all checkboxes
  146.    *
  147.    * It is obtained from the chechboxes 'hidden' field
  148.    *
  149.    * @param string $prvStateStr
  150.    *
  151.    * @return void
  152.    */
  153.    public function setCbxStateString($prvStateStr);
  154.    
  155.  
  156.    
  157.    /**
  158.    * current state of a checkbox
  159.    *
  160.    * @param mixed $key
  161.    *
  162.    * @return boolean
  163.    */
  164.    public function curChecked($key);
  165.  
  166.  
  167.    /**
  168.    * previous state of a checkbox
  169.    *
  170.    * @param mixed $key
  171.    *
  172.    * @return booleam
  173.    */
  174.    public function prvChecked($key);
  175.  
  176.    /**
  177.    * Has the checkbox changed state (user checked or unchecked it)
  178.    *
  179.    * @param mixed $key
  180.    *
  181.    * @return boolean
  182.    */
  183.    public function hasChanged($key);
  184.  
  185.  
  186.      
  187.    /**
  188.    * Set or unset a checkbox by key value
  189.    *
  190.    * @param mixed   $key
  191.    * @param boolean $checked
  192.    *
  193.    * @return void
  194.    */
  195.    public function setCheckbox($key, $checked = true);
  196.  
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement