Fix php warnings

pull/3262/head
Julio Montoya 5 years ago
parent 053bcad80a
commit c5370b0933
  1. 2
      public/main/inc/global.inc.php
  2. 51
      public/main/inc/lib/sessionmanager.lib.php
  3. 3
      src/CoreBundle/Controller/Admin/AdminController.php
  4. 1
      src/CoreBundle/Controller/SecurityController.php
  5. 7
      src/CoreBundle/Entity/CourseCategory.php
  6. 5
      src/CoreBundle/Entity/Listener/ResourceListener.php
  7. 27
      src/CoreBundle/Entity/Listener/SessionListener.php
  8. 39
      src/CoreBundle/Entity/Session.php

@ -60,8 +60,6 @@ try {
exit;
}
$newBaseUrl = substr($currentBaseUrl, 0, $pos - 1);
//$request->setBaseUrl($newBaseUrl);
$context->setBaseUrl($newBaseUrl);
$container = $kernel->getContainer();

@ -32,8 +32,6 @@ class SessionManager
public const SESSION_CHANGE_USER_REASON_ENROLLMENT_ANNULATION = 4;
public const DEFAULT_VISIBILITY = 4; //SESSION_AVAILABLE
public static $_debug = false;
/**
* Constructor.
*/
@ -74,7 +72,7 @@ class SessionManager
'nbr_courses' => $session->getNbrCourses(),
'nbr_users' => $session->getNbrUsers(),
'nbr_classes' => $session->getNbrClasses(),
'session_admin_id' => $session->getSessionAdminId(),
'session_admin_id' => $session->getSessionAdmin()->getId(),
'visibility' => $session->getVisibility(),
'promotion_id' => $session->getPromotionId(),
'display_start_date' => $session->getDisplayStartDate()
@ -250,49 +248,56 @@ class SessionManager
if ($ready_to_create) {
$sessionAdminId = !empty($sessionAdminId) ? $sessionAdminId : api_get_user_id();
$values = [
'name' => $name,
'id_coach' => $coachId,
'session_admin_id' => $sessionAdminId,
'visibility' => $visibility,
'description' => $description,
'show_description' => $showDescription,
'send_subscription_notification' => (int) $sendSubscriptionNotification,
];
$session = new Session();
$session
->setName($name)
->setGeneralCoach(api_get_user_entity($coachId))
->setSessionAdmin(api_get_user_entity($sessionAdminId))
->setVisibility($visibility)
->setDescription($description)
->setShowDescription($showDescription)
->setSendSubscriptionNotification((int) $sendSubscriptionNotification)
;
if (!empty($startDate)) {
$values['access_start_date'] = api_get_utc_datetime($startDate);
$session->setAccessStartDate(api_get_utc_datetime($startDate, true, true));
}
if (!empty($endDate)) {
$values['access_end_date'] = api_get_utc_datetime($endDate);
$session->setAccessEndDate(api_get_utc_datetime($endDate, true, true));
}
if (!empty($displayStartDate)) {
$values['display_start_date'] = api_get_utc_datetime($displayStartDate);
$session->setDisplayStartDate(api_get_utc_datetime($displayStartDate, true, true));
}
if (!empty($displayEndDate)) {
$values['display_end_date'] = api_get_utc_datetime($displayEndDate);
$session->setDisplayEndDate(api_get_utc_datetime($displayEndDate, true, true));
}
if (!empty($coachStartDate)) {
$values['coach_access_start_date'] = api_get_utc_datetime($coachStartDate);
$session->setCoachAccessStartDate(api_get_utc_datetime($coachStartDate, true, true));
}
if (!empty($coachEndDate)) {
$values['coach_access_end_date'] = api_get_utc_datetime($coachEndDate);
$session->setCoachAccessEndDate(api_get_utc_datetime($coachEndDate, true, true));
}
if (!empty($sessionCategoryId)) {
$values['session_category_id'] = $sessionCategoryId;
//$session->setCategory($category);
//$values['session_category_id'] = $sessionCategoryId;
}
if (api_get_configuration_value('allow_session_status')) {
$values['status'] = $status;
$session->setStatus($status);
}
$values['position'] = 0;
$session_id = Database::insert($tbl_session, $values);
$em = Database::getManager();
$em->persist($session);
$em->flush();
//$session_id = Database::insert($tbl_session, $values);
$session_id = $session->getId();
$duration = (int) $duration;
if (!empty($duration)) {
@ -329,7 +334,7 @@ class SessionManager
*
*/
// Adding to the correct URL
UrlManager::add_session_to_url($session_id, $accessUrlId);
//UrlManager::add_session_to_url($session_id, $accessUrlId);
// add event to system log
$user_id = api_get_user_id();

@ -11,8 +11,7 @@ use Symfony\Component\Routing\Annotation\Route;
/**
* Class Administrator.
*
* @author Julio Montoya <gugli100@gmail.com>
* @Route("/admin")
*/
class AdminController extends BaseController
{

@ -22,7 +22,6 @@ class SecurityController extends AbstractController
{
$error = $authenticationUtils->getLastAuthenticationError();
$lastUsername = $authenticationUtils->getLastUsername();
//$form = $this->createForm(LoginType::class, ['_username' => $lastUsername]);
return $this->render('@ChamiloCore/login.html.twig', [
'last_username' => $lastUsername,

@ -4,7 +4,11 @@
namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
@ -16,6 +20,9 @@ use Symfony\Component\Validator\Constraints as Assert;
* normalizationContext={"groups"={"course_category:read"}, "swagger_definition_name"="Read"},
* denormalizationContext={"groups"={"course_category:write"}},
* )
* @ApiFilter(SearchFilter::class, properties={"name": "partial", "code": "partial"})
* @ApiFilter(PropertyFilter::class)
* @ApiFilter(OrderFilter::class, properties={"name", "code"})
* @ORM\Table(
* name="course_category",
* uniqueConstraints={

@ -19,6 +19,7 @@ use Symfony\Component\Security\Core\Security;
class ResourceListener
{
protected $slugify;
protected $request;
/**
* ResourceListener constructor.
@ -28,13 +29,15 @@ class ResourceListener
$this->slugify = $slugify;
$this->security = $security;
$this->toolChain = $toolChain;
$this->request = $request;
}
public function prePersist(AbstractResource $resource, LifecycleEventArgs $args)
{
// Add resource node
$em = $args->getEntityManager();
$url = $em->getRepository('ChamiloCoreBundle:AccessUrl')->find(1);
$id = $this->request->getCurrentRequest()->getSession()->get('access_url_id');
$url = $em->getRepository('ChamiloCoreBundle:AccessUrl')->find($id);
$creator = $this->security->getUser();
$resourceNode = new ResourceNode();

@ -8,7 +8,11 @@ use Chamilo\CoreBundle\Entity\AccessUrl;
use Chamilo\CoreBundle\Entity\AccessUrlRelSession;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Repository\SessionRepository;
use Chamilo\CoreBundle\ToolChain;
use Cocur\Slugify\SlugifyInterface;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
/**
* Class SessionListener
@ -16,6 +20,17 @@ use Doctrine\ORM\Event\LifecycleEventArgs;
*/
class SessionListener
{
protected $request;
/**
* ResourceListener constructor.
*/
public function __construct(RequestStack $request, Security $security)
{
$this->security = $security;
$this->request = $request;
}
/**
* This code is executed when a new session is created.
*
@ -26,13 +41,11 @@ class SessionListener
*/
public function prePersist(Session $session, LifecycleEventArgs $args)
{
/** @var AccessUrlRelSession $urlRelSession */
$urlRelSession = $session->getUrls()->first();
$url = $urlRelSession->getUrl();
$repo = $args->getEntityManager()->getRepository('ChamiloCoreBundle:Session');
$this->checkLimit($repo, $url);
$em = $args->getEntityManager();
$id = $this->request->getCurrentRequest()->getSession()->get('access_url_id');
$url = $em->getRepository('ChamiloCoreBundle:AccessUrl')->find($id);
$session->addUrl($url);
//$this->checkLimit($repo, $url);
}
/**

@ -6,7 +6,9 @@ namespace Chamilo\CoreBundle\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use Chamilo\CourseBundle\Entity\CStudentPublication;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
@ -22,6 +24,9 @@ use Symfony\Component\Validator\Constraints as Assert;
* )
*
* @ApiFilter(SearchFilter::class, properties={"name": "partial"})
* @ApiFilter(PropertyFilter::class)
* @ApiFilter(OrderFilter::class, properties={"id", "name"})
*
* @ORM\Table(
* name="session",
* uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})},
@ -292,7 +297,7 @@ class Session
$this->nbrClasses = 0;
$this->nbrUsers = 0;
$this->sendSubscriptionNotification = false;
$this->displayStartDate = new \DateTime();
$this->displayEndDate = new \DateTime();
$this->accessStartDate = new \DateTime();
@ -307,6 +312,7 @@ class Session
$this->showDescription = false;
$this->category = null;
$this->status = 0;
$this->position = 0;
$this->studentPublications = new ArrayCollection();
}
@ -1237,6 +1243,15 @@ class Session
}
}
public function addUrl(AccessUrl $url)
{
$accessUrlRelSession = new AccessUrlRelSession();
$accessUrlRelSession->setUrl($url);
$accessUrlRelSession->setSession($this);
$this->addUrls($accessUrlRelSession);
}
public function addUrls(AccessUrlRelSession $url)
{
$url->setSession($this);
@ -1275,6 +1290,28 @@ class Session
return $this;
}
/**
* @return User
*/
public function getSessionAdmin(): User
{
return $this->sessionAdmin;
}
/**
* @param User $sessionAdmin
*
* @return Session
*/
public function setSessionAdmin(User $sessionAdmin): Session
{
$this->sessionAdmin = $sessionAdmin;
return $this;
}
public function isUserGeneralCoach(User $user): bool
{
$generalCoach = $this->getGeneralCoach();

Loading…
Cancel
Save