src/Controllers/HailController.php
public function articles(HTTPRequest $request)
    {
        if (!Security::getCurrentUser()) {
            return $this->makeJsonReponse(401, [
                'message' => 'Unauthorized.'
            ])->setStatusDescription('Unauthorized.');
        }

        $pages = HailPage::get();
        $articles = [['text' => 'Select an article']];
        foreach ($pages as $page) {
            $list = $page->getFullHailList();
            foreach ($list as $item) {
                $link = $item->getLinkForPage($page);
                if ($item->getType() === 'article') {
                    $link = Director::absoluteURL($link);
                }
                $create_at = isset($item->Date) ? $item->Date : $item->DueDate;
                $date = new \DateTime($create_at);
                $name = $date->format('d/m/Y') . ' - ' . $page->Title . ' - ' . $item->Title;
                $articles[] = [
                    'text' => $name,
                    'value' => $link
                ];
            }
        }

        return $this->makeJsonReponse(200, $articles);
    }
public function articles(HTTPRequest $request)
    {
        if (!Security::getCurrentUser()) {
            return $this->makeJsonReponse(401, [
                'message' => 'Unauthorized.'
            ])->setStatusDescription('Unauthorized.');
        }

        $pages = HailPage::get();
        $articles = [['text' => 'Select an article']];
        foreach ($pages as $page) {
            $list = $page->getFullHailList();
            foreach ($list as $item) {
                $link = $item->getLinkForPage($page);
                if ($item->getType() === 'article') {
                    $link = Director::absoluteURL($link);
                }
                $create_at = isset($item->Date) ? $item->Date : $item->DueDate;
                $date = new \DateTime($create_at);
                $name = $date->format('d/m/Y') . ' - ' . $page->Title . ' - ' . $item->Title;
                $articles[] = [
                    'text' => $name,
                    'value' => $link
                ];
            }
        }

        return $this->makeJsonReponse(200, $articles);
    }
public function articles ( HTTPRequest $ request ) { if ( ! Security :: getCurrentUser ( ) ) { return $ this -> makeJsonReponse ( 401 , [ 'message' => 'Unauthorized.' ] ) -> setStatusDescription ( 'Unauthorized.' ) ; } $ pages = HailPage :: get ( ) ; $ articles = [ [ 'text' => 'Select an article' ] ] ; foreach ( $ pages as $ page ) { $ list = $ page -> getFullHailList ( ) ; foreach ( $ list as $ item ) { $ link = $ item -> getLinkForPage ( $ page ) ; if ( $ item -> getType ( ) === 'article' ) { $ link = Director :: absoluteURL ( $ link ) ; } $ create_at = isset ( $ item -> Date ) ? $ item -> Date : $ item -> DueDate ; $ date = new \ DateTime ( $ create_at ) ; $ name = $ date -> format ( 'd/m/Y' ) . ' - ' . $ page -> Title . ' - ' . $ item -> Title ; $ articles [ ] = [ 'text' => $ name , 'value' => $ link ] ; } } return $ this -> makeJsonReponse ( 200 , $ articles ) ; }
Retrieve a list of articles from the database

Only used by the Hail TinyMCE plugin to add article links to any HTML content

@param HTTPRequest $request Current request

@return HTTPResponse JSON response
@throws
Retrieve a list of articles from the database