favcommand.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. class FavCommand extends Command
  3. {
  4. var $other = null;
  5. function __construct($user, $other)
  6. {
  7. parent::__construct($user);
  8. $this->other = $other;
  9. }
  10. function handle($channel)
  11. {
  12. $notice = $this->getNotice($this->other);
  13. $fave = new Fave();
  14. $fave->user_id = $this->user->id;
  15. $fave->notice_id = $notice->id;
  16. $fave->find();
  17. if ($fave->fetch()) {
  18. // TRANS: Error message text shown when a favorite could not be set because it has already been favorited.
  19. $channel->error($this->user, _('Could not create favorite: Already favorited.'));
  20. return;
  21. }
  22. try {
  23. $fave = Fave::addNew($this->user->getProfile(), $notice);
  24. } catch (Exception $e) {
  25. $channel->error($this->user, $e->getMessage());
  26. return;
  27. }
  28. // TRANS: Text shown when a notice has been marked as favourite successfully.
  29. $channel->output($this->user, _('Notice marked as fave.'));
  30. }
  31. }