Airship\Cabin\Bridge\Landing\Ajax::getBlogPostsForAuthor PHP Method

getBlogPostsForAuthor() public method

    public function getBlogPostsForAuthor()
    {
        $auth_bp = $this->blueprint('Author');
        $blog_bp = $this->blueprint('Blog');
        if (IDE_HACKS) {
            $db = \Airship\get_database();
            $auth_bp = new Author($db);
            $blog_bp = new Blog($db);
        }
        if (empty($_POST['author'])) {
            \Airship\json_response(['status' => 'ERROR', 'message' => \__('No author selected.')]);
        }
        $authorId = (int) ($_POST['author'] ?? 0);
        if (!$this->isSuperUser()) {
            $authors = $auth_bp->getAuthorIdsForUser($this->getActiveUserId());
            if (!\in_array($authorId, $authors)) {
                \Airship\json_response(['status' => 'ERROR', 'message' => \__('You do not have permission to access this author\'s posts.')]);
            }
        }
        $existing = $_POST['existing'] ?? [];
        if (!\is1DArray($existing)) {
            \Airship\json_response(['status' => 'ERROR', 'message' => \__('One-dimensional array expected')]);
        }
        foreach ($existing as $i => $e) {
            $existing[$i] = (int) $e;
        }
        $response = ['status' => 'OK'];
        if (!empty($_POST['add'])) {
            $newBlogPost = $blog_bp->getBlogPostById($_POST['add'] + 0);
            if (!empty($newBlogPost)) {
                if ($newBlogPost['author'] === $authorId) {
                    $existing[] = (int) ($_POST['add'] ?? 0);
                    $response['new_item'] = $this->getLensAsText('ajax/bridge_blog_series_item', ['item' => ['name' => $newBlogPost['title'], 'post' => $newBlogPost['postid'], 'data-id' => null]]);
                }
            }
        }
        $series = $blog_bp->listPostsForAuthor($authorId, $existing);
        $response['options'] = $this->getLensAsText('ajax/bridge_blog_series_select_blogpost', ['items' => $series]);
        \Airship\json_response($response);
    }