Conditions | 2 |
Paths | 12 |
Total Lines | 122 |
Code Lines | 110 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
49 | public static function createOrUpdateStudentList() |
||
50 | { |
||
51 | try { |
||
52 | $output = new \Symfony\Component\Console\Output\ConsoleOutput(); |
||
53 | $output->writeln('creating : students_list_view'); |
||
54 | $query = DB::table('security_users as stu') |
||
55 | ->select( |
||
56 | "i.id as institution_id", |
||
57 | DB::raw("eg.name as `Grade`"), |
||
58 | DB::raw("stu.openemis_no as `Student ID`"), |
||
59 | DB::raw("stu.first_name as `Full Name`"), |
||
60 | DB::raw("GROUP_CONCAT(DISTINCT edus.name) as `Subjects`"), |
||
61 | DB::raw("IFNULL(LEFT(RIGHT(count(DISTINCT edus.id),8),4),'NA') as `Number of Subjects`"), |
||
62 | DB::raw("DATE_FORMAT(stu.date_of_birth ,'%W, %M %e, %Y ' ) as `Date of Birth`"), |
||
63 | DB::raw("g.name as `Gender`"), |
||
64 | DB::raw("IFNULL(nati.name, 'NA') as `Nationality`"), |
||
65 | DB::raw("IFNULL(idt.national_code, 'NA') as `Identity Type`"), |
||
66 | DB::raw("IFNULL(LEFT(RIGHT(stu.identity_number,8),4),'NA') as `Identity Number`"), |
||
67 | DB::raw("IFNULL (stu.identity_number,'na') as `Testing`"), |
||
68 | DB::raw("ic.name as `Class`"), |
||
69 | DB::raw("IFNULL(special_need_types.name, 'NA') as `Special Need Type`"), |
||
70 | DB::raw("IFNULL(special_need_difficulties.name, 'NA') as `Special Need`"), |
||
71 | DB::raw("IFNULL(stu.address, 'NA') as `Address`"), |
||
72 | DB::raw("IFNULL(acp.name, 'NA') as `BMI Academic Period`"), |
||
73 | DB::raw("DATE_FORMAT(bmit.date,'%W, %M %e, %Y ') as `BMI Date`"), |
||
74 | DB::raw("IFNULL(bmit.height, 'NA') as `Height`"), |
||
75 | DB::raw("IFNULL(bmit.weight, 'NA') as `Weight`"), |
||
76 | DB::raw("IFNULL(acps.name, 'NA') as `Academic Periods`"), |
||
77 | DB::raw("DATE_FORMAT(ist.start_date,'%W, %M %e, %Y ') as `Start Date`"), |
||
78 | DB::raw("IFNULL(bro.name, 'NA') as `Birth Registrar Office`"), |
||
79 | DB::raw("IFNULL(ds.name, 'NA') as `DS Office`"), |
||
80 | DB::raw("stu.address_area_id"), |
||
81 | DB::raw("IFNULL(sufu.first_name, 'NA') as `Father's Name`"), |
||
82 | DB::raw("IFNULL(natif.name, 'NA') as `Father's Nationality`"), |
||
83 | DB::raw("DATE_FORMAT(sufu.date_of_birth,'%W, %M %e, %Y ') as `Father's Date Of Birth`"), |
||
84 | DB::raw("IFNULL(sufu.address , 'N/A') as `Father's Address`"), |
||
85 | DB::raw("IFNULL(idtf.national_code, 'NA') as `Father's Identity Type`"), |
||
86 | DB::raw("IFNULL(sufu.identity_number, 'NA') as `Father's Identity Number` "), |
||
87 | DB::raw("IFNULL(sumu.first_name, 'N/A') as `Mothers's Name`"), |
||
88 | DB::raw("IFNULL(natim.name, 'NA') as `Mothers's Nationality`"), |
||
89 | DB::raw("DATE_FORMAT(sumu.date_of_birth,'%W, %M %e, %Y ') as `Mothers's Date Of Birth`"), |
||
90 | DB::raw("IFNULL(sumu.address , 'N/A') as `Mothers's Address`"), |
||
91 | DB::raw("IFNULL(idtm.national_code, 'NA') as `Mothers's Identity Type`"), |
||
92 | DB::raw("IFNULL(sumu.identity_number, 'NA') as `Mother's Identity Number`"), |
||
93 | DB::raw("IFNULL(sugu.first_name , 'N/A') as `Guardian's Name`"), |
||
94 | DB::raw("IFNULL(natig.name, 'NA') as `Guardian's Nationality`"), |
||
95 | DB::raw("DATE_FORMAT(sugu.date_of_birth,'%W, %M %e, %Y ') as `Guardian's Date Of Birth`"), |
||
96 | DB::raw("IFNULL(sugu.address , 'N/A') as `Guardian's Address`"), |
||
97 | DB::raw("IFNULL(idtg.national_code, 'NA') as `Guardian's Identity Type`"), |
||
98 | DB::raw("IFNULL(sugu.identity_number, 'NA') as `Guardian's Identity Number`"), |
||
99 | DB::raw("IFNULL(ubm.body_mass_index , 'N/A') as `BMI`") |
||
100 | ) |
||
101 | ->leftJoin("institution_students as ist", "ist.student_id", "stu.id") |
||
102 | ->leftJoin("institutions as i", "ist.institution_id", "i.id") |
||
103 | ->leftJoin("education_grades as eg", "eg.id", "i.id") |
||
104 | ->leftJoin("institution_class_students as ics", "ist.student_id", "ics.student_id") |
||
105 | ->leftJoin("institution_classes as ic", "ic.id", "ics.institution_class_id") |
||
106 | ->leftJoin("student_guardians as sgf", function ($join) { |
||
107 | $join->on("sgf.student_id", "stu.id"); |
||
108 | $join->where("sgf.guardian_relation_id", 1); |
||
109 | }) |
||
110 | ->leftJoin("security_users as sufu", "sgf.guardian_id", "sufu.id") |
||
111 | ->leftJoin("student_guardians as sgm", function ($join) { |
||
112 | $join->on("sgm.student_id", "stu.id"); |
||
113 | $join->where("sgm.guardian_relation_id", 2); |
||
114 | }) |
||
115 | ->leftJoin("security_users as sumu", "sgm.guardian_id", "sumu.id") |
||
116 | ->leftJoin("student_guardians as sg", function ($join) { |
||
117 | $join->on("sg.student_id", "stu.id"); |
||
118 | $join->where("sg.guardian_relation_id", 3); |
||
119 | }) |
||
120 | ->leftJoin("security_users as sugu", "sg.guardian_id", "sugu.id") |
||
121 | ->leftJoin("user_body_masses as ubm", "ubm.security_user_id", "ist.student_id") |
||
122 | ->leftJoin("genders as g", "stu.gender_id", "g.id") |
||
123 | ->leftJoin("area_administratives as bro", "stu.birthplace_area_id", "bro.id") |
||
124 | ->leftJoin("area_administratives as ds", "stu.address_area_id", "ds.id") |
||
125 | ->leftJoin("nationalities as nati", "stu.nationality_id", "nati.id") |
||
126 | ->leftJoin("identity_types as idt", "stu.nationality_id", "idt.id") |
||
127 | ->leftJoin("user_special_needs", "ist.id", "user_special_needs.security_user_id") |
||
128 | ->leftJoin("special_need_types", "special_need_types.id", "user_special_needs.special_need_type_id") |
||
129 | ->leftJoin("special_need_difficulties", "special_need_difficulties.id", "user_special_needs.special_need_difficulty_id") |
||
130 | ->leftJoin("user_body_masses as bmit", "stu.id", "bmit.security_user_id") |
||
131 | ->leftJoin("academic_periods as acp", "acp.id", "bmit.academic_period_id") |
||
132 | ->leftJoin("academic_periods as acps", "acps.id", "ist.academic_period_id") |
||
133 | ->leftJoin("institution_subject_students as iss", "stu.id", "iss.student_id") |
||
134 | ->leftJoin("education_subjects as edus", "edus.id", "iss.education_subject_id") |
||
135 | ->leftJoin("nationalities as natif", function ($join) { |
||
136 | $join->on("sufu.nationality_id", "natif.id"); |
||
137 | $join->where("sgf.guardian_relation_id", 1); |
||
138 | }) |
||
139 | ->leftJoin("nationalities as natim", function ($join) { |
||
140 | $join->on("sumu.nationality_id", "natim.id"); |
||
141 | $join->where("sgm.guardian_relation_id", 2); |
||
142 | }) |
||
143 | ->leftJoin("nationalities as natig", function ($join) { |
||
144 | $join->on("sugu.nationality_id", "natig.id"); |
||
145 | $join->where("sg.guardian_relation_id", 3); |
||
146 | }) |
||
147 | ->leftJoin("identity_types as idtf", function ($join) { |
||
148 | $join->on("sufu.nationality_id", "idtf.id"); |
||
149 | $join->where("sgf.guardian_relation_id", 1); |
||
150 | }) |
||
151 | ->leftJoin("identity_types as idtm", function ($join) { |
||
152 | $join->on("sumu.nationality_id", "idtm.id"); |
||
153 | $join->where("sgm.guardian_relation_id", 2); |
||
154 | }) |
||
155 | ->leftJoin("identity_types as idtg", function ($join) { |
||
156 | $join->on("sugu.nationality_id", "idtg.id"); |
||
157 | $join->where("sg.guardian_relation_id", 3); |
||
158 | }) |
||
159 | ->groupBy("stu.openemis_no") |
||
160 | ->groupBy("i.id"); |
||
161 | Schema::dropIfExists("students_list_view"); |
||
162 | Schema::createOrReplaceView('students_list_view', $query); |
||
163 | $exist = Schema::hasTable('students_list_view_table'); |
||
|
|||
164 | Schema::dropIfExists('students_list_view_table'); |
||
165 | DB::statement('CREATE TABLE students_list_view_table select * from students_list_view;'); |
||
166 | DB::statement('CREATE INDEX user_institution ON students_list_view_table (institution_id);'); |
||
167 | $output->writeln('created : students_list_view_table'); |
||
168 | $output->writeln('created : students_list_view'); |
||
169 | } catch (\Throwable $th) { |
||
170 | $output->writeln($th->getMessage()); |
||
171 | } |
||
400 |