aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorFrançois D <franek@users.noreply.github.com>2017-08-23 23:06:40 +0200
committerFrançois D <franek@users.noreply.github.com>2017-08-25 21:19:47 +0200
commita991c46eedec0efb24d0a9974b1c7fcabf8cfa66 (patch)
treefa33236c5ef67e023833c889eb52d5bed99d35bd /src
parent2490f61dca635026a3eb9b5e9b6978b1981b1172 (diff)
downloadwallabag-a991c46eedec0efb24d0a9974b1c7fcabf8cfa66.tar.gz
wallabag-a991c46eedec0efb24d0a9974b1c7fcabf8cfa66.tar.zst
wallabag-a991c46eedec0efb24d0a9974b1c7fcabf8cfa66.zip
Set a starred_at field when an entry is starred.
This date is used to sort starred entries. Can not use Entry::timestamps method otherwise starred_at will be updated each time entry is updated. Add an updateStar method into Entry class A migration script has been added in order to set starred_at field.
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/ApiBundle/Controller/EntryRestController.php4
-rw-r--r--src/Wallabag/CoreBundle/Controller/EntryController.php1
-rw-r--r--src/Wallabag/CoreBundle/Entity/Entry.php47
-rw-r--r--src/Wallabag/CoreBundle/Repository/EntryRepository.php11
4 files changed, 56 insertions, 7 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
index bc1b6f92..6db97731 100644
--- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php
@@ -361,7 +361,7 @@ class EntryRestController extends WallabagRestController
361 } 361 }
362 362
363 if (null !== $data['isStarred']) { 363 if (null !== $data['isStarred']) {
364 $entry->setStarred((bool) $data['isStarred']); 364 $entry->updateStar((bool) $data['isStarred']);
365 } 365 }
366 366
367 if (!empty($data['tags'])) { 367 if (!empty($data['tags'])) {
@@ -464,7 +464,7 @@ class EntryRestController extends WallabagRestController
464 } 464 }
465 465
466 if (null !== $data['isStarred']) { 466 if (null !== $data['isStarred']) {
467 $entry->setStarred((bool) $data['isStarred']); 467 $entry->updateStar((bool) $data['isStarred']);
468 } 468 }
469 469
470 if (!empty($data['tags'])) { 470 if (!empty($data['tags'])) {
diff --git a/src/Wallabag/CoreBundle/Controller/EntryController.php b/src/Wallabag/CoreBundle/Controller/EntryController.php
index 3dcfbebe..b0b74c38 100644
--- a/src/Wallabag/CoreBundle/Controller/EntryController.php
+++ b/src/Wallabag/CoreBundle/Controller/EntryController.php
@@ -333,6 +333,7 @@ class EntryController extends Controller
333 $this->checkUserAction($entry); 333 $this->checkUserAction($entry);
334 334
335 $entry->toggleStar(); 335 $entry->toggleStar();
336 $entry->updateStar($entry->isStarred());
336 $this->getDoctrine()->getManager()->flush(); 337 $this->getDoctrine()->getManager()->flush();
337 338
338 $message = 'flashes.entry.notice.entry_unstarred'; 339 $message = 'flashes.entry.notice.entry_unstarred';
diff --git a/src/Wallabag/CoreBundle/Entity/Entry.php b/src/Wallabag/CoreBundle/Entity/Entry.php
index 61d01bdc..4367902e 100644
--- a/src/Wallabag/CoreBundle/Entity/Entry.php
+++ b/src/Wallabag/CoreBundle/Entity/Entry.php
@@ -143,6 +143,15 @@ class Entry
143 private $publishedBy; 143 private $publishedBy;
144 144
145 /** 145 /**
146 * @var \DateTime
147 *
148 * @ORM\Column(name="starred_at", type="datetime", nullable=true)
149 *
150 * @Groups({"entries_for_user", "export_all"})
151 */
152 private $starredAt = null;
153
154 /**
146 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"}) 155 * @ORM\OneToMany(targetEntity="Wallabag\AnnotationBundle\Entity\Annotation", mappedBy="entry", cascade={"persist", "remove"})
147 * @ORM\JoinTable 156 * @ORM\JoinTable
148 * 157 *
@@ -476,6 +485,44 @@ class Entry
476 } 485 }
477 486
478 /** 487 /**
488 * @return \DateTime|null
489 */
490 public function getStarredAt()
491 {
492 return $this->starredAt;
493 }
494
495 /**
496 * @param \DateTime|null $starredAt
497 *
498 * @return Entry
499 */
500 public function setStarredAt($starredAt = null)
501 {
502 $this->starredAt = $starredAt;
503
504 return $this;
505 }
506
507 /**
508 * update isStarred and starred_at fields.
509 *
510 * @param bool $isStarred
511 *
512 * @return Entry
513 */
514 public function updateStar($isStarred = false)
515 {
516 $this->setStarred($isStarred);
517 $this->setStarredAt(null);
518 if ($this->isStarred()) {
519 $this->setStarredAt(new \DateTime());
520 }
521
522 return $this;
523 }
524
525 /**
479 * @return ArrayCollection<Annotation> 526 * @return ArrayCollection<Annotation>
480 */ 527 */
481 public function getAnnotations() 528 public function getAnnotations()
diff --git a/src/Wallabag/CoreBundle/Repository/EntryRepository.php b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
index eb5e3205..ecc159fc 100644
--- a/src/Wallabag/CoreBundle/Repository/EntryRepository.php
+++ b/src/Wallabag/CoreBundle/Repository/EntryRepository.php
@@ -65,7 +65,7 @@ class EntryRepository extends EntityRepository
65 public function getBuilderForStarredByUser($userId) 65 public function getBuilderForStarredByUser($userId)
66 { 66 {
67 return $this 67 return $this
68 ->getBuilderByUser($userId) 68 ->getBuilderByUser($userId, 'starredAt', 'desc')
69 ->andWhere('e.isStarred = true') 69 ->andWhere('e.isStarred = true')
70 ; 70 ;
71 } 71 }
@@ -401,15 +401,16 @@ class EntryRepository extends EntityRepository
401 /** 401 /**
402 * Return a query builder to used by other getBuilderFor* method. 402 * Return a query builder to used by other getBuilderFor* method.
403 * 403 *
404 * @param int $userId 404 * @param int $userId
405 * @param string $sortBy
406 * @param string $direction
405 * 407 *
406 * @return QueryBuilder 408 * @return QueryBuilder
407 */ 409 */
408 private function getBuilderByUser($userId) 410 private function getBuilderByUser($userId, $sortBy = 'createdAt', $direction = 'desc')
409 { 411 {
410 return $this->createQueryBuilder('e') 412 return $this->createQueryBuilder('e')
411 ->andWhere('e.user = :userId')->setParameter('userId', $userId) 413 ->andWhere('e.user = :userId')->setParameter('userId', $userId)
412 ->orderBy('e.createdAt', 'desc') 414 ->orderBy(sprintf('e.%s', $sortBy), $direction);
413 ;
414 } 415 }
415} 416}