Skip to content

Commit

Permalink
Remove unused product reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
gauthierm committed Apr 16, 2018
1 parent cffca2c commit 41bd793
Show file tree
Hide file tree
Showing 29 changed files with 14 additions and 3,103 deletions.
4 changes: 0 additions & 4 deletions Store/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,6 @@ public static function init()
SwatDBClassMap::add('SiteArticleWrapper', 'StoreArticleWrapper');

SiteViewFactory::addPath('Store/views');
SiteViewFactory::registerView(
'product-review',
'StoreProductReviewView'
);

if (class_exists('Blorg')) {
SiteViewFactory::registerView(
Expand Down
5 changes: 2 additions & 3 deletions Store/StoreXMLRPCServerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ public function __construct(SiteApplication $app)
protected function getPageMap()
{
return array(
'product-reviews' => 'StoreProductReviewServer',
'search-panel' => 'StoreSearchPanelServer',
'cart' => 'StoreCartServer',
'search-panel' => 'StoreSearchPanelServer',
'cart' => 'StoreCartServer',
);
}

Expand Down
13 changes: 0 additions & 13 deletions Store/admin/components/Category/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,6 @@
<property name="content" translatable="yes">This will remove any items belonging to the checked products from a minimum quantity sale group.</property>
</widget>
</widget>
<widget class="SwatActionItemDivider" />
<widget class="SwatActionItem" id="categories_set_reviewable">
<property name="title" translatable="yes">allow reviews</property>
<widget class="SwatContentBlock">
<property name="content" translatable="yes">Applies to all products under the selected categories. To apply to individual products, use the product editor.</property>
</widget>
</widget>
<widget class="SwatActionItem" id="categories_unset_reviewable">
<property name="title" translatable="yes">disallow reviews</property>
<widget class="SwatContentBlock">
<property name="content" translatable="yes">This will disallow reviews on all products under the selected categories.</property>
</widget>
</widget>
</widget>
</widget>
</widget>
Expand Down
73 changes: 1 addition & 72 deletions Store/admin/components/Dashboard/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ protected function buildInternal()

protected function isNewContentFrameVisible()
{
return ($this->app->session->user->hasAccessByShortname('Order') ||
$this->app->session->user->hasAccessByShortname('ProductReview'));
return ($this->app->session->user->hasAccessByShortname('Order'));
}

// }}}
Expand Down Expand Up @@ -192,21 +191,6 @@ protected function buildNewContentData()
$this->ui->getWidget('view_all_orders')->visible = true;
$this->new_content_notes[] = Store::_('orders with comments');
}

if ($this->app->session->user->hasAccessByShortname('ProductReview')) {
$sql = 'select count(1) from
(select 1 from ProductReview limit 1) as t';

$has_product_reviews = (SwatDB::queryOne($this->app->db, $sql) > 0);
if ($has_product_reviews) {
$this->buildProductReviewsNewContentData();
$this->ui->getWidget('view_all_product_reviews')->visible =
true;

$this->new_content_notes[] =
Store::_('product reviews with less than ★★★★');
}
}
}

// }}}
Expand Down Expand Up @@ -260,34 +244,6 @@ protected function buildOrdersNewContentData()
}
}

// }}}
// {{{ protected function buildProductReviewsNewContentData()

protected function buildProductReviewsNewContentData()
{
$reviews = $this->getProductReviews();

foreach ($reviews as $review) {
$date = new SwatDate($review->createdate);

if ($review->status == StoreProductReview::STATUS_PENDING) {
$link = 'ProductReview/Approval?id='.$review->id;
} else {
$link = 'ProductReview/Edit?id='.$review->id;
}

$content = sprintf('<div><a href="%s">Product review by %s</a>
of <a href="Product/Details?id=%s">%s</a><p>%s</p></div>',
$link,
SwatString::minimizeEntities($review->fullname),
$review->product->id,
SwatString::minimizeEntities($review->product->title),
SwatString::minimizeEntities($review->bodytext));

$this->addNewContent($date, $content, $review->rating, 'edit');
}
}

