Fix student publication comments, fix php errors

pull/3844/head
Julio Montoya 4 years ago
parent f0233584b3
commit ea2a0eb69a
  1. 5
      public/main/inc/lib/agenda.lib.php
  2. 4
      public/main/inc/lib/internationalization.lib.php
  3. 29
      public/main/work/edit.php
  4. 3
      public/main/work/view.php
  5. 49
      public/main/work/work.lib.php
  6. 3
      src/CoreBundle/Form/JuryMembersType.php
  7. 9
      src/CoreBundle/Framework/Container.php
  8. 3
      src/CoreBundle/Repository/BranchSyncRepository.php
  9. 1
      src/CoreBundle/Repository/Node/IllustrationRepository.php
  10. 5
      src/CoreBundle/Repository/Node/UserRepository.php
  11. 3
      src/CoreBundle/Repository/ResourceNodeRepository.php
  12. 17
      src/CoreBundle/Repository/ResourceRepository.php
  13. 52
      src/CoreBundle/Resources/views/Work/comments.html.twig
  14. 7
      src/CourseBundle/Repository/CStudentPublicationRepository.php

@ -8,6 +8,7 @@ use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CCalendarEvent;
use Chamilo\CourseBundle\Entity\CCalendarEventAttachment;
use Chamilo\CourseBundle\Entity\CGroup;
use Doctrine\DBAL\Types\Types;
use Symfony\Component\HttpFoundation\File\UploadedFile;
/**
@ -1575,8 +1576,8 @@ class Agenda
)
)
)
->setParameter('start', $start)
->setParameter('end', $end);
->setParameter('start', $start, Types::INTEGER)
->setParameter('end', $end, Types::INTEGER);
}
/*

@ -2,6 +2,7 @@
/* For licensing terms, see /license.txt */
use Carbon\Carbon;
use Chamilo\CoreBundle\Framework\Container;
use ChamiloSession as Session;
use Westsworld\TimeAgo;
@ -590,6 +591,9 @@ function date_to_str_ago($date, $timeZone = 'UTC', $returnDateDifference = false
} else {
$language = new Westsworld\TimeAgo\Translations\En();
}
// Use carbon?
//Carbon::instance($this->getCreatedAt())->diffForHumans();
$timeAgo = new TimeAgo($language);
if (!($date instanceof DateTime)) {
$date = api_get_utc_datetime($date, null, true);

@ -16,8 +16,6 @@ if ($blockEdition && !api_is_platform_admin()) {
api_not_allowed(true);
}
$this_section = SECTION_COURSES;
$work_id = isset($_REQUEST['id']) ? (int) ($_REQUEST['id']) : null;
@ -62,7 +60,7 @@ $is_author = false;
$repo = Container::getStudentPublicationRepository();
/** @var CStudentPublication $studentPublication */
$studentPublication = $repo->find($item_id);
if (empty($studentPublication)) {
if (null === $studentPublication) {
api_not_allowed(true);
}
@ -85,7 +83,6 @@ if (!empty($my_folder_data)) {
if (!empty($homework['expires_on']) || !empty($homework['ends_on'])) {
$time_now = time();
if (!empty($homework['expires_on']) &&
!empty($homework['expires_on'])
) {
@ -113,6 +110,7 @@ if (!empty($my_folder_data)) {
}
}
$interbreadcrumb[] = [
'url' => api_get_path(WEB_CODE_PATH).'work/work.php?'.api_get_cidreq(),
'name' => get_lang('Assignments'),
@ -145,21 +143,14 @@ $show_progress_bar = false;
$form->addElement('hidden', 'id', $work_id);
$form->addElement('hidden', 'item_id', $item_id);
$form->addText('title', get_lang('Title'), true, ['id' => 'file_upload']);
if ($is_allowed_to_edit && !empty($item_id)) {
$sql = "SELECT contains_file, url
FROM $work_table
WHERE c_id = $course_id AND iid ='$item_id' ";
$result = Database::query($sql);
if (false !== $result && Database::num_rows($result) > 0) {
$row = Database::fetch_array($result);
if ($row['contains_file'] || !empty($row['url'])) {
$form->addLabel(
get_lang('Download'),
'<a href="'.api_get_path(WEB_CODE_PATH).'work/download.php?id='.$item_id.'&'.api_get_cidreq().'">'.
Display::return_icon('save.png', get_lang('Save'), [], ICON_SIZE_MEDIUM).'
</a>'
);
}
if ($is_allowed_to_edit) {
if ($studentPublication->getContainsFile()) {
$form->addLabel(
get_lang('Download'),
'<a href="'.api_get_path(WEB_CODE_PATH).'work/download.php?id='.$item_id.'&'.api_get_cidreq().'">'.
Display::return_icon('save.png', get_lang('Save'), [], ICON_SIZE_MEDIUM).'
</a>'
);
}
}
$form->addHtmlEditor(

@ -197,10 +197,13 @@ if (($isDrhOfCourse || $allowEdition || $isDrhOfSession || user_is_author($id))
break;
}
$comments = getWorkComments($work);
$commentForm = getWorkCommentForm($work, $folderData);
$tpl = new Template();
$tpl->assign('work', $work);
$tpl->assign('comments', $comments);
$actions = '';
if ($work->getContainsFile()) {

@ -2353,7 +2353,7 @@ function get_work_user_list(
['class' => 'work-name']
);
// Title
$title = $studentPublication->getTitle();
$title = $assignment->getTitle();
$work['title_clean'] = $title;
$title = Security::remove_XSS($title);
if (strlen($title) > 30) {
@ -3909,6 +3909,22 @@ function getWorkDescriptionToolbar()
];
}
function getWorkComments(CStudentPublication $work)
{
$comments = $work->getComments();
$commentList = [];
if (!empty($comments)) {
foreach ($comments as $comment) {
//$userInfo = api_get_user_info($comment['user_id']);
//$comment['picture'] = $userInfo['avatar'];
//$comment['complete_name'] = $userInfo['complete_name_with_username'];
$commentList[] = getWorkComment($comment);
}
}
return $commentList;
}
/**
* Get total score from a work list.
*
@ -4160,18 +4176,12 @@ function formatWorkScore($score, $weight)
$finalScore,
$label
);
} else {
return $scoreBasedInModel;
}
return $scoreBasedInModel;
}
/**
* @param int $id comment id
* @param array $courseInfo
*
* @return string
*/
function getWorkComment($id, $courseInfo = [])
function getWorkComment(CStudentPublicationComment $commentEntity, array $courseInfo = []): array
{
if (empty($courseInfo)) {
$courseInfo = api_get_course_info();
@ -4182,13 +4192,6 @@ function getWorkComment($id, $courseInfo = [])
}
$repo = Container::getStudentPublicationCommentRepository();
$criteria = [
'iid' => $id,
'cId' => $courseInfo['real_id'],
];
/** @var CStudentPublicationComment $commentEntity */
$commentEntity = $repo->findOneBy($criteria);
$comment = [];
if ($commentEntity) {
@ -4196,11 +4199,13 @@ function getWorkComment($id, $courseInfo = [])
$fileUrl = null;
$deleteUrl = null;
$fileName = null;
$id = $commentEntity->getIid();
if ($commentEntity->getResourceNode()->hasResourceFile()) {
$fileUrl = $repo->getResourceFileDownloadUrl($commentEntity);
$workId = $commentEntity->getWorkId();
$workId = $commentEntity->getPublication()->getIid();
$filePath = '';
$deleteUrl = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$workId.'&action=delete_attachment&comment_id='.$id;
$deleteUrl = api_get_path(WEB_CODE_PATH).
'work/view.php?'.api_get_cidreq().'&id='.$workId.'&action=delete_attachment&comment_id='.$id;
$fileName = $commentEntity->getResourceNode()->getResourceFile()->getName();
}
$comment['comment'] = $commentEntity->getComment();
@ -6089,7 +6094,7 @@ function getFileContents($id, $courseInfo, $sessionId = 0, $correction = false,
$isAllow = allowOnlySubscribedUser(
api_get_user_id(),
$studentPublication->getParentId(),
$studentPublication->getPublicationParent()->getIid(),
$courseInfo['real_id'],
$forceAccessForCourseAdmins
);
@ -6306,9 +6311,7 @@ function exportAllStudentWorkFromPublication(
$score = $work['qualification_only'];
}
throw new Exception('work comments');
//$comments = getWorkComments($work);
$comments = null;
$comments = getWorkComments($work);
$feedback = null;
if (!empty($comments)) {
$content .= '<h4>'.get_lang('Feedback').': </h4>';

@ -8,6 +8,7 @@ namespace Chamilo\CoreBundle\Form;
use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
@ -53,7 +54,7 @@ class JuryMembersType extends AbstractType
$form->add(
$factory->createNamed(
'user_id',
'hidden',
HiddenType::class,
$id,
[
'auto_initialize' => false,

@ -69,7 +69,6 @@ use Symfony\Component\Routing\Router;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorage;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Authorization\AuthorizationChecker;
use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
@ -114,14 +113,6 @@ class Container
return self::$container->get('kernel')->getEnvironment();
}
/**
* @return RoleHierarchy
*/
public static function getRoles()
{
return self::$container->get('security.role_hierarchy');
}
public static function getLogDir(): string
{
return self::$container->get('kernel')->getLogDir();

@ -6,6 +6,7 @@ declare(strict_types=1);
namespace Chamilo\CoreBundle\Repository;
use Doctrine\DBAL\Types\Types;
use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
class BranchSyncRepository extends NestedTreeRepository
@ -28,7 +29,7 @@ class BranchSyncRepository extends NestedTreeRepository
//@todo check app settings
$qb->addOrderBy('b.branchName ASC');
$qb->where('b.branchName LIKE :keyword');
$qb->setParameter('keyword', "%{$keyword}%");
$qb->setParameter('keyword', "%{$keyword}%", Types::STRING);
$q = $qb->getQuery();
return $q->execute();

@ -36,7 +36,6 @@ final class IllustrationRepository extends ResourceRepository implements GridInt
{
$qb = $this->createQueryBuilder('resource')
->select('resource')
//->from($className, 'resource')
->innerJoin(
'resource.resourceNode',
'node'

@ -52,6 +52,7 @@ use Chamilo\CourseBundle\Entity\CWiki;
use Datetime;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Query\Expr\Join;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
@ -234,7 +235,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
$qb->select('u')
->from($this->_entityName, 'u')
->where('u.roles LIKE :roles')
->setParameter('roles', '%"'.$role.'"%')
->setParameter('roles', '%"'.$role.'"%', Types::STRING)
;
return $qb->getQuery()->getResult();
@ -255,7 +256,7 @@ class UserRepository extends ResourceRepository implements UserLoaderInterface,
//@todo check app settings
$qb->orderBy('b.firstname', 'ASC');
$qb->where('b.firstname LIKE :keyword OR b.lastname LIKE :keyword ');
$qb->setParameter('keyword', "%{$keyword}%");
$qb->setParameter('keyword', "%{$keyword}%", Types::STRING);
$query = $qb->getQuery();
return $query->execute();

@ -12,6 +12,7 @@ use Chamilo\CoreBundle\Entity\ResourceLink;
use Chamilo\CoreBundle\Entity\ResourceNode;
use Chamilo\CoreBundle\Entity\ResourceType;
use Chamilo\CoreBundle\Entity\Session;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Gedmo\Tree\Entity\Repository\MaterializedPathRepository;
use League\Flysystem\FilesystemInterface;
@ -106,7 +107,7 @@ class ResourceNodeRepository extends MaterializedPathRepository
->innerJoin('node.resourceFile', 'file')
->innerJoin('node.resourceLinks', 'l')
->where('node.resourceType = :type')
->setParameter('type', $type)
->setParameter('type', $type, Types::STRING)
->andWhere('node.parent = :parentNode')
->setParameter('parentNode', $resourceNode)
->andWhere('file IS NOT NULL')

@ -25,6 +25,7 @@ use Chamilo\CourseBundle\Entity\CGroup;
use Cocur\Slugify\SlugifyInterface;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\QueryBuilder;
@ -149,7 +150,7 @@ abstract class ResourceRepository extends ServiceEntityRepository
$qb = $this->getResourcesByCourse($course, $session, $group, $parentNode);
$qb
->andWhere('node.title = :title')
->setParameter('title', $title)
->setParameter('title', $title, Types::STRING)
->setMaxResults(1)
;
@ -380,7 +381,7 @@ abstract class ResourceRepository extends ServiceEntityRepository
->leftJoin('node.resourceFile', 'file')
->where('type.name = :type')
->setParameter('type', $resourceTypeName)
->setParameter('type', $resourceTypeName, Types::STRING)
->andWhere('links.course = :course')
->setParameter('course', $course)
->addSelect('node')
@ -397,13 +398,13 @@ abstract class ResourceRepository extends ServiceEntityRepository
// Do not show deleted resources.
$qb
->andWhere('links.visibility != :visibilityDeleted')
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED)
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED, Types::INTEGER)
;
if (!$isAdmin) {
$qb
->andWhere('links.visibility = :visibility')
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED)
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED, Types::INTEGER)
;
// @todo Add start/end visibility restrictions.
}
@ -460,7 +461,7 @@ abstract class ResourceRepository extends ServiceEntityRepository
->innerJoin('node.resourceLinks', 'links')
->innerJoin('node.resourceType', 'type')
->where('type.name = :type')
->setParameter('type', $resourceTypeName)
->setParameter('type', $resourceTypeName, Types::STRING)
->andWhere('links.course = :course')
->setParameter('course', $course)
;
@ -470,13 +471,13 @@ abstract class ResourceRepository extends ServiceEntityRepository
// Do not show deleted resources
$qb
->andWhere('links.visibility != :visibilityDeleted')
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED)
->setParameter('visibilityDeleted', ResourceLink::VISIBILITY_DELETED, Types::INTEGER)
;
if (!$isAdmin) {
$qb
->andWhere('links.visibility = :visibility')
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED)
->setParameter('visibility', ResourceLink::VISIBILITY_PUBLISHED, Types::INTEGER)
;
// @todo Add start/end visibility restrictions
}
@ -547,7 +548,7 @@ abstract class ResourceRepository extends ServiceEntityRepository
->innerJoin('node.resourceLinks', 'links')
->innerJoin('node.resourceType', 'type')
->where('type.name = :type')
->setParameter('type', $resourceTypeName)
->setParameter('type', $resourceTypeName, Types::STRING)
->andWhere('links.user = :user')
->setParameter('user', $user)
;

@ -5,12 +5,12 @@
</h3>
<hr>
<ul>
{% for comment in comments %}
{% for comment in work.comments %}
<li>
<div class="page-header">
<img height="24" src="{{ comment.picture }}"/> {{ comment.complete_name }}
<img height="24" src="{{ comment.user | illustration }}"/> {{ comment.user.username }}
- {{ comment.sent_at_with_label }}
- {{ comment.sentAt | date_to_time_ago }}
</div>
<p>
{% if comment.comment is not empty %}
@ -19,21 +19,47 @@
{{ 'Here is your feedback' | trans }}
{% endif %}
</p>
{% if comment.file_url is not empty %}
{% if comment.resourceNode.hasResourceFile %}
<ul class="fa-ul">
<li>
<span class="fa-li fa fa-paperclip"></span>
<a href="{{ comment.file_url }}">
{{ comment.file_name_to_show }}
<a
href="{{ url('chamilo_core_resource_view', {
'id': comment.resourceNode.id,
'cid': course ? course.id : 0,
'sid': session ? session.id : 0,
'type' : 'student_publications_comments',
'tool' : 'student_publications',
})
}}"
/>
{{ comment.resourceNode.resourceFile }}
</a>
{% if is_allowed_to_edit %}
<a href="{{ comment.delete_file_url }}">
{{ 'delete.png'|img(22, 'Delete'|trans) }}
</a>
{% endif %}
</li>
</ul>
{# {% if is_allowed_to_edit %}#}
{# <a href="{{ comment.delete_file_url }}">#}
{# {{ 'delete.png'|img(22, 'Delete'|trans) }}#}
{# </a>#}
{# {% endif %}#}
{% endif %}
{# {% if comment.file_url is not empty %}#}
{# <ul class="fa-ul">#}
{# <li>#}
{# <span class="fa-li fa fa-paperclip"></span>#}
{# <a href="{{ comment.file_url }}">#}
{# {{ comment.file_name_to_show }}#}
{# </a>#}
{# {% if is_allowed_to_edit %}#}
{# <a href="{{ comment.delete_file_url }}">#}
{# {{ 'delete.png'|img(22, 'Delete'|trans) }}#}
{# </a>#}
{# {% endif %}#}
{# </li>#}
{# </ul>#}
{# {% endif %}#}
</li>
{% endfor %}
</ul>

@ -31,10 +31,13 @@ final class CStudentPublicationRepository extends ResourceRepository
Session $session = null,
CGroup $group = null
): QueryBuilder {
$qb = $this->getResourcesByCourse($course, $session, $group, $publication->getResourceNode());
$qb = $this->getResourcesByCourse($course, $session, $group);
$qb->andWhere($qb->expr()->in('resource.active', [1, 0]));
$qb->andWhere($qb->expr()->eq('resource.publicationParent', $publication));
$qb
->andWhere('resource.publicationParent =:publicationParent')
->setParameter('publicationParent', $publication)
;
return $qb;
}

Loading…
Cancel
Save