Adding method to mark multiple pages as online/offline

parent 9d5bcad6
...@@ -5,6 +5,7 @@ namespace Modules\Page\Repositories\Cache; ...@@ -5,6 +5,7 @@ namespace Modules\Page\Repositories\Cache;
use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Modules\Core\Repositories\Cache\BaseCacheDecorator; use Modules\Core\Repositories\Cache\BaseCacheDecorator;
use Modules\Page\Entities\Page;
use Modules\Page\Repositories\PageRepository; use Modules\Page\Repositories\PageRepository;
class CachePageDecorator extends BaseCacheDecorator implements PageRepository class CachePageDecorator extends BaseCacheDecorator implements PageRepository
...@@ -92,24 +93,46 @@ class CachePageDecorator extends BaseCacheDecorator implements PageRepository ...@@ -92,24 +93,46 @@ class CachePageDecorator extends BaseCacheDecorator implements PageRepository
} }
/** /**
* @param int $pageId * @param Page $page
* @return mixed * @return mixed
*/ */
public function markAsOnlineInAllLocales(int $pageId) public function markAsOnlineInAllLocales(Page $page)
{ {
$this->clearCache(); $this->clearCache();
return $this->repository->markAsOnlineInAllLocales($pageId); return $this->repository->markAsOnlineInAllLocales($page);
} }
/** /**
* @param int $pageId * @param Page $page
* @return mixed * @return mixed
*/ */
public function markAsOfflineInAllLocales(int $pageId) public function markAsOfflineInAllLocales(Page $page)
{ {
$this->clearCache(); $this->clearCache();
return $this->repository->markAsOfflineInAllLocales($pageId); return $this->repository->markAsOfflineInAllLocales($page);
}
/**
* @param array $pageIds [int]
* @return mixed
*/
public function markMultipleAsOnlineInAllLocales(array $pageIds)
{
$this->clearCache();
return $this->repository->markMultipleAsOnlineInAllLocales($pageIds);
}
/**
* @param array $pageIds [int]
* @return mixed
*/
public function markMultipleAsOfflineInAllLocales(array $pageIds)
{
$this->clearCache();
return $this->repository->markMultipleAsOfflineInAllLocales($pageIds);
} }
} }
...@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Builder; ...@@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Mcamara\LaravelLocalization\LaravelLocalization; use Mcamara\LaravelLocalization\LaravelLocalization;
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository; use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
use Modules\Page\Entities\Page;
use Modules\Page\Events\PageIsCreating; use Modules\Page\Events\PageIsCreating;
use Modules\Page\Events\PageIsUpdating; use Modules\Page\Events\PageIsUpdating;
use Modules\Page\Events\PageWasCreated; use Modules\Page\Events\PageWasCreated;
...@@ -174,13 +175,11 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos ...@@ -174,13 +175,11 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos
} }
/** /**
* @param int $pageId * @param Page $page
* @return mixed * @return mixed
*/ */
public function markAsOnlineInAllLocales(int $pageId) public function markAsOnlineInAllLocales(Page $page)
{ {
$page = $this->find($pageId);
$data = []; $data = [];
foreach (app(LaravelLocalization::class)->getSupportedLocales() as $locale => $supportedLocale) { foreach (app(LaravelLocalization::class)->getSupportedLocales() as $locale => $supportedLocale) {
$data[$locale] = ['status' => 1]; $data[$locale] = ['status' => 1];
...@@ -190,13 +189,11 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos ...@@ -190,13 +189,11 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos
} }
/** /**
* @param int $pageId * @param Page $page
* @return mixed * @return mixed
*/ */
public function markAsOfflineInAllLocales(int $pageId) public function markAsOfflineInAllLocales(Page $page)
{ {
$page = $this->find($pageId);
$data = []; $data = [];
foreach (app(LaravelLocalization::class)->getSupportedLocales() as $locale => $supportedLocale) { foreach (app(LaravelLocalization::class)->getSupportedLocales() as $locale => $supportedLocale) {
$data[$locale] = ['status' => 0]; $data[$locale] = ['status' => 0];
...@@ -204,4 +201,26 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos ...@@ -204,4 +201,26 @@ class EloquentPageRepository extends EloquentBaseRepository implements PageRepos
return $this->update($page, $data); return $this->update($page, $data);
} }
/**
* @param array $pageIds [int]
* @return mixed
*/
public function markMultipleAsOnlineInAllLocales(array $pageIds)
{
foreach ($pageIds as $pageId) {
$this->markAsOnlineInAllLocales($this->find($pageId));
}
}
/**
* @param array $pageIds [int]
* @return mixed
*/
public function markMultipleAsOfflineInAllLocales(array $pageIds)
{
foreach ($pageIds as $pageId) {
$this->markAsOfflineInAllLocales($this->find($pageId));
}
}
} }
...@@ -5,6 +5,7 @@ namespace Modules\Page\Repositories; ...@@ -5,6 +5,7 @@ namespace Modules\Page\Repositories;
use Illuminate\Contracts\Pagination\LengthAwarePaginator; use Illuminate\Contracts\Pagination\LengthAwarePaginator;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Modules\Core\Repositories\BaseRepository; use Modules\Core\Repositories\BaseRepository;
use Modules\Page\Entities\Page;
interface PageRepository extends BaseRepository interface PageRepository extends BaseRepository
{ {
...@@ -35,14 +36,28 @@ interface PageRepository extends BaseRepository ...@@ -35,14 +36,28 @@ interface PageRepository extends BaseRepository
public function serverPaginationFilteringFor(Request $request) : LengthAwarePaginator; public function serverPaginationFilteringFor(Request $request) : LengthAwarePaginator;
/** /**
* @param int $pageId * @param Page $page
* @return mixed * @return mixed
* @internal param int $pageId
*/ */
public function markAsOnlineInAllLocales(int $pageId); public function markAsOnlineInAllLocales(Page $page);
/** /**
* @param int $pageId * @param array $pageIds[int]
* @return mixed * @return mixed
*/ */
public function markAsOfflineInAllLocales(int $pageId); public function markMultipleAsOnlineInAllLocales(array $pageIds);
/**
* @param Page $page
* @return mixed
* @internal param int $pageId
*/
public function markAsOfflineInAllLocales(Page $page);
/**
* @param array $pageIds[int]
* @return mixed
*/
public function markMultipleAsOfflineInAllLocales(array $pageIds);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment