public function getArchives()
    {
        $all_posts = $this->getBlogPosts();
        $years = [];
        $months = [];

        foreach ($all_posts as $post) {
            if (preg_match('/^(\d\d\d\d)-(\d\d)-/', $post->PublishDate, $match)) {
                if (empty($years[$match[1]])) {
                    $years[$match[1]] = 1;
                } else {
                    $years[$match[1]]++;
                }
                if (empty($months[$match[1] . '-' . $match[2]])) {
                    $months[$match[1] . '-' . $match[2]] = 1;
                } else {
                    $months[$match[1] . '-' . $match[2]]++;
                }
            }
        }
        $output = ArrayData::create([
            'Years' => ArrayList::create(),
            'Months' => ArrayList::create(),
        ]);
        $link_base = $this->Link() . 'archive/';

        foreach ($years as $year => $count) {
            $yr = DBYear::create();
            $yr->setValue($year);
            $cnt = DBInt::create();
            $cnt->setValue($count);
            $result = ArrayData::create([
                'Year' => $yr,
                'Count' => $cnt,
                'Link' => $link_base . $year . '/'
            ]);
            $output->Years->push($result);
        }

        foreach ($months as $month => $count) {
            $mth = DBDate::create();
            $mth->setValue($month . '-01');
            $cnt = DBInt::create();
            $cnt->setValue($count);
            $result = ArrayData::create([
                'Month' => $mth,
                'Count' => $cnt,
                'Link' => $link_base . str_replace('-', '/', $month) . '/'
            ]);
            $output->Months->push($result);
        }

        return $output;
    }
public function getArchives()
    {
        $all_posts = $this->getBlogPosts();
        $years = [];
        $months = [];

        foreach ($all_posts as $post) {
            if (preg_match('/^(\d\d\d\d)-(\d\d)-/', $post->PublishDate, $match)) {
                if (empty($years[$match[1]])) {
                    $years[$match[1]] = 1;
                } else {
                    $years[$match[1]]++;
                }
                if (empty($months[$match[1] . '-' . $match[2]])) {
                    $months[$match[1] . '-' . $match[2]] = 1;
                } else {
                    $months[$match[1] . '-' . $match[2]]++;
                }
            }
        }
        $output = ArrayData::create([
            'Years' => ArrayList::create(),
            'Months' => ArrayList::create(),
        ]);
        $link_base = $this->Link() . 'archive/';

        foreach ($years as $year => $count) {
            $yr = DBYear::create();
            $yr->setValue($year);
            $cnt = DBInt::create();
            $cnt->setValue($count);
            $result = ArrayData::create([
                'Year' => $yr,
                'Count' => $cnt,
                'Link' => $link_base . $year . '/'
            ]);
            $output->Years->push($result);
        }

        foreach ($months as $month => $count) {
            $mth = DBDate::create();
            $mth->setValue($month . '-01');
            $cnt = DBInt::create();
            $cnt->setValue($count);
            $result = ArrayData::create([
                'Month' => $mth,
                'Count' => $cnt,
                'Link' => $link_base . str_replace('-', '/', $month) . '/'
            ]);
            $output->Months->push($result);
        }

        return $output;
    }
public function getArchives ( ) { $ all_posts = $ this -> getBlogPosts ( ) ; $ years = [ ] ; $ months = [ ] ; foreach ( $ all_posts as $ post ) { if ( preg_match ( '/^(\d\d\d\d)-(\d\d)-/' , $ post -> PublishDate , $ match ) ) { if ( empty ( $ years [ $ match [ 1 ] ] ) ) { $ years [ $ match [ 1 ] ] = 1 ; } else { $ years [ $ match [ 1 ] ] ++ ; } if ( empty ( $ months [ $ match [ 1 ] . '-' . $ match [ 2 ] ] ) ) { $ months [ $ match [ 1 ] . '-' . $ match [ 2 ] ] = 1 ; } else { $ months [ $ match [ 1 ] . '-' . $ match [ 2 ] ] ++ ; } } } $ output = ArrayData :: create ( [ 'Years' => ArrayList :: create ( ) , 'Months' => ArrayList :: create ( ) , ] ) ; $ link_base = $ this -> Link ( ) . 'archive/' ; foreach ( $ years as $ year => $ count ) { $ yr = DBYear :: create ( ) ; $ yr -> setValue ( $ year ) ; $ cnt = DBInt :: create ( ) ; $ cnt -> setValue ( $ count ) ; $ result = ArrayData :: create ( [ 'Year' => $ yr , 'Count' => $ cnt , 'Link' => $ link_base . $ year . '/' ] ) ; $ output -> Years -> push ( $ result ) ; } foreach ( $ months as $ month => $ count ) { $ mth = DBDate :: create ( ) ; $ mth -> setValue ( $ month . '-01' ) ; $ cnt = DBInt :: create ( ) ; $ cnt -> setValue ( $ count ) ; $ result = ArrayData :: create ( [ 'Month' => $ mth , 'Count' => $ cnt , 'Link' => $ link_base . str_replace ( '-' , '/' , $ month ) . '/' ] ) ; $ output -> Months -> push ( $ result ) ; } return $ output ; }
Return all years & months containing visible blog posts
@param null
@return ArrayData of Years and Months
Return all years & months containing visible blog posts