WikiPages controls
This commit is contained in:
		@ -34,7 +34,7 @@ class WikiMapper extends QBMapper {
 | 
			
		||||
        return $this->findEntity($qb);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function findAll(string $userId, mixed $filter=null) {
 | 
			
		||||
    public function findAll(string $userId, ?array $filter=null) {
 | 
			
		||||
        $qb = $this->db->getQueryBuilder();
 | 
			
		||||
 | 
			
		||||
        $qb->select('*')
 | 
			
		||||
@ -46,12 +46,12 @@ class WikiMapper extends QBMapper {
 | 
			
		||||
        if ($filter) {
 | 
			
		||||
            if (array_key_exists('title',$filter) ) {
 | 
			
		||||
                $qb->where(
 | 
			
		||||
                    $qb->expr()->eq('title', $qb->createNamedParameter($id))
 | 
			
		||||
                    $qb->expr()->eq('title', $qb->createNamedParameter($filter['title']))
 | 
			
		||||
                );
 | 
			
		||||
            }                    
 | 
			
		||||
            if (array_key_exists('fileId',$filter) ) {
 | 
			
		||||
                $qb->where(
 | 
			
		||||
                    $qb->expr()->eq('fileId', $qb->createNamedParameter($id))
 | 
			
		||||
                    $qb->expr()->eq('file_id', $qb->createNamedParameter($filter['fileId']))
 | 
			
		||||
                );
 | 
			
		||||
            }      
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -106,7 +106,7 @@ class WikiHelper {
 | 
			
		||||
        return $this->setWikiData($wiki) ? $wiki : null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function initWiki(string $folderPath, string $title) :?int {
 | 
			
		||||
    public function create(string $folderPath, string $title) :?int {
 | 
			
		||||
        $this->wikiFolder = $this->userFolder->get($folderPath);
 | 
			
		||||
        if ( !$this->isWikiable() ) {
 | 
			
		||||
            return null;
 | 
			
		||||
@ -119,21 +119,36 @@ class WikiHelper {
 | 
			
		||||
        return $this->wikiFolder->getId();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function add(int $parentId, string $title) {
 | 
			
		||||
// $folder = ...newFolder($path)
 | 
			
		||||
    public function add(int $parentId, string $title, ?string $content) :int {
 | 
			
		||||
        if ($parentId>0) {
 | 
			
		||||
            $parentFolder = $this->getFolderById($parentId);
 | 
			
		||||
        } else {
 | 
			
		||||
            $parentFolder = $this->wikiFolder;
 | 
			
		||||
        }
 | 
			
		||||
        try {
 | 
			
		||||
            $folder = $parentFolder->newFolder($this->sanitize_file_name($title));
 | 
			
		||||
 | 
			
		||||
$wikiData = $this->getWikiData();
 | 
			
		||||
if ($wikiData) {
 | 
			
		||||
    $wikiTree = new WikiTree($wikiData['pages']);
 | 
			
		||||
    $wikiPage = new WikiTreePage();
 | 
			
		||||
    $wikiPage->id = $id;
 | 
			
		||||
    $wikiPage->pid = $parentId;
 | 
			
		||||
    $wikiPage->title = $title;
 | 
			
		||||
    $wikiTree->set($wikiPage);
 | 
			
		||||
    $wikiData['pages'] = $wikiTree->getWikiPages();
 | 
			
		||||
    $this->setWikiData($wikiData);
 | 
			
		||||
}
 | 
			
		||||
            $wikiTreePage = new WikiTreePage();
 | 
			
		||||
            $wikiTreePage->id = $folder->getId();
 | 
			
		||||
            $wikiTreePage->pid = $parentId;
 | 
			
		||||
            $wikiTreePage->title = $title;
 | 
			
		||||
            $wikiTreePage->sort = 0;                
 | 
			
		||||
 | 
			
		||||
            if ( !is_null($content) ) {
 | 
			
		||||
                $this->update($wikiTreePage->id, $content);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $wikiData = $this->getWikiData();
 | 
			
		||||
            if ($wikiData) {
 | 
			
		||||
                $wikiTree = new WikiTree($wikiData['pages']);
 | 
			
		||||
                $wikiTree->set($wikiTreePage);
 | 
			
		||||
                $wikiData['pages'] = $wikiTree->getWikiPages();
 | 
			
		||||
                $this->setWikiData($wikiData);
 | 
			
		||||
            }
 | 
			
		||||
        } catch(\Exception $ex) {
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
        return $wikiTreePage->id; 
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function update(int $id, string $content) {
 | 
			
		||||
 | 
			
		||||
@ -58,7 +58,7 @@ class WikiService {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function create(string $folderPath, string $title, string $userId) {
 | 
			
		||||
        $folderId = $this->wikiHelper->initWiki($folderPath, $title);
 | 
			
		||||
        $folderId = $this->wikiHelper->create($folderPath, $title);
 | 
			
		||||
        if ( $folderId === null ) {
 | 
			
		||||
            throw new ReadOnlyException('Error creating wiki');
 | 
			
		||||
        }
 | 
			
		||||
@ -79,7 +79,8 @@ class WikiService {
 | 
			
		||||
        try {
 | 
			
		||||
            $wiki = $this->mapper->find($id, $userId);
 | 
			
		||||
            $wiki->setTitle($title);
 | 
			
		||||
            return $this->mapper->update($wiki);
 | 
			
		||||
            $res = $this->mapper->update($wiki);
 | 
			
		||||
            return $res;
 | 
			
		||||
        } catch(Exception $e) {
 | 
			
		||||
            $this->handleException($e);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user