// }}}
// {{{ protected function addNewContent()

Expand Down Expand Up @@ -378,33 +334,6 @@ protected function getInstanceWhereClause()
);
}

// }}}
// {{{ protected function getProductReviews()

protected function getProductReviews()
{
$date = $this->getNewContentCutoffDate();
$date->toUTC();

$sql = sprintf('select ProductReview.*
from ProductReview
where ProductReview.createdate >= %s
and ProductReview.author_review = %s
order by ProductReview.createdate desc',
$this->app->db->quote($date->getDate(), 'date'),
$this->app->db->quote(false, 'boolean'));

$reviews = SwatDB::query($this->app->db, $sql,
SwatDBClassMap::get('StoreProductReviewWrapper'));

$product_sql = 'select * from Product where id in (%s)';
$reviews->loadAllSubDataObjects('product',
$this->app->db, $product_sql,
SwatDBClassMap::get('StoreProductWrapper'), 'integer');

return $reviews;
}

// }}}

// finalize phase
Expand Down
5 changes: 0 additions & 5 deletions Store/admin/components/Dashboard/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
<property name="title" translatable="yes">View All Orders With Comments</property>
<property name="link">Orders?has_comments=true</property>
</widget>
<widget class="SwatToolLink" id="view_all_product_reviews">
<property name="visible" type="boolean">false</property>
<property name="title" translatable="yes">View All Product Reviews</property>
<property name="link">ProductReview</property>
</widget>
</widget>
<widget class="AdminNote" id="new_content_note" />
<widget class="SwatTableView" id="new_content_view">
Expand Down
154 changes: 0 additions & 154 deletions Store/admin/components/Product/Details.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ protected function initInternal()
SiteApplication::VAR_GET);

$this->initItems();

if ($this->ui->hasWidget('review_pager')) {
$this->ui->getWidget('review_pager')->page_size = 10;
}
}

// }}}
Expand Down Expand Up @@ -154,10 +150,6 @@ protected function processInternal()

$this->addNewItems();
}

if ($this->ui->hasWidget('review_pager')) {
$this->ui->getWidget('review_pager')->process();
}
}

// }}}
Expand All @@ -173,10 +165,6 @@ protected function processActions(SwatView $view, SwatActions $actions)
case 'related_articles_view':
$this->processRelatedArticleActions($view, $actions);
break;

case 'product_reviews_view':
$this->processProductReviewActions($view, $actions);
break;
}
}

Expand Down Expand Up @@ -558,80 +546,6 @@ private function processRelatedArticleActions($view, $actions)
$this->app->messages->add($message);
}

// }}}
// {{{ private function processProductReviewActions()

private function processProductReviewActions($view, $actions)
{
switch ($actions->selected->id) {
case 'product_review_delete':
$this->app->replacePage('ProductReview/Delete');
$this->app->getPage()->setItems($view->getSelection());
$this->app->getPage()->setProduct($this->id);
$this->app->getPage()->setCategory($this->category_id);
break;

case 'product_review_approve':
$sql = 'update ProductReview set status = %s, spam = %s
where id in (%s)';

SwatDB::exec($this->app->db, sprintf($sql,
$this->app->db->quote(SiteComment::STATUS_PUBLISHED, 'integer'),
$this->app->db->quote(false, 'boolean'),
SwatDB::implodeSelection($this->app->db,
$view->getSelection())));

$num = count($view->getSelection());

$message = new SwatMessage(sprintf(Store::ngettext(
'One product review has been published.',
'%s product reviews have been published.', $num),
SwatString::numberFormat($num)));

$this->app->messages->add($message);
break;

case 'product_review_deny':
$sql = 'update ProductReview set status = %s
where id in (%s)';

SwatDB::exec($this->app->db, sprintf($sql,
$this->app->db->quote(SiteComment::STATUS_UNPUBLISHED,
'integer'),
SwatDB::implodeSelection($this->app->db,
$view->getSelection())));

$num = count($view->getSelection());

$message = new SwatMessage(sprintf(Store::ngettext(
'One product review has been unpushlished.',
'%s product reviews have been unpushlished.', $num),
SwatString::numberFormat($num)));

$this->app->messages->add($message);
break;

case 'product_review_spam':
$sql = 'update ProductReview set spam = %s
where id in (%s)';

SwatDB::exec($this->app->db, sprintf($sql,
$this->app->db->quote(true, 'boolean'),
SwatDB::implodeSelection($this->app->db,
$view->getSelection())));

$num = count($view->getSelection());

$message = new SwatMessage(sprintf(Store::ngettext(
'One product review has been marked as spam.',
'%s product reviews have been marked as spam.', $num),
SwatString::numberFormat($num)));

$this->app->messages->add($message);
break;
}
}

