Conditions | 9 |
Paths | 26 |
Total Lines | 93 |
Code Lines | 72 |
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 |
||
100 | public function update() |
||
101 | { |
||
102 | $oldCertificateTable = 'gradebook_certificate_alternative'; |
||
103 | $base = api_get_path(WEB_UPLOAD_PATH); |
||
104 | if (Database::num_rows(Database::query("SHOW TABLES LIKE '$oldCertificateTable'")) == 1) { |
||
105 | $sql = "SELECT * FROM $oldCertificateTable"; |
||
106 | $res = Database::query($sql); |
||
107 | while ($row = Database::fetch_assoc($res)) { |
||
108 | $pathOrigin = $base.'certificates/'.$row['id'].'/'; |
||
109 | $params = [ |
||
110 | 'access_url_id' => api_get_current_access_url_id(), |
||
111 | 'c_id' => $row['c_id'], |
||
112 | 'session_id' => $row['session_id'], |
||
113 | 'content_course' => $row['content_course'], |
||
114 | 'contents_type' => intval($row['contents_type']), |
||
115 | 'contents' => $row['contents'], |
||
116 | 'date_change' => intval($row['date_change']), |
||
117 | 'date_start' => $row['date_start'], |
||
118 | 'date_end' => $row['date_end'], |
||
119 | 'place' => $row['place'], |
||
120 | 'type_date_expediction' => intval($row['type_date_expediction']), |
||
121 | 'day' => $row['day'], |
||
122 | 'month' => $row['month'], |
||
123 | 'year' => $row['year'], |
||
124 | 'logo_left' => $row['logo_left'], |
||
125 | 'logo_center' => $row['logo_center'], |
||
126 | 'logo_right' => $row['logo_right'], |
||
127 | 'seal' => $row['seal'], |
||
128 | 'signature1' => $row['signature1'], |
||
129 | 'signature2' => $row['signature2'], |
||
130 | 'signature3' => $row['signature3'], |
||
131 | 'signature4' => $row['signature4'], |
||
132 | 'signature_text1' => $row['signature_text1'], |
||
133 | 'signature_text2' => $row['signature_text2'], |
||
134 | 'signature_text3' => $row['signature_text3'], |
||
135 | 'signature_text4' => $row['signature_text4'], |
||
136 | 'background' => $row['background'], |
||
137 | 'margin_left' => intval($row['margin']), |
||
138 | 'margin_right' => 0, |
||
139 | 'certificate_default' => 0, |
||
140 | ]; |
||
141 | |||
142 | $certificateId = Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params); |
||
143 | |||
144 | // Image manager |
||
145 | $pathDestiny = $base.'certificates/'.$certificateId.'/'; |
||
|
|||
146 | |||
147 | if (!file_exists($pathDestiny)) { |
||
148 | mkdir($pathDestiny, api_get_permissions_for_new_directories(), true); |
||
149 | } |
||
150 | |||
151 | $imgList = [ |
||
152 | 'logo_left', |
||
153 | 'logo_center', |
||
154 | 'logo_right', |
||
155 | 'seal', |
||
156 | 'signature1', |
||
157 | 'signature2', |
||
158 | 'signature3', |
||
159 | 'signature4', |
||
160 | 'background', |
||
161 | ]; |
||
162 | foreach ($imgList as $value) { |
||
163 | if (!empty($row[$value])) { |
||
164 | copy( |
||
165 | $pathOrigin.$row[$value], |
||
166 | $pathDestiny.$row[$value] |
||
167 | ); |
||
168 | } |
||
169 | } |
||
170 | |||
171 | if ($row['certificate_default'] == 1) { |
||
172 | $params['c_id'] = 0; |
||
173 | $params['session_id'] = 0; |
||
174 | $params['certificate_default'] = 1; |
||
175 | $certificateId = Database::insert(self::TABLE_CUSTOMCERTIFICATE, $params); |
||
176 | $pathOrigin = $base.'certificates/default/'; |
||
177 | $pathDestiny = $base.'certificates/'.$certificateId.'/'; |
||
178 | foreach ($imgList as $value) { |
||
179 | if (!empty($row[$value])) { |
||
180 | copy( |
||
181 | $pathOrigin.$row[$value], |
||
182 | $pathDestiny.$row[$value] |
||
183 | ); |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | |||
189 | $sql = "DROP TABLE IF EXISTS $oldCertificateTable"; |
||
190 | Database::query($sql); |
||
191 | |||
192 | echo get_lang('MessageUpdate'); |
||
193 | } |
||
333 |