public function getSeriesForAuthor()
{
$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'])) {
$add = (int) ($_POST['add'] ?? 0);
$newSeries = $blog_bp->getSeries($add);
if (!empty($newSeries)) {
if ($newSeries['author'] === $authorId) {
$existing[] = $add;
$response['new_item'] = $this->getLensAsText('ajax/bridge_blog_series_item', ['item' => ['name' => $newSeries['name'], 'series' => $newSeries['seriesid'], 'data-id' => null]]);
}
}
}
$existing = $blog_bp->getAllSeriesParents($existing);
$series = $blog_bp->getSeriesForAuthor($authorId, $existing);
$response['options'] = $this->getLensAsText('ajax/bridge_blog_series_select_series', ['items' => $series]);
\Airship\json_response($response);
}