From fcbc7eadaac9bb5e316aa831dba223e028eab922 Mon Sep 17 00:00:00 2001 From: Angel Fernando Quiroz Campos Date: Tue, 28 Mar 2017 11:45:21 -0500 Subject: [PATCH] Adding missing ChamiloApi class - refs BT#12212 --- .../CoreBundle/Component/Utils/ChamiloApi.php | 175 ++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.php diff --git a/src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.php b/src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.php new file mode 100644 index 0000000000..86a014108a --- /dev/null +++ b/src/Chamilo/CoreBundle/Component/Utils/ChamiloApi.php @@ -0,0 +1,175 @@ + '540x405 (3/4)', + '640x480' => '640x480 (3/4)', + '720x540' => '720x540 (3/4)', + '800x600' => '800x600 (3/4)', + '1024x576' => '1024x576 (16/9)', + '1024x768' => '1000x750 (3/4)', + '1280x720' => '1280x720 (16/9)', + '1280x860' => '1280x960 (3/4)', + '1400x1050' => '1400x1050 (3/4)', + '1600x900' => '1600x900 (16/9)', + ); + } + + /** + * Get the platform logo path + * @return null|string + */ + public static function getWebPlatformLogoPath() + { + $theme = api_get_visual_theme(); + $accessUrlId = api_get_current_access_url_id(); + $customLogoPath = "themes/$theme/images/header-logo-custom$accessUrlId.png"; + + if (file_exists(api_get_path(SYS_PUBLIC_PATH) . "css/$customLogoPath")) { + return api_get_path(WEB_CSS_PATH) . $customLogoPath; + } + + $originalLogoPath = "themes/$theme/images/header-logo.png"; + + if (file_exists(api_get_path(SYS_CSS_PATH) . $originalLogoPath)) { + return api_get_path(WEB_CSS_PATH) . $originalLogoPath; + } + + return null; + } + + /** + * Get the platform logo. + * Return a if the logo image exists. Otherwise return a

with the institution name. + * @param array $imageAttributes Optional. + * @return string + */ + public static function getPlatformLogo($imageAttributes = []) + { + $logoPath = self::getWebPlatformLogoPath(); + $institution = api_get_setting('Institution'); + $institutionUrl = api_get_setting('InstitutionUrl'); + $siteName = api_get_setting('siteName'); + + if ($logoPath === null) { + $headerLogo = \Display::url($siteName, api_get_path(WEB_PATH) . 'index.php'); + + if (!empty($institutionUrl) && !empty($institution)) { + $headerLogo .= ' - ' . \Display::url($institution, $institutionUrl); + } + + $courseInfo = api_get_course_info(); + + if (isset($courseInfo['extLink']) && !empty($courseInfo['extLink']['name'])) { + $headerLogo .= ' - '; + + if (!empty($courseInfo['extLink']['url'])) { + $headerLogo .= \Display::url( + $courseInfo['extLink']['name'], + $courseInfo['extLink']['url'], + ['class' => 'extLink'] + ); + } else if (!empty($courseInfo['extLink']['url'])) { + $headerLogo .= $courseInfo['extLink']['url']; + } + } + + return \Display::tag('h2', $headerLogo, ['class' => 'text-left']); + } + + $image = \Display::img($logoPath, $institution, $imageAttributes); + + return \Display::url($image, api_get_path(WEB_PATH) . 'index.php'); + } + + /** + * Like strip_tags(), but leaves an additional space and removes only the given tags + * @param string $string + * @param array $tags Tags to be removed + * @return string The original string without the given tags + */ + public static function stripGivenTags($string, $tags) + { + foreach ($tags as $tag) { + $string2 = preg_replace('#]*>#i', ' ', $string); + if ($string2 != $string) { + $string = preg_replace('/<' . $tag . '[^>]*>/i', ' ', $string2); + } + } + return $string; + } + /** + * Adds or Subtract a time in hh:mm:ss to a datetime + * @param string $time Time in hh:mm:ss format + * @param string $datetime Datetime as accepted by the Datetime class constructor + * @param bool $operation True for Add, False to Subtract + * @return string + */ + public static function addOrSubTimeToDateTime($time, $datetime = 'now', $operation = true) + { + $date = new \DateTime($datetime); + + $hours = $minutes = $seconds = 0; + + sscanf($time, "%d:%d:%d", $hours, $minutes, $seconds); + + $timeSeconds = isset($seconds) ? $hours * 3600 + $minutes * 60 + $seconds : $hours * 60 + $minutes; + + if ($operation) { + $date->add(new \DateInterval('PT' . $timeSeconds . 'S')); + } else { + $date->sub(new \DateInterval('PT' . $timeSeconds . 'S')); + } + + + return $date->format('Y-m-d H:i:s'); + } +}