-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCommentsHelper.php
79 lines (63 loc) · 2.29 KB
/
CommentsHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
/**
* News4ward
* a contentelement driven news/blog-system
*
* @author Christoph Wiechert <wio@psitrax.de>
* @copyright 4ward.media GbR <http://www.4wardmedia.de>
* @package news4ward_comments
* @filesource
* @licence LGPL
*/
namespace Psi\News4ward;
class CommentsHelper extends \System
{
public function __construct()
{
parent::__construct();
$this->import('\Database','Database');
}
/**
* tl_comments listComments Callback
* Adds BE and FE links to the comment listing
*
* @param $arrRow
* @return string
*/
public function listComments($arrRow)
{
if($arrRow['source'] != 'tl_news4ward_article') return '';
$objParent = $this->Database->prepare(" SELECT tl_news4ward_article.id, tl_news4ward_article.title, tl_news4ward_article.alias, tl_news4ward.jumpTo AS parentJumpTo
FROM tl_news4ward_article
LEFT JOIN tl_news4ward ON (tl_news4ward_article.pid=tl_news4ward.id)
WHERE tl_news4ward_article.id=?")->execute($arrRow['parent']);
if ($objParent->numRows)
{
$this->import('\News4ward\Helper','News4wardHelper');
$title = ' (<a href="contao/main.php?do=news4ward&table=tl_news4ward_article&id=' . $objParent->id . '">' . $objParent->title . '</a>)';
$title .= ' (<a href="'.$this->News4wardHelper->generateUrl($objParent->row()).'" target="_blank">'.$GLOBALS['TL_LANG']['tl_comments']['news4ward_FElink'].'</a>)';
}
return $title;
}
/**
* Check if the user is allowed to handle the comments
*
* @param $intParent id of the parent element
* @param $strSource comment source
* @return bool
*/
public function isAllowedToEditComment($intParent, $strSource)
{
if($strSource != 'tl_news4ward_article') return;
$this->import('\BackendUser','User');
$objNews4wardArticle = $this->Database->prepare('SELECT pid FROM tl_news4ward_article WHERE id=?')->execute($intParent);
if(!$objNews4wardArticle->numRows) return;
return (is_array($this->User->news4ward) && in_array($objNews4wardArticle->pid,$this->User->news4ward));
}
public function addCommentsCount($obj, $arrArticle, $objTemplate)
{
$objComments = $this->Database->prepare('SELECT count(id) AS anz FROM tl_comments WHERE parent=? AND source="tl_news4ward_article"')
->execute($arrArticle['id']);
$objTemplate->commentCount = $objComments->anz;
}
}