Using $app['orm.ems']['db_write'] instead of $app['orm.em'] because we can use 2 databases to read or write depending in a configuration located in services.php

skala
Julio Montoya 12 years ago
parent 6dcd20b9bf
commit 6c98ad1982
  1. 6
      main/admin/extra_field_workflow.php
  2. 21
      main/exercice/testcategory.class.php
  3. 8
      main/inc/lib/extra_field_value.lib.php
  4. 15
      main/newscorm/learnpath.class.php
  5. 2
      src/ChamiloLMS/Controller/Admin/QuestionManager/QuestionManagerController.php
  6. 8
      src/ChamiloLMS/Controller/LearnpathController.php

@ -198,18 +198,18 @@ if ($form->validate()) {
$extraFieldOptionRelFieldOption->setFieldOptionId($subItemId);
$extraFieldOptionRelFieldOption->setRelatedFieldOptionId($id);
$extraFieldOptionRelFieldOption->setRoleId($roleId);
$app['orm.em']->persist($extraFieldOptionRelFieldOption);
$app['orm.ems']['db_write']->persist($extraFieldOptionRelFieldOption);
}
} else {
if ($extraFieldOptionRelFieldOption) {
$app['orm.em']->remove($extraFieldOptionRelFieldOption);
$app['orm.ems']['db_write']->remove($extraFieldOptionRelFieldOption);
}
}
}
}
$app['orm.em']->flush();
$app['orm.ems']['db_write']->flush();
header('Location:'.api_get_self().'?'.$params);
exit;
}

