Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinDev committed May 3, 2021
1 parent f72ed37 commit 96d989e
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 53 deletions.
1 change: 1 addition & 0 deletions packages/admin-block-editor/src/assets/admin.scss
Expand Up @@ -4,6 +4,7 @@
.ce-rawtool__textarea {
background-color: #f3f4f6 !important;
color: #111827 !important;
min-height: none !important;
}
.ce-rawtool__textarea:focus {
font-size: 15px !important;
Expand Down
7 changes: 4 additions & 3 deletions packages/admin/src/FormField/PagePublishedAtField.php
Expand Up @@ -31,10 +31,11 @@ private function getHelp(): string
// TODO: translate
return $this->getSubject() && $this->getSubject()->getSlug() ?
'Dernière édition le '.$this->getSubject()->getUpdatedAt()->format('d/m à H:m')
.($this->getSubject()->getLastEditBy() ? ' par '.$this->getSubject()->getLastEditBy()->getUsername() : '')
.(class_exists(PushwordVersionBundle::class)
? ' - <a href="'
.$this->admin->getRouter()->generate('pushword_version_list', ['id' => $this->getSubject()->getId()])
.'">Voir l\'historique</a>' : '')
? '<br><a href="'
.$this->admin->getRouter()->generate('pushword_version_list', ['id' => $this->getSubject()->getId()])
.'">Voir l\'historique</a>' : '')
: '';
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/Entity/Page.php
Expand Up @@ -3,6 +3,7 @@
namespace Pushword\Core\Entity;

use Doctrine\ORM\Mapping as ORM;
use Pushword\Core\Entity\PageTrait\PageEditorTrait;
use Pushword\Core\Entity\PageTrait\PageExtendedTrait;
use Pushword\Core\Entity\PageTrait\PageI18nTrait;
use Pushword\Core\Entity\PageTrait\PageMainImageTrait;
Expand Down Expand Up @@ -34,6 +35,7 @@ class Page implements PageInterface
use CustomPropertiesTrait;
use HostTrait;
use IdTrait;
use PageEditorTrait;
use PageExtendedTrait;
use PageI18nTrait;
use PageMainImageTrait;
Expand Down
20 changes: 13 additions & 7 deletions packages/core/src/Entity/PageHasEditor.php~
Expand Up @@ -8,20 +8,26 @@ use Doctrine\ORM\Mapping as ORM;
use Pushword\Core\Entity\SharedTrait\IdTrait;

/**
* @ORM\MappedSuperclass
* @ORM\HasLifecycleCallbacks
* @ORM\Entity
*/
class PageHasEditor //implements PageHasEditorInterface
{
use IdTrait;

/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;

/**
* @ORM\ManyToOne(targetEntity="Pushword\Core\Entity\UserInterface")
*/
protected UserInterface $editor;

/**
* @ORM\ManyToOne(targetEntity="Pushword\Core\Entity\PageInterface", inversedBy="pageHasEditor")
* @ORM\ManyToOne(targetEntity="Pushword\Core\Entity\PageInterface", inversedBy="pageHasEditors")
*/
protected PageInterface $page;

Expand All @@ -32,7 +38,7 @@ class PageHasEditor //implements PageHasEditorInterface

public function __toString()
{
return $this->getPage().'|'.$this->getEditor().'|'.$this->getEditedAt;
return $this->getPage().'|'.$this->getEditor().'|'.$this->getEditedAt()->format('d/m/Y');
}

public function setPage(?PageInterface $page = null): self
Expand All @@ -56,7 +62,7 @@ class PageHasEditor //implements PageHasEditorInterface

public function getEditor(): ?UserInterface
{
return $this->media;
return $this->editor;
}

public function getEditedAt(): ?DateTime
Expand All @@ -65,9 +71,9 @@ class PageHasEditor //implements PageHasEditorInterface
}

