2012-08-10 19:44:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PonderVotableView extends AphrontView {
|
|
|
|
|
|
|
|
private $phid;
|
|
|
|
private $uri;
|
|
|
|
private $count;
|
|
|
|
private $vote;
|
|
|
|
|
|
|
|
public function setPHID($phid) {
|
|
|
|
$this->phid = $phid;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setURI($uri) {
|
|
|
|
$this->uri = $uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setCount($count) {
|
|
|
|
$this->count = $count;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setVote($vote) {
|
|
|
|
$this->vote = $vote;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
require_celerity_resource('ponder-vote-css');
|
|
|
|
require_celerity_resource('javelin-behavior-ponder-votebox');
|
|
|
|
|
2012-10-01 05:12:35 +02:00
|
|
|
Javelin::initBehavior('ponder-votebox', array());
|
|
|
|
|
|
|
|
$uri = id(new PhutilURI($this->uri))->alter('phid', $this->phid);
|
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$up = javelin_tag(
|
2012-10-01 05:12:35 +02:00
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => (string)$uri,
|
|
|
|
'sigil' => 'upvote',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'class' => ($this->vote > 0) ? 'ponder-vote-active' : null,
|
|
|
|
),
|
|
|
|
"\xE2\x96\xB2");
|
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$down = javelin_tag(
|
2012-10-01 05:12:35 +02:00
|
|
|
'a',
|
2012-08-10 19:44:04 +02:00
|
|
|
array(
|
2012-10-01 05:12:35 +02:00
|
|
|
'href' => (string)$uri,
|
|
|
|
'sigil' => 'downvote',
|
|
|
|
'mustcapture' => true,
|
|
|
|
'class' => ($this->vote < 0) ? 'ponder-vote-active' : null,
|
|
|
|
),
|
|
|
|
"\xE2\x96\xBC");
|
2012-08-10 19:44:04 +02:00
|
|
|
|
2013-01-25 21:57:17 +01:00
|
|
|
$count = javelin_tag(
|
2012-10-01 05:12:35 +02:00
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'ponder-vote-count',
|
|
|
|
'sigil' => 'ponder-vote-count',
|
|
|
|
),
|
2013-01-25 21:57:17 +01:00
|
|
|
$this->count);
|
2012-08-10 19:44:04 +02:00
|
|
|
|
2012-10-01 05:12:35 +02:00
|
|
|
return javelin_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'ponder-votable',
|
|
|
|
'sigil' => 'ponder-votable',
|
|
|
|
'meta' => array(
|
|
|
|
'count' => (int)$this->count,
|
|
|
|
'vote' => (int)$this->vote,
|
|
|
|
),
|
|
|
|
),
|
2013-01-29 03:41:43 +01:00
|
|
|
array(
|
|
|
|
javelin_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'ponder-votebox',
|
|
|
|
),
|
|
|
|
array($up, $count, $down)),
|
|
|
|
phutil_render_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'ponder-votebox-content',
|
|
|
|
),
|
|
|
|
$this->renderChildren()),
|
|
|
|
));
|
2012-08-10 19:44:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|