@@ -46,7 +46,7 @@ public function initFile(int $sessionId, int $userId, int $exerciseId, int $exeI
4646
4747 $ this ->storePath = $ this ->generateDirectory ();
4848 $ this ->fileName = $ this ->generateFileName ();
49- $ this ->filePath = $ this ->storePath . $ this ->fileName ;
49+ $ this ->filePath = $ this ->storePath . $ this ->fileName ;
5050 }
5151
5252 /**
@@ -62,7 +62,7 @@ public function createAnswersForm($form): void
6262 'application/vnd.openxmlformats-officedocument.wordprocessingml.document ' , // .docx
6363 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ' , // .xlsx
6464 'application/msword ' , // .doc
65- 'application/vnd.ms-excel ' // .xls
65+ 'application/vnd.ms-excel ' , // .xls
6666 ];
6767
6868 $ form ->addElement ('file ' , 'office_file ' , get_lang ('UploadOfficeDoc ' ));
@@ -73,7 +73,7 @@ public function createAnswersForm($form): void
7373 $ form ->addElement ('static ' , 'file_hint ' , get_lang ('AllowedFormats ' ), "<p> {$ allowedExtensions }</p> " );
7474
7575 if (!empty ($ this ->extra )) {
76- $ fileUrl = api_get_path (WEB_COURSE_PATH ) . $ this ->getStoredFilePath ();
76+ $ fileUrl = api_get_path (WEB_COURSE_PATH ). $ this ->getStoredFilePath ();
7777 $ form ->addElement ('static ' , 'current_office_file ' , get_lang ('CurrentOfficeDoc ' ), "<a href=' {$ fileUrl }' target='_blank'> {$ this ->extra }</a> " );
7878 }
7979
@@ -98,8 +98,8 @@ public function processAnswersCreation($form, $exercise): void
9898 {
9999 if (!empty ($ _FILES ['office_file ' ]['name ' ])) {
100100 $ extension = pathinfo ($ _FILES ['office_file ' ]['name ' ], PATHINFO_EXTENSION );
101- $ tempFilename = "office_ " . uniqid () . ". " . $ extension ;
102- $ tempPath = sys_get_temp_dir () . '/ ' . $ tempFilename ;
101+ $ tempFilename = "office_ " . uniqid (). ". " . $ extension ;
102+ $ tempPath = sys_get_temp_dir (). '/ ' . $ tempFilename ;
103103
104104 if (!move_uploaded_file ($ _FILES ['office_file ' ]['tmp_name ' ], $ tempPath )) {
105105 return ;
@@ -117,7 +117,7 @@ public function processAnswersCreation($form, $exercise): void
117117 }
118118
119119 $ filename = "office_ " .$ this ->iid .". " .$ extension ;
120- $ filePath = $ uploadDir . $ filename ;
120+ $ filePath = $ uploadDir. $ filename ;
121121
122122 if (!rename ($ tempPath , $ filePath )) {
123123 return ;
@@ -128,20 +128,6 @@ public function processAnswersCreation($form, $exercise): void
128128 }
129129 }
130130
131- /**
132- * Generate the necessary directory for OnlyOffice documents.
133- */
134- private function generateDirectory (): string
135- {
136- $ exercisePath = api_get_path (SYS_COURSE_PATH ).$ this ->course ['path ' ]."/exercises/onlyoffice/ {$ this ->exerciseId }/ {$ this ->iid }/ " ;
137-
138- if (!is_dir ($ exercisePath )) {
139- mkdir ($ exercisePath , 0775 , true );
140- }
141-
142- return rtrim ($ exercisePath , '/ ' ) . '/ ' ;
143- }
144-
145131 /**
146132 * Get the stored file path dynamically.
147133 */
@@ -184,7 +170,7 @@ public function getFileUrl(bool $loadFromDatabase = false): ?string
184170
185171 $ filePath = $ this ->getStoredFilePath ();
186172
187- if (is_file (api_get_path (SYS_COURSE_PATH ) . $ filePath )) {
173+ if (is_file (api_get_path (SYS_COURSE_PATH ). $ filePath )) {
188174 return $ filePath ;
189175 }
190176
@@ -206,11 +192,25 @@ public function return_header(Exercise $exercise, $counter = null, $score = [])
206192 return $ header ;
207193 }
208194
195+ /**
196+ * Generate the necessary directory for OnlyOffice documents.
197+ */
198+ private function generateDirectory (): string
199+ {
200+ $ exercisePath = api_get_path (SYS_COURSE_PATH ).$ this ->course ['path ' ]."/exercises/onlyoffice/ {$ this ->exerciseId }/ {$ this ->iid }/ " ;
201+
202+ if (!is_dir ($ exercisePath )) {
203+ mkdir ($ exercisePath , 0775 , true );
204+ }
205+
206+ return rtrim ($ exercisePath , '/ ' ).'/ ' ;
207+ }
208+
209209 /**
210210 * Generate the file name for the OnlyOffice document.
211211 */
212212 private function generateFileName (): string
213213 {
214- return 'office_ ' . uniqid ();
214+ return 'office_ ' . uniqid ();
215215 }
216216}
0 commit comments