<?php 

function cp_download_link($item, $key, $table_obj) {
	$html = "";
	if($item['type'] === 'cp_lesson_material') {
		$html = "<a href=\"javaScript:void(0);\" class=\"library_file_grabber\" data-ref=\"".$item['ref']."\" title=\"\" data-original-title=\"Click to download lesson note and other attachments\"><i class=\"ni ni-cloud-download-95\"></i> Download</a>";
	}
	if($item['type'] === 'cp_lesson_material_link') {
		$link_text = (isset($item['link_text']) && $item['link_text'] !== "") ? $item['link_text'] : "Go to Link";
		$html = "<a href=\"".$item['material-url']."\" target=\"_blank\" data-original-title=\"Click to visit link\"><i class=\"fas fa-globe\"></i> ".$link_text." <i class=\"fas fa-external-link-square-alt\"></i></a>";
	}
	return $html;
}

function _cp_tf_get_week($item, $key, $table_obj) {
	if($term_meta['order'] == $item['term']) {
		if(cp_is_current_week($item['week'], $table_obj->term_meta)) {
			return $item[$key]." <span class=\"badge badge-primary\">Current Week</span>";
		} else return $item[$key];
	} else return $item[$key];
}

function _tf_cp_display_time_allowed($item, $key, $table_obj) {
	return $item[$key]." Minute(s)";
}

function cp_add_to_quiz_condition($item, $args) {
	return !db_post_unique(['type' => 'cp_quiz_question', 'question' => $item['id'], 'quiz' => $args['quiz']]);
}

function _check_student_has_written_quiz_condition($item, $args) {
	return !db_post_unique(["type" => "cp_write_quiz", "user_id" => $args['id'], "quiz" => $item['id']]);
}

function _tf_cp_get_objective_question_score($item, $key, $table_obj) {
	$answer = db_post_unique(["type" => "cp_write_quiz", "quiz" => $table_obj->quiz, 'user_id' => $item['id']]);
	if($answer) {
		if(isset($answer['objective'])) {
			return $answer['correct']."/".($answer['correct'] + $answer['wrong'] + $answer['skipped']);
		} else return "-";
	} else {
		return "NIL";
	}
}