Remove use of "api_" functions in entities

- This fires errors when serializing an object
pull/2624/head
Julio Montoya 8 years ago
parent 25ce366b12
commit ac98b7a990
  1. 3
      main/badge/criteria.php
  2. 4
      main/badge/issued.php
  3. 4
      main/badge/issued_all.php
  4. 32
      main/inc/lib/course.lib.php
  5. 30
      main/inc/lib/skill.lib.php
  6. 4
      main/inc/lib/webservices/Rest.php
  7. 2
      main/lp/lp_final_item.php
  8. 2
      main/session/about.php
  9. 36
      src/Chamilo/CoreBundle/Entity/Course.php
  10. 24
      src/Chamilo/CoreBundle/Entity/Skill.php
  11. 10
      src/Chamilo/CoreBundle/Entity/SkillRelUser.php

@ -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) {
@ -27,7 +28,7 @@ $skillInfo = [
'short_code' => $skill->getShortCode(),
'description' => $skill->getDescription(),
'criteria' => $skill->getCriteria(),
'badge_image' => $skill->getWebIconPath(),
'badge_image' => Skill::getWebIconPath($skill),
];
$template = new Template();

@ -63,7 +63,7 @@ $skillInfo = [
'short_code' => $skill->getShortCode(),
'description' => $skill->getDescription(),
'criteria' => $skill->getCriteria(),
'badge_image' => $skill->getWebIconPath(),
'badge_image' => Skill::getWebIconPath($skill),
'courses' => [],
];
@ -102,7 +102,7 @@ $skillIssueInfo = [
'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(),

@ -58,7 +58,7 @@ $skillInfo = [
'short_code' => $skill->getShortCode(),
'description' => $skill->getDescription(),
'criteria' => $skill->getCriteria(),
'badge_image' => $skill->getWebIconPath(),
'badge_image' => Skill::getWebIconPath($skill),
'courses' => [],
];
@ -86,7 +86,7 @@ foreach ($userSkills as $index => $skillIssue) {
'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(),

@ -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;
@ -6709,4 +6710,35 @@ class CourseManager
$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';
}
}

@ -2545,7 +2545,8 @@ class Skill extends Model
$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'),
@ -2874,4 +2875,31 @@ class Skill extends Model
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()}";
}
}

@ -220,7 +220,7 @@ class Rest extends WebService
'title' => $course->getTitle(),
'code' => $course->getCode(),
'directory' => $course->getDirectory(),
'urlPicture' => $course->getPicturePath(true),
'urlPicture' => CourseManager::getPicturePath($course, true),
'teachers' => $teachers,
];
}
@ -247,7 +247,7 @@ class Rest extends WebService
'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) {

@ -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'>

@ -121,7 +121,7 @@ foreach ($sessionCourses as $sessionCourse) {
$courses[] = [
'course' => $sessionCourse,
'description' => $courseDescription,
'image' => $sessionCourse->getPicturePath(true),
'image' => CourseManager::getPicturePath($sessionCourse, true),
'tags' => $courseTags,
'objectives' => $courseObjectives,
'topics' => $courseTopics,

@ -1176,36 +1176,6 @@ class Course
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
*
@ -1215,11 +1185,11 @@ class Course
{
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);

@ -254,30 +254,6 @@ class Skill
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.
*

@ -380,13 +380,13 @@ class SkillRelUser
*/
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;

Loading…
Cancel
Save