Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mage_Poll - DOC block update #758

Merged
merged 3 commits into from
Jul 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions app/code/core/Mage/Poll/Block/ActivePoll.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function setPollId($pollId)
/**
* Get current Poll Id
*
* @return int|null
* @return int
*/
public function getPollId()
{
Expand Down Expand Up @@ -144,7 +144,7 @@ public function getPollToShow()
* Get Poll related data
*
* @param int $pollId
* @return array|bool
* @return array|false
*/
public function getPollData($pollId)
{
Expand All @@ -162,6 +162,10 @@ public function getPollData($pollId)
// correct rounded percents to be always equal 100
$percentsSorted = array();
$answersArr = array();
/**
* @var int $key
* @var Mage_Poll_Model_Poll_Answer $answer
*/
foreach ($pollAnswers as $key => $answer) {
$percentsSorted[$key] = $answer->getPercent();
$answersArr[$key] = $answer;
Expand Down Expand Up @@ -204,7 +208,7 @@ public function setPollTemplate($template, $type)
*/
protected function _toHtml()
{
/** @var $coreSessionModel Mage_Core_Model_Session */
/** @var Mage_Core_Model_Session $coreSessionModel */
$coreSessionModel = Mage::getSingleton('core/session');
$justVotedPollId = $coreSessionModel->getJustVotedPoll();
if ($justVotedPollId && !$this->_pollModel->isVoted($justVotedPollId)) {
Expand Down Expand Up @@ -242,5 +246,4 @@ public function getCacheKeyInfo()

return $items;
}

}
81 changes: 57 additions & 24 deletions app/code/core/Mage/Poll/Model/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,28 @@
*
* @method Mage_Poll_Model_Resource_Poll _getResource()
* @method Mage_Poll_Model_Resource_Poll getResource()
* @method string getPollTitle()
* @method Mage_Poll_Model_Poll setPollTitle(string $value)
* @method Mage_Poll_Model_Poll setVotesCount(int $value)
* @method int getStoreId()
* @method Mage_Poll_Model_Poll setStoreId(int $value)
* @method string getDatePosted()
* @method Mage_Poll_Model_Poll setDatePosted(string $value)
* @method string getDateClosed()
* @method Mage_Poll_Model_Poll setDateClosed(string $value)
* @method Mage_Poll_Model_Resource_Poll_Collection getCollection()
*
* @method int getActive()
* @method Mage_Poll_Model_Poll setActive(int $value)
* @method int getClosed()
* @method Mage_Poll_Model_Poll setClosed(int $value)
* @method $this setActive(int $value)
* @method int getAnswersDisplay()
* @method Mage_Poll_Model_Poll setAnswersDisplay(int $value)
* @method $this setAnswersDisplay(int $value)
* @method int getClosed()
* @method $this setClosed(int $value)
* @method string getDateClosed()
* @method $this setDateClosed(string $value)
* @method string getDatePosted()
* @method $this setDatePosted(string $value)
* @method array getExcludeFilter()
* @method $this setExcludeFilter(array $value)
* @method string getPollTitle()
* @method $this setPollTitle(string $value)
* @method int getStoreId()
* @method $this setStoreId(int $value)
* @method $this setStoreIds(array $value)
* @method int getStoreFilter()
* @method $this setStoreFilter(int $value)
* @method $this setVotesCount(int $value)
*
* @category Mage
* @package Mage_Poll
Expand All @@ -55,6 +62,10 @@ class Mage_Poll_Model_Poll extends Mage_Core_Model_Abstract
const XML_PATH_POLL_CHECK_BY_IP = 'web/polls/poll_check_by_ip';

protected $_pollCookieDefaultName = 'poll';

/**
* @var Mage_Poll_Model_Poll_Answer[]
*/
protected $_answersCollection = array();
protected $_storeCollection = array();

Expand Down Expand Up @@ -99,8 +110,8 @@ public function getPoolId($pollId = null)
/**
* Retrieve defined or current Id
*
* @param int|null $pollId
* @return int
* @param string $pollId
* @return string
*/
public function getPollId($pollId = null)
{
Expand All @@ -124,9 +135,9 @@ public function isValidationByIp()
* Declare poll as voted
*
* @param int $pollId
* @return Mage_Poll_Model_Poll
* @return $this
*/
public function setVoted($pollId=null)
public function setVoted($pollId = null)
{
$this->getCookie()->set($this->getCookieName($pollId), $this->getPollId($pollId));

Expand Down Expand Up @@ -160,7 +171,7 @@ public function isVoted($pollId = null)
/**
* Get random active pool identifier
*
* @return int
* @return string
*/
public function getRandomId()
{
Expand All @@ -180,7 +191,9 @@ public function getAllIds()
/**
* Add vote to poll
*
* @return unknown
* @param Mage_Poll_Model_Poll_Vote $vote
* @return $this
* @throws Exception
*/
public function addVote(Mage_Poll_Model_Poll_Vote $vote)
{
Expand All @@ -196,15 +209,14 @@ public function addVote(Mage_Poll_Model_Poll_Vote $vote)
* Check answer existing for poll
*
* @param mixed $answer
* @return boll
* @return bool
*/
public function hasAnswer($answer)
{
$answerId = false;
if (is_numeric($answer)) {
$answerId = $answer;
}
elseif ($answer instanceof Mage_Poll_Model_Poll_Answer) {
} elseif ($answer instanceof Mage_Poll_Model_Poll_Answer) {
$answerId = $answer->getId();
}

Expand All @@ -214,13 +226,18 @@ public function hasAnswer($answer)
return false;
}

/**
* @return $this
*/
public function resetVotesCount()
{
$this->_getResource()->resetVotesCount($this);
return $this;
}


/**
* @return array
*/
public function getVotedPollsIds()
{
$idsArray = array();
Expand All @@ -243,17 +260,28 @@ public function getVotedPollsIds()
return $idsArray;
}

/**
* @param Mage_Poll_Model_Poll_Answer $object
* @return $this
*/
public function addAnswer($object)
{
$this->_answersCollection[] = $object;
return $this;
}

/**
* @return Mage_Poll_Model_Poll_Answer[]
*/
public function getAnswers()
{
return $this->_answersCollection;
}

/**
* @param int $storeId
* @return $this
*/
public function addStoreId($storeId)
{
$ids = $this->getStoreIds();
Expand All @@ -264,6 +292,9 @@ public function addStoreId($storeId)
return $this;
}

/**
* @return array
*/
public function getStoreIds()
{
$ids = $this->_getData('store_ids');
Expand All @@ -279,9 +310,11 @@ public function loadStoreIds()
$this->_getResource()->loadStoreIds($this);
}

/**
* @return int
*/
public function getVotesCount()
{
return $this->_getData('votes_count');
}

}
21 changes: 15 additions & 6 deletions app/code/core/Mage/Poll/Model/Poll/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,19 @@
*
* @method Mage_Poll_Model_Resource_Poll_Answer _getResource()
* @method Mage_Poll_Model_Resource_Poll_Answer getResource()
* @method int getPollId()
* @method Mage_Poll_Model_Poll_Answer setPollId(int $value)
* @method Mage_Poll_Model_Resource_Poll_Answer_Collection getCollection()
* @method Mage_Poll_Model_Resource_Poll_Answer_Collection getResourceCollection()
*
* @method int getAnswerOrder()
* @method $this setAnswerOrder(int $value)
* @method string getAnswerTitle()
* @method Mage_Poll_Model_Poll_Answer setAnswerTitle(string $value)
* @method $this setAnswerTitle(string $value)
* @method float getPercent()
* @method $this setPercent(float $round)
* @method int getPollId()
* @method $this setPollId(int $value)
* @method int getVotesCount()
* @method Mage_Poll_Model_Poll_Answer setVotesCount(int $value)
* @method int getAnswerOrder()
* @method Mage_Poll_Model_Poll_Answer setAnswerOrder(int $value)
* @method $this setVotesCount(int $value)
*
* @category Mage
* @package Mage_Poll
Expand All @@ -50,6 +55,10 @@ protected function _construct()
$this->_init('poll/poll_answer');
}

/**
* @param Mage_Poll_Model_Poll $poll
* @return $this
*/
public function countPercent($poll)
{
$this->setPercent(
Expand Down
11 changes: 6 additions & 5 deletions app/code/core/Mage/Poll/Model/Poll/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,17 @@
*
* @method Mage_Poll_Model_Resource_Poll_Vote _getResource()
* @method Mage_Poll_Model_Resource_Poll_Vote getResource()
*
* @method int getPollId()
* @method Mage_Poll_Model_Poll_Vote setPollId(int $value)
* @method $this setPollId(int $value)
* @method int getPollAnswerId()
* @method Mage_Poll_Model_Poll_Vote setPollAnswerId(int $value)
* @method $this setPollAnswerId(int $value)
* @method int getIpAddress()
* @method Mage_Poll_Model_Poll_Vote setIpAddress(int $value)
* @method $this setIpAddress(int $value)
* @method int getCustomerId()
* @method Mage_Poll_Model_Poll_Vote setCustomerId(int $value)
* @method $this setCustomerId(int $value)
* @method string getVoteTime()
* @method Mage_Poll_Model_Poll_Vote setVoteTime(string $value)
* @method $this setVoteTime(string $value)
*
* @category Mage
* @package Mage_Poll
Expand Down
6 changes: 3 additions & 3 deletions app/code/core/Mage/Poll/Model/Resource/Poll.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function _initUniqueFields()
* Get select object for not closed poll ids
*
* @param Mage_Poll_Model_Poll $object
* @return
* @return Varien_Db_Select
*/
protected function _getSelectIds($object)
{
Expand Down Expand Up @@ -134,7 +134,7 @@ public function checkAnswerId($poll, $answerId)
* If poll id is not empty, it will look only for records with specified value
*
* @param string $ipAddress
* @param int $pollId
* @param int|false $pollId
* @return array
*/
public function getVotedPollIdsByIp($ipAddress, $pollId = false)
Expand Down Expand Up @@ -198,7 +198,7 @@ public function loadStoreIds(Mage_Poll_Model_Poll $object)
* Delete current poll from the table poll_store and then
* insert to update "poll to store" relations
*
* @param Mage_Core_Model_Abstract $object
* @param Mage_Core_Model_Abstract|Mage_Poll_Model_Poll $object
*/
public function _afterSave(Mage_Core_Model_Abstract $object)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
* @category Mage
* @package Mage_Poll
* @author Magento Core Team <core@magentocommerce.com>
*
* @method Mage_Poll_Model_Poll_Answer[] getItems()
*/
class Mage_Poll_Model_Resource_Poll_Answer_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
Expand Down
3 changes: 3 additions & 0 deletions app/code/core/Mage/Poll/Model/Resource/Poll/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* @category Mage
* @package Mage_Poll
* @author Magento Core Team <core@magentocommerce.com>
*
* @method int getId()
* @method $this setSelectStores(array $value)
*/
class Mage_Poll_Model_Resource_Poll_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Poll/Model/Resource/Poll/Vote.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected function _construct()
/**
* Perform actions after object save
*
* @param Varien_Object $object
* @param Mage_Core_Model_Abstract|Mage_Poll_Model_Poll_Vote $object
* @return $this
*/
protected function _afterSave(Mage_Core_Model_Abstract $object)
Expand Down
2 changes: 1 addition & 1 deletion app/code/core/Mage/Poll/controllers/VoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function addAction()
$pollId = intval($this->getRequest()->getParam('poll_id'));
$answerId = intval($this->getRequest()->getParam('vote'));

/** @var $poll Mage_Poll_Model_Poll */
/** @var Mage_Poll_Model_Poll $poll */
$poll = Mage::getModel('poll/poll')->load($pollId);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/


/* @var $installer Mage_Core_Model_Resource_Setup */
/* @var Mage_Core_Model_Resource_Setup $installer */

$installer = $this;

Expand All @@ -42,7 +42,7 @@
array('Magenta', 2)
);

foreach( $answers as $key => $answer ) {
foreach ($answers as $key => $answer) {
$answerModel = Mage::getModel('poll/poll_answer');
$answerModel->setAnswerTitle($answer[0])
->setVotesCount($answer[1]);
Expand All @@ -51,4 +51,3 @@
}

$pollModel->save();

Loading