Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 50a22b6

Browse files
committed
A block that displays the most recent posts implemented. Also, a block that displays the top commenters implemented
1 parent ea2cb60 commit 50a22b6

13 files changed

+380
-170
lines changed

Block/EZComments.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

Block/EZCommentsBlock.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* EZComments
4+
*
5+
* @copyright (C) EZComments Development Team
6+
* @link https://github.com/zikula-modules/EZComments
7+
* @license See license.txt
8+
*/
9+
namespace Zikula\EZCommentsModule\Block;
10+
11+
use Zikula\BlocksModule\AbstractBlockHandler;
12+
use Zikula\EZCommentsModule\Block\Form\EZCommentsBlockType;
13+
14+
class EZCommentsBlock extends AbstractBlockHandler
15+
{
16+
/**
17+
* display block
18+
*
19+
* @param array $blockinfo a blockinfo structure
20+
* @return output the rendered bock
21+
*/
22+
public function display(array $properties)
23+
{
24+
if (!$this->hasPermission('ZikulaEZComments:EZCommentsBlock:', $properties['bid'] . '::', ACCESS_OVERVIEW)) {
25+
return '';
26+
}
27+
28+
$currentUserApi = $this->get('zikula_users_module.current_user');
29+
if (!$currentUserApi->isLoggedIn()) {
30+
return '';
31+
}
32+
33+
// set default values for all params which are not properly set
34+
$defaults = $this->getDefaults();
35+
$properties = array_merge($defaults, $properties);
36+
37+
$ezCommentsRepository = $this->get('zikula_ezcomments_module.ezcomments_module_repository');
38+
39+
//return the desired items based upon how the properties have been set
40+
$items = $ezCommentsRepository->getLatestComments($properties);
41+
42+
return $this->renderView("@ZikulaEZCommentsModule\Block\list_latest_comments.html.twig",
43+
[ 'items' => $items,
44+
'days' => $properties['numdays'],
45+
'showdate' => $properties['showdate'] == 'yes',
46+
'showuser' => $properties['showuser'] == 'yes',
47+
'linksuer' => $properties['linkuser'] == 'yes']);
48+
}
49+
50+
public function getFormClassName(){
51+
return EZCommentsBlockType::class;
52+
}
53+
54+
public function getFormTemplate()
55+
{
56+
return '@ZikulaEZCommentsModule/Block/options_modify.html.twig';
57+
}
58+
59+
public function getDefaults(){
60+
return [
61+
'numcomments' => 5,
62+
'numdays' => 14,
63+
'showdate' => 'yes',
64+
'showuser' => 'yes',
65+
'linkuser' => 'no'
66+
];
67+
}
68+
69+
}

