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_Tag - DOC block update #746

Merged
merged 1 commit into from
May 7, 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
21 changes: 19 additions & 2 deletions app/code/core/Mage/Tag/Block/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@

class Mage_Tag_Block_All extends Mage_Core_Block_Template
{

protected $_tags;
protected $_minPopularity;
protected $_maxPopularity;

/**
* @return $this
* @throws Mage_Core_Model_Store_Exception
*/
protected function _loadTags()
{
if (empty($this->_tags)) {
Expand All @@ -49,14 +52,15 @@ protected function _loadTags()
->load()
->getItems();

if( count($tags) == 0 ) {
if (count($tags) == 0) {
return $this;
}

$this->_maxPopularity = reset($tags)->getPopularity();
$this->_minPopularity = end($tags)->getPopularity();
$range = $this->_maxPopularity - $this->_minPopularity;
$range = ( $range == 0 ) ? 1 : $range;
/** @var Mage_Tag_Model_Tag $tag */
foreach ($tags as $tag) {
$tag->setRatio(($tag->getPopularity()-$this->_minPopularity)/$range);
$this->_tags[$tag->getName()] = $tag;
Expand All @@ -66,22 +70,35 @@ protected function _loadTags()
return $this;
}

/**
* @return Mage_Tag_Model_Tag[]
* @throws Mage_Core_Model_Store_Exception
*/
public function getTags()
{
$this->_loadTags();
return $this->_tags;
}

/**
* @return int
*/
public function getMaxPopularity()
{
return $this->_maxPopularity;
}

/**
* @return int
*/
public function getMinPopularity()
{
return $this->_minPopularity;
}

/**
* @return string
*/
protected function _getHeadText()
{
return Mage::helper('tag')->__('All Tags');
Expand Down
11 changes: 10 additions & 1 deletion app/code/core/Mage/Tag/Block/Customer/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,29 @@ class Mage_Tag_Block_Customer_Edit extends Mage_Core_Block_Template
{
protected $_tag;

/**
* @return Mage_Tag_Model_Tag_Relation
*/
public function getTag()
{
if( !$this->_tag ) {
if (!$this->_tag) {
$this->_tag = Mage::registry('tagModel');
}

return $this->_tag;
}

/**
* @return string
*/
public function getFormAction()
{
return $this->getUrl('*/*/save', array('tagId' => $this->getTag()->getTagId()));
}

/**
* @return string
*/
public function getBackUrl()
{
return $this->getUrl('*/*/view', array('tagId' => $this->getTag()->getTagId()));
Expand Down
23 changes: 22 additions & 1 deletion app/code/core/Mage/Tag/Block/Customer/Recent.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@

class Mage_Tag_Block_Customer_Recent extends Mage_Core_Block_Template
{
/**
* @var Mage_Tag_Model_Resource_Product_Collection
*/
protected $_collection;

protected function _construct()
Expand All @@ -54,37 +57,55 @@ protected function _construct()
->addVisibleInSiteFilterToCollection($this->_collection);
}

/**
* @return int
*/
public function count()
{
return $this->_collection->getSize();
}

/**
* @return Mage_Tag_Model_Resource_Product_Collection
*/
protected function _getCollection()
{
return $this->_collection;
}

/**
* @return Mage_Tag_Model_Resource_Product_Collection
*/
public function getCollection()
{
return $this->_getCollection();
}

/**
* @param string $date
* @return string
*/
public function dateFormat($date)
{
return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);
}

/**
* @return string
*/
public function getAllTagsUrl()
{
return Mage::getUrl('tag/customer');
}

/**
* @return string
*/
protected function _toHtml()
{
if ($this->_collection->getSize() > 0) {
return parent::_toHtml();
}
return '';
}

}
12 changes: 11 additions & 1 deletion app/code/core/Mage/Tag/Block/Customer/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ protected function _loadTags()
return;
}

if( isset($tags) && count($tags) == 0 ) {
if (isset($tags) && count($tags) == 0) {
return;
}

Expand All @@ -63,24 +63,34 @@ protected function _loadTags()
$range = $this->_maxPopularity - $this->_minPopularity;
$range = ( $range == 0 ) ? 1 : $range;

/** @var Mage_Tag_Model_Tag $tag */
foreach ($tags as $tag) {
$tag->setRatio(($tag->getPopularity()-$this->_minPopularity)/$range);
$this->_tags[$tag->getName()] = $tag;
}
ksort($this->_tags);
}

/**
* @return Mage_Tag_Model_Tag[]
*/
public function getTags()
{
$this->_loadTags();
return $this->_tags;
}

/**
* @return int
*/
public function getMaxPopularity()
{
return $this->_maxPopularity;
}

/**
* @return int
*/
public function getMinPopularity()
{
return $this->_minPopularity;
Expand Down
5 changes: 4 additions & 1 deletion app/code/core/Mage/Tag/Block/Customer/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
* @category Mage
* @package Mage_Tag
* @author Magento Core Team <core@magentocommerce.com>
*
* @method int getTagId()
* @method $this setTagId(int $value)
*/
class Mage_Tag_Block_Customer_View extends Mage_Catalog_Block_Product_Abstract
{
Expand Down Expand Up @@ -106,7 +109,7 @@ public function getReviewUrl($productId)
/**
* Preparing block layout
*
* @return $this
* @inheritDoc
*/
protected function _prepareLayout()
{
Expand Down
24 changes: 21 additions & 3 deletions app/code/core/Mage/Tag/Block/Popular.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@

class Mage_Tag_Block_Popular extends Mage_Core_Block_Template
{

protected $_tags;
protected $_minPopularity;
protected $_maxPopularity;

/**
* @return $this
* @throws Mage_Core_Model_Store_Exception
*/
protected function _loadTags()
{
if (empty($this->_tags)) {
Expand All @@ -50,15 +53,16 @@ protected function _loadTags()
->load()
->getItems();

if( count($tags) == 0 ) {
if (count($tags) == 0) {
return $this;
}


$this->_maxPopularity = reset($tags)->getPopularity();
$this->_minPopularity = end($tags)->getPopularity();
$range = $this->_maxPopularity - $this->_minPopularity;
$range = ($range == 0) ? 1 : $range;

/** @var Mage_Tag_Model_Tag $tag */
foreach ($tags as $tag) {
$tag->setRatio(($tag->getPopularity()-$this->_minPopularity)/$range);
$this->_tags[$tag->getName()] = $tag;
Expand All @@ -68,22 +72,36 @@ protected function _loadTags()
return $this;
}

/**
* @return Mage_Tag_Model_Tag[]
* @throws Mage_Core_Model_Store_Exception
*/
public function getTags()
{
$this->_loadTags();
return $this->_tags;
}

/**
* @return int
*/
public function getMaxPopularity()
{
return $this->_maxPopularity;
}

/**
* @return int
*/
public function getMinPopularity()
{
return $this->_minPopularity;
}

/**
* @return string
* @throws Mage_Core_Model_Store_Exception
*/
protected function _toHtml()
{
if (count($this->getTags()) > 0) {
Expand Down
32 changes: 28 additions & 4 deletions app/code/core/Mage/Tag/Block/Product/List.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,27 @@ class Mage_Tag_Block_Product_List extends Mage_Core_Block_Template
*/
protected $_uniqueHtmlId = null;

/**
* @return int
* @throws Mage_Core_Model_Store_Exception
*/
public function getCount()
{
return count($this->getTags());
}

/**
* @return mixed
* @throws Mage_Core_Model_Store_Exception
*/
public function getTags()
{
return $this->_getCollection()->getItems();
}

/**
* @return bool
*/
public function getProductId()
{
if ($product = Mage::registry('current_product')) {
Expand All @@ -53,10 +64,13 @@ public function getProductId()
return false;
}

/**
* @return mixed
* @throws Mage_Core_Model_Store_Exception
*/
protected function _getCollection()
{
if( !$this->_collection && $this->getProductId() ) {

if (!$this->_collection && $this->getProductId()) {
$model = Mage::getModel('tag/tag');
$this->_collection = $model->getResourceCollection()
->addPopularity()
Expand All @@ -70,6 +84,9 @@ protected function _getCollection()
return $this->_collection;
}

/**
* @inheritDoc
*/
protected function _beforeToHtml()
{
if (!$this->getProductId()) {
Expand All @@ -79,6 +96,9 @@ protected function _beforeToHtml()
return parent::_beforeToHtml();
}

/**
* @return string
*/
public function getFormAction()
{
return Mage::getUrl('tag/index/save', array(
Expand All @@ -94,13 +114,17 @@ public function getFormAction()
* @param string $pattern
* @param string $glue
* @return string
* @throws Mage_Core_Model_Store_Exception
*/
public function renderTags($pattern, $glue = ' ')
{
$out = array();
foreach ($this->getTags() as $tag) {
$out[] = sprintf($pattern,
$tag->getTaggedProductsUrl(), $this->escapeHtml($tag->getName()), $tag->getProducts()
$out[] = sprintf(
$pattern,
$tag->getTaggedProductsUrl(),
$this->escapeHtml($tag->getName()),
$tag->getProducts()
);
}
return implode($out, $glue);
Expand Down
Loading