| 1 |
<?php |
| 2 |
|
| 3 |
/** =====================( Functions Details )====================== |
| 4 |
|
| 5 |
# Educare Grading Systems |
| 6 |
* usage => echo educare_grade_system("85"); |
| 7 |
|
| 8 |
* @since 1.2.0 |
| 9 |
* @last-update 1.2.0 |
| 10 |
|
| 11 |
* @param $marks int/str for grading system |
| 12 |
* @return str |
| 13 |
|
| 14 |
===================( function for create menu )=================== **/ |
| 15 |
|
| 16 |
function educare_grade_system($marks) { |
| 17 |
/* default grading system is |
| 18 |
$grade_system = array( |
| 19 |
'current' => 'Default', |
| 20 |
'rules' => [ |
| 21 |
'Default' => [ |
| 22 |
'80-100' => [5, 'A+'], |
| 23 |
'70-79' => [4, 'A'], |
| 24 |
'60-69' => [3.5, 'A-'], |
| 25 |
'50-59' => [3, 'B'], |
| 26 |
'40-49' => [2, 'C'], |
| 27 |
'33-39' => [1, 'D'], |
| 28 |
'0-32' => [0, 'F'] |
| 29 |
] |
| 30 |
] |
| 31 |
); |
| 32 |
*/ |
| 33 |
|
| 34 |
$grade_system = educare_check_status('grade_system'); |
| 35 |
$current = $grade_system->current; |
| 36 |
$grade_system = $grade_system->rules->$current; |
| 37 |
|
| 38 |
// check optional marks |
| 39 |
$optional_marks = substr(strstr($marks, ' '), 1); |
| 40 |
if ($optional_marks) { |
| 41 |
$marks = $optional_marks; |
| 42 |
} |
| 43 |
|
| 44 |
foreach ($grade_system as $rules => $grade) { |
| 45 |
if ($rules == 'failed' or $rules == 'success') break; |
| 46 |
// get first rules number to compare |
| 47 |
$rules1 = strtok($rules, '-'); |
| 48 |
// get second rules number to compare |
| 49 |
$rules2 = substr(strstr($rules, '-'), 1); |
| 50 |
|
| 51 |
if ($marks >= $rules1 and $marks <= $rules2) { |
| 52 |
$marks = $grade; |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
return $marks; |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
/** =====================( Functions Details )====================== |
| 62 |
|
| 63 |
# Save Grading System |
| 64 |
* usage => echo educare_save_results_system(); |
| 65 |
|
| 66 |
* @since 1.2.0 |
| 67 |
* @last-update 1.2.0 |
| 68 |
|
| 69 |
* @return void |
| 70 |
|
| 71 |
===================( function for proccess grading rules )=================== **/ |
| 72 |
|
| 73 |
function educare_save_results_system() { |
| 74 |
global $wpdb; |
| 75 |
$table = $wpdb->prefix . "educare_settings"; |
| 76 |
|
| 77 |
$search = $wpdb->get_row("SELECT * FROM $table WHERE list='Settings'"); |
| 78 |
|
| 79 |
if ($search) { |
| 80 |
if (isset($_POST['update_grade_rules'])) { |
| 81 |
$id = $search->id; |
| 82 |
$data = $search->data; |
| 83 |
$data = json_decode($data); |
| 84 |
|
| 85 |
$rules_name = sanitize_text_field($_POST['rules']); |
| 86 |
$rules1 = array_map( 'sanitize_text_field', $_POST['rules1'] ); |
| 87 |
$rules2 = array_map( 'sanitize_text_field', $_POST['rules2'] ); |
| 88 |
$grade = array_map( 'sanitize_text_field', $_POST['grade'] ); |
| 89 |
$point = array_map( 'sanitize_text_field', $_POST['point'] ); |
| 90 |
|
| 91 |
$count1 = $count2 = $count3 = 0; |
| 92 |
$rules = array(); |
| 93 |
foreach ($grade as $value) { |
| 94 |
$key = $rules1[$count1++] . '-' . $rules2[$count2++]; |
| 95 |
$rules[$key][0] = $point[$count3++]; |
| 96 |
$rules[$key][1] = $value; |
| 97 |
} |
| 98 |
|
| 99 |
$grade_system = educare_check_status('grade_system'); |
| 100 |
$grade_system->rules->$rules_name = $rules; |
| 101 |
$data->grade_system = $grade_system; |
| 102 |
|
| 103 |
// now update desired data |
| 104 |
$wpdb->update( |
| 105 |
$table, //table |
| 106 |
array( // data |
| 107 |
// we need to encode our data for store array/object into databases |
| 108 |
"data" => json_encode($data) |
| 109 |
), |
| 110 |
|
| 111 |
array( //where |
| 112 |
'ID' => $id |
| 113 |
) |
| 114 |
|
| 115 |
); |
| 116 |
|
| 117 |
echo "<div class='notice notice-success is-dismissible'><p>Successfully updated " . wp_kses_post($rules_name) . " grading systems</p></div>"; |
| 118 |
} |
| 119 |
} else { |
| 120 |
echo educare_guide_for('db_error'); |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
/** =====================( Functions Details )====================== |
| 127 |
|
| 128 |
### Showing Grading System |
| 129 |
* usage => echo educare_save_results_system(); |
| 130 |
|
| 131 |
* @since 1.2.0 |
| 132 |
* @last-update 1.2.0 |
| 133 |
|
| 134 |
* @return void |
| 135 |
|
| 136 |
===================( function for Showing Grading System )=================== **/ |
| 137 |
|
| 138 |
function educare_show_grade_rule() { |
| 139 |
$grade_system = educare_check_status('grade_system'); |
| 140 |
$current = $grade_system->current; |
| 141 |
$grade_system = $grade_system->rules->$current; |
| 142 |
|
| 143 |
// echo '<pre>'; |
| 144 |
// print_r($grade_system); |
| 145 |
// echo '</pre>'; |
| 146 |
|
| 147 |
echo '<table class="grading-system"> |
| 148 |
<thead> |
| 149 |
<tr> |
| 150 |
<th>Class interval</th> |
| 151 |
<th>Grade point</th> |
| 152 |
<th>Letter grade</th> |
| 153 |
</tr> |
| 154 |
</thead>'; |
| 155 |
|
| 156 |
foreach ($grade_system as $marks => $value) { |
| 157 |
echo '<tr> |
| 158 |
<td>'. esc_html($marks) .'</td> |
| 159 |
<td>'. esc_html($value[0]) .'</td> |
| 160 |
<td>'. esc_html($value[1]) .'</td> |
| 161 |
</tr>'; |
| 162 |
} |
| 163 |
|
| 164 |
echo '</table>'; |
| 165 |
} |
| 166 |
|
| 167 |
?> |
| 168 |
|
| 169 |
|
| 170 |
<div class="educare_post"> |
| 171 |
<h1>Results System</h1> |
| 172 |
<blockquote>Here you can change your custom results system. Also, you can change or add your country's result rules by code, Educare provides some powerful functions to manage or add custom result rules based on your demand. If you don't khow, How to add custom results rules? Visit the Educare support forum to add your custom rules.</blockquote> |
| 173 |
|
| 174 |
<?php |
| 175 |
educare_save_results_system(); |
| 176 |
|
| 177 |
echo educare_guide_for('If you need to change default grading value, simply click edit button and inter your custom (Country) starndard rules. Allso, you can add your custom results rules using code. For this please visit Educare suppor forum or carfully read plugin readme files'); |
| 178 |
?> |
| 179 |
|
| 180 |
<p>Grading systems: <i id="help" title="How does it work? Click to view" class="dashicons dashicons-editor-help"></i></p> |
| 181 |
<div class="select"> |
| 182 |
<select id="Class" name="Class" class="form-control"> |
| 183 |
<option value="Default">Default</option> |
| 184 |
<option value="Custom" disabled>Custom</option> |
| 185 |
</select> |
| 186 |
</div> |
| 187 |
|
| 188 |
<div id="show_help" style="display: none;"> |
| 189 |
<div class="notice notice-success add_results"><p> |
| 190 |
<h3>How it's work?</h3> |
| 191 |
<p> |
| 192 |
We are mentioning the process how to calculate CGPA (GPA) from Marks in HSC. To do this, add up the grade points for the six major subjects and divide with 6 (total subject). For example, your grade points for <b>six</b> main subjects are listed below:</p><br> |
| 193 |
|
| 194 |
<table> |
| 195 |
<thead> |
| 196 |
<tr> |
| 197 |
<th>Subject</th> |
| 198 |
<th>Mark</th> |
| 199 |
<th>Grade Points</th> |
| 200 |
<th>Letter grade</th> |
| 201 |
</tr> |
| 202 |
</thead> |
| 203 |
<tbody> |
| 204 |
<tr> |
| 205 |
<td>Subject 1</td> |
| 206 |
<td>85</td> |
| 207 |
<td>5</td> |
| 208 |
<td>A+</td> |
| 209 |
</tr> |
| 210 |
<tr> |
| 211 |
<td>Subject 2</td> |
| 212 |
<td>70</td> |
| 213 |
<td>4</td> |
| 214 |
<td>A</td> |
| 215 |
</tr> |
| 216 |
<tr> |
| 217 |
<td>Subject 3</td> |
| 218 |
<td>68</td> |
| 219 |
<td>3.5</td> |
| 220 |
<td>A-</td> |
| 221 |
</tr> |
| 222 |
<tr> |
| 223 |
<td>Subject 4</td> |
| 224 |
<td>55</td> |
| 225 |
<td>3</td> |
| 226 |
<td>B</td> |
| 227 |
</tr> |
| 228 |
<tr> |
| 229 |
<td>Subject 5</td> |
| 230 |
<td>95</td> |
| 231 |
<td>5</td> |
| 232 |
<td>A+</td> |
| 233 |
</tr> |
| 234 |
<tr> |
| 235 |
<td>Subject 6</td> |
| 236 |
<td>80</td> |
| 237 |
<td>5</td> |
| 238 |
<td>A+</td> |
| 239 |
</tr> |
| 240 |
<tr> |
| 241 |
<td>Total</td> |
| 242 |
<td></td> |
| 243 |
<td>21</td> |
| 244 |
<td></td> |
| 245 |
</tr> |
| 246 |
<tr> |
| 247 |
<td><strong>GPA</strong></td> |
| 248 |
<td></td> |
| 249 |
<td><strong>25.5/6 = 4.25</strong></td> |
| 250 |
<td>A</td> |
| 251 |
</tr> |
| 252 |
</tbody> |
| 253 |
</table> |
| 254 |
|
| 255 |
<p> |
| 256 |
<ul style="list-style-type:circle;"> |
| 257 |
<li><strong>Step 1:</strong> Add the grade points i.e <code>5+4+3.5+3+5+5 = 25.5</code></li> |
| 258 |
<li><strong>Step 2:</strong> Divide the sum by (total subject) 6 i.e <code>25.5/6 = 4.25</code></li> |
| 259 |
<li>Thus, your GPA is <code>4.25</code></li> |
| 260 |
<li>And, Letter grade is <code>A</code></li> |
| 261 |
</ul> |
| 262 |
</p> |
| 263 |
|
| 264 |
<p>Basically, <strong>GPA = Total grade points/Total subject</strong></p> |
| 265 |
<br> |
| 266 |
<strong>How to define grade point and letter grade?</strong> |
| 267 |
<pre><code>if ($marks >= 80 and $marks <= 100) { $point = 5; }</code></pre>or<pre><code>if ($marks >= 80 and $marks <= 100) { $grade = 'A+'; }</code></pre> |
| 268 |
</p> |
| 269 |
</div> |
| 270 |
</div> |
| 271 |
|
| 272 |
<div id="result_msg"> |
| 273 |
<p><b>Default Rules</b></p> |
| 274 |
<?php educare_show_grade_rule();?> |
| 275 |
|
| 276 |
|
| 277 |
</div> |
| 278 |
<div id="update_button" class="button-container"> |
| 279 |
<button type="submit" name="save_grade_system" class="educare_button disabled"><i class="dashicons dashicons-update" disabled></i></button> |
| 280 |
<button id="edit_grade" type="submit" name="edit_grade_system" class="educare_button"><i class="dashicons dashicons-edit"></i></button> |
| 281 |
</div> |
| 282 |
</div> |
| 283 |
|
| 284 |
<script> |
| 285 |
$(document).on("click", "#edit_grade", function() { |
| 286 |
$(this).attr('disabled', true); |
| 287 |
var class_name = $('#Class').val(); |
| 288 |
$.ajax({ |
| 289 |
url: "<?php echo esc_url(admin_url('admin-ajax.php')); ?>", |
| 290 |
data: { |
| 291 |
action: 'educare_proccess_grade_system', |
| 292 |
class: class_name |
| 293 |
}, |
| 294 |
type: 'POST', |
| 295 |
success: function(data) { |
| 296 |
$('#result_msg').hide(); |
| 297 |
$('#result_msg').html(data).fadeIn(); |
| 298 |
$('#update_button').fadeOut(); |
| 299 |
$('#edit_grade').attr('disabled', false); |
| 300 |
}, |
| 301 |
error: function(data) { |
| 302 |
$('#result_msg').html("<?php echo educare_guide_for('db_error')?>"); |
| 303 |
}, |
| 304 |
}); |
| 305 |
}); |
| 306 |
|
| 307 |
$("#help").click(function() { |
| 308 |
$(this).css('color', 'green'); |
| 309 |
$("#show_help").slideToggle(); |
| 310 |
}); |
| 311 |
|
| 312 |
$(document).on("click", ".notice-dismiss", function(event) { |
| 313 |
$(this).parent('div').fadeOut(); |
| 314 |
$('#update_button').fadeIn(); |
| 315 |
}); |
| 316 |
|
| 317 |
</script> |
| 318 |
|
| 319 |
|