Mage_Poll_Model_Poll Class Reference

Inheritance diagram for Mage_Poll_Model_Poll:

Mage_Core_Model_Abstract Varien_Object

List of all members.

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()


Detailed Description

Poll model

Author:
Magento Core Team <core@magentocommerce.com>

Definition at line 33 of file Poll.php.


Member Function Documentation

_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  ) 

Definition at line 204 of file Poll.php.

00205     {
00206         $this->_answersCollection[] = $object;
00207         return $this;
00208     }

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  ) 

Add vote to poll

Returns:
unknown

Definition at line 143 of file Poll.php.

00144     {
00145         if ($this->hasAnswer($vote->getPollAnswerId())) {
00146             $vote->setPollId($this->getId())
00147                 ->save();
00148             $this->setVoted();
00149         }
00150         return $this;
00151     }

getAnswers (  ) 

Definition at line 210 of file Poll.php.

00211     {
00212         return $this->_answersCollection;
00213     }

getCookie (  ) 

Retrieve Cookie Object

Returns:
Mage_Core_Model_Cookie

Definition at line 51 of file Poll.php.

00052     {
00053         return Mage::app()->getCookie();
00054     }

getCookieName ( pollId = null  ) 

Get Cookie Name

Parameters:
int $pollId
Returns:
string

Definition at line 62 of file Poll.php.

00063     {
00064         return $this->_pollCookieDefaultName . $this->getPoolId($pollId);
00065     }

getPoolId ( pollId = null  ) 

Retrieve defined or current Id

Parameters:
int $pollId
Returns:
int

Definition at line 73 of file Poll.php.

00074     {
00075         if (is_null($pollId)) {
00076             $pollId = $this->getId();
00077         }
00078         return $pollId;
00079     }

getRandomId (  ) 

Get random active pool identifier

Returns:
int

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 (  ) 

Definition at line 240 of file Poll.php.

00241     {
00242         return $this->_getData('votes_count');
00243     }

hasAnswer ( answer  ) 

Check answer existing for poll

Parameters:
mixed $answer
Returns:
boll

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

Returns:
bool

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

Parameters:
int $pollId
Returns:
bool

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

Parameters:
int $pollId
Returns:
Mage_Poll_Model_Poll

Definition at line 97 of file Poll.php.

00098     {
00099         $this->getCookie()->set($this->getCookieName($pollId), $this->getPoolId($pollId));
00100 
00101         return $this;
00102     }


Member Data Documentation

$_answersCollection = array() [protected]

Definition at line 38 of file Poll.php.

$_pollCookieDefaultName = 'poll' [protected]

Definition at line 37 of file Poll.php.

$_storeCollection = array() [protected]

Definition at line 39 of file Poll.php.

const XML_PATH_POLL_CHECK_BY_IP = 'web/polls/poll_check_by_ip'

Definition at line 35 of file Poll.php.


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:34 2009 for Magento by  doxygen 1.5.8