Attachments... .

This commit is contained in:
Matias De lellis
2020-06-14 13:55:25 -03:00
parent 16d82bcbae
commit 20e150341c
16 changed files with 532 additions and 73 deletions

28
lib/Db/Attach.php Normal file
View File

@@ -0,0 +1,28 @@
<?php
namespace OCA\QuickNotes\Db;
use JsonSerializable;
use OCP\AppFramework\Db\Entity;
class Attach extends Entity implements JsonSerializable {
protected $userId;
protected $noteId;
protected $fileId;
protected $createdAt;
protected $previewUrl;
public function setPreviewUrl($previewUrl) {
$this->previewUrl = $previewUrl;
}
public function jsonSerialize() {
return [
'id' => $this->id,
'note_id' => $this->noteId,
'file_id' => $this->fileId,
'created_at' => $this->createdAt,
'preview_url' => $this->previewUrl,
];
}
}

89
lib/Db/AttachMapper.php Normal file
View File

@@ -0,0 +1,89 @@
<?php declare(strict_types=1);
namespace OCA\QuickNotes\Db;
use OCP\IDBConnection;
use OCP\AppFramework\Db\QBMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\DB\QueryBuilder\IQueryBuilder;
class AttachMapper extends QBMapper {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'quicknotes_attach');
}
/**
* @param int $id
* @param string $userId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Attach
*/
public function find($id, $userId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('id', $qb->createNamedParameter($id, IQueryBuilder::PARAM_INT))
);
return $this->findEntity($qb);
}
public function findAll($userId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR))
);
return $this->findEntities($qb);
}
/**
* @param string $userId
* @param int $noteId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Attach
*/
public function findFileAttachFromNote($userId, $noteId, $fileId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('note_id', $qb->createNamedParameter($noteId, IQueryBuilder::PARAM_INT)),
$qb->expr()->eq('file_id', $qb->createNamedParameter($fileId, IQueryBuilder::PARAM_INT))
);
return $this->findEntity($qb);
}
public function fileAttachExists($userId, $noteId, $fileId) {
try {
return $this->findFileAttachFromNote($userId, $noteId, $fileId);
} catch (DoesNotExistException $e) {
return false;
}
return false;
}
/**
* @param string $userId
* @param int $noteId
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Note[]
*/
public function findFromNote($userId, $noteId) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('note_id', $qb->createNamedParameter($noteId, IQueryBuilder::PARAM_INT))
);
return $this->findEntities($qb);
}
}

View File

@@ -16,6 +16,7 @@ class Note extends Entity implements JsonSerializable {
protected $sharedWith;
protected $isShared;
protected $tags;
protected $attachts;
protected $color;
protected $isPinned;
@@ -41,7 +42,8 @@ class Note extends Entity implements JsonSerializable {
'userid' => $this->userId,
'sharedwith' => $this->sharedWith,
'isshared' => $this->isShared,
'tags' => $this->tags
'tags' => $this->tags,
'attachts' => $this->attachts
];
}
}