-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathactivities.php
More file actions
executable file
·163 lines (140 loc) · 4.28 KB
/
Copy pathactivities.php
File metadata and controls
executable file
·163 lines (140 loc) · 4.28 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<?php
/**
* @package Activitystream
* @subpackage Com_Activitystream
*
* @author Techjoomla <extensions@techjoomla.com>
* @copyright Copyright (C) 2016 - 2021 Techjoomla. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
*/
// No direct access to this file
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Log\Log;
use Joomla\CMS\Table\Table;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Language\Text;
use Joomla\Utilities\ArrayHelper;
use Joomla\CMS\MVC\Controller\AdminController;
/**
* Activity Stream Controller
*
* @since 0.0.1
*/
class ActivityStreamControllerActivities extends AdminController
{
/**
* Proxy for getModel.
*
* @param string $name The model name. Optional.
* @param string $prefix The class prefix. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return object The model.
*
* @since 0.0.1
*/
public function getModel($name = 'Activity', $prefix = 'ActivityStreamModel', $config = array('ignore_request' => true))
{
$model = parent::getModel($name, $prefix, $config);
return $model;
}
/**
* Function to get activities internaly
*
* @return object activities
*
* @since 0.0.1
*/
public function getActivities()
{
// Load component tables
Table::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_activitystream/tables');
// Variable to store activity data fetched
$result = array();
// Variable to store request response
$result_arr = array();
$ActivityStreamModelActivities = $this->getModel('Activities');
$jinput = Factory::getApplication()->input;
$type = $jinput->get("type", '', 'STRING');
// Return result related to specified activity type
if (empty($type))
{
$result_arr['success'] = false;
$result_arr['message'] = Text::_("COM_ACTIVITYSTREAM_ERROR_ACTIVITY_TYPE");
echo json_encode($result_arr);
jexit();
}
$actor_id = $jinput->get('actor_id', '', 'CMD');
$object_id = $jinput->get('object_id', '', 'CMD');
$target_id = $jinput->get('target_id', '', 'STRING');
$from_date = $jinput->get('from_date', '');
$limit = $jinput->get('limit') ? $jinput->get('limit'): 0;
// Set model state
$ActivityStreamModelActivities->setState("type", $type);
$ActivityStreamModelActivities->setState("actor_id", $actor_id);
$ActivityStreamModelActivities->setState("object_id", $object_id);
$ActivityStreamModelActivities->setState("target_id", $target_id);
$ActivityStreamModelActivities->setState("from_date", $from_date);
$ActivityStreamModelActivities->setState("limit", $limit);
$ActivityStreamModelActivities->setState("access", "1");
$ActivityStreamModelActivities->setState("state", '1');
$result['results'] = $ActivityStreamModelActivities->getItems();
// If no activities found then return the error message
if (empty($result['results']))
{
$result_arr['success'] = false;
$result_arr['message'] = Text::_("COM_ACTIVITYSTREAM_NO_ACTIVITY");
}
else
{
$result_arr['success'] = true;
$result_arr['data'] = $result;
$result_arr['data']['total'] = $ActivityStreamModelActivities->getTotal();
}
echo json_encode($result_arr);
jexit();
}
/**
* Function to delete the activity
*
* @return void
*
* @since 1.0.1
*/
public function delete()
{
$input = Factory::getApplication()->input;
$client = $input->get('client', '', 'STRING');
$id = Factory::getApplication()->input->get('cid', array(), 'array');
if (!is_array($id) || count($id) < 1)
{
Log::add(Text::_($this->text_prefix . '_NO_ITEM_SELECTED'), Log::WARNING, 'jerror');
}
else
{
// Get the model.
$model = $this->getModel('activity');
// Make sure the item ids are integers
jimport('joomla.utilities.arrayhelper');
ArrayHelper::toInteger($id);
// Remove the activity.
if ($model->delete($id))
{
$this->setMessage(Text::plural($this->text_prefix . '_N_ITEMS_DELETED', count($id)));
}
else
{
$this->setMessage($model->getError());
}
if (isset($client))
{
$this->setRedirect(Route::_('index.php?option=com_activitystream&view=activities&client=' . $client, false));
}
else
{
$this->setRedirect(Route::_('index.php?option=com_activitystream&view=activities', false));
}
}
}
}