<?php 

function qf_get_users_filter_response_eedu_portal($response) {
	$post = new post;
	$roles = array_flip(get_system_roles());
	$classes = $post->get_post_by_meta_data(['type' => 'class'], 'LIKE', true);
	$categories = $post->get_post_by_meta_data(['type' => 'category'], 'LIKE', true);
	if(_count($response['users']) && is_array($response['users'])) {
		foreach ($response['users'] as $key => &$value) {
			if($value['role'] == 'student') {
				$value['profile_link'] = 'student-profile?id='.$value['id'];
				$value['phone'] = isset($value['n1_phone']) ? '+'.$value['n1_phone'] : '';
			} else {
				$value['phone'] = isset($value['phone']) ? '+'.$value['phone'] : '';
			}
			$value['full_name'] = get_fullname($value);
			$value['username'] = strtoupper($value['username']);
			$value['profile_picture'] = get_user_image($value);
			if(isset($value['class'])) {
				$value['class'] = get_class_name($classes[$value['class']], $categories[$value['category']]);
			}
			$value['role'] = $roles[$value['role']];
		}
	}
	return $response;
}

function eedu_portal_users_filter_system_roles_filter($system_roles) {
	unset($system_roles['Candidate']);
	return $system_roles;
}

function eedu_portal_email_validation_filter($res) {
	return false;
}

function eedu_portal_before_users_table_display($table, $args) {
	$table->set_dynamic_columns([
		'class' => '_tf_eedu_display_student_class',
		'phone' => '_tf_eedu_display_phone',
		'email' => '_tf_eedu_display_email'
	]);
	return $table;
}

function eedu_portal_filter_user_args($query) {
	if($query['class'] == "") {
		unset($query['class']);
	}
	if($query['category'] == "") {
		unset($query['category']);
	}
	return $query;
}

function eedu_portal_users_columns_filter($filters) {
	$filters['all']['class'] = "Class";
	$filters['all']['gender'] = "Gender";
	$filters['all']['username'] = "Student/ Staff ID";
	$filters['all']['state_reg_number'] = "State Reg. Number";
	$filters['selected']['class'] = true;
	return $filters;
}