Block/Form/EZCommentsBlockType.php

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
3+
namespace Zikula\EZCommentsModule\Block\Form;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Zikula\Common\Translator\TranslatorTrait;
7+
use Zikula\Common\Translator\TranslatorInterface;
8+
use Symfony\Component\Form\FormBuilderInterface;
9+
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
10+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
11+
12+
class EZCommentsBlockType extends AbstractType
13+
{
14+
use TranslatorTrait;
15+
16+
public function __construct(
17+
TranslatorInterface $translator) {
18+
$this->setTranslator($translator);
19+
}
20+
21+
public function setTranslator(TranslatorInterface $translator)
22+
{
23+
$this->translator = $translator;
24+
}
25+
26+
public function buildForm(FormBuilderInterface $builder, array $options)
27+
{
28+
$this->addNumCommentsToDisplay($builder, $options);
29+
$this->addNumDaysToDisplay($builder, $options);
30+
$this->addShowDateField($builder, $options);
31+
$this->addShowUsernameField($builder, $options);
32+
$this->addLinkUsernameField($builder, $options);
33+
}
34+
35+
public function addNumCommentsToDisplay(FormBuilderInterface $builder, array $options = [])
36+
{
37+
$helpText = $this->__('The number of comments to display.', 'zikulaezcommentsmodule')
38+
. ' ' . $this->__('Only digits are allowed.', 'zikulaezcommentsmodule')
39+
;
40+
$builder->add('numcomments', IntegerType::class, [
41+
'label' => $this->__('Number Comments', 'zikulaezcommentsmodule') . ':',
42+
'attr' => [
43+
'maxlength' => 2,
44+
'title' => $helpText
45+
],
46+
'help' => $helpText,
47+
'empty_data' => 5
48+
]);
49+
}
50+
51+
public function addNumDaysToDisplay(FormBuilderInterface $builder, array $options = [])
52+
{
53+
$helpText = $this->__('The number of days from today to display.', 'zikulaezcommentsmodule')
54+
. ' ' . $this->__('Only digits are allowed.', 'zikulaezcommentsmodule')
55+
;
56+
$builder->add('numdays', IntegerType::class, [
57+
'label' => $this->__('Number of Days', 'zikulaezcommentsmodule') . ':',
58+
'attr' => [
59+
'maxlength' => 2,
60+
'title' => $helpText
61+
],
62+
'help' => $helpText,
63+
'empty_data' => 14
64+
]);
65+
}
66+
67+
public function addShowDateField(FormBuilderInterface $builder, array $options = [])
68+
{
69+
$builder->add('showdate', ChoiceType::class, [
70+
'label' => $this->__('Show Date', 'zikulaezcommentsmodule') . ':',
71+
'label_attr' => ['class' => 'radio-inline'],
72+
'empty_data' => 'default',
73+
'choices' => [
74+
$this->__('Yes', 'zikulaezcommentsmodule') => 'yes',
75+
$this->__('No', 'zikulaezcommentsmodule') => 'no',
76+
],
77+
'multiple' => false,
78+
'expanded' => true
79+
]);
80+
}
81+
82+
public function addShowUsernameField(FormBuilderInterface $builder, array $options = [])
83+
{
84+
$builder->add('showuser', ChoiceType::class, [
85+
'label' => $this->__('Show Username', 'zikulaezcommentsmodule') . ':',
86+
'label_attr' => ['class' => 'radio-inline'],
87+
'empty_data' => 'default',
88+
'choices' => [
89+
$this->__('Yes', 'zikulaezcommentsmodule') => 'yes',
90+
$this->__('No', 'zikulaezcommentsmodule') => 'no',
91+
],
92+
'multiple' => false,
93+
'expanded' => true
94+
]);
95+
}
96+
97+
98+
public function addLinkUsernameField(FormBuilderInterface $builder, array $options = [])
99+
{
100+
$builder->add('linkuser', ChoiceType::class, [
101+
'label' => $this->__('Show Date', 'zikulaezcommentsmodule') . ':',
102+
'label_attr' => ['class' => 'radio-inline'],
103+
'empty_data' => 'default',
104+
'choices' => [
105+
$this->__('Yes', 'zikulaezcommentsmodule') => 'yes',
106+
$this->__('No', 'zikulaezcommentsmodule') => 'no',
107+
],
108+
'multiple' => false,
109+
'expanded' => true
110+
]);
111+
}
112+
113+
public function getBlockPrefix()
114+
{
115+
return 'zikulaezcommentsmodule_commentblock';
116+
}
117+
}

Block/Form/MostCommentsBlockType.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
namespace Zikula\EZCommentsModule\Block\Form;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Zikula\Common\Translator\TranslatorTrait;
7+
use Zikula\Common\Translator\TranslatorInterface;
8+
use Symfony\Component\Form\FormBuilderInterface;
9+
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
10+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
11+
12+
class MostCommentsBlockType extends AbstractType
13+
{
14+
use TranslatorTrait;
15+
16+
public function __construct(
17+
TranslatorInterface $translator) {
18+
$this->setTranslator($translator);
19+
}
20+
21+
public function setTranslator(TranslatorInterface $translator)
22+
{
23+
$this->translator = $translator;
24+
}
25+
26+
public function buildForm(FormBuilderInterface $builder, array $options)
27+
{
28+
$this->addNumCommentsToDisplay($builder, $options);
29+
$this->addShowCountField($builder, $options);
30+
}
31+
32+
public function addNumCommentsToDisplay(FormBuilderInterface $builder, array $options = [])
33+
{
34+
$helpText = $this->__('The number of commenters to display.', 'zikulaezcommentsmodule')
35+
. ' ' . $this->__('Only digits are allowed.', 'zikulaezcommentsmodule')
36+
;
37+
$builder->add('numcommenters', IntegerType::class, [
38+
'label' => $this->__('Number Comments', 'zikulaezcommentsmodule') . ':',
39+
'attr' => [
40+
'maxlength' => 2,
41+
'title' => $helpText
42+
],
43+
'help' => $helpText,
44+
'empty_data' => 5
45+
]);
46+
}
47+
48+
public function addShowCountField(FormBuilderInterface $builder, array $options = [])
49+
{
50+
$builder->add('showcount', ChoiceType::class, [
51+
'label' => $this->__('Show Count', 'zikulaezcommentsmodule') . ':',
52+
'label_attr' => ['class' => 'radio-inline'],
53+
'empty_data' => 'default',
54+
'choices' => [
55+
$this->__('Yes', 'zikulaezcommentsmodule') => 'yes',
56+
$this->__('No', 'zikulaezcommentsmodule') => 'no',
57+
],
58+
'multiple' => false,
59+
'expanded' => true
60+
]);
61+
}
62+
63+
public function getBlockPrefix()
64+
{
65+
return 'zikulaezcommentsmodule_mostcommentsblock';
66+
}
67+
}

0 commit comments

Comments
 (0)