/pimcore/models/Document/Tag/Checkbox.php

https://github.com/ngocanh/pimcore · PHP · 104 lines · 33 code · 16 blank · 55 comment · 2 complexity · 83d8d99e709bea09c5aaac921f04f928 MD5 · raw file

  1. <?php
  2. /**
  3. * Pimcore
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://www.pimcore.org/license
  11. *
  12. * @category Pimcore
  13. * @package Document
  14. * @copyright Copyright (c) 2009-2010 elements.at New Media Solutions GmbH (http://www.elements.at)
  15. * @license http://www.pimcore.org/license New BSD License
  16. */
  17. class Document_Tag_Checkbox extends Document_Tag {
  18. /**
  19. * Contains the checkbox value
  20. *
  21. * @var boolean
  22. */
  23. public $value = false;
  24. /**
  25. * @see Document_Tag_Interface::getType
  26. * @return string
  27. */
  28. public function getType() {
  29. return "checkbox";
  30. }
  31. /**
  32. * @see Document_Tag_Interface::getData
  33. * @return mixed
  34. */
  35. public function getData() {
  36. return $this->value;
  37. }
  38. /**
  39. * @see Document_Tag_Interface::frontend
  40. * @return string
  41. */
  42. public function frontend() {
  43. return $this->value;
  44. }
  45. /**
  46. * @see Document_Tag_Interface::setDataFromResource
  47. * @param mixed $data
  48. * @return void
  49. */
  50. public function setDataFromResource($data) {
  51. $this->value = $data;
  52. }
  53. /**
  54. * @see Document_Tag_Interface::setDataFromEditmode
  55. * @param mixed $data
  56. * @return void
  57. */
  58. public function setDataFromEditmode($data) {
  59. $this->value = $data;
  60. }
  61. /**
  62. * @return boolean
  63. */
  64. public function isEmpty() {
  65. return $this->value;
  66. }
  67. /**
  68. * @return boolean
  69. */
  70. public function isChecked() {
  71. return $this->isEmpty();
  72. }
  73. /**
  74. * Receives a Webservice_Data_Document_Element from webservice import and fill the current tag's data
  75. *
  76. * @abstract
  77. * @param Webservice_Data_Document_Element $data
  78. * @return void
  79. */
  80. public function getFromWebserviceImport($wsElement){
  81. $data = $wsElement->value;
  82. if($data->bool === null or is_bool($data)){
  83. $this->value = (bool) $data->value;
  84. } else {
  85. throw new Exception("cannot get values from web service import - invalid data");
  86. }
  87. }
  88. }