Wiki navigation bar
This commit is contained in:
@ -51,12 +51,12 @@
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
*
|
||||
* @param string $folderPath
|
||||
* @param string $title
|
||||
* @param string $fileId
|
||||
*/
|
||||
public function create(string $title, int $fileId) {
|
||||
return $this->handleReadOnly(function () use ($title, $fileId) {
|
||||
return $this->service->create($title, $fileId, $this->userId);
|
||||
*/
|
||||
public function create(string $folderPath, string $title) {
|
||||
return $this->handleReadOnly(function () use ($folderPath, $title) {
|
||||
return $this->service->create($folderPath, $title, $this->userId);
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ class Wiki extends Entity implements JsonSerializable {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'file_id' => $this->file_id
|
||||
'fileId' => $this->fileId
|
||||
];
|
||||
}
|
||||
}
|
@ -7,7 +7,7 @@ use OCP\AppFramework\Db\QBMapper;
|
||||
class WikiMapper extends QBMapper {
|
||||
|
||||
public function __construct(IDBConnection $db) {
|
||||
parent::__construct($db, 'mywiki_wikis', Note::class);
|
||||
parent::__construct($db, 'mywiki', Wiki::class);
|
||||
}
|
||||
|
||||
public function usersCount(int $folderId) {
|
||||
@ -24,18 +24,17 @@ class WikiMapper extends QBMapper {
|
||||
public function find(int $id, string $userId) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where(
|
||||
$qb->expr()->eq('id', $qb->createNamedParameter($id))
|
||||
)->andWhere(
|
||||
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
||||
);
|
||||
|
||||
$qb->select('*')
|
||||
->from($this->getTableName())
|
||||
->where(
|
||||
$qb->expr()->eq('id', $qb->createNamedParameter($id))
|
||||
)->andWhere(
|
||||
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
||||
);
|
||||
return $this->findEntity($qb);
|
||||
}
|
||||
|
||||
public function findAll(string $userId) {
|
||||
|
||||
public function findAll(string $userId, mixed $filter=null) {
|
||||
$qb = $this->db->getQueryBuilder();
|
||||
|
||||
$qb->select('*')
|
||||
@ -44,6 +43,18 @@ class WikiMapper extends QBMapper {
|
||||
$qb->expr()->eq('user_id', $qb->createNamedParameter($userId))
|
||||
);
|
||||
|
||||
if ($filter) {
|
||||
if (array_key_exists('title',$filter) ) {
|
||||
$qb->where(
|
||||
$qb->expr()->eq('title', $qb->createNamedParameter($id))
|
||||
);
|
||||
}
|
||||
if (array_key_exists('fileId',$filter) ) {
|
||||
$qb->where(
|
||||
$qb->expr()->eq('fileId', $qb->createNamedParameter($id))
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
|
@ -96,16 +96,24 @@ class WikiHelper {
|
||||
return true;
|
||||
}
|
||||
|
||||
public function initWiki(string $title) :bool {
|
||||
$wiki = [
|
||||
"title"=>$title,
|
||||
"folderId"=>$this->wikiFolder->getId(),
|
||||
"pages"=>$this->rebuildWikiTree()
|
||||
];
|
||||
if ( $this->getWikiData() === null ) {
|
||||
return $this->setWikiData($wiki);
|
||||
public function initWiki(string $folderPath, string $title) :?int {
|
||||
$this->wikiFolder = $this->userFolder->get($folderPath);
|
||||
if ( !$this->isWiki() ) {
|
||||
return null;
|
||||
}
|
||||
return true;
|
||||
|
||||
$folderId = $this->wikiFolder->getId();
|
||||
if ( $this->getWikiData() === null ) {
|
||||
$wiki = [
|
||||
"title"=>$title,
|
||||
"folderId"=>$folderId,
|
||||
"pages"=>$this->rebuildWikiTree()
|
||||
];
|
||||
if ( !$this->setWikiData($wiki) ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return $folderId;
|
||||
}
|
||||
|
||||
public function add(int $parentId, string $title) {
|
||||
|
@ -39,6 +39,7 @@
|
||||
|
||||
$table->setPrimaryKey(['id']);
|
||||
$table->addIndex(['user_id'], 'mywiki_user_id_index');
|
||||
$table->addIndex(['file_id'], 'mywiki_file_id_index');
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -25,7 +25,7 @@ class WikiService {
|
||||
}
|
||||
|
||||
public function test() {
|
||||
$folderId = 381;
|
||||
$folderId = 880;
|
||||
return $this->wikiHelper->setFolderId($folderId)->reloadWikiTree();
|
||||
return $this->wikiHelper->setFolderId($folderId)->rename(707, 'UnoMasUno');
|
||||
return $this->wikiHelper->setFolderId($folderId)->rename(647, 'RenameTest3');
|
||||
@ -57,17 +57,20 @@ class WikiService {
|
||||
}
|
||||
}
|
||||
|
||||
public function create(string $title, int $fileId, string $userId) {
|
||||
$this->wikiHelper->setFolderId($fileId);
|
||||
if ( $this->wikiHelper->isWiki() ) {
|
||||
if ( !$this->wikiHelper->initWiki($title) ) {
|
||||
throw new ReadOnlyException('Error creating wiki');
|
||||
}
|
||||
public function create(string $folderPath, string $title, string $userId) {
|
||||
$folderId = $this->wikiHelper->initWiki($folderPath, $title);
|
||||
if ( $folderId === null ) {
|
||||
throw new ReadOnlyException('Error creating wiki');
|
||||
}
|
||||
|
||||
$wikis = $this->mapper->findAll($userId, ['fileId'=>$folderId]);
|
||||
if ( count($wikis)>0 ) {
|
||||
return $wikis[0];
|
||||
}
|
||||
|
||||
$wiki = new Wiki();
|
||||
$wiki->setTitle($title);
|
||||
$wiki->setFileId($fileId);
|
||||
$wiki->setFileId($folderId);
|
||||
$wiki->setUserId($userId);
|
||||
return $this->mapper->insert($wiki);
|
||||
}
|
||||
|
Reference in New Issue
Block a user