Skip to content

Commit 985f2f4

Browse files
Merge pull request #45 from prismathic/v3
Add application v3
2 parents 5a575a5 + 8555a98 commit 985f2f4

173 files changed

Lines changed: 168796 additions & 6109 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.php-cs-fixer.php

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<?php
2+
3+
use PhpCsFixer\Finder;
4+
use PhpCsFixer\Config;
5+
6+
$directoriesToExclude = [
7+
'bootstrap',
8+
'storage',
9+
'node_modules',
10+
];
11+
12+
$filesToExclude = [
13+
'*.blade.php',
14+
'index.php',
15+
'server.php',
16+
];
17+
18+
$fixerRules = [
19+
'@PSR2' => true,
20+
21+
'align_multiline_comment' => true,
22+
'array_indentation' => true,
23+
'array_syntax' => ['syntax' => 'short'],
24+
'binary_operator_spaces' => true,
25+
'blank_line_after_opening_tag' => true,
26+
'blank_line_before_statement' => true,
27+
'cast_spaces' => true,
28+
'class_attributes_separation' => ['elements' => ['method' => 'one']],
29+
'compact_nullable_typehint' => true,
30+
'concat_space' => true,
31+
'declare_equal_normalize' => true,
32+
'fully_qualified_strict_types' => true,
33+
'function_typehint_space' => true,
34+
'heredoc_to_nowdoc' => true,
35+
'include' => true,
36+
'linebreak_after_opening_tag' => true,
37+
'list_syntax' => ['syntax' => 'short'],
38+
'lowercase_cast' => true,
39+
'lowercase_static_reference' => true,
40+
'magic_constant_casing' => true,
41+
'magic_method_casing' => true,
42+
'method_argument_space' => ['on_multiline' => 'ensure_fully_multiline'],
43+
'method_chaining_indentation' => true,
44+
'modernize_types_casting' => true,
45+
'multiline_comment_opening_closing' => true,
46+
'multiline_whitespace_before_semicolons' => true,
47+
'native_function_casing' => true,
48+
'native_function_type_declaration_casing' => true,
49+
'new_with_braces' => true,
50+
'no_alias_functions' => true,
51+
'no_alternative_syntax' => true,
52+
'no_blank_lines_after_class_opening' => true,
53+
'no_blank_lines_after_phpdoc' => true,
54+
'no_empty_phpdoc' => true,
55+
'no_empty_statement' => true,
56+
'no_extra_blank_lines' => true,
57+
'no_leading_import_slash' => true,
58+
'no_leading_namespace_whitespace' => true,
59+
'no_mixed_echo_print' => true,
60+
'no_multiline_whitespace_around_double_arrow' => true,
61+
'no_null_property_initialization' => true,
62+
'no_short_bool_cast' => true,
63+
'no_spaces_around_offset' => true,
64+
'no_singleline_whitespace_before_semicolons' => true,
65+
'no_superfluous_elseif' => true,
66+
'no_trailing_comma_in_list_call' => true,
67+
'no_trailing_comma_in_singleline_array' => true,
68+
'no_unneeded_control_parentheses' => true,
69+
'no_unneeded_curly_braces' => true,
70+
'no_unreachable_default_argument_value' => true,
71+
'no_unused_imports' => true,
72+
'no_useless_else' => true,
73+
'no_useless_return' => true,
74+
'no_whitespace_before_comma_in_array' => true,
75+
'no_whitespace_in_blank_line' => true,
76+
'normalize_index_brace' => true,
77+
'not_operator_with_successor_space' => true,
78+
'object_operator_without_whitespace' => true,
79+
'ordered_imports' => ['sort_algorithm' => 'alpha'],
80+
'php_unit_method_casing' => true,
81+
'phpdoc_align' => ['align' => 'left', 'tags' => ['param', 'property', 'return', 'throws', 'type', 'var', 'method']],
82+
'phpdoc_indent' => true,
83+
'phpdoc_inline_tag_normalizer' => true,
84+
'phpdoc_no_access' => true,
85+
'phpdoc_no_package' => true,
86+
'phpdoc_no_useless_inheritdoc' => true,
87+
'phpdoc_scalar' => true,
88+
'phpdoc_separation' => true,
89+
'phpdoc_single_line_var_spacing' => true,
90+
'phpdoc_summary' => true,
91+
'phpdoc_to_comment' => true,
92+
'phpdoc_trim' => true,
93+
'phpdoc_types' => true,
94+
'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
95+
'phpdoc_var_without_name' => true,
96+
'psr_autoloading' => true,
97+
'return_type_declaration' => true,
98+
'self_accessor' => true,
99+
'self_static_accessor' => true,
100+
'short_scalar_cast' => true,
101+
'simplified_null_return' => true,
102+
'single_blank_line_before_namespace' => true,
103+
'single_line_comment_style' => true,
104+
'single_quote' => true,
105+
'space_after_semicolon' => true,
106+
'standardize_not_equals' => true,
107+
'switch_case_semicolon_to_colon' => true,
108+
'ternary_operator_spaces' => true,
109+
'ternary_to_null_coalescing' => true,
110+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
111+
'trim_array_spaces' => true,
112+
'unary_operator_spaces' => true,
113+
'whitespace_after_comma_in_array' => true,
114+
];
115+
116+
$finder = Finder::create()
117+
->exclude($directoriesToExclude)
118+
->notName($filesToExclude)
119+
->in(__DIR__);
120+
121+
return (new Config())
122+
->setRules($fixerRules)
123+
->setRiskyAllowed(true)
124+
->setFinder($finder);

