Skip to content

Commit

Permalink
Remove use of "api_" functions in entities
Browse files Browse the repository at this point in the history
- This fires errors when serializing an object
  • Loading branch information
jmontoyaa committed Aug 2, 2018
1 parent 25ce366 commit ac98b7a
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 72 deletions.
3 changes: 2 additions & 1 deletion main/badge/criteria.php
Expand Up @@ -11,6 +11,7 @@
require_once __DIR__.'/../inc/global.inc.php';

$entityManager = Database::getManager();
/** @var \Chamilo\CoreBundle\Entity\Skill $skill */
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $_GET['id']);

if (!$skill) {
Expand All @@ -27,7 +28,7 @@
'short_code' => $skill->getShortCode(),
'description' => $skill->getDescription(),
'criteria' => $skill->getCriteria(),
'badge_image' => $skill->getWebIconPath(),
'badge_image' => Skill::getWebIconPath($skill),
];

$template = new Template();
Expand Down
4 changes: 2 additions & 2 deletions main/badge/issued.php
Expand Up @@ -63,7 +63,7 @@
'short_code' => $skill->getShortCode(),
'description' => $skill->getDescription(),
'criteria' => $skill->getCriteria(),
'badge_image' => $skill->getWebIconPath(),
'badge_image' => Skill::getWebIconPath($skill),
'courses' => [],
];

Expand Down Expand Up @@ -102,7 +102,7 @@
'user_id' => $skillIssue->getUser()->getId(),
'user_complete_name' => $skillIssue->getUser()->getCompleteName(),
'skill_id' => $skillIssue->getSkill()->getId(),
'skill_badge_image' => $skillIssue->getSkill()->getWebIconPath(),
'skill_badge_image' => Skill::getWebIconPath($skillIssue->getSkill()),
'skill_name' => $skillIssue->getSkill()->getName(),
'skill_short_code' => $skillIssue->getSkill()->getShortCode(),
'skill_description' => $skillIssue->getSkill()->getDescription(),
Expand Down
4 changes: 2 additions & 2 deletions main/badge/issued_all.php
Expand Up @@ -58,7 +58,7 @@
'short_code' => $skill->getShortCode(),
'description' => $skill->getDescription(),
'criteria' => $skill->getCriteria(),
'badge_image' => $skill->getWebIconPath(),
'badge_image' => Skill::getWebIconPath($skill),
'courses' => [],
];

Expand Down Expand Up @@ -86,7 +86,7 @@
'user_id' => $skillIssue->getUser()->getId(),
'user_complete_name' => $skillIssue->getUser()->getCompleteName(),
'skill_id' => $skillIssue->getSkill()->getId(),
'skill_badge_image' => $skillIssue->getSkill()->getWebIconPath(),
'skill_badge_image' => Skill::getWebIconPath($skillIssue->getSkill()),
'skill_name' => $skillIssue->getSkill()->getName(),
'skill_short_code' => $skillIssue->getSkill()->getShortCode(),
'skill_description' => $skillIssue->getSkill()->getDescription(),
Expand Down
32 changes: 32 additions & 0 deletions main/inc/lib/course.lib.php
@@ -1,6 +1,7 @@
<?php
/* For licensing terms, see /license.txt*/

use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\ExtraField as EntityExtraField;
use Chamilo\CourseBundle\Component\CourseCopy\CourseBuilder;
use Chamilo\CourseBundle\Component\CourseCopy\CourseRestorer;
Expand Down Expand Up @@ -6709,4 +6710,35 @@ private static function fillCourse($courseInfo, $params, $authorId = 0)
$courseFieldValue = new ExtraFieldValue('course');
$courseFieldValue->saveFieldValues($params);
}

/**
* @param Course $course
*
* @return bool
*/
public static function hasPicture(Course $course)
{
return file_exists(api_get_path(SYS_COURSE_PATH).$course->getDirectory().'/course-pic85x85.png');
}

