Replacing $app[orm.em]

1.10.x
jmontoya 11 years ago
parent b42b2cd944
commit c930e64162
  1. 2
      main/auth/inscription.php
  2. 13
      main/exercice/exercise.class.php
  3. 3
      main/exercice/exercise_reminder.php
  4. 36
      main/exercice/testcategory.class.php
  5. 15
      main/exercice/tests_category.php
  6. 4
      main/group/group_edit.php
  7. 6
      main/inc/ajax/exercise.ajax.php
  8. 8
      main/inc/lib/api.lib.php
  9. 3
      main/inc/lib/document.lib.php
  10. 5
      main/inc/lib/extra_field.lib.php
  11. 32
      main/inc/lib/extra_field_value.lib.php
  12. 3
      main/inc/lib/fileManager.lib.php
  13. 50
      main/newscorm/learnpath.class.php

@ -448,7 +448,7 @@ if ($form->validate()) {
}
// Symfony way to login as a user
$user = $app['orm.em']->getRepository('ChamiloLMS\Entity\User')->find($user_id);
$user = Database::getManager()->getRepository('ChamiloLMSCoreBundle:User')->find($user_id);
// Here, "secured" is the name of the firewall in your security.yml
$token = new UsernamePasswordToken($user, $user->getPassword(), 'secured', $user->getRoles());

