Skip to content

Commit

Permalink
Add comments to Products
Browse files Browse the repository at this point in the history
  • Loading branch information
hamidpeywasti committed Jun 4, 2019
1 parent 1acf746 commit fc7abfb
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 4 deletions.
8 changes: 8 additions & 0 deletions src/dca/tl_module.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@
'sql' => "varchar(64) NOT NULL default ''"
);

$bundles = Contao\System::getContainer()->getParameter('kernel.bundles');

// Add the comments template drop-down menu
if (isset($bundles['ContaoCommentsBundle']))
{
$GLOBALS['TL_DCA']['tl_module']['palettes']['product_detail'] = str_replace('{protected_legend:hide}', '{comment_legend:hide},com_template;{protected_legend:hide}', $GLOBALS['TL_DCA']['tl_module']['palettes']['product_detail']);
}



/**
Expand Down
78 changes: 75 additions & 3 deletions src/dca/tl_product_catalog.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,15 @@
// Palettes
'palettes' => array
(
'__selector__' => array('protected'),
'default' => '{title_legend},title;{redirect_legend},jumpTo;{protected_legend:hide},protected;'
'__selector__' => array('protected', 'allowComments'),
'default' => '{title_legend},title;{redirect_legend},jumpTo;{protected_legend:hide},protected;{comments_legend:hide},allowComments'
),

// Subpalettes
'subpalettes' => array
(
'protected' => 'groups',
'allowComments' => 'notify,sortOrder,perPage,moderate,bbcode,requireLogin,disableCaptcha'
),

// Fields
Expand Down Expand Up @@ -161,6 +162,77 @@
'eval' => array('mandatory'=>true, 'multiple'=>true),
'sql' => "blob NULL",
'relation' => array('type'=>'hasMany', 'load'=>'lazy')
),
'allowComments' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_product_catalog']['allowComments'],
'exclude' => true,
'filter' => true,
'inputType' => 'checkbox',
'eval' => array('submitOnChange'=>true),
'sql' => "char(1) NOT NULL default ''"
),
'notify' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_product_catalog']['notify'],
'default' => 'notify_admin',
'exclude' => true,
'inputType' => 'select',
'options' => array('notify_admin', 'notify_author', 'notify_both'),
'eval' => array('tl_class'=>'w50'),
'reference' => &$GLOBALS['TL_LANG']['tl_product_catalog'],
'sql' => "varchar(16) NOT NULL default ''"
),
'sortOrder' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_product_catalog']['sortOrder'],
'default' => 'ascending',
'exclude' => true,
'inputType' => 'select',
'options' => array('ascending', 'descending'),
'reference' => &$GLOBALS['TL_LANG']['MSC'],
'eval' => array('tl_class'=>'w50 clr'),
'sql' => "varchar(32) NOT NULL default ''"
),
'perPage' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_product_catalog']['perPage'],
'exclude' => true,
'inputType' => 'text',
'eval' => array('rgxp'=>'natural', 'tl_class'=>'w50'),
'sql' => "smallint(5) unsigned NOT NULL default '0'"
),
'moderate' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_product_catalog']['moderate'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'bbcode' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_product_catalog']['bbcode'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'requireLogin' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_product_catalog']['requireLogin'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w50'),
'sql' => "char(1) NOT NULL default ''"
),
'disableCaptcha' => array
(
'label' => &$GLOBALS['TL_LANG']['tl_product_catalog']['disableCaptcha'],
'exclude' => true,
'inputType' => 'checkbox',
'eval' => array('tl_class'=>'w50'),
'sql' => "char(1) NOT NULL default ''"
)
)
);
Expand All @@ -179,7 +251,7 @@ public function __construct()
}

/**
* Check permissions to edit table tl_news_archive
* Check permissions to edit table tl_product_catalog
*/
public function checkPermission()
{
Expand Down
57 changes: 56 additions & 1 deletion src/library/Frontend/Module/ModuleProductDetail.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,62 @@ protected function compile()

$this->Template->relateds = $this->parseRelateds($objProducts);
}
}
}

$bundles = \System::getContainer()->getParameter('kernel.bundles');

// HOOK: comments extension required
if ($objProduct->noComments || !isset($bundles['ContaoCommentsBundle']))
{
$this->Template->allowComments = false;

return;
}

/** @var NewsArchiveModel $objCatalog */
$objCatalog = $objProduct->getRelated('pid');
$this->Template->allowComments = $objCatalog->allowComments;

// Comments are not allowed
if (!$objCatalog->allowComments)
{
return;
}

// Adjust the comments headline level
$intHl = min((int) str_replace('h', '', $this->hl), 5);
$this->Template->hlc = 'h' . ($intHl + 1);

$this->import(\Comments::class, 'Comments');
$arrNotifies = array();

// Notify the system administrator
if ($objCatalog->notify != 'notify_author')
{
$arrNotifies[] = $GLOBALS['TL_ADMIN_EMAIL'];
}

// Notify the author
if ($objCatalog->notify != 'notify_admin')
{
/** @var UserModel $objAuthor */
if (($objAuthor = $objProduct->getRelated('author')) instanceof UserModel && $objAuthor->email != '')
{
$arrNotifies[] = $objAuthor->email;
}
}

$objConfig = new \stdClass();

$objConfig->perPage = $objCatalog->perPage;
$objConfig->order = $objCatalog->sortOrder;
$objConfig->template = $this->com_template;
$objConfig->requireLogin = $objCatalog->requireLogin;
$objConfig->disableCaptcha = $objCatalog->disableCaptcha;
$objConfig->bbcode = $objCatalog->bbcode;
$objConfig->moderate = $objCatalog->moderate;

$this->Comments->addCommentsToTemplate($this->Template, $objConfig, 'tl_news', $objProduct->id, $arrNotifies);

}
}
10 changes: 10 additions & 0 deletions src/templates/modules/mod_product_detail.html5
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,14 @@
<p class="back"><a href="<?= $this->referer; ?>" title="<?= $this->back; ?>"><?= $this->back; ?></a></p>
<!-- indexer::continue -->

<?php if ($this->allowComments): ?>
<div class="ce_comments block">
<<?= $this->hlc ?>><?= $this->hlcText ?></<?= $this->hlc ?>>
<?= implode('', $this->comments) ?>
<?= $this->pagination ?>
<<?= $this->hlc ?>><?= $this->addComment ?></<?= $this->hlc ?>>
<?php $this->insert('mod_comment_form', $this->arrData); ?>
</div>
<?php endif; ?>

<?php $this->endblock(); ?>

0 comments on commit fc7abfb

Please sign in to comment.