/**
* Get the course picture path.
*
* @param Course $course
* @param bool $fullSize
*
* @return null|string
*/
public static function getPicturePath(Course $course, $fullSize = false)
{
if (!self::hasPicture($course)) {
return null;
}

if ($fullSize) {
return api_get_path(WEB_COURSE_PATH).$course->getDirectory().'/course-pic.png';
}

return api_get_path(WEB_COURSE_PATH).$course->getDirectory().'/course-pic85x85.png';
}
}
30 changes: 29 additions & 1 deletion main/inc/lib/skill.lib.php
Expand Up @@ -2545,7 +2545,8 @@ public static function addSkillsToForm(FormValidator $form, $typeId, $itemId = 0
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();

$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=search_skills_in_course&course_id='.$courseId.'&session_id='.$sessionId;
$url = api_get_path(WEB_AJAX_PATH).
'skill.ajax.php?a=search_skills_in_course&course_id='.$courseId.'&session_id='.$sessionId;
$form->addSelectAjax(
'skills',
get_lang('Skills'),
Expand Down Expand Up @@ -2874,4 +2875,31 @@ public static function saveSkillsToCourse($skills, $courseId, $sessionId)

return true;
}

/**
*
* Get the icon (badge image) URL.
*
* @param SkillEntity $skill
* @param bool $getSmall Optional. Allow get the small image
*
* @return string
*
*/
public static function getWebIconPath(SkillEntity $skill, $getSmall = false)
{
if ($getSmall) {
if (empty($skill->getIcon())) {
return \Display::return_icon('badges-default.png', null, null, ICON_SIZE_BIG, null, true);
}

return api_get_path(WEB_UPLOAD_PATH).'badges/'.sha1($skill->getName()).'-small.png';
}

if (empty($skill->getIcon())) {
return \Display::return_icon('badges-default.png', null, null, ICON_SIZE_HUGE, null, true);
}

return api_get_path(WEB_UPLOAD_PATH)."badges/{$skill->getIcon()}";
}
}
4 changes: 2 additions & 2 deletions main/inc/lib/webservices/Rest.php
Expand Up @@ -220,7 +220,7 @@ public function getUserCourses()
'title' => $course->getTitle(),
'code' => $course->getCode(),
'directory' => $course->getDirectory(),
'urlPicture' => $course->getPicturePath(true),
'urlPicture' => CourseManager::getPicturePath($course, true),
'teachers' => $teachers,
];
}
Expand All @@ -247,7 +247,7 @@ public function getCourseInfo()
'title' => $this->course->getTitle(),
'code' => $this->course->getCode(),
'directory' => $this->course->getDirectory(),
'urlPicture' => $this->course->getPicturePath(true),
'urlPicture' => CourseManager::getPicturePath($this->course, true),
'teachers' => $teachers,
'tools' => array_map(
function ($tool) {
Expand Down
2 changes: 1 addition & 1 deletion main/lp/lp_final_item.php
Expand Up @@ -257,7 +257,7 @@ function generateLPFinalItemTemplateBadgeLinks($userId, $courseId, $sessionId =
<div class='row'>
<div class='col-md-2 col-xs-4'>
<div class='thumbnail'>
<img class='skill-badge-img' src='".$skill->getWebIconPath()."' >
<img class='skill-badge-img' src='".Skill::getWebIconPath($skill)."' >
</div>
</div>
<div class='col-md-8 col-xs-8'>
Expand Down
2 changes: 1 addition & 1 deletion main/session/about.php
Expand Up @@ -121,7 +121,7 @@
$courses[] = [
'course' => $sessionCourse,
'description' => $courseDescription,
'image' => $sessionCourse->getPicturePath(true),
'image' => CourseManager::getPicturePath($sessionCourse, true),
'tags' => $courseTags,
'objectives' => $courseObjectives,
'topics' => $courseTopics,
Expand Down
36 changes: 3 additions & 33 deletions src/Chamilo/CoreBundle/Entity/Course.php
Expand Up @@ -1176,36 +1176,6 @@ public function setCurrentSession(Session $session)
return $this;
}

/**
* Check if the course has a picture.
*
* @return bool
*/
public function hasPicture()
{
return file_exists(api_get_path(SYS_COURSE_PATH).$this->directory.'/course-pic85x85.png');
}

/**
* Get the course picture path.
*
* @param bool $fullSize
*
* @return null|string
*/
public function getPicturePath($fullSize = false)
{
if (!$this->hasPicture()) {
return null;
}

if ($fullSize) {
return api_get_path(WEB_COURSE_PATH).$this->directory.'/course-pic.png';
}

return api_get_path(WEB_COURSE_PATH).$this->directory.'/course-pic85x85.png';
}

/**
* @param CourseRelUser $subscription
*
Expand All @@ -1215,11 +1185,11 @@ private function hasSubscription(CourseRelUser $subscription)
{
if ($this->getUsers()->count()) {
$criteria = Criteria::create()->where(
Criteria::expr()->eq("user", $subscription->getUser())
Criteria::expr()->eq('user', $subscription->getUser())
)->andWhere(
Criteria::expr()->eq("status", $subscription->getStatus())
Criteria::expr()->eq('status', $subscription->getStatus())
)->andWhere(
Criteria::expr()->eq("relationType", $subscription->getRelationType())
Criteria::expr()->eq('relationType', $subscription->getRelationType())
);

$relation = $this->getUsers()->matching($criteria);
Expand Down
24 changes: 0 additions & 24 deletions src/Chamilo/CoreBundle/Entity/Skill.php
Expand Up @@ -254,30 +254,6 @@ public function getIcon()
return $this->icon;
}

/**
* Get the icon (badge image) URL.
*
* @param bool $getSmall Optional. Allow get the small image
*
* @return string
*/
public function getWebIconPath($getSmall = false)
{
if ($getSmall) {
if (empty($this->icon)) {
return \Display::return_icon('badges-default.png', null, null, ICON_SIZE_BIG, null, true);
}

return api_get_path(WEB_UPLOAD_PATH).'badges/'.sha1($this->name).'-small.png';
}

if (empty($this->icon)) {
return \Display::return_icon('badges-default.png', null, null, ICON_SIZE_HUGE, null, true);
}

return api_get_path(WEB_UPLOAD_PATH)."badges/{$this->icon}";
}

/**
* Set criteria.
*
Expand Down
10 changes: 5 additions & 5 deletions src/Chamilo/CoreBundle/Entity/SkillRelUser.php
Expand Up @@ -380,13 +380,13 @@ public function getIssueUrlAll()
*/
public function getAssertionUrl()
{
$url = api_get_path(WEB_CODE_PATH)."badge/assertion.php?";
$url = api_get_path(WEB_CODE_PATH).'badge/assertion.php?';

$url .= http_build_query([
'user' => $this->user->getId(),
'skill' => $this->skill->getId(),
'course' => $this->course ? $this->course->getId() : 0,
'session' => $this->session ? $this->session->getId() : 0,
'user' => $this->getUser()->getId(),
'skill' => $this->getSkill()->getId(),
'course' => $this->course ? $this->getCourse()->getId() : 0,
'session' => $this->session ? $this->getSession()->getId() : 0,
]);

return $url;
Expand Down

0 comments on commit ac98b7a

Please sign in to comment.