1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-13 10:22:42 +01:00
phorge-phorge/src/applications/phame/view/PhameBlogListView.php
Bob Trahan ae13d33859 Phame - introduce blogs
Summary:
blogs are collections of posts. a blog also has metadata like a name, description and "bloggers" that can edit the metadata of the blog and contribute posts.

changes include the post edit flow where bloggers can now select which blogs to publish to. also made various small tweaks throughout the UI to make things sensical and clean as the concept of blogs is introduced.

there's edges powering this stuff.  bloggers <=> blogs and posts <=> blogs in particular.

Test Plan:
made blogs, deleted blogs, tried to make blogs with no bloggers. all went well.
verified ui to publish only showed up for public posts, published posts to blogs, un-published posts to blogs, re-published posts to blogs, deleted posts and verified they disappeared from blogs.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T1373

Differential Revision: https://secure.phabricator.com/D3003
2012-07-19 09:03:10 -07:00

125 lines
3 KiB
PHP

<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* @group phame
*/
final class PhameBlogListView extends AphrontView {
private $user;
private $blogs;
private $header;
public function setHeader($header) {
$this->header = $header;
return $this;
}
private function getHeader() {
return $this->header;
}
public function setUser(PhabricatorUser $user) {
$this->user = $user;
return $this;
}
private function getUser() {
return $this->user;
}
public function setBlogs(array $blogs) {
assert_instances_of($blogs, 'PhameBlog');
$this->blogs = $blogs;
return $this;
}
private function getBlogs() {
return $this->blogs;
}
public function render() {
$user = $this->getUser();
$blogs = $this->getBlogs();
$panel = new AphrontPanelView();
if (empty($blogs)) {
$panel = id(new AphrontPanelView())
->setHeader('No blogs... Yet!')
->setCaption('Will you answer the call to phame?')
->setCreateButton('New Blog',
'/phame/blog/new');
return $panel->render();
}
$table_data = array();
foreach ($blogs as $blog) {
$view_link = phutil_render_tag(
'a',
array(
'href' => $blog->getViewURI(),
),
phutil_escape_html($blog->getName()));
$bloggers = $blog->getBloggers();
if (isset($bloggers[$user->getPHID()])) {
$edit = phutil_render_tag(
'a',
array(
'class' => 'button small grey',
'href' => $blog->getEditURI(),
),
'Edit');
} else {
$edit = null;
}
$view = phutil_render_tag(
'a',
array(
'class' => 'button small grey',
'href' => $blog->getViewURI(),
),
'View');
$table_data[] =
array(
$view_link,
implode(', ', mpull($blog->getBloggers(), 'renderLink')),
$view,
$edit,
);
}
$table = new AphrontTableView($table_data);
$table->setHeaders(
array(
'Name',
'Bloggers',
'',
'',
));
$table->setColumnClasses(
array(
null,
null,
'action',
'action',
));
$panel->setCreateButton('Create a Blog', '/phame/blog/new/');
$panel->setHeader($this->getHeader());
$panel->appendChild($table);
return $panel->render();
}
}