types
3 months ago
class-group-ad-relation.php
5 days ago
class-group-factory.php
1 day ago
class-group-ordered.php
1 year ago
class-group-repository.php
1 day ago
class-group-slider.php
5 months ago
class-group-standard.php
1 year ago
class-group-types.php
1 day ago
class-groups.php
1 day ago
index.php
1 year ago
class-group-slider.php
61 lines
| 1 | <?php |
| 2 | /** |
| 3 | * This class is responsible to model slider groups. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.48.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Groups; |
| 11 | |
| 12 | use AdvancedAds\Abstracts\Group; |
| 13 | use AdvancedAds\Utilities\Conditional; |
| 14 | use AdvancedAds\Interfaces\Group_Interface; |
| 15 | |
| 16 | defined( 'ABSPATH' ) || exit; |
| 17 | |
| 18 | /** |
| 19 | * Slider group. |
| 20 | */ |
| 21 | class Group_Slider extends Group implements Group_Interface { |
| 22 | |
| 23 | /** |
| 24 | * Get delay. |
| 25 | * |
| 26 | * @param string $context What the value is for. Valid values are view and edit. |
| 27 | * |
| 28 | * @return int |
| 29 | */ |
| 30 | public function get_delay( $context = 'view' ): int { |
| 31 | return $this->get_prop( 'delay', $context ); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Is grid display random. |
| 36 | * |
| 37 | * @param string $context What the value is for. Valid values are view and edit. |
| 38 | * |
| 39 | * @return bool |
| 40 | */ |
| 41 | public function is_random( $context = 'view' ): bool { |
| 42 | return $this->get_prop( 'random', $context ); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Get ordered ids of the ads that belong to the group |
| 47 | * |
| 48 | * @return array |
| 49 | */ |
| 50 | public function get_ordered_ad_ids() { |
| 51 | $ordered_ad_ids = []; |
| 52 | $weights = $this->get_ad_weights(); |
| 53 | |
| 54 | $ordered_ad_ids = ( $this->is_random() || Conditional::is_amp() ) |
| 55 | ? $this->shuffle_ads() |
| 56 | : array_keys( $weights ); |
| 57 | |
| 58 | return apply_filters( 'advanced-ads-group-output-ad-ids', $ordered_ad_ids, $this->get_type(), $this->get_ads(), $weights, $this ); |
| 59 | } |
| 60 | } |
| 61 |