X-Git-Url: http://source.bookstackapp.com/bookstack/blobdiff_plain/8d80e7311cf4166b5c9597dc793a8f53b13fd7f3..refs/pull/236/head:/app/Repos/EntityRepo.php diff --git a/app/Repos/EntityRepo.php b/app/Repos/EntityRepo.php index 012a64967..7ecfb758c 100644 --- a/app/Repos/EntityRepo.php +++ b/app/Repos/EntityRepo.php @@ -6,6 +6,7 @@ use BookStack\Entity; use BookStack\Page; use BookStack\Services\PermissionService; use BookStack\User; +use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; class EntityRepo @@ -131,9 +132,8 @@ class EntityRepo */ public function getUserDraftPages($count = 20, $page = 0) { - $user = auth()->user(); return $this->page->where('draft', '=', true) - ->where('created_by', '=', $user->id) + ->where('created_by', '=', user()->id) ->orderBy('updated_at', 'desc') ->skip($count * $page)->take($count)->get(); } @@ -168,15 +168,16 @@ class EntityRepo * @param $termString * @return array */ - protected function prepareSearchTerms($termString) + public function prepareSearchTerms($termString) { $termString = $this->cleanSearchTermString($termString); - preg_match_all('/"(.*?)"/', $termString, $matches); + preg_match_all('/(".*?")/', $termString, $matches); + $terms = []; if (count($matches[1]) > 0) { - $terms = $matches[1]; + foreach ($matches[1] as $match) { + $terms[] = $match; + } $termString = trim(preg_replace('/"(.*?)"/', '', $termString)); - } else { - $terms = []; } if (!empty($termString)) $terms = array_merge($terms, explode(' ', $termString)); return $terms; @@ -259,6 +260,28 @@ class EntityRepo return $query; } + /** + * Alias method to update the book jointPermissions in the PermissionService. + * @param Collection $collection collection on entities + */ + public function buildJointPermissions(Collection $collection) + { + $this->permissionService->buildJointPermissionsForEntities($collection); + } + + /** + * Format a name as a url slug. + * @param $name + * @return string + */ + protected function nameToSlug($name) + { + $slug = str_replace(' ', '-', strtolower($name)); + $slug = preg_replace('/[\+\/\\\?\@\}\{\.\,\=\[\]\#\&\!\*\'\;\:\$\%]/', '', $slug); + if ($slug === "") $slug = substr(md5(rand(1, 500)), 0, 5); + return $slug; + } + }