FEATURE: change directory structure
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Search;
|
||||
|
||||
use App\Models\Content\Content as ContentModel;
|
||||
|
||||
class Content extends Search
|
||||
{
|
||||
/**
|
||||
* Search for given patttern/term
|
||||
*
|
||||
* @param string $term searched word
|
||||
*
|
||||
* @return array list of found objects
|
||||
*/
|
||||
public function search($term)
|
||||
{
|
||||
$token = $this->tokenize($term);
|
||||
|
||||
return ContentModel::where('content', 'LIKE', $token)
|
||||
->orWhere('meta_description', 'LIKE', $token)
|
||||
->orWhere('meta_keywords', 'LIKE', $token)
|
||||
->orWhere('title', 'LIKE', $token)
|
||||
->orWhere('url', 'LIKE', $token)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return 'content';
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return trans('search.content');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Search;
|
||||
|
||||
use App\Models\FileManager\File;
|
||||
|
||||
class Files extends Search
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return "files";
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return trans('search.files');
|
||||
}
|
||||
|
||||
/**
|
||||
* Search for given patttern/term
|
||||
*
|
||||
* @param string $term searched word
|
||||
*
|
||||
* @return array list of found objects
|
||||
*/
|
||||
public function search($term)
|
||||
{
|
||||
$token = $this->tokenize($term);
|
||||
|
||||
return File::where('original_filename', 'LIKE', $token)
|
||||
->orWhere('name', 'LIKE', $token)
|
||||
->orWhere('keywords', 'LIKE', $token)
|
||||
->orWhere('description', 'LIKE', $token)
|
||||
->orWhere('mime_type', 'LIKE', $token)
|
||||
->get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Search\Presenters;
|
||||
|
||||
use App\CMS\Enumerations\ContentStatuses;
|
||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
||||
|
||||
class AdminContent implements SearchPresenterHandler
|
||||
{
|
||||
public function render($foundItems)
|
||||
{
|
||||
return view('admin.search.results.content', [
|
||||
'pages' => $foundItems,
|
||||
'statuses' => ContentStatuses::getWithTranslations(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Search\Presenters;
|
||||
|
||||
use App\CMS\Handlers\Contracts\SearchPresenterHandler;
|
||||
|
||||
class AdminFiles implements SearchPresenterHandler
|
||||
{
|
||||
/**
|
||||
* Method for rendering list of found results
|
||||
*
|
||||
* @param $foundItems
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function render($foundItems)
|
||||
{
|
||||
return view('admin.fileManager.filesTiles', ['files' => $foundItems, 'hideDelete' => true]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace App\CMS\Handlers\Search;
|
||||
|
||||
use App\CMS\Handlers\Contracts\SearchHandler;
|
||||
use Symfony\Component\Process\Exception\InvalidArgumentException;
|
||||
|
||||
abstract class Search implements SearchHandler
|
||||
{
|
||||
/**
|
||||
* Tokenize string for usage in LIKE clausules
|
||||
*
|
||||
* @param $term
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function tokenize($term)
|
||||
{
|
||||
$term = trim($term);
|
||||
|
||||
if (empty($term)) {
|
||||
throw new InvalidArgumentException(trans('search.emptyString'));
|
||||
}
|
||||
|
||||
return '%' . str_replace(' ', '%', $term) . '%';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user