PageRenderTime 46ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Form/Element/Country.php

https://bitbucket.org/claudiu_marginean/magento-hg-mirror
PHP | 169 lines | 91 code | 20 blank | 58 comment | 15 complexity | 2b36bb90635cbe764671eac6cc6ec0c6 MD5 | raw file
Possible License(s): CC-BY-SA-3.0, LGPL-2.1, GPL-2.0, WTFPL
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_XmlConnect
  23. * @copyright Copyright (c) 2010 Magento Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * XmlConnect Country selector form element
  28. *
  29. * @category Mage
  30. * @package Mage_XmlConnect
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_XmlConnect_Block_Adminhtml_Mobile_Form_Element_Country extends Varien_Data_Form_Element_Checkboxes
  34. {
  35. /**
  36. * Flag of using the border in the table's TD
  37. *
  38. * @var bool
  39. */
  40. protected $_useBorderClass = false;
  41. /**
  42. * Init Element
  43. *
  44. * @param array $attributes
  45. */
  46. public function __construct($attributes=array())
  47. {
  48. parent::__construct($attributes);
  49. $this->setType('checkbox');
  50. $this->setExtType('country');
  51. }
  52. /**
  53. * Retrieve HTML
  54. *
  55. * @return string
  56. */
  57. public function getElementHtml()
  58. {
  59. $values = $this->_prepareValues();
  60. if (empty($values)) {
  61. return '';
  62. }
  63. $columns = (int)$this->getData('columns');
  64. $columns = $columns ? $columns : 1;
  65. $rows = ceil(count($values) / $columns);
  66. $row = $column = 0;
  67. $options = array();
  68. foreach ($values as $value) {
  69. if (empty($value['value'])) {
  70. continue;
  71. }
  72. $options[$row++][$column] = $value;
  73. if ($row == $rows) {
  74. $row = 0;
  75. $column++;
  76. }
  77. }
  78. while ($row < $rows) {
  79. $options[$row++][$column] = '';
  80. }
  81. $id = $this->getData('id');
  82. $id = empty($id) ? '' : ' id="' . $id . '-table"';
  83. $class = $this->getData('class');
  84. $html = "\n<table class=\"countries {$class}\"{$id}>\n";
  85. $zebrine = '';
  86. $stripy = false;
  87. if (strpos($class, 'stripy')) {
  88. $stripy = true;
  89. }
  90. $columns--;
  91. foreach ($options as $row) {
  92. $html .= " <tr{$zebrine}>\n ";
  93. if ($stripy) {
  94. $zebrine = empty($zebrine) ? ' class="odd"' : '';
  95. $this->_useBorderClass = true;
  96. foreach ($row as $idx => $option) {
  97. /**
  98. * for istore (as shown by $stripy) use border settings in TD
  99. */
  100. if ($idx == $columns) {
  101. /**
  102. * for last table's column TD should not have a border
  103. */
  104. $this->_useBorderClass = false;
  105. }
  106. $html .= $this->_optionToHtml($option);
  107. }
  108. } else {
  109. foreach ($row as $option) {
  110. $html .= $this->_optionToHtml($option);
  111. }
  112. }
  113. $html .= "\n </tr>\n";
  114. }
  115. $html .= "</table>\n"
  116. . $this->getAfterElementHtml();
  117. return $html;
  118. }
  119. /**
  120. * Get HTML code for the one option
  121. *
  122. * @param array $option
  123. * @return string
  124. */
  125. protected function _optionToHtml($option)
  126. {
  127. if (empty($option)) {
  128. $html = '<td>&nbsp;</td><td>&nbsp;</td>';
  129. } else {
  130. $id = $this->getHtmlId() . '_' . $this->_escape($option['value']);
  131. $isNameLeft = $this->getData('place_name_left');
  132. $border = $this->_useBorderClass ? ' class="border"' : '';
  133. $html = '<td' . $border . '><input id="' . $id . '"';
  134. foreach ($this->getHtmlAttributes() as $attribute) {
  135. if ($value = $this->getDataUsingMethod($attribute, $option['value'])) {
  136. $html .= ' ' . $attribute . '="' . $value . '"';
  137. }
  138. }
  139. $html .= ' value="' . $option['value'] . '" /></td>';
  140. $label = '<td><label for="' . $id . '" style="white-space: nowrap;">' . $option['label'] . '</label></td>';
  141. if ($isNameLeft) {
  142. $html = $label . $html;
  143. } else {
  144. $html = $html . $label;
  145. }
  146. }
  147. return $html;
  148. }
  149. }