/** * Populate a single simple HTML Div Element (leaf). * * @global string $currentCourseLanguage * @param string $fullKey * @return string */ private function appendLeafDivElement($fullKey) { global $currentCourseLanguage; // init vars $keyLbl = (isset($GLOBALS['langCMeta'][$fullKey])) ? $GLOBALS['langCMeta'][$fullKey] : $fullKey; $fullKeyNoLang = $fullKey; $sameAsCourseLang = false; $lang = ''; if ($this->getAttribute('lang')) { $fullKey .= '_' . $this->getAttribute('lang'); $lang = ' (' . $GLOBALS['langCMeta'][(string) $this->getAttribute('lang')] . ')'; if ($this->getAttribute('lang') == langname_to_code($currentCourseLanguage)) { $sameAsCourseLang = true; } } // proper divs initializations $fieldStart = ""; if (array_key_exists($fullKey, CourseXMLConfig::$breakAccordionStartFields)) { $fieldStart .= "<div class='panel-group'> <div class='panel panel-default'> <div class='panel-heading'> <h3 class='panel-title'> <a data-toggle='collapse' href='#metacollapse-" . CourseXMLConfig::$breakAccordionStartFields[$fullKey] . "'>" . $GLOBALS['langMore'] . "</a> </h3> </div> <div id='metacollapse-" . CourseXMLConfig::$breakAccordionStartFields[$fullKey] . "' class='panel-collapse collapse'> <div class='panel-body'>"; } $cmetalabel = (in_array($fullKey, CourseXMLConfig::$mandatoryFields) || strpos($fullKey, 'course_unit_') === 0 || strpos($fullKey, 'course_numberOfUnits') === 0) ? 'cmetalabel cmetalabel-wd' : 'cmetalabelinaccordion cmetalabelinaccordion-wd'; $fieldStart .= "<div class='row margin-top-thin margin-bottom-thin'><div class='col-sm-3'><strong>" . q($keyLbl . $lang) . ":</strong></div><div class='col-sm-9'>"; $fieldEnd = "</div></div>"; if (in_array($fullKey, CourseXMLConfig::$breakAccordionEndFields)) { $fieldEnd .= "</div></div></div></div>"; } if (array_key_exists($fullKey, CourseXMLConfig::$breakFields)) { $fieldEnd .= "</div><div class='tab-pane fade' style='padding-top:20px' id='tabs-" . CourseXMLConfig::$breakFields[$fullKey] . "'>"; } // hidden/auto-generated fields if (in_array($fullKeyNoLang, CourseXMLConfig::$hiddenFields) && (!$this->getAttribute('lang') || $sameAsCourseLang)) { return; } // fields hidden from anonymous users if ((!isset($GLOBALS['course_code']) || $_SESSION['courses'][$GLOBALS['course_code']] == 0) && in_array($fullKeyNoLang, CourseXMLConfig::$hiddenFromAnonymousFields)) { return; } // print nothing for empty and non-breaking-necessary fields if (!array_key_exists($fullKey, CourseXMLConfig::$breakAccordionStartFields) && !in_array($fullKey, CourseXMLConfig::$breakAccordionEndFields) && !array_key_exists($fullKey, CourseXMLConfig::$breakFields) && strlen((string) $this) <= 0) { return; } // boolean fields if (in_array($fullKeyNoLang, CourseXMLConfig::$booleanFields)) { $value = (string) $this; if (empty($value)) { $value = 'false'; } $valueOut = $GLOBALS['langCMeta'][$value]; return $fieldStart . $valueOut . $fieldEnd; } // enumeration and multiple enumeration fields if (in_array($fullKeyNoLang, CourseXMLConfig::$enumerationFields)) { $valArr = CourseXMLConfig::getEnumerationValues($fullKey); $value = ""; if (!isset($valArr[(string) $this]) && isset($GLOBALS['langCMeta'][(string) $this])) { $value = $GLOBALS['langCMeta'][(string) $this]; } else { $value = $valArr[(string) $this]; } return $fieldStart . $value . $fieldEnd; } // multiple enumeration fiels if (in_array($fullKeyNoLang, CourseXMLConfig::$multiEnumerationFields)) { $valueOut = ''; $valArr = CourseXMLConfig::getEnumerationValues($fullKey); $i = 1; foreach (explode(',', (string) $this) as $value) { if ($i > 1) { $valueOut .= ', '; } $valueOut .= $valArr[$value]; $i++; } return $fieldStart . $valueOut . $fieldEnd; } // binary (file-upload) fields if (in_array($fullKeyNoLang, CourseXMLConfig::$binaryFields)) { $html = $fieldStart; $value = (string) $this; if (!empty($value)) { // image already exists $mime = (string) $this->getAttribute('mime'); $html .= "<img src='data:" . q($mime) . ";base64," . q($value) . "'/>"; } $html .= $fieldEnd; return $html; } if ($fullKey == 'course_language') { return $fieldStart . $GLOBALS['native_language_names_init'][((string) $this)] . $fieldEnd; } // all others get a typical printout return $fieldStart . q((string) $this) . $fieldEnd; }