-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathVideosHandler.php
More file actions
101 lines (92 loc) · 3.3 KB
/
VideosHandler.php
File metadata and controls
101 lines (92 loc) · 3.3 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
<?php
/**
* Class responsible for managing profile videos objects
*
* @copyright GNU General Public License (GPL)
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License (GPL)
* @since 1.4
* @author phoenyx
* @package profile
* @version $Id$
*/
defined("ICMS_ROOT_PATH") or die("ICMS root path not defined");
class mod_profile_VideosHandler extends icms_ipf_Handler {
/**
* Constructor
*
* @param icms_db_legacy_Database $db database object
*/
public function __construct(&$db) {
parent::__construct($db, 'videos', 'videos_id', 'video_title', '', basename(dirname(__FILE__, 2)));
}
/**
* Create the criteria that will be used by getVideos and getVideosCount
*
* @param int $start to which record to start
* @param int $limit limit of videos to return
* @param int $uid_owner if specifid, only the videos of this user will be returned
* @param int $video_id ID of a single video to retrieve
* @return icms_db_criteria_Compo $criteria
*/
private function getVideosCriteria($start = 0, $limit = 0, $uid_owner = false, $video_id = false) {
$criteria = new icms_db_criteria_Compo();
if ($start) $criteria->setStart((int)$start);
if ($limit) $criteria->setLimit((int)$limit);
$criteria->setSort('creation_time');
$criteria->setOrder('DESC');
if ($uid_owner) $criteria->add(new icms_db_criteria_Item('uid_owner', (int)$uid_owner));
if ($video_id) $criteria->add(new icms_db_criteria_Item('videos_id', (int)$video_id));
return $criteria;
}
/**
* Get single video object
*
* @param int $videos_id
* @return ProfileVideo
*/
public function getVideo($videos_id) {
$ret = $this->getVideos(0, 0, false, $videos_id);
return isset($ret[$videos_id]) ? $ret[$videos_id] : false;
}
/**
* Get videos as array, ordered by creation_time DESC
*
* @param int $start to which record to start
* @param int $limit max videos to display
* @param int $uid_owner if specifid, only the video of this user will be returned
* @param int $videos_id ID of a single video to retrieve
* @return array of videos
*/
public function getVideos($start = 0, $limit = 0, $uid_owner = false, $videos_id = false): array
{
$criteria = $this->getVideosCriteria($start, $limit, $uid_owner, $videos_id);
$ret = $this->getObjects($criteria, true, false);
return $ret;
}
/**
* Check wether the current user can submit a new video or not
*
* @return bool true if he can false if not
*/
public function userCanSubmit(): bool
{
return is_object(icms::$user);
}
/**
* AfterInsert event
*
* Event automatically triggered by IcmsPersistable Framework after the object is inserted
*
* @param mod_profile_Videos $obj object
* @return true
*/
protected function afterInsert(&$obj) {
$thisUser = icms::handler("icms_member")->getUser($obj->getVar('uid_owner'));
$module = icms::handler("icms_module")->getByDirname(basename(dirname(__FILE__, 2)), TRUE);
$tags['VIDEO_TITLE'] = $obj->getVar('video_title');
$tags['VIDEO_OWNER'] = $thisUser->getVar('uname');
$tags['VIDEO_URL'] = ICMS_URL.'/modules/'.basename(dirname(__FILE__, 2)).'/videos.php?uid='.$obj->getVar('uid_owner');
icms::handler('icms_data_notification')->triggerEvent('videos', $obj->getVar('uid_owner'), 'new_video', $tags, array(), $module->getVar('mid'));
return true;
}
}