/**
* Set the value of editedAt
* Set the value of editedAt.
*
* @return self
* @return self
*/
public function setEditedAt(DateTime $editedAt)
{
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/Entity/PageInterface.php
Expand Up @@ -4,12 +4,13 @@

use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Pushword\Core\Entity\PageTrait\PageEditorInterface;
use Pushword\Core\Entity\SharedTrait\CustomPropertiesInterface;
use Pushword\Core\Entity\SharedTrait\HostInterface;
use Pushword\Core\Entity\SharedTrait\IdInterface;
use Pushword\Core\Entity\SharedTrait\TimestampableInterface;

interface PageInterface extends HostInterface, IdInterface, TimestampableInterface, CustomPropertiesInterface
interface PageInterface extends HostInterface, IdInterface, TimestampableInterface, CustomPropertiesInterface, PageEditorInterface
{
// PageTrait
public function getSlug(): string;
Expand Down
36 changes: 36 additions & 0 deletions packages/core/src/Entity/PageTrait/PageEditorInterface.php
@@ -0,0 +1,36 @@
<?php

namespace Pushword\Core\Entity\PageTrait;

use Doctrine\Common\Collections\ArrayCollection;
//use Pushword\Core\Entity\PageHasEditor;
use Pushword\Core\Entity\UserInterface;

interface PageEditorInterface
{
public function getLastEditBy(): ?UserInterface;

public function setLastEditBy(?UserInterface $lastEditor): void;

/**
* Get targetEntity="Pushword\Core\Entity\UserInterface",.
*/
public function getCreatedBy(): ?UserInterface;

/**
* Set targetEntity="Pushword\Core\Entity\UserInterface",.
*/
public function setCreatedBy(?UserInterface $createdBy): void;

/*
public function setPageHasEditors($pageHasEditors): void;
public function getPageHasEditors(): ?ArrayCollection;
public function addPageHasEditor(PageHasEditor $pageHasEditor): void;
public function resetPageHasEditors(): void;
public function removePageHasEditor(PageHasEditor $pageHasEditor): void;
*/
}
Expand Up @@ -3,23 +3,19 @@
namespace Pushword\Core\Entity\PageTrait;

use Doctrine\Common\Collections\ArrayCollection;
use Pushword\Core\Entity\UserInterface;
use Pushword\Core\Entity\PageHasEditor;
use Pushword\Core\Entity\UserInterface;

trait PageEditorTrait
{

/**
* @ORM\ManyToOne(
* targetEntity="Pushword\Core\Entity\UserInterface",
* cascade={"all"},
* nullable=true
* )
*/
protected UserInterface $lastEditor;
protected $lastEditBy;


/**
/*
* @ORM\OneToMany(
* targetEntity="Pushword\Core\Entity\PageHasEditor",
* mappedBy="page",
Expand All @@ -28,75 +24,59 @@ trait PageEditorTrait
* )
* @ORM\OrderBy({"editedAt": "DESC"})
*/
protected $pageHasEditors;

//protected ArrayCollection $pageHasEditors;

/**
* @ORM\ManyToOne(
* targetEntity="Pushword\Core\Entity\UserInterface",
* cascade={"all"},
* nullable=true
* )
*/
protected UserInterface $createdBy;
protected $createdBy;


public function __constructEditor()
{
$this->pageHasEditors = new ArrayCollection();
}

public function getLastEditor(): ?UserInterface
public function getLastEditBy(): ?UserInterface
{
return $this->lastEditor;
return $this->lastEditBy;
}

public function setLastEditor(?UserInterface $lastEditor): self
public function setLastEditBy(?UserInterface $lastEditBy): void
{
$this->lastEditor = $lastEditor;

return $this;
$this->lastEditBy = $lastEditBy;
}

/**
* Get targetEntity="Pushword\Core\Entity\UserInterface",
* Get targetEntity="Pushword\Core\Entity\UserInterface",.
*/
public function getCreatedBy(): ?UserInterface
{
return $this->createdBy;
}

/**
* Set targetEntity="Pushword\Core\Entity\UserInterface",
*
* @return self
* Set targetEntity="Pushword\Core\Entity\UserInterface",.
*/
public function setCreatedBy(?UserInterface $createdBy)
public function setCreatedBy(?UserInterface $createdBy): void
{
$this->createdBy = $createdBy;

return $this;
}

public function setPageHasEditors($pageHasEditors)
/*
public function setPageHasEditors($pageHasEditors): void
{
$this->pageHasEditors = new ArrayCollection();
foreach ($pageHasEditors as $pageHasEditor) {
$this->addPageHasEditor($pageHasEditor);
}
}
public function getPageHasEditors()
public function getPageHasEditors(): ?ArrayCollection
{
return $this->pageHasEditors;
}
public function addPageHasEditor(PageHasEditor $pageHasEditor): self
public function addPageHasEditor(PageHasEditor $pageHasEditor): void
{
$pageHasEditor->setPage($this);
$this->pageHasEditors[] = $pageHasEditor;

return $this;
}
public function resetPageHasEditors(): void
Expand All @@ -110,4 +90,5 @@ public function removePageHasEditor(PageHasEditor $pageHasEditor): void
{
$this->pageHasEditors->removeElement($pageHasEditor);
}
*/
}
53 changes: 49 additions & 4 deletions packages/core/src/EventListener/PageListener.php
Expand Up @@ -2,17 +2,62 @@

namespace Pushword\Core\EventListener;

use Pushword\Core\Entity\PageInterface as Page;
use Doctrine\ORM\EntityManagerInterface;
use Pushword\Core\Entity\PageInterface;
use Symfony\Component\Security\Core\Security;

class PageListener
{
public function preRemove(Page $page)
private Security $security;
private EntityManagerInterface $entityManager;

public function __construct(Security $security, EntityManagerInterface $entityManager)
{
$this->security = $security;
$this->entityManager = $entityManager;
}

public function preRemove(PageInterface $page)
{
// method_exists($page, 'getChildrenPages') &&
if (! $page->getChildrenPages()->isEmpty()) {
foreach ($page->getChildrenPages() as $cPage) {
$cPage->setParentPage(null);
foreach ($page->getChildrenPages() as $childrenPage) {
$childrenPage->setParentPage(null);
}
}
}

public function prePersist(PageInterface $page): void
{
$this->updatePageEditor($page);
}

public function preUpdate(PageInterface $page): void
{
$this->updatePageEditor($page);
}

private function updatePageEditor(PageInterface $page): void
{
/*
HUGE BUG: une fois la page mise à jour avec ce code, impossible d'afficher la page d'édition
de Admin sans être déconnecté
if (!$user = $this->security->getUser())
return;
if (null === $page->getCreatedBy()) {
$page->setCreatedBy($user);
}
if (!$page->getLastEditBy() || $page->getLastEditBy() !== $user)
$page->setLastEditBy($user);
*/
//$this->entityManager->flush();
//$pageHasEditor = (new PageHasEditor())->setPage($page)->setEditor($user)->setEditedAt(new \DateTime());
//$this->entityManager->persist($pageHasEditor);
//$this->entityManager->flush();

//$page->addPageHasEditor($pageHasEditor);
//$this->entityManager->flush();
}
}
4 changes: 3 additions & 1 deletion packages/core/src/Resources/config/services.yaml
Expand Up @@ -44,10 +44,12 @@ services:
# Page
# --------

# Todo: move to EventSuscriber
# Todo: move to EventSuscriber
Pushword\Core\EventListener\PageListener:
tags:
- { name: doctrine.orm.entity_listener, entity: "%pw.entity_page%", event: preRemove }
- { name: doctrine.orm.entity_listener, entity: "%pw.entity_page%", event: preUpdate }
- { name: doctrine.orm.entity_listener, entity: "%pw.entity_page%", event: prePersist }

Pushword\Core\Repository\PageRepositoryInterface:
class: Pushword\Core\Repository\PageRepository
Expand Down
2 changes: 2 additions & 0 deletions packages/docs/content/roadmap.md
Expand Up @@ -23,6 +23,8 @@ parent: contribute

## Feature

- Toward wiki ! **Change requester** and **Public Historic** + **page authors**
- Youtube Importer (from a youtube hash, create a page with video and text is imported from subtitle)
- **Multi-upload** (see https://packagist.org/packages/silasjoisten/sonata-multiupload-bundle)
- Intégrer **LinksImprover** (+ UX)
- **Page-Scanner** :
Expand Down
Binary file modified packages/skeleton/var/app.db
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/version/src/templates/list.html.twig
Expand Up @@ -50,7 +50,7 @@
</a>
</td>
<td class="sonata-ba-list-field sonata-ba-list-field-text">
{{ p.updatedAt|date }}
{{ p.updatedAt|date }} {{ p.lastEditBy ? '(<small>' ~ p.lastEditBy ~ ')</small>':'' }}
</td>
<td class="sonata-ba-list-field sonata-ba-list-field-text" objectid="34" style="text-align:right">
<div class="btn-group">
Expand Down

0 comments on commit 96d989e

Please sign in to comment.