diff --git a/includes/class-PageYearMonthDayPDCs.php b/includes/class-PageYearMonthDayPDCs.php index 94ca6af..f7f5967 100644 --- a/includes/class-PageYearMonthDayPDCs.php +++ b/includes/class-PageYearMonthDayPDCs.php @@ -1,101 +1,116 @@ . namespace itwikidelbot; /** * Abstraction of a page containing PDCs of a day */ abstract class PageYearMonthDayPDCs extends PageYearMonthDay { /** * PDCs indexed by type * * @var array */ private $pdcsByType; /** * Constructor * * @param $year int * @param $month int 1-12 * @param $day int 1-31 * @param $pdcs_by_type array PDCs by type * @see PageYearMonthDay::__construct() */ public function __construct( $year, $month, $day, $pdcs_by_type = [] ) { $this->pdcsByType = $pdcs_by_type; parent::__construct( $year, $month, $day ); } /** * Static constructor * * @param $datetime DateTime * @param $pdcs_by_type PDCs by type * @return self */ public static function createFromDateTimePDCs( $datetime, $pdcs_by_type = [] ) { return new static( $datetime->format('Y'), $datetime->format('m'), $datetime->format('d'), $pdcs_by_type ); } + /** + * Get all the PDCs + * + * @return array + */ + public function getPDCs() { + $all = []; + foreach( $this->pdcsByType as $pdcs ) { + foreach( $pdcs as $pdc ) { + $all[] = $pdc; + } + } + return $all; + } + /** * Get the PDCs indexed by type * * @return array */ public function getPDCsByType() { return $this->pdcsByType; } /** * Get the running PDCs indexed by type * * @return array */ public function getRunningPDCsByType() { return $this->getPDCsByTypeFilteringRunning( true ); } /** * Get the ended PDCs indexed by type * * @return array */ public function getEndedPDCsByType() { return $this->getPDCsByTypeFilteringRunning( false ); } /** * Get the PDCs indexed by type, but only which of them are running (or not) * * @param $is_running bool * @return array */ private function getPDCsByTypeFilteringRunning( $is_running ) { $pdcs_by_type = $this->getPDCsByType(); foreach( $pdcs_by_type as $type => $pdcs ) { foreach( $pdcs as $i => $pdc ) { if( $pdc->isRunning() !== $is_running ) { unset( $pdcs_by_type[ $type ][ $i ] ); } } } return $pdcs_by_type; } }