-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinjector.php
96 lines (83 loc) · 2.85 KB
/
injector.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @package com_meego_ratings
* @author The Midgard Project, http://www.midgard-project.org
* @copyright The Midgard Project, http://www.midgard-project.org
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
*/
/**
* Injector
*
* @package com_meego_ratings
*/
class com_meego_ratings_injector
{
private $connected = false;
private function get_connected()
{
$mvc = midgardmvc_core::get_instance();
$language = $mvc->configuration->get('default_language');
if (! $language)
{
$language = 'en_US';
}
$mvc->i18n->set_language($language, false);
midgard_object_class::connect_default('com_meego_comments_comment', 'action-deleted', array('com_meego_ratings_injector', 'delete_rating_handler'));
$this->connected = true;
}
public function inject_template(midgardmvc_core_request $request)
{
if (! $this->connected)
{
self::get_connected();
}
$mvc = midgardmvc_core::get_instance();
$request->add_component_to_chain($mvc->component->get('com_meego_ratings'), true);
}
/**
* A signal handler for deleting comments
* Checks if the comment was attached to a rating object
* If the rating object has no rating, then it will delete this object
*
* @param object com_meego_comments_comment object
*/
public static function delete_rating_handler(com_meego_comments_comment $comment)
{
$mvc = midgardmvc_core::get_instance();
if ($comment)
{
$storage = new midgard_query_storage('com_meego_ratings_rating');
$q = new midgard_query_select($storage);
$qc = new midgard_query_constraint_group('AND');
$qc->add_constraint(new midgard_query_constraint(
new midgard_query_property('comment'),
'=',
new midgard_query_value($comment->id)
));
$qc->add_constraint(new midgard_query_constraint(
new midgard_query_property('rating'),
'=',
new midgard_query_value('')
));
$q->set_constraint($qc);
$q->execute();
$ratings = $q->list_objects();
if (count($ratings))
{
foreach ($ratings as $rating)
{
$res = $rating->delete();
if ($res)
{
$mvc->log(__CLASS__, 'Rating object with id: ' . $rating->id . ' has been successfuly deleted.', 'info');
}
else
{
$mvc->log(__CLASS__, 'Rating object with id: ' . $rating->id . ' could not be deleted.', 'info');
}
}
}
}
}
}
?>