Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| RelatedPagesCell | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 1 |
| display | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | namespace DefaultTheme\View\Cell; |
| 5 | |
| 6 | use Cake\View\Cell; |
| 7 | |
| 8 | /** |
| 9 | * RelatedPages cell |
| 10 | * |
| 11 | * Displays related or child pages for a given article |
| 12 | */ |
| 13 | class RelatedPagesCell extends Cell |
| 14 | { |
| 15 | /** |
| 16 | * List of valid options that can be passed into this |
| 17 | * cell's constructor. |
| 18 | * |
| 19 | * @var array<string> |
| 20 | */ |
| 21 | protected array $_validCellOptions = ['articleId', 'cacheKey', 'title']; |
| 22 | |
| 23 | /** |
| 24 | * Default display method |
| 25 | * |
| 26 | * Fetches and displays child pages for an article |
| 27 | * |
| 28 | * @param string|null $articleId The article ID to get children for |
| 29 | * @param string|null $cacheKey Optional cache key for performance |
| 30 | * @param string|null $title Optional custom title for the section |
| 31 | * @return void |
| 32 | */ |
| 33 | public function display(?string $articleId = null, ?string $cacheKey = null, ?string $title = null): void |
| 34 | { |
| 35 | $pages = []; |
| 36 | |
| 37 | if ($articleId) { |
| 38 | $articlesTable = $this->fetchTable('Articles'); |
| 39 | |
| 40 | // Generate cache key if not provided |
| 41 | if ($cacheKey === null) { |
| 42 | $lang = $this->request->getParam('lang', 'en'); |
| 43 | $cacheKey = 'related_' . $lang . '_' . $articleId; |
| 44 | } |
| 45 | |
| 46 | $pages = $articlesTable->find('children', for: $articleId) |
| 47 | ->select(['id', 'title', 'slug', 'lede', 'published', 'image_id']) |
| 48 | ->contain(['Images']) |
| 49 | ->where(['Articles.is_published' => true]) |
| 50 | ->cache($cacheKey . '_children', 'content') |
| 51 | ->all(); |
| 52 | } |
| 53 | |
| 54 | $this->set('pages', $pages); |
| 55 | $this->set('title', $title ?? __('Related pages')); |
| 56 | } |
| 57 | } |