<?php 

function cp_qf_get_streams($args) {
	$session = Session::getInstance();
	$options = ["status" => "active"];
	$user = new user;
	$user_meta = $user->get_user_meta($session->id);
	if($user_meta['role'] === 'student') {
		$options['class_id'] = $user_meta['class'];
	}
	if($user_meta['role'] === 'teacher') {
		$options['teacher_id'] = "%i".$session->id."e%";
	}
	$streams = cp_get_streams(
		$options,
		$args['limit'], 
		$args['offset']
	);
	if(is_array($streams) && _count($streams)) {
		$response['html'] = "";
		foreach ($streams as $stream) {
			$time = date("Y-m-d H:i:s", $stream["log_time"]);
			$response['html'] .= "<div class=\"card card-stats\" onclick=\"window.location = '".$stream['link']."'\" style=\"cursor: pointer\">";
	    	$response['html'] .= "<div class=\"card-body\"><div class=\"row\"><div class=\"col\">";
	        $response['html'] .= "<h5 class=\"card-title text-uppercase text-muted mb-0\">".get_fullname($stream['user_id'], true)."</h5>";
	        $response['html'] .= "<span class=\"h2 font-weight-bold mb-0\">".cp_get_stream_caption($stream)."</span>";
	        $response['html'] .= "</div><div class=\"col-auto\">".cp_get_stream_icon($stream)."</div></div>";
	      	$response['html'] .= "<p class=\"mt-3 mb-0 text-sm\"><span class=\"text-success mr-2\"><i class=\"fas fa-clock\"></i>&nbsp;"; 
	      	$response['html'] .= time_elapsed_string($time);
	      	$response['html'] .= "</span><span class=\"\">";
	      	$response['html'] .= $stream['message'];
	      	$response['html'] .= "</span></p></div></div>";
		}
		$response['continue'] = true;
	}
	else {
		if($args['count'] > 0) {
			$response['html'] = "";
		} else $response['html'] = "no result found";
		$response['continue'] = false;
	}
	return $response;
}