Skip to content

Commit f13da45

Browse files
committed
Minor: Format code
1 parent 6ab51ae commit f13da45

File tree

7 files changed

+48
-41
lines changed

7 files changed

+48
-41
lines changed

main/cron/import_users_from_xlsx.php

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
* - Username format: lastname + first letter of each firstname word; for active duplicates, append next letter from last firstname part
1818
* - For 3+ occurrences of lastname + firstname, append increasing letters from last firstname part (e.g., jpii, jpiii)
1919
* - Generates unmatched_db_users.xlsx listing database users not found in the input XLSX based on username
20-
* - Exports terminal output to import-yyyymmddhhiiss.log in the output directory
20+
* - Exports terminal output to import-yyyymmddhhiiss.log in the output directory.
2121
*/
2222

2323
// Ensure the script is run from the command line
2424
if (php_sapi_name() !== 'cli') {
25-
die('This script must be run from the command line.');
25+
exit('This script must be run from the command line.');
2626
}
2727

2828
// Configuration
@@ -57,11 +57,11 @@
5757
// Validate and prepare output directory
5858
if (!is_dir($outputDir)) {
5959
if (!mkdir($outputDir, 0755, true)) {
60-
die("Error: Could not create output directory '$outputDir'\n");
60+
exit("Error: Could not create output directory '$outputDir'\n");
6161
}
6262
}
6363
if (!is_writable($outputDir)) {
64-
die("Error: Output directory '$outputDir' is not writable\n");
64+
exit("Error: Output directory '$outputDir' is not writable\n");
6565
}
6666
// Ensure trailing slash for consistency
6767
$outputDir = rtrim($outputDir, '/').'/';
@@ -80,7 +80,7 @@
8080
echo " Output directory: $outputDir\n";
8181

8282
if (empty($xlsxFile) || !file_exists($xlsxFile)) {
83-
die("Usage: php import_users_from_xlsx.php <path_to_xlsx_file> [-p|--proceed] [-o <directory>|--output-dir=<directory>]\n");
83+
exit("Usage: php import_users_from_xlsx.php <path_to_xlsx_file> [-p|--proceed] [-o <directory>|--output-dir=<directory>]\n");
8484
}
8585

8686
// Initialize database connection
@@ -94,7 +94,7 @@
9494
$worksheet = $phpExcel->getActiveSheet();
9595
$xlsxRows = $worksheet->toArray();
9696
} catch (Exception $e) {
97-
die("Error loading XLSX file: {$e->getMessage()}\n");
97+
exit("Error loading XLSX file: {$e->getMessage()}\n");
9898
}
9999

100100
// Map XLSX columns to Chamilo database user table fields
@@ -115,7 +115,7 @@
115115
foreach ($xlsxColumnMap as $xlsxHeader => $dbField) {
116116
$index = array_search($xlsxHeader, $xlsxHeaders);
117117
if ($index === false) {
118-
die("Missing required column: {$xlsxHeader}\n");
118+
exit("Missing required column: {$xlsxHeader}\n");
119119
}
120120
$xlsxColumnIndices[$dbField] = $index;
121121
}
@@ -138,21 +138,25 @@ function normalizeName($name)
138138
{
139139
$name = strtolower(trim($name));
140140
$name = preg_replace('/[\s-]+/', ' ', $name);
141+
141142
return $name;
142143
}
143144