@ -126,14 +126,14 @@ class Testcategory
$category->setDescription($this->description);
if (!empty($parent_id)) {
$parent = $app['orm.em']->find('\Entity\CQuizCategory', $parent_id);
$parent = $app['orm.ems']['db_write']->find('\Entity\CQuizCategory', $parent_id);
if ($parent) {
$category->setParent($parent);
}
}
$category->setCId($course_id);
$app['orm.em']->persist($category);
$app['orm.em']->flush();
$app['orm.ems']['db_write']->persist($category);
$app['orm.ems']['db_write']->flush();
if ($category->getIid()) {
return $category->getIid();
@ -152,7 +152,7 @@ class Testcategory
{
// @todo inject the app in the class
global $app;
$category = $app['orm.em']->find('\Entity\CQuizCategory', $this->id);
$category = $app['orm.ems']['db_write']->find('\Entity\CQuizCategory', $this->id);
if (!$category) {
return false;
}
@ -171,7 +171,7 @@ class Testcategory
if ($this->id == $parentId) {
continue;
}
$parent = $app['orm.em']->find('\Entity\CQuizCategory', $parentId);
$parent = $app['orm.ems']['db_write']->find('\Entity\CQuizCategory', $parentId);
if ($parent) {
$category->setParent($parent);
}
@ -181,8 +181,8 @@ class Testcategory
$category->setParent(null);
}
$app['orm.em']->persist($category);
$app['orm.em']->flush();
$app['orm.ems']['db_write']->persist($category);
$app['orm.ems']['db_write']->flush();
if ($category->getIid()) {
return $category->getIid();
@ -200,7 +200,7 @@ class Testcategory
public function removeCategory()
{
global $app;
$category = $app['orm.em']->find('\Entity\CQuizCategory', $this->id);
$category = $app['orm.ems']['db_write']->find('\Entity\CQuizCategory', $this->id);
if (!$category) {
return false;
}
@ -212,9 +212,10 @@ class Testcategory
return false;
}
$repo = $app['orm.em']->getRepository('Entity\CQuizCategory');
$repo = $app['orm.ems']['db_write']->getRepository('Entity\CQuizCategory');
$repo->removeFromTree($category);
$app['orm.em']->clear(); // clear cached nodes
// clear cached nodes
$app['orm.ems']['db_write']->clear();
return true;
}

@ -216,8 +216,8 @@ class ExtraFieldValue extends Model
$extraFieldValue->setFieldValue($params['field_value']);
$extraFieldValue->setFieldId($params['field_id']);
$extraFieldValue->setTms(api_get_utc_datetime(null, false, true));
$app['orm.em']->persist($extraFieldValue);
$app['orm.em']->flush();
$app['orm.ems']['db_write']->persist($extraFieldValue);
$app['orm.ems']['db_write']->flush();
}
}
@ -270,8 +270,8 @@ class ExtraFieldValue extends Model
$extraFieldValue->setFieldValue($params['field_value']);
$extraFieldValue->setFieldId($params['field_id']);
$extraFieldValue->setTms(api_get_utc_datetime(null, false, true));
$app['orm.em']->persist($extraFieldValue);
$app['orm.em']->flush();
$app['orm.ems']['db_write']->persist($extraFieldValue);
$app['orm.ems']['db_write']->flush();
}
}
} else {

@ -10518,7 +10518,7 @@ EOD;
static function create_category($params)
{
global $app;
$em = $app['orm.em'];
$em = $app['orm.ems']['db_write'];
$item = new Entity\CLpCategory();
$item->setName($params['name']);
$item->setCId($params['c_id']);
@ -10529,7 +10529,7 @@ EOD;
static function update_category($params)
{
global $app;
$em = $app['orm.em'];
$em = $app['orm.ems']['db_write'];
$item = $em->find('Entity\CLpCategory', $params['id']);
if ($item) {
$item->setName($params['name']);
@ -10542,7 +10542,7 @@ EOD;
static function move_up_category($id)
{
global $app;
$em = $app['orm.em'];
$em = $app['orm.ems']['db_write'];
$item = $em->find('Entity\CLpCategory', $id);
if ($item) {
$position = $item->getPosition() - 1;
@ -10555,7 +10555,7 @@ EOD;
static function move_down_category($id)
{
global $app;
$em = $app['orm.em'];
$em = $app['orm.ems']['db_write'];
$item = $em->find('Entity\CLpCategory', $id);
if ($item) {
$position = $item->getPosition() + 1;
@ -10616,7 +10616,7 @@ EOD;
static function delete_category($id)
{
global $app;
$em = $app['orm.em'];
$em = $app['orm.ems']['db_write'];
$item = $em->find('Entity\CLpCategory', $id);
if ($item) {
@ -10626,16 +10626,15 @@ EOD;
$query->setParameter('catId', $item->getId());
$lps = $query->getResult();
//Setting category = 0
// Setting category = 0.
if ($lps) {
foreach ($lps as $lpItem) {
$lpItem->setCategoryId(0);
}
}
//Removing category
// Removing category.
$em->remove($item);
$em->flush();
}
}

@ -407,7 +407,7 @@ class QuestionManagerController
*/
public function deleteCategoryAction(Application $app, $id)
{
$repo = $app['orm.em']->getRepository('Entity\CQuizCategory');
$repo = $app['orm.ems']['db_write']->getRepository('Entity\CQuizCategory');
$category = $repo->find($id);
if (empty($category)) {
$app->abort(404);

@ -61,21 +61,21 @@ class LearnpathController
$session = $app['orm.em']->getRepository('Entity\Session')->find($sessionId);
}
//Find course
// Find course.
$course = $app['orm.em']->getRepository('Entity\Course')->find($courseId);
//Getting subscribe users to the course
// Getting subscribe users to the course.
$subscribedUsers = $app['orm.em']->getRepository('Entity\Course')->getSubscribedStudents($course);
$subscribedUsers = $subscribedUsers->getQuery();
$subscribedUsers = $subscribedUsers->execute();
//Getting all users in a nice format
// Getting all users in a nice format.
$choices = array();
foreach ($subscribedUsers as $user) {
$choices[$user->getUserId()] = $user->getCompleteNameWithClasses();
}
//Getting subscribed users to a LP
// Getting subscribed users to a LP.
$subscribedUsersInLp = $app['orm.em']->getRepository('Entity\CItemProperty')->getUsersSubscribedToItem(
'learnpath',
$lpId,

Loading…
Cancel
Save