/**
* @var \Doctrine\Common\Collections\Collection
*/
- private Collection $assets;
+ private Collection $elements;
/**
* Constructor
$this->updated = new \DateTime('now');
//Set collections
- $this->assets = new ArrayCollection();
+ $this->elements = new ArrayCollection();
}
/**
}
/**
- * Add asset
+ * Add element
*
- * @param Asset $asset
+ * @param Element $element
*
* @return User
*/
- public function addAsset(Asset $asset): User {
- $this->assets[] = $asset;
+ public function addElement(Element $element): User {
+ $this->elements[] = $element;
return $this;
}
/**
- * Remove asset
+ * Remove element
*
- * @param Asset $asset
+ * @param Element $element
*
* @return \Doctrine\Common\Collections\Collection
*/
- public function removeAsset(Asset $asset): Collection {
- return $this->assets->removeElement($asset);
+ public function removeElement(Element $element): Collection {
+ return $this->elements->removeElement($element);
}
/**
- * Get assets
+ * Get elements
*
* @return \Doctrine\Common\Collections\Collection
*/
- public function getAssets(): Collection {
- return $this->assets;
+ public function getElements(): Collection {
+ return $this->elements;
}
/**
use Doctrine\ORM\Event\PreUpdateEventArgs;
/**
- * Asset
+ * Element
*/
-class Asset {
+class Element {
/**
* @var ?int
*/
/**
* Constructor
*
- * @param ?string $path The asset path
+ * @param ?string $path The element path
*/
public function __construct(private Album $album, private User $user, private ?string $path = null) {
$this->created = new \DateTime('now');
*
* @param \Rapsys\TreeBundle\Entity\Album $album
*
- * @return Asset
+ * @return Element
*/
- public function setAlbum(Album $album): Asset {
+ public function setAlbum(Album $album): Element {
$this->album = $album;
return $this;
*
* @param \Rapsys\TreeBundle\Entity\User $user
*
- * @return Asset
+ * @return Element
*/
- public function setUser(User $user): Asset {
+ public function setUser(User $user): Element {
$this->user = $user;
return $this;
*
* @param ?string $path
*
- * @return Asset
+ * @return Element
*/
- public function setPath(?string $path): Asset {
+ public function setPath(?string $path): Element {
$this->path = $path;
return $this;
*
* @param \DateTime $created
*
- * @return Asset
+ * @return Element
*/
- public function setCreated(\DateTime $created): Asset {
+ public function setCreated(\DateTime $created): Element {
$this->created = $created;
return $this;
*
* @param \DateTime $updated
*
- * @return Asset
+ * @return Element
*/
- public function setUpdated(\DateTime $updated): Asset {
+ public function setUpdated(\DateTime $updated): Element {
$this->updated = $updated;
return $this;
/**
* {@inheritdoc}
*/
- public function preUpdate(PreUpdateEventArgs $eventArgs): ?Asset {
+ public function preUpdate(PreUpdateEventArgs $eventArgs): ?Element {
//Check that we have an snippet instance
- if (($entity = $eventArgs->getEntity()) instanceof Asset) {
+ if (($entity = $eventArgs->getEntity()) instanceof Element) {
//Set updated value
return $entity->setUpdated(new \DateTime('now'));
}
/**
* @var \Doctrine\Common\Collections\Collection
*/
- private Collection $assets;
+ private Collection $elements;
/**
* Constructor
//Set defaults
//Set collections
- $this->assets = new ArrayCollection();
+ $this->elements = new ArrayCollection();
}
/**
- * Add asset
+ * Add element
*
- * @param Asset $asset
+ * @param Element $element
*
* @return User
*/
- public function addAsset(Asset $asset): User {
- $this->assets[] = $asset;
+ public function addElement(Element $element): User {
+ $this->elements[] = $element;
return $this;
}
/**
- * Remove asset
+ * Remove element
*
- * @param Asset $asset
+ * @param Element $element
*
* @return \Doctrine\Common\Collections\Collection
*/
- public function removeAsset(Asset $asset): Collection {
- return $this->assets->removeElement($asset);
+ public function removeElement(Element $element): Collection {
+ return $this->elements->removeElement($element);
}
/**
- * Get assets
+ * Get elements
*
* @return \Doctrine\Common\Collections\Collection
*/
- public function getAssets(): Collection {
- return $this->assets;
+ public function getElements(): Collection {
+ return $this->elements;
}
}
$tables = [
'Rapsys\TreeBundle\Entity\UserGroup' => $qs->getJoinTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User')->getAssociationMapping('groups'), $manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp),
'Rapsys\TreeBundle\Entity\Album' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Album'), $dp),
- 'Rapsys\TreeBundle\Entity\Asset' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Asset'), $dp),
'Rapsys\TreeBundle\Entity\Civility' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Civility'), $dp),
+ 'Rapsys\TreeBundle\Entity\Element' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Element'), $dp),
'Rapsys\TreeBundle\Entity\Group' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\Group'), $dp),
'Rapsys\TreeBundle\Entity\User' => $qs->getTableName($manager->getClassMetadata('Rapsys\TreeBundle\Entity\User'), $dp),
//Set locale
//Set the request
$req = <<<SQL
SELECT COUNT(DISTINCT a.album_id) AS count
-FROM Rapsys\TreeBundle\Entity\Asset AS a
+FROM Rapsys\TreeBundle\Entity\Element AS a
WHERE $userSql
SQL;
public function findAllAsArray(?int $id, int $page, int $count): array {
//Set user sql
$userSql = <<<SQL
-s.user_id = :id
+e.user_id = :id
SQL;
//With null id
if ($id === null) {
//Set user sql
$userSql = <<<SQL
-s.user_id IS NULL
+e.user_id IS NULL
SQL;
}
SELECT
a.id,
a.path,
- GROUP_CONCAT(s.id ORDER BY s.id SEPARATOR "\\n") AS s_ids,
- GROUP_CONCAT(IFNULL(s.path, '/') ORDER BY s.id SEPARATOR "\\n") AS s_paths,
+ GROUP_CONCAT(e.id ORDER BY e.id SEPARATOR "\\n") AS s_ids,
+ GROUP_CONCAT(IFNULL(e.path, '/') ORDER BY e.id SEPARATOR "\\n") AS s_paths,
a.slug,
- GREATEST(a.created, s.created) AS created,
- GREATEST(a.updated, s.updated) AS updated,
- GREATEST(a.created, s.created, a.updated, s.updated) AS modified
+ GREATEST(a.created, e.created) AS created,
+ GREATEST(a.updated, e.updated) AS updated,
+ GREATEST(a.created, e.created, a.updated, e.updated) AS modified
FROM Rapsys\TreeBundle\Entity\Album AS a
-JOIN Rapsys\TreeBundle\Entity\Asset AS s ON (s.album_id = a.id AND {$userSql})
+JOIN Rapsys\TreeBundle\Entity\Element AS e ON (e.album_id = a.id AND {$userSql})
GROUP BY a.id
ORDER BY updated, created DESC, a.id
LIMIT :offset, :count
'updated' => $data['updated'],
'modified' => $data['modified'],
'link' => $this->router->generate('rapsystree_album', ['id' => $id, 'slug' => $slug, 'path' => '/']),
- 'assets' => []
+ 'elements' => []
];
- //Explode asset ids
+ //Explode element ids
$data['s_ids'] = explode("\n", $data['s_ids']);
- //Explode asset paths
+ //Explode element paths
$data['s_paths'] = explode("\n", $data['s_paths']);
foreach($data['s_ids'] as $s => $id) {
- $return[$data['id']]['assets'][$id] = [
+ $return[$data['id']]['elements'][$id] = [
'id' => $id,
'path' => $path = $data['s_paths'][$s],
- 'link' => $this->router->generate('rapsystree_asset', ['id' => $id, 'path' => $path]),
+ 'link' => $this->router->generate('rapsystree_element', ['id' => $id, 'path' => $path]),
];
}
}
updated:
type: datetime
oneToMany:
- assets:
- targetEntity: Rapsys\TreeBundle\Entity\Asset
+ elements:
+ targetEntity: Rapsys\TreeBundle\Entity\Element
mappedBy: album
lifecycleCallbacks:
preUpdate: ['preUpdate']
-Rapsys\TreeBundle\Entity\Asset:
+Rapsys\TreeBundle\Entity\Element:
type: entity
- #repositoryClass: Rapsys\TreeBundle\Repository\AssetRepository
- table: assets
+ #repositoryClass: Rapsys\TreeBundle\Repository\ElementRepository
+ table: elements
id:
id:
type: integer
manyToOne:
album:
targetEntity: Rapsys\TreeBundle\Entity\Album
- inversedBy: assets
+ inversedBy: elements
user:
targetEntity: Rapsys\TreeBundle\Entity\User
- inversedBy: assets
+ inversedBy: elements
uniqueConstraints:
album_user_path:
columns: [ album_id, user_id, path ]
# unique: true
# nullable: true
oneToMany:
- assets:
- targetEntity: Rapsys\TreeBundle\Entity\Asset
+ elements:
+ targetEntity: Rapsys\TreeBundle\Entity\Element
mappedBy: user
# manyToMany:
# groups:
slug: '[\w-]+'
methods: GET|POST
-rapsystree_asset:
- path:
- en_gb: '/en/asset/{id}{path}'
- fr_fr: '/actif/{id}{path}'
- controller: Rapsys\TreeBundle\Controller\TreeController::asset
- defaults:
- id: ~
- path: ~
- requirements:
- id: '\d+'
- path: '/.*'
- methods: GET|POST
-
rapsystree_contact:
path:
en_gb: '/en/contact'
hash: '[a-zA-Z0-9=_-]+'
methods: GET|POST
+rapsystree_element:
+ path:
+ en_gb: '/en/element/{id}{path}'
+ fr_fr: '/element/{id}{path}'
+ controller: Rapsys\TreeBundle\Controller\TreeController::element
+ defaults:
+ id: ~
+ path: ~
+ requirements:
+ id: '\d+'
+ path: '/.*'
+ methods: GET|POST
+
rapsysuser_index:
path:
en_gb: '/en/user'
{% for id, album in albums %}
<article>
<header>
- <h2><a href="{{ album.link }}">{{ album.slug }}</a></h2>
+ <h2><a href="{{ album.link }}">{{ album.slug|capitalize }}</a></h2>
</header>
- {% if album.assets is defined and album.assets %}
- {% for id, asset in album.assets %}
+ {% if album.elements is defined and album.elements %}
+ {% for id, element in album.elements %}
<section>
<header>
- <h3><a href="{{ asset.link }}">{{ asset.path }}</a></h3>
+ <h3><a href="{{ element.link }}">{{ element.path }}</a></h3>
</header>
<p>
TODO: miniature if target is a file or image list when directory ?