144145
// Remove accents from strings
145-
function removeAccents($str) {
146+
function removeAccents($str)
147+
{
146148
$str = str_replace(
147-
['à','á','â','ã','ä','ç','è','é','ê','ë','ì','í','î','ï','ñ','ò','ó','ô','õ','ö','ù','ú','û','ü','ý','ÿ','À','Á','Â','Ã','Ä','Å','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ñ','Ò','Ó','Ô','Õ','Ö','Ù','Ú','Û','Ü','Ý'],
148-
['a','a','a','a','a','c','e','e','e','e','i','i','i','i','n','o','o','o','o','o','u','u','u','u','y','y','A','A','A','A','A','A','C','E','E','E','E','I','I','I','I','N','O','O','O','O','O','U','U','U','U','Y'],
149+
['à', 'á', 'â', 'ã', 'ä', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ú', 'û', 'ü', 'ý', 'ÿ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'Ù', 'Ú', 'Û', 'Ü', 'Ý'],
150+
['a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'u', 'y', 'y', 'A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'N', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U', 'U', 'Y'],
149151
$str
150152
);
153+
151154
return $str;
152155
}
153156

154157
// Generate login based on lastname and firstname
155-
function generateProposedLogin($xlsxLastname, $xlsxFirstname, $isActive, &$usedLogins) {
158+
function generateProposedLogin($xlsxLastname, $xlsxFirstname, $isActive, &$usedLogins)
159+
{
156160
$lastname = strtolower(trim(removeAccents($xlsxLastname)));
157161
$lastname = preg_replace('/[\s-]+/', '', $lastname);
158162

@@ -210,13 +214,16 @@ function generateProposedLogin($xlsxLastname, $xlsxFirstname, $isActive, &$usedL
210214

211215
// Store login with active status
212216
$usedLogins['logins'][$login] = ['active' => $isActive];
217+
213218
return $login;
214219
}
215220

216221
// Generate XLSX files for missing fields and duplicates
217-
function createMissingFieldFile($filename, $rows, $columns) {
222+
function createMissingFieldFile($filename, $rows, $columns)
223+
{
218224
if (empty($rows)) {
219225
echo "No rows to write for $filename\n";
226+
220227
return;
221228
}
222229

@@ -526,7 +533,7 @@ function createMissingFieldFile($filename, $rows, $columns) {
526533
'Official Code' => $xlsxUserData['official_code'],
527534
'E-mail' => $xlsxUserData['email'],
528535
'External User ID' => $xlsxMatricule,
529-
'Updated Fields' => implode(', ', array_map(function($update) { return trim(explode(':', $update)[0]); }, $updates)),
536+
'Updated Fields' => implode(', ', array_map(function ($update) { return trim(explode(':', $update)[0]); }, $updates)),
530537
];
531538
} else {
532539
echo " Error: Could not update user (username: $dbUsername)\n";
@@ -561,7 +568,7 @@ function createMissingFieldFile($filename, $rows, $columns) {
561568
'Official Code' => $xlsxUserData['official_code'],
562569
'E-mail' => $xlsxUserData['email'],
563570
'External User ID' => $xlsxMatricule,
564-
'Updated Fields' => implode(', ', array_map(function($update) { return trim(explode(':', $update)[0]); }, $updates)),
571+
'Updated Fields' => implode(', ', array_map(function ($update) { return trim(explode(':', $update)[0]); }, $updates)),
565572
];
566573
}
567574
} else {

main/exercise/exercise.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4089,7 +4089,7 @@ function ($answerId) use ($objAnswerTmp) {
40894089
for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
40904090
$answer = $objAnswerTmp->selectAnswer($answerId);
40914091
$hideComment = (int) $this->getPageConfigurationAttribute('hide_comment');
4092-
if (1 === $hideComment) {
4092+
if (1 === $hideComment) {
40934093
$answerComment = null;
40944094
} else {
40954095
$answerComment = $objAnswerTmp->selectComment($answerId);

main/inc/lib/PortfolioController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,13 +1418,13 @@ public function view(Portfolio $item, $urlUser)
14181418

14191419
$urlUserString = "";
14201420
if (isset($urlUser)) {
1421-
$urlUserString = "user=" . $urlUser;
1421+
$urlUserString = "user=".$urlUser;
14221422
}
14231423

14241424
$actions = [];
14251425
$actions[] = Display::url(
14261426
Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM),
1427-
$this->baseUrl . $urlUserString
1427+
$this->baseUrl.$urlUserString
14281428
);
14291429

14301430
if ($this->itemBelongToOwner($item)) {
@@ -3696,7 +3696,6 @@ private function createFormStudentFilter(bool $listByUser = false, bool $listHig
36963696
}
36973697

36983698
$frmStudentList->addHtml("<p>$link</p>");
3699-
37003699
}
37013700

37023701
return $frmStudentList;

main/inc/lib/ScheduledAnnouncement.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function returnSimpleForm($id, $url, $action, $sessionInfo = [])
120120
$id,
121121
'use_base_progress'
122122
);
123-
$form->addNumeric ('progress',
123+
$form->addNumeric('progress',
124124
get_lang('Progress'),
125125
[
126126
'step' => 1,
@@ -237,7 +237,7 @@ public function returnForm($url, $action, $sessionInfo = [])
237237
$form->addHtml('</div>');
238238

239239
$form->addHtml('<div id="base_progress" style="display:none">');
240-
$form->addNumeric ('progress',
240+
$form->addNumeric('progress',
241241
get_lang('Progress'),
242242
[
243243
'step' => 1,

main/inc/lib/banner.lib.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ function return_navigation_array()
512512
];
513513
}
514514

515-
function buildParentCourseCategoriesMenu(array &$navigation) {
515+
function buildParentCourseCategoriesMenu(array &$navigation)
516+
{
516517
if (!api_get_configuration_value('display_menu_use_course_categories')
517518
|| 'true' !== api_get_setting('course_catalog_published')
518519
) {

main/inc/lib/exercise.lib.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7479,20 +7479,6 @@ public static function getFeedbackComments(int $examId): string
74797479
return $output;
74807480
}
74817481

7482-
private static function subscribeSessionWhenFinishedFailure(int $exerciseId): void
7483-
{
7484-
$failureSession = self::getSessionWhenFinishedFailure($exerciseId);
7485-
7486-
if ($failureSession) {
7487-
SessionManager::subscribeUsersToSession(
7488-
$failureSession->getId(),
7489-
[api_get_user_id()],
7490-
SESSION_VISIBLE_READ_ONLY,
7491-
false
7492-
);
7493-
}
7494-
}
7495-
74967482
public static function replaceTermsInContent(string $search, string $replace): array
74977483
{
74987484
$replacements = [
@@ -7807,7 +7793,7 @@ public static function replaceTermsInContent(string $search, string $replace): a
78077793
],
78087794
Database::get_main_table(TABLE_MAIN_BLOCK) => [
78097795
'id' => ['name', 'description', 'path'],
7810-
]
7796+
],
78117797
];
78127798

78137799
if (api_get_configuration_value('attendance_allow_comments')) {
@@ -7821,13 +7807,13 @@ public static function replaceTermsInContent(string $search, string $replace): a
78217807
}
78227808

78237809
$changes = array_map(
7824-
fn($table) => 0,
7810+
fn ($table) => 0,
78257811
$replacements
78267812
);
78277813

78287814
foreach ($replacements as $table => $replacement) {
78297815
foreach ($replacement as $idColumn => $columns) {
7830-
$keys = array_map(fn($column) => "$column LIKE %?%", $columns);
7816+
$keys = array_map(fn ($column) => "$column LIKE %?%", $columns);
78317817
$values = array_fill(0, count($columns), $search);
78327818

78337819
$result = Database::select(
@@ -7837,15 +7823,15 @@ public static function replaceTermsInContent(string $search, string $replace): a
78377823
'where' => [
78387824
implode(' OR ', $keys) => $values,
78397825
],
7840-
'order' => "$idColumn ASC"
7826+
'order' => "$idColumn ASC",
78417827
]
78427828
);
78437829

78447830
foreach ($result as $row) {
78457831
$attributes = array_combine(
78467832
$columns,
78477833
array_map(
7848-
fn($column) => preg_replace('#'.$search.'#', $replace, $row[$column]),
7834+
fn ($column) => preg_replace('#'.$search.'#', $replace, $row[$column]),
78497835
$columns
78507836
)
78517837
);
@@ -7867,4 +7853,18 @@ public static function replaceTermsInContent(string $search, string $replace): a
78677853

78687854
return $changes;
78697855
}
7856+
7857+
private static function subscribeSessionWhenFinishedFailure(int $exerciseId): void
7858+
{
7859+
$failureSession = self::getSessionWhenFinishedFailure($exerciseId);
7860+
7861+
if ($failureSession) {
7862+
SessionManager::subscribeUsersToSession(
7863+
$failureSession->getId(),
7864+
[api_get_user_id()],
7865+
SESSION_VISIBLE_READ_ONLY,
7866+
false
7867+
);
7868+
}
7869+
}
78707870
}

plugin/h5pimport/src/H5pImplementation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function getPlatformInfo()
4343
// TODO: Implement getPlatformInfo() method.
4444
}
4545

46-
public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $fullData = false, $headers = Array(), $files = Array(), $method = 'POST')
46+
public function fetchExternalData($url, $data = null, $blocking = true, $stream = null, $fullData = false, $headers = [], $files = [], $method = 'POST')
4747
{
4848
// TODO: Implement fetchExternalData() method.
4949
}

0 commit comments

Comments
 (0)