Skip to content

Commit

Permalink
Merge pull request #4136 from mjansenDatabay/review/8/php8-glossary
Browse files Browse the repository at this point in the history
PHP 8: Code Review `Glossary`
  • Loading branch information
alex40724 authored Mar 17, 2022
2 parents 99a5b2c + 234c785 commit f0eda34
Show file tree
Hide file tree
Showing 17 changed files with 97 additions and 147 deletions.
9 changes: 0 additions & 9 deletions Modules/Glossary/Definition/class.ilGlossaryDefPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,4 @@ public function beforePageContentUpdate(ilPageContent $a_page_content) : void
$a_page_content->autoLinkGlossaries($glos);
}
}

/**
* Get object id of repository object that contains this page,
* return 0 if page does not belong to a repo object
*/
public function getRepoObjId() : ?int
{
return $this->getParentId();
}
}
4 changes: 2 additions & 2 deletions Modules/Glossary/Export/class.ilGlossaryDataSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public function getSupportedVersions() : array
{
return array("5.1.0", "5.4.0");
}
public function getXmlNamespace(string $a_entity, string $a_schema_version) : string

protected function getXmlNamespace(string $a_entity, string $a_schema_version) : string
{
return "https://www.ilias.de/xml/Modules/Glossary/" . $a_entity;
}
Expand Down
6 changes: 3 additions & 3 deletions Modules/Glossary/Export/class.ilGlossaryExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function getXmlExportTailDependencies(
$tax_ids[$t_ids[0]] = $t_ids[0];
}
}
if (sizeof($tax_ids)) {
if (count($tax_ids)) {
$deps[] = array(
"component" => "Services/Taxonomy",
"entity" => "tax",
Expand All @@ -101,13 +101,13 @@ public function getXmlExportTailDependencies(
$advmd_ids = array();
foreach ($a_ids as $id) {
$rec_ids = $this->getActiveAdvMDRecords($id);
if (sizeof($rec_ids)) {
if (count($rec_ids)) {
foreach ($rec_ids as $rec_id) {
$advmd_ids[] = $id . ":" . $rec_id;
}
}
}
if (sizeof($advmd_ids)) {
if (count($advmd_ids)) {
$deps[] = array(
"component" => "Services/AdvancedMetaData",
"entity" => "advmd",
Expand Down
40 changes: 19 additions & 21 deletions Modules/Glossary/Presentation/class.ilGlossaryPresentationGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ public function listDefinitions(
// toc
if (count($defs) > 1 && $a_page_mode == ilPageObjectGUI::PRESENTATION) {
$def_tpl->setCurrentBlock("toc");
for ($j = 1; $j <= count($defs); $j++) {
for ($j = 1, $jMax = count($defs); $j <= $jMax; $j++) {
$def_tpl->setCurrentBlock("toc_item");
$def_tpl->setVariable("TOC_DEF_NR", $j);
$def_tpl->setVariable("TOC_DEF", $lng->txt("cont_definition"));
Expand All @@ -462,7 +462,7 @@ public function listDefinitions(
$def_tpl->parseCurrentBlock();
}

for ($j = 0; $j < count($defs); $j++) {
for ($j = 0, $jMax = count($defs); $j < $jMax; $j++) {
$def = $defs[$j];
$page_gui = new ilGlossaryDefPageGUI($def["id"]);
$this->basicPageGuiInit($page_gui);
Expand Down Expand Up @@ -511,27 +511,25 @@ public function listDefinitions(
foreach ($sources as $src) {
$type = explode(':', $src['type']);

if ($type[0] == 'lm') {
if ($type[1] == 'pg') {
$title = ilLMPageObject::_getPresentationTitle($src['id']);
$lm_id = ilLMObject::_lookupContObjID($src['id']);
$lm_title = ilObject::_lookupTitle($lm_id);
$def_tpl->setCurrentBlock('backlink_item');
$ref_ids = ilObject::_getAllReferences($lm_id);
$access = false;
foreach ($ref_ids as $rid) {
if ($ilAccess->checkAccess("read", "", $rid)) {
$access = true;
}
}
if ($access) {
$def_tpl->setCurrentBlock("backlink_item");
$def_tpl->setVariable("BACKLINK_LINK", ILIAS_HTTP_PATH . "/goto.php?target=" . $type[1] . "_" . $src['id']);
$def_tpl->setVariable("BACKLINK_ITEM", $lm_title . ": " . $title);
$def_tpl->parseCurrentBlock();
$backlist_shown = true;
if ($type[0] == 'lm' && $type[1] == 'pg') {
$title = ilLMPageObject::_getPresentationTitle($src['id']);
$lm_id = ilLMObject::_lookupContObjID($src['id']);
$lm_title = ilObject::_lookupTitle($lm_id);
$def_tpl->setCurrentBlock('backlink_item');
$ref_ids = ilObject::_getAllReferences($lm_id);
$access = false;
foreach ($ref_ids as $rid) {
if ($ilAccess->checkAccess("read", "", $rid)) {
$access = true;
}
}
if ($access) {
$def_tpl->setCurrentBlock("backlink_item");
$def_tpl->setVariable("BACKLINK_LINK", ILIAS_HTTP_PATH . "/goto.php?target=" . $type[1] . "_" . $src['id']);
$def_tpl->setVariable("BACKLINK_ITEM", $lm_title . ": " . $title);
$def_tpl->parseCurrentBlock();
$backlist_shown = true;
}
}
}
if ($backlist_shown) {
Expand Down
19 changes: 5 additions & 14 deletions Modules/Glossary/Presentation/class.ilPresentationListTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public function initFilter() : void

public function numericOrdering(string $a_field) : bool
{
if (substr($a_field, 0, 3) == "md_") {
if (strpos($a_field, "md_") === 0) {
$md_id = (int) substr($a_field, 3);
if ($this->adv_fields[$md_id]["type"] == ilAdvancedMDFieldDefinition::TYPE_DATE) {
return true;
Expand All @@ -187,14 +187,11 @@ protected function fillRow(array $a_set) : void
);
$this->tpl->parseCurrentBlock();
} else {
if (sizeof($defs)) {
for ($j = 0; $j < count($defs); $j++) {
if (count($defs)) {
for ($j = 0, $jMax = count($defs); $j < $jMax; $j++) {
$def = $defs[$j];
if (count($defs) > 1) {
if (!$this->offline) {
if (!empty($filter)) {
$this->ctrl->setParameter($this->parent_obj, "term", $filter);
}
$this->ctrl->setParameter($this->parent_obj, "term_id", $a_set["id"]);
$def_href = $this->ctrl->getLinkTarget($this->parent_obj, "listDefinitions");
$this->ctrl->clearParameters($this->parent_obj);
Expand All @@ -221,8 +218,7 @@ protected function fillRow(array $a_set) : void
}

if (!$this->page_config->getPreventHTMLUnmasking()) {
$short_str = str_replace("&lt;", "<", $short_str);
$short_str = str_replace("&gt;", ">", $short_str);
$short_str = str_replace(["&lt;", "&gt;"], ["<", ">"], $short_str);
}

// replace tex
Expand All @@ -244,9 +240,7 @@ protected function fillRow(array $a_set) : void
$short_str = ilMathJax::getInstance()->insertLatexImages(
$short_str,
'[tex]',
'[/tex]',
$this->parent_obj->getOfflineDirectory() . '/teximg',
'./teximg'
'[/tex]'
);
}

Expand Down Expand Up @@ -278,9 +272,6 @@ protected function fillRow(array $a_set) : void
if ($c["id"] == 0) {
$this->tpl->setCurrentBlock("link_start");
if (!$this->offline) {
if (!empty($filter)) {
$this->ctrl->setParameter($this->parent_obj, "term", $filter);
}
$this->ctrl->setParameter($this->parent_obj, "term_id", $a_set["id"]);
$this->tpl->setVariable(
"LINK_VIEW_TERM",
Expand Down
6 changes: 3 additions & 3 deletions Modules/Glossary/Term/class.ilGlossaryTerm.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function _getIdForImportId(
" ORDER BY create_date DESC";
$term_set = $ilDB->query($q);
while ($term_rec = $ilDB->fetchAssoc($term_set)) {
$glo_id = ilGlossaryTerm::_lookGlossaryID($term_rec["id"]);
$glo_id = self::_lookGlossaryID($term_rec["id"]);

$ref_ids = ilObject::_getAllReferences($glo_id); // will be 0 if import of lm is in progress (new import)
if (count($ref_ids) == 0 || ilObject::_hasUntrashedReference($glo_id)) {
Expand Down Expand Up @@ -294,7 +294,7 @@ public static function getTermList(
global $DIC;

if (count($a_glo_ref_id) > 1) {
$a_glo_id = array_map(function ($id) {
$a_glo_id = array_map(static function ($id) : int {
return ilObject::_lookupObjectId($id);
}, $a_glo_ref_id);
} else {
Expand Down Expand Up @@ -449,7 +449,7 @@ public function exportXML(

public static function getNumberOfUsages(int $a_term_id) : int
{
return count(ilGlossaryTerm::getUsages($a_term_id));
return count(self::getUsages($a_term_id));
}

public static function getUsages(int $a_term_id) : array
Expand Down
6 changes: 3 additions & 3 deletions Modules/Glossary/Term/class.ilGlossaryTermGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public function output(

$tpl->setVariable("TXT_TERM", $this->term->getTerm());

for ($j = 0; $j < count($defs); $j++) {
for ($j = 0, $jMax = count($defs); $j < $jMax; $j++) {
$def = $defs[$j];
$page_gui = new ilGlossaryDefPageGUI($def["id"]);
$page_gui->setSourcecodeDownloadScript("ilias.php?baseClass=ilGlossaryPresentationGUI&amp;ref_id=" . $this->ref_id);
Expand Down Expand Up @@ -338,7 +338,7 @@ public function getInternalLinks() : array
$defs = ilGlossaryDefinition::getDefinitionList($this->term->getId());

$term_links = array();
for ($j = 0; $j < count($defs); $j++) {
for ($j = 0, $jMax = count($defs); $j < $jMax; $j++) {
$def = $defs[$j];
$page = new ilGlossaryDefPage($def["id"]);
$page->buildDom();
Expand Down Expand Up @@ -394,7 +394,7 @@ public function listDefinitions() : void

$tpl->setVariable("TXT_TERM", $this->term->getTerm());

for ($j = 0; $j < count($defs); $j++) {
for ($j = 0, $jMax = count($defs); $j < $jMax; $j++) {
$def = $defs[$j];
$page_gui = new ilGlossaryDefPageGUI($def["id"]);
$page_gui->setStyleId(
Expand Down
36 changes: 16 additions & 20 deletions Modules/Glossary/Term/class.ilTermListTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,8 @@ public function __construct(
foreach ($this->adv_cols_order as $c) {
if ($c["id"] == 0) {
$this->addColumn($this->lng->txt("cont_term"), "term");
} else {
if (in_array("md_" . $c["id"], $this->selected_cols)) {
$this->addColumn($c["text"], "md_" . $c["id"]);
}
} elseif (in_array("md_" . $c["id"], $this->selected_cols)) {
$this->addColumn($c["text"], "md_" . $c["id"]);
}
}

Expand Down Expand Up @@ -143,7 +141,7 @@ public function getSelectableColumns() : array

public function numericOrdering(string $a_field) : bool
{
if (substr($a_field, 0, 3) == "md_") {
if (strpos($a_field, "md_") === 0) {
$md_id = (int) substr($a_field, 3);
if ($this->adv_fields[$md_id]["type"] == ilAdvancedMDFieldDefinition::TYPE_DATE) {
return true;
Expand Down Expand Up @@ -209,7 +207,7 @@ protected function fillRow(array $a_set) : void
}


for ($j = 0; $j < count($defs); $j++) {
for ($j = 0, $jMax = count($defs); $j < $jMax; $j++) {
$def = $defs[$j];


Expand Down Expand Up @@ -295,22 +293,20 @@ protected function fillRow(array $a_set) : void
$this->tpl->setCurrentBlock("td");
$this->tpl->setVariable("TD_VAL", $a_set["term"]);
$this->tpl->parseCurrentBlock();
} else {
if (in_array("md_" . $c["id"], $this->selected_cols)) {
$id = (int) $c["id"];

$val = " ";
if (isset($a_set["md_" . $id . "_presentation"])) {
$pb = $a_set["md_" . $id . "_presentation"]->getHTML();
if ($pb) {
$val = $pb;
}
} elseif (in_array("md_" . $c["id"], $this->selected_cols)) {
$id = (int) $c["id"];

$val = " ";
if (isset($a_set["md_" . $id . "_presentation"])) {
$pb = $a_set["md_" . $id . "_presentation"]->getHTML();
if ($pb) {
$val = $pb;
}

$this->tpl->setCurrentBlock("td");
$this->tpl->setVariable("TD_VAL", $val);
$this->tpl->parseCurrentBlock();
}

$this->tpl->setCurrentBlock("td");
$this->tpl->setVariable("TD_VAL", $val);
$this->tpl->parseCurrentBlock();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Glossary/Term/class.ilTermQuickListTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function fillRow(array $a_set) : void
$ilCtrl->setParameterByClass("ilglossarytermgui", "term_id", $a_set["id"]);

$sep = ": ";
for ($j = 0; $j < count($defs); $j++) {
for ($j = 0, $jMax = count($defs); $j < $jMax; $j++) {
$def = $defs[$j];

$this->tpl->setCurrentBlock("definition");
Expand Down
4 changes: 2 additions & 2 deletions Modules/Glossary/Term/class.ilTermUsagesTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ protected function fillRow(array $a_set) : void
//$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]);
switch ($cont_type) {
case "sahs":
$page_obj = new ilSCORM2004Page($usage["id"]);
$page_obj = new ilSCORM2004Page($usage["id"]); // This class does not exist (anymore?)
$lm_obj = new ilObjSAHSLearningModule($page_obj->getParentId(), false);
$item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type);
$item["obj_title"] = $lm_obj->getTitle();
$item["sub_txt"] = $this->lng->txt("pg");
$item["sub_title"] = ilSCORM2004PageNode::_lookupTitle($page_obj->getId());
$item["sub_title"] = ilSCORM2004PageNode::_lookupTitle($page_obj->getId()); // This class does not exist (anymore?)
$ref_id = $this->getFirstWritableRefId($lm_obj->getId());
if ($ref_id > 0) {
$item["obj_link"] = ilLink::_getStaticLink($ref_id, "sahs");
Expand Down
4 changes: 2 additions & 2 deletions Modules/Glossary/classes/class.ilECSGlossarySettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
*/
class ilECSGlossarySettings extends ilECSObjectSettings
{
protected function getECSObjectType()
protected function getECSObjectType() : string
{
return '/campusconnect/glossaries';
}

protected function buildJson(ilECSSetting $a_server)
protected function buildJson(ilECSSetting $a_server) : stdClass
{
$json = $this->getJsonCore('application/ecs-glossary');

Expand Down
Loading

0 comments on commit f0eda34

Please sign in to comment.