// }}}

// build phase
Expand All @@ -646,7 +560,6 @@ protected function buildInternal()
$this->buildRelatedProducts();
$this->buildProductCollections();
$this->buildRelatedArticles();
$this->buildProductReviews();
}

// }}}
Expand Down Expand Up @@ -684,8 +597,6 @@ protected function getTableModel(SwatView $view)
return $this->getProductCollectionsTableModel($view);
case 'related_articles_view':
return $this->getRelatedArticlesTableModel($view);
case 'product_reviews_view':
return $this->getProductReviewsTableModel($view);
}
}

Expand Down Expand Up @@ -1459,71 +1370,6 @@ private function getRelatedArticlesTableModel(SwatTableView $view)
}

// }}}

// build phase - product reviews
// {{{ private function buildProductReviews()

private function buildProductReviews()
{
$toolbar = $this->ui->getWidget('product_reviews_toolbar');
$view = $this->ui->getWidget('product_reviews_view');
$this->buildCategoryToolBarLinks($toolbar);
$this->buildCategoryTableViewLinks($view);

if (!$this->product->reviewable) {
$toolbar->parent->sensitive = false;
$this->ui->getWidget('product_reviews_note')->visible = true;
}
}

// }}}
// {{{ private function getProductReviewsTableModel()

private function getProductReviewsTableModel($view)
{
$instance_id = $this->app->getInstanceId();

$sql = sprintf('select count(id) from ProductReview
where product = %s and spam = %s and instance %s %s',
$this->app->db->quote($this->id, 'integer'),
$this->app->db->quote(false, 'boolean'),
SwatDB::equalityOperator($instance_id),
$this->app->db->quote($instance_id, 'integer'));

$pager = $this->ui->getWidget('review_pager');
$pager->total_records = SwatDB::queryOne($this->app->db, $sql);

$sql = 'select * from ProductReview
where product = %s and spam = %s and instance %s %s
order by %s';

$sql = sprintf($sql,
$this->app->db->quote($this->id, 'integer'),
$this->app->db->quote(false, 'boolean'),
SwatDB::equalityOperator($instance_id),
$this->app->db->quote($instance_id, 'integer'),
$this->getOrderByClause($view, 'createdate'));

$this->app->db->setLimit($pager->page_size, $pager->current_record);
$reviews = SwatDB::query($this->app->db, $sql,
SwatDBClassMap::get('StoreProductReviewWrapper'));

$store = new SwatTableStore();
foreach ($reviews as $review) {
$ds = new SwatDetailsStore($review);
if (class_exists('Blorg') && $review->author !== null)
$ds->fullname = $review->author->name;

$ds->bodytext = SwatString::condense(
SwatString::ellipsizeRight($review->bodytext, 500));

$store->add($ds);
}

return $store;
}

// }}}
}

?>
Loading

0 comments on commit 41bd793

Please sign in to comment.