@ -957,9 +957,9 @@ class Exercise
// Adding category info in the category list with question list:
if (!empty($questions_by_category)) {
global $app;
$em = $app['orm.em'];
$repo = $em->getRepository('ChamiloLMS\Entity\CQuizCategory');
$em = Database::getManager();
$repo = $em->getRepository('ChamiloLMSCoreBundle:CQuizCategory');
$newCategoryList = array();
@ -974,7 +974,7 @@ class Exercise
if (!empty($cat['parent_id'])) {
if (!isset($parentsLoaded[$cat['parent_id']])) {
$categoryEntity = $em->find('ChamiloLMS\Entity\CQuizCategory', $cat['parent_id']);
$categoryEntity = $em->find('ChamiloLMSCoreBundle:CQuizCategory', $cat['parent_id']);
$parentsLoaded[$cat['parent_id']] = $categoryEntity;
} else {
$categoryEntity = $parentsLoaded[$cat['parent_id']];
@ -1746,9 +1746,8 @@ class Exercise
// QuestionScoreType
global $app;
$em = $app['orm.em'];
$types = $em->getRepository('ChamiloLMS\Entity\QuestionScore')->findAll();
$em = Database::getManager();
$types = $em->getRepository('ChamiloLMSCoreBundle:QuestionScore')->findAll();
$options = array(
'0' => get_lang('SelectAnOption')
);

@ -204,8 +204,7 @@ foreach ($question_list as $questionId) {
}
$rootCategories = null;
global $app;
$repo = $app['orm.em']->getRepository('ChamiloLMS\Entity\CQuizCategory');
$repo = Database::getManager()->getRepository('ChamiloLMSCoreBundle:CQuizCategory');
foreach ($objQuestionTmp->category_list as $categoryId) {
$cat = $repo->find($categoryId);
$parentCat = $repo->getPath($cat);

@ -3,6 +3,8 @@
/**
* @author hubert.borderiou & jmontoya
*/
use ChamiloLMS\CoreBundle\CQuizCategory;
class Testcategory
{
public $id;
@ -127,21 +129,19 @@ class Testcategory
// lets add in BD if not the same name
if ($data['nb'] <= 0) {
// @todo inject the app in the class
global $app;
$category = new ChamiloLMS\Entity\CQuizCategory();
$category = new CQuizCategory();
$category->setTitle($this->name);
$category->setDescription($this->description);
if (!empty($parent_id)) {
$parent = $app['orm.ems']['db_write']->find('\Entity\CQuizCategory', $parent_id);
$parent = Database::getManager()->find('\Entity\CQuizCategory', $parent_id);
if ($parent) {
$category->setParent($parent);
}
}
$category->setCId($course_id);
$app['orm.ems']['db_write']->persist($category);
$app['orm.ems']['db_write']->flush();
Database::getManager()->persist($category);
Database::getManager()->flush();
if ($category->getIid()) {
return $category->getIid();
@ -158,9 +158,7 @@ class Testcategory
*/
public function modifyCategory()
{
// @todo inject the app in the class
global $app;
$category = $app['orm.ems']['db_write']->find('\Entity\CQuizCategory', $this->id);
$category = Database::getManager()->find('\Entity\CQuizCategory', $this->id);
if (!$category) {
return false;
}
@ -180,7 +178,7 @@ class Testcategory
if ($this->id == $parentId) {
continue;
}
$parent = $app['orm.ems']['db_write']->find('\Entity\CQuizCategory', $parentId);
$parent = Database::getManager()->find('\Entity\CQuizCategory', $parentId);
if ($parent) {
$category->setParent($parent);
}
@ -190,8 +188,8 @@ class Testcategory
$category->setParent(null);
}
$app['orm.ems']['db_write']->persist($category);
$app['orm.ems']['db_write']->flush();
Database::getManager()->persist($category);
Database::getManager()->flush();
if ($category->getIid()) {
return $category->getIid();
@ -208,8 +206,7 @@ class Testcategory
*/
public function removeCategory()
{
global $app;
$category = $app['orm.ems']['db_write']->find('\Entity\CQuizCategory', $this->id);
$category = Database::getManager()->find('ChamiloLMS\CoreBundle\CQuizCategory', $this->id);
if (!$category) {
return false;
}
@ -221,10 +218,10 @@ class Testcategory
return false;
}
$repo = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\CQuizCategory');
$repo = Database::getManager()->getRepository('ChamiloLMSCoreBundle:CQuizCategory');
$repo->removeFromTree($category);
// clear cached nodes
$app['orm.ems']['db_write']->clear();
Database::getManager()->clear();
return true;
}
@ -932,7 +929,6 @@ class Testcategory
*/
public static function get_stats_table_by_attempt($exercise_id, $category_list = array(), $categoryMinusOne = false)
{
global $app;
if (empty($category_list)) {
return null;
}
@ -956,8 +952,8 @@ class Testcategory
$total = $category_list['total'];
unset($category_list['total']);
}
$em = $app['orm.em'];
$repo = $em->getRepository('ChamiloLMS\Entity\CQuizCategory');
$em = Database::getManager();
$repo = $em->getRepository('ChamiloLMSCoreBundle:CQuizCategory');
$redefineCategoryList = array();
@ -965,7 +961,7 @@ class Testcategory
$globalCategoryScore = array();
foreach ($category_list as $category_id => $category_item) {
$cat = $em->find('ChamiloLMS\Entity\CQuizCategory', $category_id);
$cat = $em->find('ChamiloLMSCoreBundle:CQuizCategory', $category_id);
$path = $repo->getPath($cat);
$categoryName = $category_name_list[$category_id];

@ -234,9 +234,8 @@ function display_add_category($type) {
// Display category list
function display_categories($type = 'simple') {
global $app;
function display_categories($type = 'simple')
{
$options = array(
'decorate' => true,
'rootOpen' => '<ul>',
@ -278,22 +277,22 @@ function display_categories($type = 'simple') {
);
// @todo put this in a function
$repo = $app['orm.em']->getRepository('ChamiloLMS\Entity\CQuizCategory');
$repo = Database::getManager()->getRepository('ChamiloLMSCoreBundle:CQuizCategory');
$query = null;
if ($type == 'global') {
$query = $app['orm.em']
$query = Database::getManager()
->createQueryBuilder()
->select('node')
->from('ChamiloLMS\Entity\CQuizCategory', 'node')
->from('ChamiloLMSCoreBundle:CQuizCategory', 'node')
->where('node.cId = 0')
->orderBy('node.root, node.lft', 'ASC')
->getQuery();
} else {
$query = $app['orm.em']
$query = Database::getManager()
->createQueryBuilder()
->select('node')
->from('ChamiloLMS\Entity\CQuizCategory', 'node')
->from('ChamiloLMSCoreBundle:CQuizCategory', 'node')
->where('node.cId = :courseId')
//->add('orderBy', 'node.title ASC')
->orderBy('node.root, node.lft', 'ASC')

@ -138,10 +138,10 @@ $form->add_textfield('name', get_lang('GroupName'));
$form->addElement('textarea', 'description', get_lang('Description'), array('class' => 'span6', 'rows' => 6));
// Getting course info
$course = $app['orm.em']->getRepository('ChamiloLMS\Entity\Course')->find(api_get_course_int_id());
$course = Database::getManager()->getRepository('ChamiloLMSCoreBundle:Course')->find(api_get_course_int_id());
//Getting subscribed students
$subscribedUsers = $app['orm.em']->getRepository('ChamiloLMS\Entity\Course')->getSubscribedStudents($course);
$subscribedUsers = Database::getManager()->getRepository('ChamiloLMSCoreBundle:Course')->getSubscribedStudents($course);
$subscribedUsers = $subscribedUsers->getQuery();
$subscribedUsers = $subscribedUsers->execute();

@ -108,15 +108,15 @@ switch ($action) {
$courseId = api_get_course_int_id();
$em = $this->get('orm.em');
$repo = $em->getRepository('ChamiloLMS\Entity\CQuizCategory');
$em = Database::getManager();
$repo = $em->getRepository('ChamiloLMSCoreBundle:CQuizCategory');
$json_items = array();
if (!empty($items)) {
foreach ($items as $item) {
if ($item['c_id'] == 0) {
if ($filterByGlobal) {
$cat = $em->find('ChamiloLMS\Entity\CQuizCategory', $item['iid']);
$cat = $em->find('ChamiloLMSCoreBundle:CQuizCategory', $item['iid']);
$idList = array();
if ($cat) {
$path = $repo->getPath($cat);

@ -10,6 +10,8 @@
use \ChamiloSession as Session;
use Symfony\Component\Validator\Constraints as Assert;
use ChamiloLMS\CoreBundle\Entity\User;
use ChamiloLMS\CoreBundle\Entity\Course;
/**
* Constants declaration
@ -1690,7 +1692,7 @@ function api_generate_password($length = 8) {
*/
function api_check_password($password) {
global $app;
$constraints = ChamiloLMS\Entity\User::getPasswordConstraints();
$constraints = User::getPasswordConstraints();
$errors = $app['validator']->validateValue($password, $constraints);
return count($errors) > 0 ? false : true;
}
@ -3095,7 +3097,7 @@ function api_item_property_update(
if (is_array($_course)) {
$course_id = $_course['real_id'];
} else {
if ($_course instanceof \ChamiloLMS\Entity\Course) {
if ($_course instanceof Course) {
$course_id = $_course->getId();
}
}
@ -6091,7 +6093,7 @@ function api_set_default_visibility($course, $item_id, $tool_id, $group_id = nul
if (is_array($course)) {
$courseId = $course['real_id'];
} else {
if ($course instanceof \ChamiloLMS\Entity\Course) {
if ($course instanceof Course) {
$courseId = $course->getId();
}
}

@ -9,6 +9,7 @@
*
* @package chamilo.library
*/
use ChamiloLMS\CoreBundle\Entity\Course;
/**
* Code
@ -960,7 +961,7 @@ class DocumentManager
if (is_array($_course)) {
$course_id = $_course['real_id'];
} else {
if ($_course instanceof \ChamiloLMS\Entity\Course) {
if ($_course instanceof Course) {
$course_id = $_course->getId();
$_course = api_get_course_info_by_id($course_id);
}

@ -735,10 +735,11 @@ class ExtraField extends Model
'extra_'.$field_details['field_variable'].'_comment',
$field_details['field_display_text'].' '.get_lang('Comment')
);
$em = Database::getManager();
$extraFieldValue = new ExtraFieldValue($this->type);
$repo = $app['orm.em']->getRepository($extraFieldValue->entityName);
$repoLog = $app['orm.em']->getRepository('Gedmo\Loggable\Entity\LogEntry');
$repo = $em->getRepository($extraFieldValue->entityName);
$repoLog = $em->getRepository('Gedmo\Loggable\Entity\LogEntry');
$newEntity = $repo->findOneBy(
array(
$this->handlerEntityId => $itemId,

@ -6,11 +6,15 @@
* fields for any datatype
* @package chamilo.library
*/
use ChamiloLMS\CoreBundle\QuestionFieldValues;
use ChamiloLMS\CoreBundle\CourseFieldValues;
use ChamiloLMS\CoreBundle\UserFieldValues;
use ChamiloLMS\CoreBundle\SessionFieldValues;
/**
* Class managing the values in extra fields for any datatype
* @package chamilo.library.extrafields
*/
class ExtraFieldValue extends Model
{
public $type = null;
@ -36,31 +40,31 @@ class ExtraFieldValue extends Model
$this->table = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_COURSE_FIELD);
$this->author_id = 'user_id';
$this->entityName = 'ChamiloLMS\Entity\CourseFieldValues';
$this->entityName = 'ChamiloLMSCoreBundle:CourseFieldValues';
break;
case 'user':
$this->table = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_USER_FIELD);
$this->author_id = 'author_id';
$this->entityName = 'ChamiloLMS\Entity\UserFieldValues';
$this->entityName = 'ChamiloLMSCoreBundle:UserFieldValues';
break;
case 'session':
$this->table = Database::get_main_table(TABLE_MAIN_SESSION_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_SESSION_FIELD);
$this->author_id = 'user_id';
$this->entityName = 'ChamiloLMS\Entity\SessionFieldValues';
$this->entityName = 'ChamiloLMSCoreBundle:SessionFieldValues';
break;
case 'question':
$this->table = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_QUESTION_FIELD);
$this->author_id = 'user_id';
$this->entityName = 'ChamiloLMS\Entity\QuestionFieldValues';
$this->entityName = 'ChamiloLMSCoreBundle:QuestionFieldValues';
break;
case 'lp':
$this->table = Database::get_main_table(TABLE_MAIN_LP_FIELD_VALUES);
$this->table_handler_field = Database::get_main_table(TABLE_MAIN_LP_FIELD);
$this->author_id = 'lp_id';
//$this->entityName = 'ChamiloLMS\Entity\QuestionFieldValues';
//$this->entityName = 'ChamiloLMSCoreBundle:QuestionFieldValues';
break;
default:
//unmanaged datatype, return false to let the caller know it
@ -260,22 +264,22 @@ class ExtraFieldValue extends Model
global $app;
switch($this->type) {
case 'question':
$extraFieldValue = new ChamiloLMS\Entity\QuestionFieldValues();
$extraFieldValue = new QuestionFieldValues();
$extraFieldValue->setUserId(api_get_user_id());
$extraFieldValue->setQuestionId($params[$this->handler_id]);
break;
case 'course':
$extraFieldValue = new ChamiloLMS\Entity\CourseFieldValues();
$extraFieldValue = new CourseFieldValues();
$extraFieldValue->setUserId(api_get_user_id());
$extraFieldValue->setQuestionId($params[$this->handler_id]);
break;
case 'user':
$extraFieldValue = new ChamiloLMS\Entity\UserFieldValues();
$extraFieldValue = new UserFieldValues();
$extraFieldValue->setUserId($params[$this->handler_id]);
$extraFieldValue->setAuthorId(api_get_user_id());
break;
case 'session':
$extraFieldValue = new ChamiloLMS\Entity\SessionFieldValues();
$extraFieldValue = new SessionFieldValues();
$extraFieldValue->setUserId(api_get_user_id());
$extraFieldValue->setSessionId($params[$this->handler_id]);
break;
@ -319,22 +323,22 @@ class ExtraFieldValue extends Model
global $app;
switch($this->type) {
case 'question':
$extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\QuestionFieldValues')->find($field_values['id']);
$extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMSCoreBundle:QuestionFieldValues')->find($field_values['id']);
$extraFieldValue->setUserId(api_get_user_id());
$extraFieldValue->setQuestionId($params[$this->handler_id]);
break;
case 'course':
$extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\CourseFieldValues')->find($field_values['id']);
$extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMSCoreBundle:CourseFieldValues')->find($field_values['id']);
$extraFieldValue->setUserId(api_get_user_id());
$extraFieldValue->setCourseCode($params[$this->handler_id]);
break;
case 'user':
$extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\UserFieldValues')->find($field_values['id']);
$extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMSCoreBundle:UserFieldValues')->find($field_values['id']);
$extraFieldValue->setUserId(api_get_user_id());
$extraFieldValue->setAuthorId(api_get_user_id());
break;
case 'session':
$extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMS\Entity\SessionFieldValues')->find($field_values['id']);
$extraFieldValue = $app['orm.ems']['db_write']->getRepository('ChamiloLMSCoreBundle:SessionFieldValues')->find($field_values['id']);
$extraFieldValue->setUserId(api_get_user_id());
$extraFieldValue->setSessionId($params[$this->handler_id]);
break;

@ -15,6 +15,7 @@
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use ChamiloLMS\CoreBundle\Entity\Course;
class FileManager
{
@ -1627,7 +1628,7 @@ class FileManager
if (is_array($course)) {
$c_id = $course['real_id'];
} else {
if ($course instanceof \ChamiloLMS\Entity\Course) {
if ($course instanceof Course) {
$c_id = $course->getId();
}
}

@ -13,6 +13,8 @@
* Defines the learnpath parent class
* @package chamilo.learnpath
*/
use ChamiloLMS\CoreBundle\Entity\CLpCategory;
use \ChamiloSession as Session;
class learnpath
@ -10543,9 +10545,8 @@ EOD;
static function create_category($params)
{
global $app;
$em = $app['orm.ems']['db_write'];
$item = new ChamiloLMS\Entity\CLpCategory();
$em = Database::getManager();
$item = new CLpCategory();
$item->setName($params['name']);
$item->setCId($params['c_id']);
$em->persist($item);
@ -10554,9 +10555,8 @@ EOD;
static function update_category($params)
{
global $app;
$em = $app['orm.ems']['db_write'];
$item = $em->find('ChamiloLMS\Entity\CLpCategory', $params['id']);
$em = Database::getManager();
$item = $em->find('ChamiloLMSCoreBundle:CLpCategory', $params['id']);
if ($item) {
$item->setName($params['name']);
$item->setCId($params['c_id']);
@ -10567,9 +10567,8 @@ EOD;
static function move_up_category($id)
{
global $app;
$em = $app['orm.ems']['db_write'];
$item = $em->find('ChamiloLMS\Entity\CLpCategory', $id);
$em = Database::getManager();
$item = $em->find('ChamiloLMSCoreBundle:CLpCategory', $id);
if ($item) {
$position = $item->getPosition() - 1;
$item->setPosition($position);
@ -10580,9 +10579,8 @@ EOD;
static function move_down_category($id)
{
global $app;
$em = $app['orm.ems']['db_write'];
$item = $em->find('ChamiloLMS\Entity\CLpCategory', $id);
$em = Database::getManager();
$item = $em->find('ChamiloLMSCoreBundle:CLpCategory', $id);
if ($item) {
$position = $item->getPosition() + 1;
$item->setPosition($position);
@ -10593,12 +10591,11 @@ EOD;
static function get_count_categories($course_id)
{
global $app;
if (empty($course_id)) {
return 0;
}
$em = $app['orm.em'];
$query = $em->createQuery('SELECT COUNT(u.id) FROM ChamiloLMS\Entity\CLpCategory u WHERE u.cId = :id');
$em = Database::getManager();
$query = $em->createQuery('SELECT COUNT(u.id) FROM ChamiloLMSCoreBundle:CLpCategory u WHERE u.cId = :id');
$query->setParameter('id', $course_id);
return $query->getSingleScalarResult();
}
@ -10606,16 +10603,15 @@ EOD;
static function get_categories($course_id)
{
global $app;
$em = $app['orm.em'];
$em = Database::getManager();
//Default behaviour
/*$items = $em->getRepository('ChamiloLMS\Entity\CLpCategory')->findBy(
/*$items = $em->getRepository('ChamiloLMSCoreBundle:CLpCategory')->findBy(
array('cId' => $course_id),
array('name' => 'ASC')
);*/
//Using doctrine extensions
$items = $em->getRepository('ChamiloLMS\Entity\CLpCategory')->getBySortableGroupsQuery(
$items = $em->getRepository('ChamiloLMSCoreBundle:CLpCategory')->getBySortableGroupsQuery(
array('cId' => $course_id)
)->getResult();
@ -10624,30 +10620,28 @@ EOD;
static function get_category($id)
{
global $app;
$em = $app['orm.em'];
$item = $em->find('ChamiloLMS\Entity\CLpCategory', $id);
$em = Database::getManager();
$item = $em->find('ChamiloLMSCoreBundle:CLpCategory', $id);
return $item;
}
static function get_category_by_course($course_id)
{
global $app;
$items = $app['orm.em']->getRepository('ChamiloLMS\Entity\CLpCategory')->findBy(array('cId' => $course_id));
$em = Database::getManager();
$items = $em->getRepository('ChamiloLMSCoreBundle:CLpCategory')->findBy(array('cId' => $course_id));
return $items;
}
static function delete_category($id)
{
global $app;
$em = $app['orm.ems']['db_write'];
$item = $em->find('ChamiloLMS\Entity\CLpCategory', $id);
$em = Database::getManager();
$item = $em->find('ChamiloLMSCoreBundle:CLpCategory', $id);
if ($item) {
$courseId = $item->getCId();
$query = $em->createQuery('SELECT u FROM ChamiloLMS\Entity\CLp u WHERE u.cId = :id AND u.categoryId = :catId');
$query = $em->createQuery('SELECT u FROM ChamiloLMSCoreBundle:CLp u WHERE u.cId = :id AND u.categoryId = :catId');
$query->setParameter('id', $courseId);
$query->setParameter('catId', $item->getId());
$lps = $query->getResult();

Loading…
Cancel
Save