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_AdminNotification
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:
28: /**
29: * AdminNotification survey model
30: *
31: * @category Mage
32: * @package Mage_AdminNotification
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_AdminNotification_Model_Survey
36: {
37: protected static $_flagCode = 'admin_notification_survey';
38: protected static $_flagModel = null;
39:
40: const SURVEY_URL = 'www.magentocommerce.com/instsurvey.html';
41:
42: /**
43: * Check if survey url valid (exists) or not
44: *
45: * @return boolen
46: */
47: public static function isSurveyUrlValid()
48: {
49: $curl = new Varien_Http_Adapter_Curl();
50: $curl->setConfig(array('timeout' => 5))
51: ->write(Zend_Http_Client::GET, self::getSurveyUrl(), '1.0');
52: $response = $curl->read();
53: $curl->close();
54:
55: if (Zend_Http_Response::extractCode($response) == 200) {
56: return true;
57: }
58: return false;
59: }
60:
61: /**
62: * Return survey url
63: *
64: * @return string
65: */
66: public static function getSurveyUrl()
67: {
68: $host = Mage::app()->getRequest()->isSecure() ? 'https://' : 'http://';
69: return $host . self::SURVEY_URL;
70: }
71:
72: /**
73: * Return core flag model
74: *
75: * @return Mage_Core_Model_Flag
76: */
77: protected static function _getFlagModel()
78: {
79: if (self::$_flagModel === null) {
80: self::$_flagModel = Mage::getModel('core/flag', array('flag_code' => self::$_flagCode))->loadSelf();
81: }
82: return self::$_flagModel;
83: }
84:
85: /**
86: * Check if survey question was already asked
87: * or survey url was viewed during installation process
88: *
89: * @return boolean
90: */
91: public static function isSurveyViewed()
92: {
93: $flagData = self::_getFlagModel()->getFlagData();
94: if (isset($flagData['survey_viewed']) && $flagData['survey_viewed'] == 1) {
95: return true;
96: }
97: return false;
98: }
99:
100: /**
101: * Save survey viewed flag in core flag
102: *
103: * @param boolean $viewed
104: */
105: public static function saveSurveyViewed($viewed)
106: {
107: $flagData = self::_getFlagModel()->getFlagData();
108: if (is_null($flagData)) {
109: $flagData = array();
110: }
111: $flagData = array_merge($flagData, array('survey_viewed' => (bool)$viewed));
112: self::_getFlagModel()->setFlagData($flagData)->save();
113: }
114: }
115: