diff --git a/psalm.xml b/psalm.xml index d774ba6205..4fe07427d5 100644 --- a/psalm.xml +++ b/psalm.xml @@ -87,7 +87,7 @@ - + diff --git a/public/main/auth/inscription.php b/public/main/auth/inscription.php index c7bd4f7e5e..88f9972bb3 100644 --- a/public/main/auth/inscription.php +++ b/public/main/auth/inscription.php @@ -1105,5 +1105,4 @@ if ($form->validate()) { $inscription = $tpl->get_template('auth/inscription.tpl'); $tpl->display($inscription); - } diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index 170e683ac8..e687b906e5 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -8393,13 +8393,11 @@ function api_is_student_view_active() * @param int $itemId * @param string $cropParameters * - * * @return array|bool */ function api_upload_file($type, $file, $itemId, $cropParameters = '') { throw new Exception('api_upload_file not implemented'); - $upload = process_uploaded_file($file); if ($upload) { $name = api_replace_dangerous_char($file['name']); diff --git a/public/main/inc/lib/notebook.lib.php b/public/main/inc/lib/notebook.lib.php index 60cdddbd30..ebb749e562 100644 --- a/public/main/inc/lib/notebook.lib.php +++ b/public/main/inc/lib/notebook.lib.php @@ -1,6 +1,7 @@ "; } - /** - * This functions stores the note in the database. - * - * @param array $values - * @param int $userId Optional. The user ID - * @param int $courseId Optional. The course ID - * @param int $sessionId Optional. The session ID - * - * @return bool - * - * @author Christian Fasanando - * @author Patrick Cool , Ghent University, Belgium - * - * @version januari 2009, dokeos 1.8.6 - */ - public static function save_note($values, $userId = 0, $courseId = 0, $sessionId = 0) + public static function saveNote(array $values, $userId = 0, $courseId = 0, $sessionId = 0) { if (!is_array($values) || empty($values['note_title'])) { return false; } - // Database table definition - $table = Database::get_course_table(TABLE_NOTEBOOK); $userId = $userId ?: api_get_user_id(); $courseId = $courseId ?: api_get_course_int_id(); - $courseInfo = api_get_course_info_by_id($courseId); - $courseCode = $courseInfo['code']; + $course = api_get_course_entity($courseId); $sessionId = $sessionId ?: api_get_session_id(); - $now = api_get_utc_datetime(); - $params = [ - 'notebook_id' => 0, - 'c_id' => $courseId, - 'user_id' => $userId, - 'course' => $courseCode, - 'session_id' => $sessionId, - 'title' => $values['note_title'], - 'description' => $values['note_comment'], - 'creation_date' => $now, - 'update_date' => $now, - 'status' => 0, - ]; - $id = Database::insert($table, $params); - - if ($id > 0) { - $sql = "UPDATE $table SET notebook_id = $id WHERE iid = $id"; - Database::query($sql); - - //insert into item_property - api_item_property_update( - $courseInfo, - TOOL_NOTEBOOK, - $id, - 'NotebookAdded', - $userId - ); + $session = api_get_session_entity($sessionId); - return $id; - } + $notebook = new CNotebook(); + $notebook + ->setTitle($values['note_title']) + ->setDescription($values['note_comment']) + ->setUserId($userId) + ->addCourseLink($course, $session) + ; + + $repo = Container::getNotebookRepository(); + $repo->getEntityManager()->persist($notebook); + $repo->getEntityManager()->flush(); + + return $notebook->getIid(); } /** @@ -118,12 +86,12 @@ class NotebookManager $notebook_id = (int) $notebook_id; $sql = "SELECT - notebook_id AS notebook_id, + iid AS notebook_id, title AS note_title, description AS note_comment, session_id AS session_id FROM $table - WHERE c_id = $course_id AND notebook_id = '".$notebook_id."' "; + WHERE iid = '".$notebook_id."' "; $result = Database::query($sql); if (1 != Database::num_rows($result)) { return []; @@ -133,57 +101,28 @@ class NotebookManager } /** - * This functions updates the note in the database. - * * @param array $values - * - * @author Christian Fasanando - * @author Patrick Cool , Ghent University, Belgium - * - * @return bool - * - * @version januari 2009, dokeos 1.8.6 */ - public static function update_note($values) + public static function updateNote($values) { if (!is_array($values) || empty($values['note_title'])) { return false; } - // Database table definition - $table = Database::get_course_table(TABLE_NOTEBOOK); + $repo = Container::getNotebookRepository(); + $notebook = $repo->find($values['notebook_id']); - $course_id = api_get_course_int_id(); - $sessionId = api_get_session_id(); + if (!$notebook) { + return false; + } - $params = [ - 'user_id' => api_get_user_id(), - 'course' => api_get_course_id(), - 'session_id' => $sessionId, - 'title' => $values['note_title'], - 'description' => $values['note_comment'], - 'update_date' => api_get_utc_datetime(), - ]; - - Database::update( - $table, - $params, - [ - 'c_id = ? AND notebook_id = ?' => [ - $course_id, - $values['notebook_id'], - ], - ] - ); - - // update item_property (update) - api_item_property_update( - api_get_course_info(), - TOOL_NOTEBOOK, - $values['notebook_id'], - 'NotebookUpdated', - api_get_user_id() - ); + $notebook + ->setTitle($values['note_title']) + ->setDescription($values['note_comment']) + ; + + $repo->getEntityManager()->persist($notebook); + $repo->getEntityManager()->flush(); return true; } @@ -207,8 +146,7 @@ class NotebookManager $sql = "DELETE FROM $table WHERE - c_id = $course_id AND - notebook_id='".$notebook_id."' AND + iid='".$notebook_id."' AND user_id = '".api_get_user_id()."'"; $result = Database::query($sql); $affected_rows = Database::affected_rows($result); @@ -218,13 +156,13 @@ class NotebookManager } // Update item_property (delete) - api_item_property_update( + /*api_item_property_update( api_get_course_info(), TOOL_NOTEBOOK, $notebook_id, 'delete', api_get_user_id() - ); + );*/ return true; } diff --git a/public/main/notebook/index.php b/public/main/notebook/index.php index 1ea2002348..fcf0eba6b4 100644 --- a/public/main/notebook/index.php +++ b/public/main/notebook/index.php @@ -106,7 +106,7 @@ if ('addnote' === $action) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); - $res = NotebookManager::save_note($values); + $res = NotebookManager::saveNote($values); if ($res) { echo Display::return_message(get_lang('Note added'), 'confirmation'); } @@ -169,7 +169,7 @@ if ('addnote' === $action) { $check = Security::check_token('post'); if ($check) { $values = $form->exportValues(); - $res = NotebookManager::update_note($values); + $res = NotebookManager::updateNote($values); if ($res) { echo Display::return_message(get_lang('Note updated'), 'confirmation'); } diff --git a/src/CoreBundle/Framework/Container.php b/src/CoreBundle/Framework/Container.php index ffa7b18124..45e89ef891 100644 --- a/src/CoreBundle/Framework/Container.php +++ b/src/CoreBundle/Framework/Container.php @@ -33,6 +33,7 @@ use Chamilo\CourseBundle\Repository\CLinkCategoryRepository; use Chamilo\CourseBundle\Repository\CLinkRepository; use Chamilo\CourseBundle\Repository\CLpCategoryRepository; use Chamilo\CourseBundle\Repository\CLpRepository; +use Chamilo\CourseBundle\Repository\CNotebookRepository; use Chamilo\CourseBundle\Repository\CQuizQuestionCategoryRepository; use Chamilo\CourseBundle\Repository\CQuizQuestionRepository; use Chamilo\CourseBundle\Repository\CQuizRepository; @@ -405,6 +406,11 @@ class Container return self::$container->get(CLpCategoryRepository::class); } + public static function getNotebookRepository(): CNotebookRepository + { + return self::$container->get(CNotebookRepository::class); + } + public static function getUserRepository(): UserRepository { return self::$container->get(UserRepository::class); diff --git a/src/CourseBundle/Entity/CNotebook.php b/src/CourseBundle/Entity/CNotebook.php index 19dcbf1910..b91067e27d 100644 --- a/src/CourseBundle/Entity/CNotebook.php +++ b/src/CourseBundle/Entity/CNotebook.php @@ -4,21 +4,20 @@ namespace Chamilo\CourseBundle\Entity; +use Chamilo\CoreBundle\Entity\AbstractResource; +use Chamilo\CoreBundle\Entity\ResourceInterface; use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as Gedmo; /** * CNotebook. * + * @ORM\Entity * @ORM\Table( - * name="c_notebook", - * indexes={ - * @ORM\Index(name="course", columns={"c_id"}) - * } + * name="c_notebook" * ) - * @ORM\Entity(repositoryClass="Chamilo\CourseBundle\Repository\CNotebookRepository") */ -class CNotebook +class CNotebook extends AbstractResource implements ResourceInterface { /** * @var int @@ -36,13 +35,6 @@ class CNotebook */ protected $cId; - /** - * @var int - * - * @ORM\Column(name="notebook_id", type="integer") - */ - protected $notebookId; - /** * @var int * @@ -108,6 +100,12 @@ class CNotebook $this->status = 0; } + public function __toString(): string + { + return $this->getTitle(); + } + + /** * Set userId. * @@ -201,7 +199,7 @@ class CNotebook */ public function getTitle() { - return $this->title; + return (string) $this->title; } /** @@ -300,30 +298,6 @@ class CNotebook return $this->status; } - /** - * Set notebookId. - * - * @param int $notebookId - * - * @return CNotebook - */ - public function setNotebookId($notebookId) - { - $this->notebookId = $notebookId; - - return $this; - } - - /** - * Get notebookId. - * - * @return int - */ - public function getNotebookId() - { - return $this->notebookId; - } - /** * Set cId. * @@ -357,4 +331,19 @@ class CNotebook { return $this->iid; } + + public function getResourceIdentifier(): int + { + return $this->getIid(); + } + + public function getResourceName(): string + { + return $this->getTitle(); + } + + public function setResourceName(string $name): self + { + return $this->setTitle($name); + } } diff --git a/src/CourseBundle/Repository/CNotebookRepository.php b/src/CourseBundle/Repository/CNotebookRepository.php index 4720e502f2..63a06ca034 100644 --- a/src/CourseBundle/Repository/CNotebookRepository.php +++ b/src/CourseBundle/Repository/CNotebookRepository.php @@ -7,23 +7,13 @@ namespace Chamilo\CourseBundle\Repository; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\User; -use Chamilo\CourseBundle\Entity\CNotebook; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Common\Persistence\ManagerRegistry; +use Chamilo\CoreBundle\Repository\ResourceRepository; /** * Class CNotebookRepository. */ -class CNotebookRepository extends ServiceEntityRepository +class CNotebookRepository extends ResourceRepository { - /** - * CNotebookRepository constructor. - */ - public function __construct(ManagerRegistry $registry) - { - parent::__construct($registry, CNotebook::class); - } - /** * Get the user notebooks in a course. *