template rapport_dactivitees avec pdf à télécharger
This commit is contained in:
@@ -420,9 +420,11 @@ trait PageRoutableTrait
|
||||
return $this->_parentCache;
|
||||
}
|
||||
|
||||
// Use filesystem as \dirname() does not work in Windows because of '/foo' becomes '\'.
|
||||
$filesystem = Filesystem::getInstance(false);
|
||||
$directory = $this->getFlexDirectory();
|
||||
$parentKey = ltrim(dirname("/{$this->getKey()}"), '/');
|
||||
if ($parentKey) {
|
||||
$parentKey = ltrim($filesystem->dirname("/{$this->getKey()}"), '/');
|
||||
if ('' !== $parentKey) {
|
||||
$parent = $directory->getObject($parentKey);
|
||||
$language = $this->getLanguage();
|
||||
if ($language && $parent && method_exists($parent, 'getTranslation')) {
|
||||
@@ -433,7 +435,7 @@ trait PageRoutableTrait
|
||||
} else {
|
||||
$index = $directory->getIndex();
|
||||
|
||||
$this->_parentCache = method_exists($index, 'getRoot') ? $index->getRoot() : null;
|
||||
$this->_parentCache = \is_callable([$index, 'getRoot']) ? $index->getRoot() : null;
|
||||
}
|
||||
|
||||
return $this->_parentCache;
|
||||
@@ -497,22 +499,22 @@ trait PageRoutableTrait
|
||||
public function activeChild(): bool
|
||||
{
|
||||
$grav = Grav::instance();
|
||||
/** @var Uri $uri */
|
||||
$uri = $grav['uri'];
|
||||
/** @var Pages $pages */
|
||||
$pages = $grav['pages'];
|
||||
$uri_path = rtrim(urldecode($uri->path()), '/');
|
||||
$routes = $pages->routes();
|
||||
|
||||
if (isset($routes[$uri_path])) {
|
||||
/** @var PageInterface $child_page|null */
|
||||
$child_page = $pages->find($uri->route())->parent();
|
||||
if (null !== $child_page) {
|
||||
while (!$child_page->root()) {
|
||||
if ($this->path() === $child_page->path()) {
|
||||
return true;
|
||||
}
|
||||
/** @var PageInterface $child_page|null */
|
||||
$child_page = $child_page->parent();
|
||||
$page = $pages->find($uri->route());
|
||||
/** @var PageInterface|null $child_page */
|
||||
$child_page = $page ? $page->parent() : null;
|
||||
while ($child_page && !$child_page->root()) {
|
||||
if ($this->path() === $child_page->path()) {
|
||||
return true;
|
||||
}
|
||||
$child_page = $child_page->parent();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,10 @@ use Grav\Common\Grav;
|
||||
use Grav\Common\Media\Interfaces\MediaCollectionInterface;
|
||||
use Grav\Common\Media\Interfaces\MediaUploadInterface;
|
||||
use Grav\Common\Media\Traits\MediaTrait;
|
||||
use Grav\Common\Page\Media;
|
||||
use Grav\Common\Page\Medium\Medium;
|
||||
use Grav\Common\Page\Medium\MediumFactory;
|
||||
use Grav\Common\Utils;
|
||||
use Grav\Framework\Cache\CacheInterface;
|
||||
use Grav\Framework\Filesystem\Filesystem;
|
||||
use Grav\Framework\Flex\FlexDirectory;
|
||||
@@ -23,6 +25,7 @@ use Grav\Framework\Form\FormFlashFile;
|
||||
use Psr\Http\Message\UploadedFileInterface;
|
||||
use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
|
||||
use RuntimeException;
|
||||
use function array_key_exists;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use function is_callable;
|
||||
@@ -75,11 +78,40 @@ trait FlexMediaTrait
|
||||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @return MediaCollectionInterface|null
|
||||
*/
|
||||
public function getMediaField(string $field): ?MediaCollectionInterface
|
||||
{
|
||||
// Field specific media.
|
||||
$settings = $this->getFieldSettings($field);
|
||||
if (!empty($settings['media_field'])) {
|
||||
$var = 'destination';
|
||||
} elseif (!empty($settings['media_picker_field'])) {
|
||||
$var = 'folder';
|
||||
}
|
||||
|
||||
if (empty($var)) {
|
||||
// Not a media field.
|
||||
$media = null;
|
||||
} elseif ($settings['self']) {
|
||||
// Uses main media.
|
||||
$media = $this->getMedia();
|
||||
} else {
|
||||
// Uses custom media.
|
||||
$media = new Media($settings[$var]);
|
||||
$this->addUpdatedMedia($media);
|
||||
}
|
||||
|
||||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @return array|null
|
||||
*/
|
||||
protected function getFieldSettings(string $field): ?array
|
||||
public function getFieldSettings(string $field): ?array
|
||||
{
|
||||
if ($field === '') {
|
||||
return null;
|
||||
@@ -88,14 +120,32 @@ trait FlexMediaTrait
|
||||
// Load settings for the field.
|
||||
$schema = $this->getBlueprint()->schema();
|
||||
$settings = $field && is_object($schema) ? (array)$schema->getProperty($field) : null;
|
||||
if (!isset($settings) || !is_array($settings)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isset($settings['type']) && (in_array($settings['type'], ['avatar', 'file', 'pagemedia']) || !empty($settings['destination']))) {
|
||||
// Set destination folder.
|
||||
$type = $settings['type'] ?? '';
|
||||
|
||||
// Media field.
|
||||
if (!empty($settings['media_field']) || array_key_exists('destination', $settings) || in_array($type, ['avatar', 'file', 'pagemedia'], true)) {
|
||||
$settings['media_field'] = true;
|
||||
if (empty($settings['destination']) || in_array($settings['destination'], ['@self', 'self@', '@self@'], true)) {
|
||||
$settings['destination'] = $this->getMediaFolder();
|
||||
$var = 'destination';
|
||||
}
|
||||
|
||||
// Media picker field.
|
||||
if (!empty($settings['media_picker_field']) || in_array($type, ['filepicker', 'pagemediaselect'], true)) {
|
||||
$settings['media_picker_field'] = true;
|
||||
$var = 'folder';
|
||||
}
|
||||
|
||||
// Set media folder for media fields.
|
||||
if (isset($var)) {
|
||||
$folder = $settings[$var] ?? '';
|
||||
if (in_array(rtrim($folder, '/'), ['', '@self', 'self@', '@self@'], true)) {
|
||||
$settings[$var] = $this->getMediaFolder();
|
||||
$settings['self'] = true;
|
||||
} else {
|
||||
$settings[$var] = Utils::getPathFromToken($folder, $this);
|
||||
$settings['self'] = false;
|
||||
}
|
||||
}
|
||||
@@ -115,7 +165,6 @@ trait FlexMediaTrait
|
||||
return $settings + ['accept' => '*', 'limit' => 1000, 'self' => true];
|
||||
}
|
||||
|
||||
|
||||
protected function getMediaFields(): array
|
||||
{
|
||||
// Load settings for the field.
|
||||
@@ -206,12 +255,13 @@ trait FlexMediaTrait
|
||||
*/
|
||||
public function uploadMediaFile(UploadedFileInterface $uploadedFile, string $filename = null, string $field = null): void
|
||||
{
|
||||
$media = $this->getMedia();
|
||||
$settings = $this->getMediaFieldSettings($field ?? '');
|
||||
|
||||
$media = $field ? $this->getMediaField($field) : $this->getMedia();
|
||||
if (!$media instanceof MediaUploadInterface) {
|
||||
throw new RuntimeException("Media for {$this->getFlexDirectory()->getFlexType()} doesn't support file uploads.");
|
||||
}
|
||||
|
||||
$settings = $this->getMediaFieldSettings($field ?? '');
|
||||
$filename = $media->checkUploadedFile($uploadedFile, $filename, $settings);
|
||||
$media->copyUploadedFile($uploadedFile, $filename, $settings);
|
||||
$this->clearMediaCache();
|
||||
@@ -322,13 +372,20 @@ trait FlexMediaTrait
|
||||
foreach ($this->getUpdatedMedia() as $filename => $upload) {
|
||||
if (is_array($upload)) {
|
||||
// Uses new format with [UploadedFileInterface, array].
|
||||
$upload = $upload[0];
|
||||
$settings = $upload[1];
|
||||
if ($settings['destination'] === $media->getPath()) {
|
||||
$upload = $upload[0];
|
||||
} else {
|
||||
$upload = false;
|
||||
}
|
||||
}
|
||||
if ($upload) {
|
||||
$medium = MediumFactory::fromUploadedFile($upload);
|
||||
if (false !== $upload) {
|
||||
$medium = $upload ? MediumFactory::fromUploadedFile($upload) : null;
|
||||
$updated = true;
|
||||
if ($medium) {
|
||||
$updated = true;
|
||||
$media->add($filename, $medium);
|
||||
} else {
|
||||
$media->hide($filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -356,7 +413,6 @@ trait FlexMediaTrait
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Upload/delete altered files.
|
||||
/**
|
||||
* @var string $filename
|
||||
|
||||
Reference in New Issue
Block a user