85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
/*************************************************************************************/
|
|
/* Copyright (c) Open Studio */
|
|
/* web : https://open.studio */
|
|
/* */
|
|
/* For the full copyright and license information, please view the LICENSE */
|
|
/* file that was distributed with this source code. */
|
|
/*************************************************************************************/
|
|
|
|
/**
|
|
* Created by Franck Allimant, OpenStudio <fallimant@openstudio.fr>
|
|
* Date: 02/01/2021 19:05
|
|
*/
|
|
namespace Agenda;
|
|
|
|
use Propel\Runtime\Connection\ConnectionInterface;
|
|
use Tags\Model\Map\TagsTableMap;
|
|
use Tags\Model\TagsQuery;
|
|
use Thelia\Install\Database;
|
|
use Thelia\Model\Content;
|
|
use Thelia\Model\FolderQuery;
|
|
use Thelia\Module\BaseModule;
|
|
|
|
class Agenda extends BaseModule
|
|
{
|
|
/** @var string */
|
|
const DOMAIN_NAME = 'agenda';
|
|
|
|
const TAG_AGENDA = 'agenda';
|
|
|
|
public function postActivation(ConnectionInterface $con = null)
|
|
{
|
|
if (true !== (bool) Agenda::getConfigValue('is-initialized', false)) {
|
|
$database = new Database($con);
|
|
|
|
$database->insertSql(null, [__DIR__ . "/Config/thelia.sql"]);
|
|
|
|
Agenda::setConfigValue('is-initialized', true);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Déterminer si un contenu fait partie d'un dossier de type agenda (e.g. qui a le tag Agenda)
|
|
*
|
|
* @param Content $content
|
|
* @return bool
|
|
* @throws \Propel\Runtime\Exception\PropelException
|
|
*/
|
|
public static function estContenuAgenda(Content $content)
|
|
{
|
|
static $listeDossierAgenda;
|
|
static $contentCache = [];
|
|
|
|
if (null === $listeDossierAgenda) {
|
|
$listeDossierAgenda = TagsQuery::create()
|
|
->filterBySource('folder')
|
|
->filterByTag(self::TAG_AGENDA)
|
|
->select([ TagsTableMap::SOURCE_ID ])
|
|
->find()
|
|
->getData();
|
|
}
|
|
|
|
if (empty($listeDossierAgenda)) {
|
|
return false;
|
|
}
|
|
|
|
if (! isset($contentCache[$content->getId()])) {
|
|
$folderId = $content->getDefaultFolderId();
|
|
|
|
$contentCache[$content->getId()] = false;
|
|
|
|
while ($folderId > 0) {
|
|
if (in_array($folderId, $listeDossierAgenda)) {
|
|
$contentCache[$content->getId()] = true;
|
|
break;
|
|
}
|
|
|
|
$folderId = FolderQuery::create()->findPk($folderId)->getParent();
|
|
}
|
|
}
|
|
|
|
return $contentCache[$content->getId()];
|
|
}
|
|
}
|