AppsService.php
3 days ago
CollaborationCommentService.php
3 weeks ago
CollaborationService.php
3 weeks ago
CollectionItemService.php
3 weeks ago
CollectionService.php
3 weeks ago
EditorService.php
3 weeks ago
FontService.php
3 days ago
GlobalDataService.php
3 days ago
MediaService.php
3 weeks ago
PageService.php
3 days ago
PageSettingsService.php
3 weeks ago
UtilityPageService.php
3 days ago
UtilityPageService.php
70 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Kirki\App\Services; |
| 4 | |
| 5 | defined('ABSPATH') || exit; |
| 6 | |
| 7 | use Exception; |
| 8 | use Kirki\Ajax\Collection; |
| 9 | use Kirki\App\Constants\PageMetaKeys; |
| 10 | use Kirki\App\Constants\PostTypes; |
| 11 | use Kirki\App\Constants\UtilityPageType; |
| 12 | use Kirki\App\Models\Page as PageModel; |
| 13 | use Kirki\Framework\Database\Query\QueryBuilder; |
| 14 | use Kirki\Framework\Http\Response; |
| 15 | |
| 16 | class UtilityPageService |
| 17 | { |
| 18 | /** |
| 19 | * Create a new instance of the service |
| 20 | * @return UtilityPageService |
| 21 | */ |
| 22 | public static function create() |
| 23 | { |
| 24 | return new static(); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Check if a utility page exists |
| 29 | * |
| 30 | * @param string $utility_type |
| 31 | * |
| 32 | * @return bool |
| 33 | */ |
| 34 | public function exists(string $utility_type) |
| 35 | { |
| 36 | if (!in_array($utility_type, UtilityPageType::get_constant_values(), true)) { |
| 37 | throw new Exception( |
| 38 | /* translators: %s: Utility page type */ |
| 39 | sprintf(esc_html__('Invalid utility page type: %s', 'kirki'), esc_html($utility_type)), |
| 40 | Response::UNPROCESSABLE_ENTITY |
| 41 | ); |
| 42 | } |
| 43 | |
| 44 | return PageModel::query() |
| 45 | ->where('post_type', '=', PostTypes::UTILITY) |
| 46 | ->where_has('meta', function (QueryBuilder $query) use ($utility_type) { |
| 47 | $query->where('meta_key', '=', PageMetaKeys::UTILITY_PAGE_TYPE) |
| 48 | ->where('meta_value', '=', $utility_type); |
| 49 | }) |
| 50 | ->exists(); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get all utility pages |
| 55 | * |
| 56 | * @return Collection |
| 57 | */ |
| 58 | public function get_utility_pages() |
| 59 | { |
| 60 | return PageModel::query() |
| 61 | ->with([ |
| 62 | 'meta' => function (QueryBuilder $query) { |
| 63 | $query->where('meta_key', '=', PageMetaKeys::UTILITY_PAGE_TYPE) |
| 64 | ->where_in('meta_value', UtilityPageType::get_constant_values()); |
| 65 | } |
| 66 | ]) |
| 67 | ->where('post_type', '=', PostTypes::UTILITY) |
| 68 | ->get(); |
| 69 | } |
| 70 | } |