Skip to content

Commit

Permalink
Merge pull request #13 from sulu/feature/authored-date
Browse files Browse the repository at this point in the history
added authored date and settings tab
  • Loading branch information
alexander-schranz authored Aug 17, 2016
2 parents 4e0882a + 78507bd commit 958f12c
Show file tree
Hide file tree
Showing 16 changed files with 544 additions and 9 deletions.
9 changes: 8 additions & 1 deletion Admin/ArticleContententNavigationProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ public function getNavigationItems(array $options = [])
$excerpt->setComponent('articles/edit/excerpt@suluarticle');
$excerpt->setDisplay(['edit']);

return [$details, $seo, $excerpt];
$settings = new ContentNavigationItem('content-navigation.contents.settings');
$settings->setId('settings');
$settings->setPosition(40);
$settings->setAction('settings');
$settings->setComponent('articles/edit/settings@suluarticle');
$settings->setDisplay(['edit']);

return [$details, $seo, $excerpt, $settings];
}
}
24 changes: 22 additions & 2 deletions Controller/ArticleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Sulu\Component\Rest\Exception\MissingParameterException;
use Sulu\Component\Rest\ListBuilder\FieldDescriptor;
use Sulu\Component\Rest\ListBuilder\ListRepresentation;
use Sulu\Component\Rest\ListBuilder\ListRestHelper;
use Sulu\Component\Rest\RequestParametersTrait;
use Sulu\Component\Rest\RestController;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -77,7 +76,7 @@ public function cgetFieldsAction()
*/
public function cgetAction(Request $request)
{
$restHelper = new ListRestHelper($request);
$restHelper = $this->get('sulu_core.list_rest_helper');

/** @var Manager $manager */
$manager = $this->get('es.manager.default');
Expand Down Expand Up @@ -269,6 +268,11 @@ private function persistDocument($data, $document, $locale)
);
$form->submit($data, false);

if (array_key_exists('authored', $data)) {
$document->setAuthored(new \DateTime($data['authored']));
}
$document->setAuthors($this->getAuthors($data));

if (!$form->isValid()) {
throw new InvalidFormException($form);
}
Expand All @@ -283,6 +287,22 @@ private function persistDocument($data, $document, $locale)
);
}

/**
* Returns authors or current user.
*
* @param array $data
*
* @return int[]
*/
private function getAuthors(array $data)
{
if (!array_key_exists('authors', $data)) {
return [$this->getUser()->getContact()->getId()];
}

return $data['authors'];
}

/**
* Returns document-manager.
*
Expand Down
62 changes: 62 additions & 0 deletions Document/ArticleDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,20 @@ class ArticleDocument implements
*/
protected $published;

/**
* Timestamp of authoring (can be set by user).
*
* @var \DateTime
*/
protected $authored;

/**
* Array of contact-ids which has authored this article.
*
* @var int[]
*/
protected $authors = [];

public function __construct()
{
$this->structure = new Structure();
Expand Down Expand Up @@ -399,4 +413,52 @@ public function getPublished()
{
return $this->published;
}

/**
* Set authored date-time.
*
* @param \DateTime $authored
*
* @return $this
*/
public function setAuthored(\DateTime $authored = null)
{
$this->authored = $authored;

return $this;
}

/**
* Returns date-time of authoring this article.
*
* @return \DateTime
*/
public function getAuthored()
{
return $this->authored;
}

/**
* Returns id of authors.
*
* @return int[]
*/
public function getAuthors()
{
return $this->authors;
}

/**
* Set authors.
*
* @param int[] $authors
*
* @return $this
*/
public function setAuthors($authors)
{
$this->authors = $authors;

return $this;
}
}
62 changes: 62 additions & 0 deletions Document/ArticleOngrDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@ class ArticleOngrDocument
*/
protected $seo;

/**
* @var \DateTime
*
* @Property(type="date")
*/
protected $authored;

/**
* @var int[]
*
* @Property(type="integer")
*/
protected $authors;

/**
* @param string $uuid
*/
Expand Down Expand Up @@ -340,4 +354,52 @@ public function setSeo($seo)

return $this;
}

/**
* Returns authored.
*
* @return \DateTime
*/
public function getAuthored()
{
return $this->authored;
}

/**
* Set authored date.
*
* @param \DateTime $authored
*
* @return $this
*/
public function setAuthored(\DateTime $authored = null)
{
$this->authored = $authored;

return $this;
}

/**
* Returns authors.
*
* @return int[]
*/
public function getAuthors()
{
return $this->authors;
}

