Send notifications when a card is overdue
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
committed by
Julius Härtl
parent
52fc971529
commit
a346e215cd
@@ -41,6 +41,7 @@ class Card extends RelationalEntity implements JsonSerializable {
|
||||
protected $order;
|
||||
protected $archived = false;
|
||||
protected $duedate = null;
|
||||
protected $notified = false;
|
||||
|
||||
const DUEDATE_FUTURE = 0;
|
||||
const DUEDATE_NEXT = 1;
|
||||
@@ -54,6 +55,7 @@ class Card extends RelationalEntity implements JsonSerializable {
|
||||
$this->addType('lastModified', 'integer');
|
||||
$this->addType('createdAt', 'integer');
|
||||
$this->addType('archived', 'boolean');
|
||||
$this->addType('notified', 'boolean');
|
||||
$this->addRelation('labels');
|
||||
$this->addResolvable('owner');
|
||||
}
|
||||
@@ -92,6 +94,7 @@ class Card extends RelationalEntity implements JsonSerializable {
|
||||
}
|
||||
}
|
||||
$json['duedate'] = $this->getDuedate();
|
||||
unset($json['notified']);
|
||||
return $json;
|
||||
}
|
||||
|
||||
|
||||
@@ -45,11 +45,28 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
return parent::insert($entity);
|
||||
}
|
||||
|
||||
public function update(Entity $entity) {
|
||||
$entity->setLastModified(time());
|
||||
public function update(Entity $entity, $updateModified = true) {
|
||||
if ($updateModified)
|
||||
$entity->setLastModified(time());
|
||||
|
||||
// make sure we only reset the notification flag if the duedate changes
|
||||
if (in_array('duedate', $entity->getUpdatedFields())) {
|
||||
$existing = $this->find($entity->getId());
|
||||
if ($existing->getDuedate() !== $entity->getDuedate())
|
||||
$entity->setNotified(false);
|
||||
}
|
||||
|
||||
// TODO: also remove pending notifications
|
||||
|
||||
return parent::update($entity);
|
||||
}
|
||||
|
||||
public function markNotified(Card $card) {
|
||||
$cardUpdate = new Card();
|
||||
$cardUpdate->setId($card->getId());
|
||||
$cardUpdate->setNotified(true);
|
||||
return parent::update($cardUpdate);
|
||||
}
|
||||
/**
|
||||
* @param $id
|
||||
* @return RelationalEntity if not found
|
||||
@@ -84,6 +101,12 @@ class CardMapper extends DeckMapper implements IPermissionMapper {
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function findOverdue() {
|
||||
$sql = 'SELECT id,title,duedate,notified from `*PREFIX*deck_cards` WHERE duedate < NOW()';
|
||||
$entities = $this->findEntities($sql);
|
||||
return $entities;
|
||||
}
|
||||
|
||||
public function delete(Entity $entity) {
|
||||
// delete assigned labels
|
||||
$this->labelMapper->deleteLabelAssignmentsForCard($entity->getId());
|
||||
|
||||
Reference in New Issue
Block a user