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

/app/code/core/Mage/XmlConnect/Block/Adminhtml/Mobile/Edit/Tab/Social.php

https://bitbucket.org/sevenly/magento-ce
PHP | 330 lines | 216 code | 33 blank | 81 comment | 13 complexity | e731b66a9685a8019874af3487cb218e MD5 | raw file
  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) 2012 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. * Tab for Social Networking settings
  28. *
  29. * @category Mage
  30. * @package Mage_XmlConnect
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_XmlConnect_Block_Adminhtml_Mobile_Edit_Tab_Social
  34. extends Mage_XmlConnect_Block_Adminhtml_Mobile_Widget_Form
  35. implements Mage_Adminhtml_Block_Widget_Tab_Interface
  36. {
  37. /**
  38. * Prepare form before rendering HTML
  39. * Setting Form Fieldsets and fields
  40. *
  41. * @return Mage_Adminhtml_Block_Widget_Form
  42. */
  43. protected function _prepareForm()
  44. {
  45. $form = new Varien_Data_Form();
  46. $this->setForm($form);
  47. $data = Mage::helper('xmlconnect')->getApplication()->getFormData();
  48. $yesNoValues = Mage::getModel('adminhtml/system_config_source_yesno')->toOptionArray();
  49. /**
  50. * Default values for social networks is DISABLED
  51. */
  52. $twitterStatus = $facebookStatus = $linkedinStatus = 0;
  53. $noteText = $this->__('Please <a href="%s" target="_blank">click here</a> to see how to setup and retrieve API credentials.');
  54. /**
  55. * Twitter fieldset options
  56. */
  57. $fieldsetTwitter = $form->addFieldset('twitter', array(
  58. 'legend' => $this->__('Twitter API')
  59. ));
  60. if (isset($data['conf[native][socialNetworking][twitter][isActive]'])) {
  61. $twitterStatus = (int)$data['conf[native][socialNetworking][twitter][isActive]'];
  62. }
  63. $twitterActiveField = $fieldsetTwitter->addField(
  64. 'conf/native/socialNetworking/twitter/isActive',
  65. 'select',
  66. array(
  67. 'label' => $this->__('Enable Twitter'),
  68. 'name' => 'conf[native][socialNetworking][twitter][isActive]',
  69. 'values' => $yesNoValues,
  70. 'value' => $twitterStatus,
  71. )
  72. );
  73. if (isset($data['conf[native][socialNetworking][twitter][apiKey]'])) {
  74. $twitterApiKey = $data['conf[native][socialNetworking][twitter][apiKey]'];
  75. } else {
  76. $twitterApiKey = '';
  77. }
  78. $twitterApiKeyField = $fieldsetTwitter->addField(
  79. 'conf/native/socialNetworking/twitter/apiKey',
  80. 'text',
  81. array(
  82. 'label' => $this->__('Twitter API Key'),
  83. 'name' => 'conf[native][socialNetworking][twitter][apiKey]',
  84. 'required' => true,
  85. 'value' => $twitterApiKey
  86. )
  87. );
  88. if (isset($data['conf[native][socialNetworking][twitter][secretKey]'])) {
  89. $twitterSecretKey = $data['conf[native][socialNetworking][twitter][secretKey]'];
  90. } else {
  91. $twitterSecretKey = '';
  92. }
  93. $twitterSecretKeyField = $fieldsetTwitter->addField(
  94. 'conf/native/socialNetworking/twitter/secretKey',
  95. 'text',
  96. array(
  97. 'label' => $this->__('Twitter Secret Key'),
  98. 'name' => 'conf[native][socialNetworking][twitter][secretKey]',
  99. 'required' => true,
  100. 'value' => $twitterSecretKey
  101. )
  102. );
  103. $fieldsetTwitter->addField(
  104. 'twitterNote',
  105. 'note',
  106. array(
  107. 'text' => sprintf(
  108. $noteText,
  109. Mage::getStoreConfig(Mage_XmlConnect_Model_Application::XML_PATH_HOWTO_TWITTER_URL)
  110. ),
  111. )
  112. );
  113. /**
  114. * Facebook fieldset options
  115. */
  116. $fieldsetFacebook = $form->addFieldset('facebook', array(
  117. 'legend' => $this->__('Facebook API'),
  118. ));
  119. if (isset($data['conf[native][socialNetworking][facebook][isActive]'])) {
  120. $facebookStatus = (int)$data['conf[native][socialNetworking][facebook][isActive]'];
  121. }
  122. $facebookActiveField = $fieldsetFacebook->addField(
  123. 'conf/native/socialNetworking/facebook/isActive',
  124. 'select',
  125. array(
  126. 'label' => $this->__('Enable Facebook'),
  127. 'name' => 'conf[native][socialNetworking][facebook][isActive]',
  128. 'values' => $yesNoValues,
  129. 'value' => $facebookStatus,
  130. )
  131. );
  132. if (isset($data['conf[native][socialNetworking][facebook][appID]'])) {
  133. $facebookAppID = $data['conf[native][socialNetworking][facebook][appID]'];
  134. } else {
  135. $facebookAppID = '';
  136. }
  137. $facebookAppIDField = $fieldsetFacebook->addField(
  138. 'conf/native/socialNetworking/facebook/appID',
  139. 'text',
  140. array(
  141. 'label' => $this->__('Facebook Application ID'),
  142. 'name' => 'conf[native][socialNetworking][facebook][appID]',
  143. 'required' => true,
  144. 'value' => $facebookAppID
  145. )
  146. );
  147. $fieldsetFacebook->addField(
  148. 'facebookNote',
  149. 'note',
  150. array(
  151. 'text' => sprintf(
  152. $noteText,
  153. Mage::getStoreConfig(Mage_XmlConnect_Model_Application::XML_PATH_HOWTO_FACEBOOK_URL)
  154. ),
  155. )
  156. );
  157. /**
  158. * LinkedIn fieldset options
  159. */
  160. $fieldsetLinkedin = $form->addFieldset('linkedin', array(
  161. 'legend' => $this->__('LinkedIn API'),
  162. ));
  163. if (isset($data['conf[native][socialNetworking][linkedin][isActive]'])) {
  164. $linkedinStatus = (int)$data['conf[native][socialNetworking][linkedin][isActive]'];
  165. }
  166. $linkedinActiveField = $fieldsetLinkedin->addField(
  167. 'conf/native/socialNetworking/linkedin/isActive',
  168. 'select',
  169. array(
  170. 'label' => $this->__('Enable LinkedIn'),
  171. 'name' => 'conf[native][socialNetworking][linkedin][isActive]',
  172. 'values' => $yesNoValues,
  173. 'value' => $linkedinStatus,
  174. )
  175. );
  176. if (isset($data['conf[native][socialNetworking][linkedin][apiKey]'])) {
  177. $linkedinApiKey = $data['conf[native][socialNetworking][linkedin][apiKey]'];
  178. } else {
  179. $linkedinApiKey = '';
  180. }
  181. $linkedinApiKeyField = $fieldsetLinkedin->addField(
  182. 'conf/native/socialNetworking/linkedin/apiKey',
  183. 'text',
  184. array(
  185. 'label' => $this->__('LinkedIn API Key'),
  186. 'name' => 'conf[native][socialNetworking][linkedin][apiKey]',
  187. 'required' => true,
  188. 'value' => $linkedinApiKey
  189. )
  190. );
  191. if (isset($data['conf[native][socialNetworking][linkedin][secretKey]'])) {
  192. $linkedinSecretKey = $data['conf[native][socialNetworking][linkedin][secretKey]'];
  193. } else {
  194. $linkedinSecretKey = '';
  195. }
  196. $linkedinSecretKeyField = $fieldsetLinkedin->addField(
  197. 'conf/native/socialNetworking/linkedin/secretKey',
  198. 'text',
  199. array(
  200. 'label' => $this->__('LinkedIn Secret Key'),
  201. 'name' => 'conf[native][socialNetworking][linkedin][secretKey]',
  202. 'required' => true,
  203. 'value' => $linkedinSecretKey
  204. )
  205. );
  206. $fieldsetLinkedin->addField(
  207. 'linkedinNote',
  208. 'note',
  209. array(
  210. 'text' => sprintf(
  211. $noteText,
  212. Mage::getStoreConfig(Mage_XmlConnect_Model_Application::XML_PATH_HOWTO_LINKEDIN_URL)
  213. ),
  214. )
  215. );
  216. /**
  217. * Set field dependencies
  218. */
  219. $this->setChild('form_after', $this->getLayout()
  220. ->createBlock('adminhtml/widget_form_element_dependence')
  221. /**
  222. * Facebook field dependencies
  223. */
  224. ->addFieldMap($facebookActiveField->getHtmlId(), $facebookActiveField->getName())
  225. ->addFieldMap($facebookAppIDField->getHtmlId(), $facebookAppIDField->getName())
  226. ->addFieldDependence(
  227. $facebookAppIDField->getName(),
  228. $facebookActiveField->getName(),
  229. 1)
  230. /**
  231. * Twitter field dependencies
  232. */
  233. ->addFieldMap($twitterApiKeyField->getHtmlId(), $twitterApiKeyField->getName())
  234. ->addFieldMap($twitterActiveField->getHtmlId(), $twitterActiveField->getName())
  235. ->addFieldMap($twitterSecretKeyField->getHtmlId(), $twitterSecretKeyField->getName())
  236. ->addFieldDependence(
  237. $twitterApiKeyField->getName(),
  238. $twitterActiveField->getName(),
  239. 1)
  240. ->addFieldDependence(
  241. $twitterSecretKeyField->getName(),
  242. $twitterActiveField->getName(),
  243. 1)
  244. /**
  245. * LinkedIn field dependencies
  246. */
  247. ->addFieldMap($linkedinApiKeyField->getHtmlId(), $linkedinApiKeyField->getName())
  248. ->addFieldMap($linkedinActiveField->getHtmlId(), $linkedinActiveField->getName())
  249. ->addFieldMap($linkedinSecretKeyField->getHtmlId(), $linkedinSecretKeyField->getName())
  250. ->addFieldDependence(
  251. $linkedinApiKeyField->getName(),
  252. $linkedinActiveField->getName(),
  253. 1)
  254. ->addFieldDependence(
  255. $linkedinSecretKeyField->getName(),
  256. $linkedinActiveField->getName(),
  257. 1)
  258. );
  259. return parent::_prepareForm();
  260. }
  261. /**
  262. * Tab label getter
  263. *
  264. * @return string
  265. */
  266. public function getTabLabel()
  267. {
  268. return $this->__('Social Networking');
  269. }
  270. /**
  271. * Tab title getter
  272. *
  273. * @return string
  274. */
  275. public function getTabTitle()
  276. {
  277. return $this->__('Social Networking');
  278. }
  279. /**
  280. * Check if tab can be shown
  281. *
  282. * @return bool
  283. */
  284. public function canShowTab()
  285. {
  286. return (bool) !Mage::getSingleton('adminhtml/session')->getNewApplication();
  287. }
  288. /**
  289. * Check if tab hidden
  290. *
  291. * @return bool
  292. */
  293. public function isHidden()
  294. {
  295. return false;
  296. }
  297. }