mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-16 22:43:19 +00:00
Add NullableDateTime formatting class
This commit is contained in:
@@ -61,6 +61,7 @@ use Alchemy\Phrasea\SearchEngine\SearchEngineResult;
|
||||
use Alchemy\Phrasea\SearchEngine\SearchEngineSuggestion;
|
||||
use Alchemy\Phrasea\Status\StatusStructure;
|
||||
use Alchemy\Phrasea\TaskManager\LiveInformation;
|
||||
use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
use Doctrine\ORM\EntityManager;
|
||||
use Symfony\Component\Form\Form;
|
||||
use Symfony\Component\HttpFoundation\File\UploadedFile;
|
||||
@@ -138,10 +139,10 @@ class V1Controller extends Controller
|
||||
'pid' => $data['process-id'],
|
||||
'jobId' => $task->getJobId(),
|
||||
'period' => $task->getPeriod(),
|
||||
'last_exec_time' => $task->getLastExecution() ? $task->getLastExecution()->format(DATE_ATOM) : null,
|
||||
'last_execution' => $task->getLastExecution() ? $task->getLastExecution()->format(DATE_ATOM) : null,
|
||||
'updated' => $task->getUpdated() ? $task->getUpdated()->format(DATE_ATOM) : null,
|
||||
'created' => $task->getCreated() ? $task->getCreated()->format(DATE_ATOM) : null,
|
||||
'last_exec_time' => NullableDateTime::format($task->getLastExecution()),
|
||||
'last_execution' => NullableDateTime::format($task->getLastExecution()),
|
||||
'updated' => NullableDateTime::format($task->getUpdated()),
|
||||
'created' => NullableDateTime::format($task->getCreated()),
|
||||
'auto_start' => $task->getStatus() === Task::STATUS_STARTED,
|
||||
'crashed' => $task->getCrashed(),
|
||||
];
|
||||
@@ -709,9 +710,9 @@ class V1Controller extends Controller
|
||||
'position' => $user->getActivity() ?: null,
|
||||
'company' => $user->getCompany() ?: null,
|
||||
'geoname_id' => $user->getGeonameId() ?: null,
|
||||
'last_connection' => $user->getLastConnection() ? $user->getLastConnection()->format(DATE_ATOM) : null,
|
||||
'created_on' => $user->getCreated() ? $user->getCreated()->format(DATE_ATOM) : null,
|
||||
'updated_on' => $user->getUpdated() ? $user->getUpdated()->format(DATE_ATOM) : null,
|
||||
'last_connection' => NullableDateTime::format($user->getLastConnection()),
|
||||
'created_on' => NullableDateTime::format($user->getCreated()),
|
||||
'updated_on' => NullableDateTime::format($user->getUpdated()),
|
||||
'locale' => $user->getLocale() ?: null,
|
||||
];
|
||||
}
|
||||
@@ -1466,11 +1467,7 @@ class V1Controller extends Controller
|
||||
];
|
||||
}, iterator_to_array($basket->getValidation()->getParticipants()));
|
||||
|
||||
$expires_on_atom = $basket->getValidation()->getExpires();
|
||||
|
||||
if ($expires_on_atom instanceof \DateTime) {
|
||||
$expires_on_atom = $expires_on_atom->format(DATE_ATOM);
|
||||
}
|
||||
$expires_on_atom = NullableDateTime::format($basket->getValidation()->getExpires());
|
||||
|
||||
$ret = array_merge([
|
||||
'validation_users' => $users,
|
||||
|
@@ -17,6 +17,7 @@ use Alchemy\Phrasea\Feed\FeedInterface;
|
||||
use Alchemy\Phrasea\Feed\Link\FeedLink;
|
||||
use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterface
|
||||
@@ -48,8 +49,6 @@ class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterf
|
||||
*/
|
||||
public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null)
|
||||
{
|
||||
$updated_on = $feed->getUpdatedOn();
|
||||
|
||||
$document = new \DOMDocument('1.0', 'UTF-8');
|
||||
$document->formatOutput = true;
|
||||
$document->standalone = true;
|
||||
@@ -59,8 +58,7 @@ class AtomFormatter extends FeedFormatterAbstract implements FeedFormatterInterf
|
||||
$root->setAttribute('xmlns:media', 'http://search.yahoo.com/mrss/');
|
||||
|
||||
$this->addTag($document, $root, 'title', $feed->getTitle());
|
||||
if ($updated_on instanceof \DateTime) {
|
||||
$updated_on = $updated_on->format(DATE_ATOM);
|
||||
if (null !== $updated_on = NullableDateTime::format($feed->getUpdatedOn())) {
|
||||
$this->addTag($document, $root, 'updated', $updated_on);
|
||||
}
|
||||
|
||||
|
@@ -19,6 +19,7 @@ use Alchemy\Phrasea\Model\Entities\FeedEntry;
|
||||
use Alchemy\Phrasea\Model\Entities\FeedItem;
|
||||
use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
use DateTime;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
@@ -52,8 +53,6 @@ class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterIn
|
||||
*/
|
||||
public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null)
|
||||
{
|
||||
$updated_on = $feed->getUpdatedOn();
|
||||
|
||||
$doc = new \DOMDocument('1.0', 'UTF-8');
|
||||
$doc->formatOutput = true;
|
||||
$doc->standalone = true;
|
||||
@@ -89,8 +88,7 @@ class CoolirisFormatter extends FeedFormatterAbstract implements FeedFormatterIn
|
||||
$this->addTag($doc, $channel, 'managingEditor', $this->managingEditor);
|
||||
if (isset($this->webMaster))
|
||||
$this->addTag($doc, $channel, 'webMaster', $this->webMaster);
|
||||
if ($updated_on instanceof DateTime) {
|
||||
$updated_on = $updated_on->format(DATE_RFC2822);
|
||||
if (null !== $updated_on = NullableDateTime::format($feed->getUpdatedOn(), DATE_RFC2822)) {
|
||||
$this->addTag($doc, $channel, 'pubDate', $updated_on);
|
||||
}
|
||||
if (isset($this->lastBuildDate) && $this->lastBuildDate instanceof DateTime) {
|
||||
|
@@ -17,6 +17,7 @@ use Alchemy\Phrasea\Feed\Link\FeedLink;
|
||||
use Alchemy\Phrasea\Feed\Link\LinkGeneratorCollection;
|
||||
use Alchemy\Phrasea\Feed\RSS\FeedRSSImage;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Alchemy\Phrasea\Model\Entities\FeedEntry;
|
||||
use Alchemy\Phrasea\Feed\Link\FeedLinkGenerator;
|
||||
@@ -51,8 +52,6 @@ class RssFormatter extends FeedFormatterAbstract implements FeedFormatterInterfa
|
||||
*/
|
||||
public function format(FeedInterface $feed, $page, User $user = null, $generator = 'Phraseanet', Application $app = null)
|
||||
{
|
||||
$updated_on = $feed->getUpdatedOn();
|
||||
|
||||
$next = $prev = null;
|
||||
|
||||
if ($feed->hasPage($page + 1, self::PAGE_SIZE)) {
|
||||
@@ -104,11 +103,10 @@ class RssFormatter extends FeedFormatterAbstract implements FeedFormatterInterfa
|
||||
$this->addTag($doc, $channel, 'managingEditor', $this->managingEditor);
|
||||
if (isset($this->webMaster))
|
||||
$this->addTag($doc, $channel, 'webMaster', $this->webMaster);
|
||||
if ($updated_on instanceof \DateTime) {
|
||||
$updated_on = $updated_on->format(DATE_RFC2822);
|
||||
if (null !== $updated_on = NullableDateTime::format($feed->getUpdatedOn(), DATE_RFC2822)) {
|
||||
$this->addTag($doc, $channel, 'pubDate', $updated_on);
|
||||
}
|
||||
if (isset($this->lastBuildDate) && $this->lastBuildDate instanceof DateTime) {
|
||||
if (isset($this->lastBuildDate) && $this->lastBuildDate instanceof \DateTime) {
|
||||
$last_build = $this->lastBuildDate->format(DATE_RFC2822);
|
||||
$this->addTag($doc, $channel, 'lastBuildDate', $last_build);
|
||||
}
|
||||
|
@@ -94,8 +94,8 @@ class ApiOrderController extends BaseOrderController
|
||||
$pager = new Pagerfanta(new DoctrineORMAdapter($builder, false));
|
||||
$pager->setCurrentPage($page);
|
||||
$pager->setMaxPerPage($perPage);
|
||||
$paginator = new PagerfantaPaginatorAdapter($pager, $routeGenerator);
|
||||
$resource->setPaginator($paginator);
|
||||
|
||||
$resource->setPaginator(new PagerfantaPaginatorAdapter($pager, $routeGenerator));
|
||||
|
||||
return $this->returnResourceResponse($request, $fractal, $resource);
|
||||
}
|
||||
|
19
lib/Alchemy/Phrasea/Utilities/NullableDateTime.php
Normal file
19
lib/Alchemy/Phrasea/Utilities/NullableDateTime.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2016 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Utilities;
|
||||
|
||||
final class NullableDateTime
|
||||
{
|
||||
public static function format(\DateTime $dateTime = null, $format = DATE_ATOM, $default = null)
|
||||
{
|
||||
return $dateTime ? $dateTime->format($format) : $default;
|
||||
}
|
||||
}
|
@@ -26,6 +26,7 @@ use Alchemy\Phrasea\Core\Event\Acl\SysadminChangedEvent;
|
||||
use Alchemy\Phrasea\Model\Entities\User;
|
||||
use Alchemy\Phrasea\Model\RecordInterface;
|
||||
use Alchemy\Phrasea\Model\RecordReferenceInterface;
|
||||
use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
use Doctrine\DBAL\DBALException;
|
||||
|
||||
|
||||
@@ -1706,10 +1707,10 @@ class ACL implements cache_cacheableInterface
|
||||
}
|
||||
|
||||
$params = [
|
||||
':usr_id' => $this->user->getId()
|
||||
, ':base_id' => $base_id
|
||||
, 'limited_from' => ($limit_from ? $limit_from->format(DATE_ISO8601) : null)
|
||||
, 'limited_to' => ($limit_to ? $limit_to->format(DATE_ISO8601) : null)
|
||||
':usr_id' => $this->user->getId(),
|
||||
':base_id' => $base_id,
|
||||
'limited_from' => NullableDateTime::format($limit_from, DATE_ISO8601),
|
||||
'limited_to' => NullableDateTime::format($limit_to, DATE_ISO8601),
|
||||
];
|
||||
|
||||
$stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql);
|
||||
|
@@ -10,6 +10,7 @@
|
||||
*/
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
|
||||
class Bridge_Element
|
||||
{
|
||||
@@ -383,9 +384,9 @@ class Bridge_Element
|
||||
SET uploaded_on = :uploaded_on, updated_on = :update WHERE id = :id';
|
||||
|
||||
$params = [
|
||||
':uploaded_on' => $this->uploaded_on ? $this->uploaded_on->format(DATE_ISO8601) : null
|
||||
, ':id' => $this->id
|
||||
, ':update' => $this->updated_on->format(DATE_ISO8601)
|
||||
':uploaded_on' => NullableDateTime::format($this->uploaded_on, DATE_ISO8601),
|
||||
':id' => $this->id,
|
||||
':update' => $this->updated_on->format(DATE_ISO8601),
|
||||
];
|
||||
|
||||
$stmt = $this->app->getApplicationBox()->get_connection()->prepare($sql);
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
use Alchemy\Phrasea\Application;
|
||||
use Alchemy\Phrasea\Http\StaticFile\Symlink\SymLinker;
|
||||
use Alchemy\Phrasea\Utilities\NullableDateTime;
|
||||
use Guzzle\Http\Url;
|
||||
use MediaAlchemyst\Alchemyst;
|
||||
use MediaVorus\Media\MediaInterface;
|
||||
@@ -206,8 +207,8 @@ SQL;
|
||||
'physically_present' => $this->is_physically_present,
|
||||
'is_substituted' => $this->is_substituted,
|
||||
'subdef_id' => $this->subdef_id,
|
||||
'updated_on' => $this->modification_date ? $this->modification_date->format(DATE_ATOM) : '',
|
||||
'created_on' => $this->creation_date ? $this->creation_date->format(DATE_ATOM) : '',
|
||||
'updated_on' => NullableDateTime::format($this->modification_date),
|
||||
'created_on' => NullableDateTime::format($this->creation_date),
|
||||
'etag' => $this->etag,
|
||||
'url' => (string)$this->url,
|
||||
];
|
||||
|
Reference in New Issue
Block a user