/pimcore/models/Tool/Qrcode/Config.php

https://github.com/timglabisch/pimcore · PHP · 231 lines · 107 code · 34 blank · 90 comment · 4 complexity · 8b38504a10a47aff93ecdbc3e9b64977 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 Tool
  14. * @copyright Copyright (c) 2009-2013 pimcore GmbH (http://www.pimcore.org)
  15. * @license http://www.pimcore.org/license New BSD License
  16. */
  17. class Tool_Qrcode_Config {
  18. /**
  19. * @var string
  20. */
  21. public $name = "";
  22. /**
  23. * @var string
  24. */
  25. public $description = "";
  26. /**
  27. * @var string
  28. */
  29. public $url = "";
  30. /**
  31. * @var
  32. */
  33. public $foreColor = "";
  34. /**
  35. * @var string
  36. */
  37. public $backgroundColor = "";
  38. /**
  39. * @var bool
  40. */
  41. public $googleAnalytics = true;
  42. /**
  43. * @static
  44. * @param $name
  45. * @return Tool_Qrcode_Config
  46. */
  47. public static function getByName ($name) {
  48. $code = new self();
  49. $code->setName($name);
  50. if(!$code->load()) {
  51. throw new Exception("qr-code definition : " . $name . " does not exist");
  52. }
  53. return $code;
  54. }
  55. /**
  56. * @static
  57. * @return string
  58. */
  59. public static function getWorkingDir () {
  60. $dir = PIMCORE_CONFIGURATION_DIRECTORY . "/qrcodes";
  61. if(!is_dir($dir)) {
  62. mkdir($dir);
  63. }
  64. return $dir;
  65. }
  66. /**
  67. * @return void
  68. */
  69. public function save () {
  70. $arrayConfig = object2array($this);
  71. $config = new Zend_Config($arrayConfig);
  72. $writer = new Zend_Config_Writer_Xml(array(
  73. "config" => $config,
  74. "filename" => $this->getConfigFile()
  75. ));
  76. $writer->write();
  77. return true;
  78. }
  79. /**
  80. * @return void
  81. */
  82. public function load () {
  83. $configXml = new Zend_Config_Xml($this->getConfigFile());
  84. $configArray = $configXml->toArray();
  85. foreach ($configArray as $key => $value) {
  86. $setter = "set" . ucfirst($key);
  87. if(method_exists($this, $setter)) {
  88. $this->$setter($value);
  89. }
  90. }
  91. return true;
  92. }
  93. /**
  94. * @return void
  95. */
  96. public function delete() {
  97. if(is_file($this->getConfigFile())) {
  98. unlink($this->getConfigFile());
  99. }
  100. }
  101. /**
  102. * @return string
  103. */
  104. protected function getConfigFile () {
  105. return self::getWorkingDir() . "/" . $this->getName() . ".xml";
  106. }
  107. /**
  108. * @param string $description
  109. */
  110. public function setDescription($description)
  111. {
  112. $this->description = $description;
  113. return $this;
  114. }
  115. /**
  116. * @return string
  117. */
  118. public function getDescription()
  119. {
  120. return $this->description;
  121. }
  122. /**
  123. * @param string $name
  124. */
  125. public function setName($name)
  126. {
  127. $this->name = $name;
  128. return $this;
  129. }
  130. /**
  131. * @return string
  132. */
  133. public function getName()
  134. {
  135. return $this->name;
  136. }
  137. /**
  138. * @param string $url
  139. */
  140. public function setUrl($url)
  141. {
  142. $this->url = $url;
  143. return $this;
  144. }
  145. /**
  146. * @return string
  147. */
  148. public function getUrl()
  149. {
  150. return $this->url;
  151. }
  152. /**
  153. * @param string $backgroundColor
  154. */
  155. public function setBackgroundColor($backgroundColor)
  156. {
  157. $this->backgroundColor = $backgroundColor;
  158. return $this;
  159. }
  160. /**
  161. * @return string
  162. */
  163. public function getBackgroundColor()
  164. {
  165. return $this->backgroundColor;
  166. }
  167. /**
  168. * @param $foreColor
  169. */
  170. public function setForeColor($foreColor)
  171. {
  172. $this->foreColor = $foreColor;
  173. return $this;
  174. }
  175. /**
  176. * @return
  177. */
  178. public function getForeColor()
  179. {
  180. return $this->foreColor;
  181. }
  182. /**
  183. * @param boolean $googleAnalytics
  184. */
  185. public function setGoogleAnalytics($googleAnalytics)
  186. {
  187. $this->googleAnalytics = (bool) $googleAnalytics;
  188. return $this;
  189. }
  190. /**
  191. * @return boolean
  192. */
  193. public function getGoogleAnalytics()
  194. {
  195. return $this->googleAnalytics;
  196. }
  197. }