2_START_CBT.bat

Lines changed: 0 additions & 1 deletion
This file was deleted.

app/Admin.php

Lines changed: 0 additions & 62 deletions
This file was deleted.

app/AdminSubject.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

app/Classes.php

Lines changed: 20 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,37 @@
22

33
namespace App;
44

5+
use Illuminate\Database\Eloquent\Builder;
56
use Illuminate\Database\Eloquent\Model;
6-
use App\Mark;
77

88
class Classes extends Model
99
{
1010
protected $table = 'classes';
1111

12-
public function students() {
13-
return $this->hasMany(User::class, 'class_id');
12+
/**
13+
* The "booted" method of the model.
14+
*
15+
* @return void
16+
*/
17+
protected static function booted()
18+
{
19+
static::addGlobalScope('active', function (Builder $builder) {
20+
$builder->where('name', '<>', 'Graduated');
21+
});
1422
}
1523

16-
public function subjects() {
17-
return $this->belongsToMany(Subject::class, 'class_subject','class_id');
24+
public function students()
25+
{
26+
return $this->hasMany(Student::class, 'class_id');
1827
}
1928

20-
public function admins() {
21-
return $this->belongsToMany(Admin::class);
29+
public function subjects()
30+
{
31+
return $this->belongsToMany(Subject::class, 'class_subject', 'class_id');
2232
}
2333

24-
public function hasStarted($subject_id) {
25-
//check if a specific class has started exams for a specific subject
26-
$mark = Mark::where('subject_id',$subject_id)->where('class_id', $this->id)->first();
27-
return $mark ? $mark->hasStarted : 0;
34+
public function getTrimmedNameAttribute()
35+
{
36+
return strtolower(str_replace(' ', '', $this->name));
2837
}
29-
30-
public function hasPendingExamToday($subject_id) {
31-
//check if a specific class has started exams for a specific subject
32-
$exam = Exam::where('subject_id',$subject_id)->where('class_id',$this->id)->orderBy('date','desc')->orderBy('updated_at','desc')->first();
33-
34-
if (!$exam) {
35-
return false;
36-
}
37-
else {
38-
//only return true for subjects that have questions
39-
return $exam->date == date('Y-m-d') && count($exam->questions) > 0;
40-
}
41-
}
42-
43-
public function getAllExams($subject_id) {
44-
$exams = Exam::where('subject_id',$subject_id)->where('class_id',$this->id)->orderBy('date','desc')->orderBy('updated_at','desc')->get();
45-
46-
return $exams;
47-
}
48-
49-
5038
}
51-
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use App\Classes;
6+
use App\Student;
7+
use Illuminate\Console\Command;
8+
use Illuminate\Support\Facades\DB;
9+
10+
class PromoteStudents extends Command
11+
{
12+
/**
13+
* The name and signature of the console command.
14+
*
15+
* @var string
16+
*/
17+
protected $signature = 'promote:students';
18+
19+
/**
20+
* The console command description.
21+
*
22+
* @var string
23+
*/
24+
protected $description = 'This command runs the action of promoting students to the next class.';
25+
26+
/**
27+
* Create a new command instance.
28+
*
29+
* @return void
30+
*/
31+
public function __construct()
32+
{
33+
parent::__construct();
34+
}
35+
36+
/**
37+
* Execute the console command.
38+
*
39+
* @return int
40+
*/
41+
public function handle()
42+
{
43+
$graduandClass = Classes::where('name', 'Graduated')->first();
44+
45+
try {
46+
Student::where('class_id', '<>', $graduandClass->id)
47+
->update(['class_id' => DB::raw('class_id + 1')]);
48+
49+
$this->info('Students promoted successfully');
50+
} catch (\Throwable $th) {
51+
$this->error('An error occurred while promoting students: '.$th->getMessage());
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)