1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Widgets\Front\Newcomment; |
4
|
|
|
|
5
|
|
|
use Ffcms\Core\App; |
6
|
|
|
use Extend\Core\Arch\FrontWidget as AbstractWidget; |
7
|
|
|
use Ffcms\Core\Traits\OopTools; |
8
|
|
|
use Apps\ActiveRecord\CommentPost; |
9
|
|
|
use Apps\Model\Api\Comments\EntityCommentData; |
10
|
|
|
|
11
|
|
|
class Newcomment extends AbstractWidget |
12
|
|
|
{ |
13
|
|
|
use OopTools; |
14
|
|
|
|
15
|
|
|
public $snippet; |
16
|
|
|
public $count; |
17
|
|
|
public $cache; |
18
|
|
|
|
19
|
|
|
public function init() |
20
|
|
|
{ |
21
|
|
|
$cfg = $this->getConfigs(); |
22
|
|
|
if ($this->snippet === null) { |
23
|
|
|
$this->snippet = $cfg['snippet']; |
24
|
|
|
} |
25
|
|
|
if ($this->count === null) { |
26
|
|
|
$this->count = $cfg['count']; |
27
|
|
|
} |
28
|
|
|
if ($this->cache === null) { |
29
|
|
|
$this->cache = $cfg['cache']; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function display() |
34
|
|
|
{ |
35
|
|
|
$classHash = $this->createStringClassSnapshotHash(); |
36
|
|
|
|
37
|
|
|
$records = null; |
|
|
|
|
38
|
|
|
if ((int)$this->cache > 0) { |
39
|
|
|
if (App::$Cache->get('widget.newcomment.' . $classHash) !== null) { |
40
|
|
|
$records = App::$Cache->get('widget.newcomment.' . $classHash); |
41
|
|
|
} else { |
42
|
|
|
$records = $this->makeQuery(); |
43
|
|
|
} |
44
|
|
|
} else { |
45
|
|
|
$records = $this->makeQuery(); |
46
|
|
|
} |
47
|
|
|
// check if records is found |
48
|
|
|
if ($records === null) { |
49
|
|
|
return __('Comments not yet found'); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
return App::$View->render('widgets/newcomment/default', [ |
53
|
|
|
'records' => $records, |
54
|
|
|
'snippet' => $this->snippet |
55
|
|
|
]); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function makeQuery() |
59
|
|
|
{ |
60
|
|
|
$records = CommentPost::where('lang', '=', App::$Request->getLanguage()); |
61
|
|
|
|
62
|
|
|
if ($records === null || $records->count() < 1) { |
63
|
|
|
return null; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $records->orderBy('id', 'DESC') |
67
|
|
|
->take($this->count) |
68
|
|
|
->get(); |
69
|
|
|
} |
70
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.