Public Member Functions | |
getCookie () | |
getCookieName ($pollId=null) | |
getPoolId ($pollId=null) | |
isValidationByIp () | |
setVoted ($pollId=null) | |
isVoted ($pollId=null) | |
getRandomId () | |
addVote (Mage_Poll_Model_Poll_Vote $vote) | |
hasAnswer ($answer) | |
resetVotesCount () | |
getVotedPollsIds () | |
addAnswer ($object) | |
getAnswers () | |
addStoreId ($storeId) | |
getStoreIds () | |
loadStoreIds () | |
getVotesCount () | |
Public Attributes | |
const | XML_PATH_POLL_CHECK_BY_IP = 'web/polls/poll_check_by_ip' |
Protected Member Functions | |
_construct () | |
Protected Attributes | |
$_pollCookieDefaultName = 'poll' | |
$_answersCollection = array() | |
$_storeCollection = array() |
Definition at line 33 of file Poll.php.
_construct | ( | ) | [protected] |
Enter description here...
Reimplemented from Varien_Object.
Definition at line 41 of file Poll.php.
00042 { 00043 $this->_init('poll/poll'); 00044 }
addAnswer | ( | $ | object | ) |
addStoreId | ( | $ | storeId | ) |
Definition at line 215 of file Poll.php.
00216 { 00217 $ids = $this->getStoreIds(); 00218 if (!in_array($storeId, $ids)) { 00219 $ids[] = $storeId; 00220 } 00221 $this->setStoreIds($ids); 00222 return $this; 00223 }
addVote | ( | Mage_Poll_Model_Poll_Vote $ | vote | ) |
getAnswers | ( | ) |
getCookie | ( | ) |
Retrieve Cookie Object
Definition at line 51 of file Poll.php.
00052 { 00053 return Mage::app()->getCookie(); 00054 }
getCookieName | ( | $ | pollId = null |
) |
getPoolId | ( | $ | pollId = null |
) |
getRandomId | ( | ) |
Get random active pool identifier
Definition at line 133 of file Poll.php.
00134 { 00135 return $this->_getResource()->getRandomId($this); 00136 }
getStoreIds | ( | ) |
Definition at line 225 of file Poll.php.
00226 { 00227 $ids = $this->_getData('store_ids'); 00228 if (is_null($ids)) { 00229 $this->loadStoreIds(); 00230 $ids = $this->getData('store_ids'); 00231 } 00232 return $ids; 00233 }
getVotedPollsIds | ( | ) |
Definition at line 182 of file Poll.php.
00183 { 00184 $idsArray = array(); 00185 00186 foreach ($this->getCookie()->get() as $cookieName => $cookieValue) { 00187 $pattern = '#^' . preg_quote($this->_pollCookieDefaultName, '#') . '(\d+)$#'; 00188 $match = array(); 00189 if (preg_match($pattern, $cookieName, $match)) { 00190 if ($match[1] != Mage::getSingleton('core/session')->getJustVotedPoll()) { 00191 $idsArray[$match[1]] = $match[1]; 00192 } 00193 } 00194 } 00195 00196 // load from db for this ip 00197 foreach ($this->_getResource()->getVotedPollIdsByIp($_SERVER['REMOTE_ADDR']) as $pollId) { 00198 $idsArray[$pollId] = $pollId; 00199 } 00200 00201 return $idsArray; 00202 }
getVotesCount | ( | ) |
hasAnswer | ( | $ | answer | ) |
Check answer existing for poll
mixed | $answer |
Definition at line 159 of file Poll.php.
00160 { 00161 $answerId = false; 00162 if (is_numeric($answer)) { 00163 $answerId = $answer; 00164 } 00165 elseif ($answer instanceof Mage_Poll_Model_Poll_Answer) { 00166 $answerId = $answer->getId(); 00167 } 00168 00169 if ($answerId) { 00170 return $this->_getResource()->checkAnswerId($this, $answerId); 00171 } 00172 return false; 00173 }
isValidationByIp | ( | ) |
Check if validation by IP option is enabled in config
Definition at line 86 of file Poll.php.
00087 { 00088 return (1 == Mage::getStoreConfig(self::XML_PATH_POLL_CHECK_BY_IP)); 00089 }
isVoted | ( | $ | pollId = null |
) |
Check if poll is voted
int | $pollId |
Definition at line 110 of file Poll.php.
00111 { 00112 $pollId = $this->getPoolId($pollId); 00113 00114 // check if it is in cookie 00115 $cookie = $this->getCookie()->get($this->getCookieName($pollId)); 00116 if (false !== $cookie) { 00117 return true; 00118 } 00119 00120 // check by ip 00121 if (count($this->_getResource()->getVotedPollIdsByIp($_SERVER['REMOTE_ADDR'], $pollId))) { 00122 return true; 00123 } 00124 00125 return false; 00126 }
loadStoreIds | ( | ) |
Definition at line 235 of file Poll.php.
00236 { 00237 $this->_getResource()->loadStoreIds($this); 00238 }
resetVotesCount | ( | ) |
Definition at line 175 of file Poll.php.
00176 { 00177 $this->_getResource()->resetVotesCount($this); 00178 return $this; 00179 }
setVoted | ( | $ | pollId = null |
) |
Declare poll as voted
int | $pollId |
Definition at line 97 of file Poll.php.
00098 { 00099 $this->getCookie()->set($this->getCookieName($pollId), $this->getPoolId($pollId)); 00100 00101 return $this; 00102 }
const XML_PATH_POLL_CHECK_BY_IP = 'web/polls/poll_check_by_ip' |