Fix add course with content.

pull/3124/head
Julio Montoya 5 years ago
parent e0bea15586
commit e2a8d145c6
  1. 154
      public/main/inc/lib/add_course.lib.inc.php
  2. 1
      public/main/inc/lib/course.lib.php
  3. 2
      src/CoreBundle/Controller/ResourceController.php
  4. 3
      src/CoreBundle/Repository/IllustrationRepository.php
  5. 3
      src/CoreBundle/Repository/PersonalFileRepository.php
  6. 5
      src/CoreBundle/Repository/ResourceRepository.php
  7. 3
      src/CourseBundle/Repository/CDocumentRepository.php
  8. 3
      src/CourseBundle/Repository/CForumAttachmentRepository.php
  9. 3
      src/CourseBundle/Repository/CForumCategoryRepository.php
  10. 3
      src/CourseBundle/Repository/CLinkCategoryRepository.php
  11. 3
      src/CourseBundle/Repository/CLinkRepository.php
  12. 3
      src/CourseBundle/Repository/CShortcutRepository.php
  13. 3
      src/CourseBundle/Repository/CToolRepository.php

@ -82,124 +82,6 @@ class AddCourse
return $keys;
}
/**
* Initializes a file repository for a newly created course.
*
* @param string Course repository
* @param string Course code
*
* @return int
* @assert (null,null) === false
*/
public static function prepare_course_repository($course_repository)
{
return true;
$perm = api_get_permissions_for_new_directories();
$perm_file = api_get_permissions_for_new_files();
$htmlpage = "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\">\n <title>Not authorized</title>\n </head>\n <body>\n </body>\n</html>";
$cp = api_get_path(SYS_COURSE_PATH).$course_repository;
//Creating document folder
mkdir($cp, $perm);
mkdir($cp.'/document', $perm);
$cpt = $cp.'/document/index.html';
$fd = fopen($cpt, 'w');
fwrite($fd, $htmlpage);
fclose($fd);
/*
@chmod($cpt, $perm_file);
@copy($cpt, $cp . '/document/index.html');
mkdir($cp . '/document/images', $perm);
@copy($cpt, $cp . '/document/images/index.html');
mkdir($cp . '/document/images/gallery/', $perm);
@copy($cpt, $cp . '/document/images/gallery/index.html');
mkdir($cp . '/document/shared_folder/', $perm);
@copy($cpt, $cp . '/document/shared_folder/index.html');
mkdir($cp . '/document/audio', $perm);
@copy($cpt, $cp . '/document/audio/index.html');
mkdir($cp . '/document/flash', $perm);
@copy($cpt, $cp . '/document/flash/index.html');
mkdir($cp . '/document/video', $perm);
@copy($cpt, $cp . '/document/video/index.html'); */
//Creatind dropbox folder
mkdir($cp.'/dropbox', $perm);
$cpt = $cp.'/dropbox/index.html';
$fd = fopen($cpt, 'w');
fwrite($fd, $htmlpage);
fclose($fd);
@chmod($cpt, $perm_file);
mkdir($cp.'/group', $perm);
@copy($cpt, $cp.'/group/index.html');
mkdir($cp.'/page', $perm);
@copy($cpt, $cp.'/page/index.html');
mkdir($cp.'/scorm', $perm);
@copy($cpt, $cp.'/scorm/index.html');
mkdir($cp.'/upload', $perm);
@copy($cpt, $cp.'/upload/index.html');
mkdir($cp.'/upload/forum', $perm);
@copy($cpt, $cp.'/upload/forum/index.html');
mkdir($cp.'/upload/forum/images', $perm);
@copy($cpt, $cp.'/upload/forum/images/index.html');
mkdir($cp.'/upload/test', $perm);
@copy($cpt, $cp.'/upload/test/index.html');
mkdir($cp.'/upload/blog', $perm);
@copy($cpt, $cp.'/upload/blog/index.html');
mkdir($cp.'/upload/learning_path', $perm);
@copy($cpt, $cp.'/upload/learning_path/index.html');
mkdir($cp.'/upload/learning_path/images', $perm);
@copy($cpt, $cp.'/upload/learning_path/images/index.html');
mkdir($cp.'/upload/calendar', $perm);
@copy($cpt, $cp.'/upload/calendar/index.html');
mkdir($cp.'/upload/calendar/images', $perm);
@copy($cpt, $cp.'/upload/calendar/images/index.html');
mkdir($cp.'/work', $perm);
@copy($cpt, $cp.'/work/index.html');
mkdir($cp.'/upload/announcements', $perm);
@copy($cpt, $cp.'/upload/announcements/index.html');
mkdir($cp.'/upload/announcements/images', $perm);
@copy($cpt, $cp.'/upload/announcements/images/index.html');
//Oral expression question type
mkdir($cp.'/exercises', $perm);
@copy($cpt, $cp.'/exercises/index.html');
// Create .htaccess in the dropbox directory.
$fp = fopen($cp.'/dropbox/.htaccess', 'w');
fwrite(
$fp,
"AuthName AllowLocalAccess
AuthType Basic
order deny,allow
deny from all
php_flag zlib.output_compression off"
);
fclose($fp);
// Build index.php of the course.
/*$fd = fopen($cp . '/index.php', 'w');
// str_replace() removes \r that cause squares to appear at the end of each line
//@todo fix the harcoded include
$string = str_replace(
"\r",
"",
"<?" . "php
\$cidReq = \"$course_code\";
\$dbname = \"$course_code\";
include(\"" . api_get_path(SYS_CODE_PATH) . "course_home/course_home.php\");
?>"
);
fwrite($fd, $string);
@chmod($cp . '/index.php', $perm_file);*/
return 0;
}
/**
* Gets an array with all the course tables (deprecated?).
*
@ -371,8 +253,6 @@ class AddCourse
$TABLESETTING = Database::get_course_table(TABLE_COURSE_SETTING);
$TABLEGRADEBOOK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CATEGORY);
$TABLEGRADEBOOKLINK = Database::get_main_table(TABLE_MAIN_GRADEBOOK_LINK);
$visible_for_course_admin = 0;
$em = Database::getManager();
$course = api_get_course_entity($course_id);
$settingsManager = CourseManager::getCourseSettingsManager();
$settingsManager->setCourse($course);
@ -479,30 +359,40 @@ class AddCourse
$finder = new Symfony\Component\Finder\Finder();
$defaultPath = api_get_path(SYS_PUBLIC_PATH).'img/document';
$finder->in($defaultPath);
/** @var SplFileInfo $file */
foreach ($finder as $file) {
$path = str_replace($defaultPath, '', $file->getRealPath());
$parentName = dirname(str_replace($defaultPath, '', $file->getRealPath()));
$title = $file->getFilename();
if ($file->isDir()) {
create_unexisting_directory(
$courseInfo,
api_get_user_id(),
0,
0,
0,
$path,
$path,
$title
);
} else {
$parent = DocumentManager::getDocumentByPathInCourse($courseInfo, $parentName);
$parentId = 0;
if (!empty($parent)) {
$parent = $parent[0];
$parentId = $parent['iid'];
}
if ($file->isDir()) {
$realPath = str_replace($defaultPath, '', $file->getRealPath());
DocumentManager::addDocument(
$courseInfo,
$realPath,
'folder',
null,
$title,
'',
null,
null,
null,
null,
null,
false,
null,
$parentId,
$file->getRealPath()
);
} else {
$realPath = str_replace($defaultPath, '', $file->getRealPath());
$document = DocumentManager::addDocument(
$courseInfo,

@ -6409,7 +6409,6 @@ class CourseManager
{
$authorId = empty($authorId) ? api_get_user_id() : (int) $authorId;
AddCourse::prepare_course_repository($courseInfo['directory']);
AddCourse::fillCourse(
$courseInfo,
$params['exemplary_content'],

@ -148,7 +148,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$course = $this->getCourse();
$session = $this->getSession();
/** @var QueryBuilder $qb */
$qb = $repository->getResources($this->getUser(), $parentNode, $course, $session, null);
// 3. Set QueryBuilder to the source.

@ -15,6 +15,7 @@ use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -23,7 +24,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
*/
final class IllustrationRepository extends ResourceRepository implements ResourceRepositoryInterface
{
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
$repo = $this->getRepository();
$className = $repo->getClassName();

@ -13,12 +13,13 @@ use Chamilo\CoreBundle\Entity\Resource\ResourceNode;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
final class PersonalFileRepository extends ResourceRepository implements ResourceRepositoryInterface
{
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
return $this->getResourcesByCreator($user, $parentNode);
}

@ -451,10 +451,7 @@ class ResourceRepository extends BaseEntityRepository
return $repo->findOneBy(['name' => $name]);
}
/**
* @return QueryBuilder
*/
public function getResourcesByCourse(Course $course, Session $session = null, CGroupInfo $group = null, ResourceNode $parentNode = null)
public function getResourcesByCourse(Course $course, Session $session = null, CGroupInfo $group = null, ResourceNode $parentNode = null): QueryBuilder
{
$repo = $this->getRepository();
$className = $repo->getClassName();

@ -16,6 +16,7 @@ use Chamilo\CoreBundle\Repository\ResourceRepositoryInterface;
use Chamilo\CourseBundle\Entity\CDocument;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -24,7 +25,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
*/
final class CDocumentRepository extends ResourceRepository implements ResourceRepositoryInterface
{
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
return $this->getResourcesByCourse($course, $session, $group, $parentNode);
}

@ -10,13 +10,14 @@ use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\QueryBuilder;
/**
* Class CForumAttachmentRepository.
*/
class CForumAttachmentRepository extends ResourceRepository
{
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
return $this->getResourcesByCourse($course, $session, $group, $parentNode);
}

@ -10,10 +10,11 @@ use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\ResourceRepository;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\QueryBuilder;
class CForumCategoryRepository extends ResourceRepository
{
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
return $this->getResourcesByCourse($course, $session, $group, $parentNode);
}

@ -16,6 +16,7 @@ use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\CourseBundle\Entity\CLink;
use Chamilo\CourseBundle\Entity\CLinkCategory;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -24,7 +25,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
*/
final class CLinkCategoryRepository extends ResourceRepository implements ResourceRepositoryInterface
{
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
return $this->getResourcesByCourse($course, $session, $group, $parentNode);
}

@ -15,6 +15,7 @@ use Chamilo\CoreBundle\Repository\ResourceRepositoryInterface;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\CourseBundle\Entity\CLink;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -23,7 +24,7 @@ use Symfony\Component\HttpFoundation\File\UploadedFile;
*/
final class CLinkRepository extends ResourceRepository implements ResourceRepositoryInterface
{
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
return $this->getResourcesByCourse($course, $session, $group, $parentNode);
}

@ -17,6 +17,7 @@ use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\CourseBundle\Entity\CShortcut;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
@ -33,7 +34,7 @@ final class CShortcutRepository extends ResourceRepository implements ResourceRe
return $repo->findOneBy($criteria);
}
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
$repo = $this->getRepository();
$className = $repo->getClassName();

@ -16,6 +16,7 @@ use Chamilo\CoreBundle\Repository\ResourceRepositoryInterface;
use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\UserBundle\Entity\User;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
@ -34,7 +35,7 @@ final class CToolRepository extends ResourceRepository implements ResourceReposi
return $settings;
}
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null)
public function getResources(User $user, ResourceNode $parentNode, Course $course = null, Session $session = null, CGroupInfo $group = null): QueryBuilder
{
$repo = $this->getRepository();
$className = $repo->getClassName();

Loading…
Cancel
Save