Skip to content

Commit

Permalink
Show number of new videos in my courses, close #668 (#842)
Browse files Browse the repository at this point in the history
Co-authored-by: Dennis Benz <[email protected]>
  • Loading branch information
dennis531 and Dennis Benz authored Nov 27, 2023
1 parent 7902a1c commit b218116
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 3 deletions.
21 changes: 19 additions & 2 deletions OpenCast.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Opencast\Models\Helpers;
use Opencast\Models\SeminarSeries;
use Opencast\Models\Videos;

use Opencast\AppFactory;
use Opencast\RouteMap;
Expand Down Expand Up @@ -124,8 +125,9 @@ public function _n($string0, $string1, $n)
/**
* This method takes care of the Navigation
*
* @param string course_id
* @param string last_visit
* @param string $course_id
* @param int $last_visit
* @param string $user_id
*/
public function getIconNavigation($course_id, $last_visit, $user_id = null)
{
Expand All @@ -137,6 +139,21 @@ public function getIconNavigation($course_id, $last_visit, $user_id = null)
);
$navigation->setImage(Icon::create('video2'));

// Get number of new videos since last visit
$new_videos = Videos::getNumberOfNewCourseVideos($course_id, $last_visit, $user_id);

if ($new_videos > 0) {
if ($new_videos == 1) {
$text = $this->_('neues Video');
} else {
$text = $this->_('neue Videos');
}
$navigation->setImage(Icon::create('video2', Icon::ROLE_ATTENTION, [
'title' => $new_videos . ' ' . $text,
]));
$navigation->setBadgeNumber($new_videos);
}

return $navigation;
}

Expand Down
1 change: 1 addition & 0 deletions app/controllers/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function before_filter(&$action, &$args)
{
parent::before_filter($action, $args);
$this->course_id = Context::getId();
object_set_visit_module($this->plugin->getPluginId());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/Models/PlaylistVideos.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Opencast\Models;

class PlaylistVideos extends \SimpleORMap
class PlaylistVideos extends UPMap
{
protected static function configure($config = [])
{
Expand Down
45 changes: 45 additions & 0 deletions lib/Models/Videos.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,51 @@ protected static function getFilteredVideos($query, $filters)
];
}

/**
* Count number of new videos in a course since last visit
*
* @param string $course_id course id
* @param int $last_visit time of last visit
* @param string $user_id user id
*
* @return int number of new videos
*/
public static function getNumberOfNewCourseVideos($course_id, $last_visit, $user_id = null) {
global $perm;

$sql = 'SELECT COUNT(DISTINCT video.id)
FROM `oc_video` AS video
INNER JOIN `oc_playlist_video` AS opv ON (opv.video_id = video.id)
INNER JOIN `oc_playlist` AS op ON (op.id = opv.playlist_id)
INNER JOIN `oc_playlist_seminar` AS ops ON (ops.playlist_id = op.id)';

$where = 'WHERE ops.seminar_id = :course_id
AND (UNIX_TIMESTAMP(video.chdate) > :last_visit OR UNIX_TIMESTAMP(opv.mkdate) > :last_visit)
AND video.trashed = 0
AND video.token IS NOT NULL
AND video.state IS NULL
AND video.available = 1';

if (!$perm->have_perm('dozent', $user_id)) {
$sql .= ' LEFT JOIN oc_playlist_seminar_video AS opsv ON (opsv.playlist_seminar_id = ops.id AND opsv.video_id = opv.video_id)';

$where .= ' AND (opsv.visibility IS NULL AND opsv.visible_timestamp IS NULL AND ops.visibility = "visible"
OR opsv.visibility = "visible" AND opsv.visible_timestamp IS NULL
OR opsv.visible_timestamp < NOW()) ';
}

$sql .= $where;

$stmt = \DBManager::get()->prepare($sql);

$stmt->execute([
'course_id' => $course_id,
'last_visit' => $last_visit,
]);

return (int) $stmt->fetchColumn();
}

public static function findByToken($token)
{
return self::findOneBySQL('token = ?', [$token]);
Expand Down
30 changes: 30 additions & 0 deletions migrations/079_add_playlist_video_dates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

class AddPlaylistVideoDates extends Migration
{
public function description()
{
return 'Add mkdate and chdate columns to table playlist video';
}

public function up()
{
$db = DBManager::get();

$db->exec("ALTER TABLE `oc_playlist_video`
ADD COLUMN `chdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP(),
ADD COLUMN `mkdate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP()
");

SimpleOrMap::expireTableScheme();
}

public function down()
{
$db = DBManager::get();

$db->exec("ALTER TABLE `oc_playlist_video` DROP COLUMN `chdate`, DROP COLUMN `mkdate`");

SimpleOrMap::expireTableScheme();
}
}

0 comments on commit b218116

Please sign in to comment.