/**
* Set authors.
*
* @param int[] $authors
*
* @return $this
*/
public function setAuthors($authors)
{
$this->authors = $authors;

return $this;
}
}
1 change: 1 addition & 0 deletions Document/Index/ArticleIndexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public function index(ArticleDocument $document)
$article->setTitle($document->getTitle());
$article->setChanged($document->getChanged());
$article->setCreated($document->getCreated());
$article->setAuthored($document->getAuthored());
$article->setChanger($this->userManager->getFullNameByUserId($document->getChanger()));
$article->setCreator($this->userManager->getFullNameByUserId($document->getCreator()));
$article->setType($this->getType($structure->getStructure()));
Expand Down
14 changes: 14 additions & 0 deletions Document/Subscriber/ArticleSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,19 @@ public function handleMetadataLoad(MetadataLoadEvent $event)
'property' => 'routePath',
]
);
$metadata->addFieldMapping(
'authored',
[
'encoding' => 'system_localized',
'property' => 'authored',
]
);
$metadata->addFieldMapping(
'authors',
[
'encoding' => 'system_localized',
'property' => 'authors',
]
);
}
}
4 changes: 4 additions & 0 deletions Resources/config/serializer/Document.ArticleDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
<property name="changed" type="DateTime" groups="defaultPage"/>

<property name="published" type="DateTime" groups="defaultPage,smallPage"/>
<property name="authored" type="DateTime" groups="defaultPage,smallPage"/>
<property name="authors" groups="defaultPage,smallPage">
<type><![CDATA[array<integer>]]></type>
</property>
<property name="extensions" type="Sulu\Component\Content\Document\Extension\ExtensionContainer" serialized-name="ext" groups="defaultPage,preview"/>
</class>
</serializer>
56 changes: 56 additions & 0 deletions Resources/public/dist/components/articles/edit/settings/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<form id="settings-form" class="grid">
<div class="grid-row">
<div class="grid-col-6 form-group">
<label for="authored"><%= translations.authored %></label>

<div id="authored"
data-mapper-property="authored"
data-aura-component="input@husky"
data-aura-skin="date"
data-aura-instance-name="authored"
data-aura-input-id="authored"
data-type="husky-input"
data-form="true"
class="trigger-save-button"/>
</div>
</div>
<div class="grid-row">
<div class="grid-col-12 form-group">
<label for="authors"><%= translations.authors %></label>

<div id="authors"
data-mapper-property="authors"
data-form="true"
data-type="contact-selection"
data-type-instance-name="authors"
data-aura-component="contact-selection@sulucontact"
data-aura-instance-name="authors"
data-aura-contact="true"
data-aura-account="false"
data-aura-url="/admin/api/customers"
data-aura-contact-url="/admin/api/contacts?flat=true&sortBy=lastName"/>
</div>
</div>

<div class="grid-row section m-top-40" id="changelog-container" style="display: none;">
<h2 class="divider m-bottom-20" title="Shadow Section">
<%= translations.changelog %>
</h2>

<div class="grid">
<div class="grid-row">
<div class="grid-col-2"><%= translations.changed %></div>
<div class="grid-col-10" id="changed">
<span class="name">...</span> (<span class="date">...</span>)
</div>
</div>

<div class="grid-row">
<div class="grid-col-2"><%= translations.created %></div>
<div class="grid-col-10" id="created">
<span class="name">...</span> (<span class="date">...</span>)
</div>
</div>
</div>
</div>
</form>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 56 additions & 0 deletions Resources/public/js/components/articles/edit/settings/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<form id="settings-form" class="grid">
<div class="grid-row">
<div class="grid-col-6 form-group">
<label for="authored"><%= translations.authored %></label>

<div id="authored"
data-mapper-property="authored"
data-aura-component="input@husky"
data-aura-skin="date"
data-aura-instance-name="authored"
data-aura-input-id="authored"
data-type="husky-input"
data-form="true"
class="trigger-save-button"/>
</div>
</div>
<div class="grid-row">
<div class="grid-col-12 form-group">
<label for="authors"><%= translations.authors %></label>

<div id="authors"
data-mapper-property="authors"
data-form="true"
data-type="contact-selection"
data-type-instance-name="authors"
data-aura-component="contact-selection@sulucontact"
data-aura-instance-name="authors"
data-aura-contact="true"
data-aura-account="false"
data-aura-url="/admin/api/customers"
data-aura-contact-url="/admin/api/contacts?flat=true&sortBy=lastName"/>
</div>
</div>

<div class="grid-row section m-top-40" id="changelog-container" style="display: none;">
<h2 class="divider m-bottom-20" title="Shadow Section">
<%= translations.changelog %>
</h2>

<div class="grid">
<div class="grid-row">
<div class="grid-col-2"><%= translations.changed %></div>
<div class="grid-col-10" id="changed">
<span class="name">...</span> (<span class="date">...</span>)
</div>
</div>

<div class="grid-row">
<div class="grid-col-2"><%= translations.created %></div>
<div class="grid-col-10" id="created">
<span class="name">...</span> (<span class="date">...</span>)
</div>
</div>
</div>
</div>
</form>
Loading

0 comments on commit 958f12c

Please sign in to comment.