00001 <?php
00008 class TKCSERDClassicReview extends TKNullBox {
00009
00010 const APPEARANCE_FULL = 'full';
00011 const APPEARANCE_COMPACT = 'compact';
00012 const APPEARANCE_MINIMAL = 'minimal';
00013
00014 const PARAM_APPEARANCE = 'appearance';
00015 const PARAM_SHOW_BUTTONS = 'showButtons';
00016 const PARAM_LANDING_URL = 'landingURL';
00017
00018 private $review;
00019 private $params;
00020 private $appearance;
00021
00031 public function __construct($review, $params = array()) {
00032 parent::__construct();
00033 $this->review = $review;
00034 $this->params = $params;
00035 if (isset($params[self::PARAM_APPEARANCE]))
00036 $this->appearance = $params[self::PARAM_APPEARANCE];
00037 else
00038 $this->appearance = self::APPEARANCE_FULL;
00039 }
00040
00045 public function setAppearance($app) {
00046 $this->appearance = $app;
00047 }
00048
00052 public function setParams($params) {
00053 $this->params = $params;
00054 }
00055
00060 protected function layoutReviewBox() {
00061 global $PATH, $CSERD_DBI;
00062
00063 $source = $this->review;
00064 $params = $this->params;
00065
00066
00067 $author = new CSERDuser(array('userId' => $source->authorId));
00068
00069 if ($source->ownerId == $source->authorId)
00070 $owner = $author;
00071 else
00072 $owner = new CSERDuser(array('userId' => $source->ownerId));
00073
00074
00075 $reviewText = $source->cache;
00076 $reviewText = HTMLQuestionnaireEncoder::encode($source->getQuestionnaire());
00077
00078
00079
00080
00081 $rating = $source->getQuestionnaire()->getRating();
00082
00083
00084 $project = 'Added from ' . strtoupper($source->project);
00085
00086
00087 $this->set('class', array('review', $source->state . 'Review'));
00088 $modified = new TKLabel('Modified ' . DateParser::formatTimeAgo($source->modified)
00089 . ' / ' . $project);
00090 $modified->set('class', array('reviewModified'));
00091 $title = new TKNullBox();
00092 $title->set('class', array('reviewTitle'));
00093 if (!isset($this->params[self::PARAM_SHOW_BUTTONS])
00094 || ($this->params[self::PARAM_SHOW_BUTTONS]))
00095 $title->add($this->buildButtonBox());
00096 $title->addLabel($source->type . ' by ' . $author->getFullName());
00097 $title->add($modified);
00098 $title->addLabel(SDRHelpers::getRatingImageTag($rating+1));
00099 $text = new TKLabel($reviewText);
00100 $text->set('class', array('reviewText'));
00101 $content = new TKNullBox();
00102 $content->set('class', array('reviewContent'));
00103 $content->add($text);
00104
00105 switch($this->appearance) {
00106 case self::APPEARANCE_FULL:
00107 case self::APPEARANCE_COMPACT:
00108 $this->add($title);
00109 $this->add($content);
00110 break;
00111 case self::APPEARANCE_MINIMAL:
00112 $this->add($title);
00113 break;
00114 }
00115 }
00116
00122 protected function buildButtonBox() {
00123 global $SWAT;
00124 $source = $this->review;
00125 $params = $this->params;
00126
00127
00128 $landingURLString = SiteURL::getLandingURLArgs();
00129 if (isset($params[self::PARAM_LANDING_URL]))
00130 $landingURLString = SiteURL::getLandingURLArgs($params[self::PARAM_LANDING_URL]);
00131
00132 $viewLink = SiteURL::get(SiteURL::VIEW_REVIEW,
00133 array(
00134 'cserdId' => $source->cserdId,
00135 'reviewId' => $source->reviewId));
00136 $editLink = SiteURL::get(SiteURL::EDIT_REVIEW,
00137 array(
00138 'cserdId' => $source->cserdId,
00139 'reviewId' => $source->reviewId));
00140
00141
00142
00143 $buttonsBox = new TKNullBox();
00144 $buttonsBox->set('style', array('float' => 'right', 'width' => '250px',
00145 'text-align' => 'right'));
00146 $formsBox = new TKNullBox();
00147
00148 $lp = new LocalPermission();
00149 $target = $this->review;
00150 $user = $SWAT->getProjectUser();
00151
00152
00153 if ($lp->canViewReview($user, $target)) {
00154 $viewButton = new TKButton('View');
00155 $viewButton->onclick = new TKLinkAction($viewLink);
00156 $buttonsBox->add($viewButton);
00157 }
00158
00159 if ($lp->canEditReview($user, $target)) {
00160 $editButton = new TKButton('Edit');
00161 $editButton->onclick = new TKLinkAction($editLink);
00162 $buttonsBox->add($editButton);
00163 }
00164
00165 if ($lp->canSubmitReview($user, $target)) {
00166 $this->buildActionButton(LocalEventHandler::SUBMIT_REVIEW,
00167 'Submit', $buttonsBox, $formsBox);
00168 }
00169
00170 if ($lp->canApproveReview($user, $target)) {
00171 $this->buildActionButton(LocalEventHandler::APPROVE_REVIEW,
00172 'Approve', $buttonsBox, $formsBox);
00173 }
00174
00175 if ($lp->canRejectReview($user, $target)) {
00176 $this->buildActionButton(LocalEventHandler::REJECT_REVIEW,
00177 'Deny', $buttonsBox, $formsBox);
00178 }
00179
00180 if ($lp->canUnpublishReview($user, $target)) {
00181 $this->buildActionButton(LocalEventHandler::UNPUBLISH_REVIEW,
00182 'Unpublish', $buttonsBox, $formsBox);
00183 }
00184
00185 if ($lp->canDeleteReview($user, $target)) {
00186 $this->buildActionButton(LocalEventHandler::DELETE_REVIEW,
00187 'Delete', $buttonsBox, $formsBox);
00188 }
00189 $buttonsBox->add($formsBox);
00190
00191
00192 return $buttonsBox;
00193 }
00194
00195 public function buildActionButton($action, $text, $buttonsBox, $formsBox) {
00196 $source = $this->review;
00197 $form = new TKForm();
00198 $button = new TKButton($text);
00199 $button->onclick = new TKSWATAction(
00200 $source->reviewId,
00201 $action,
00202 $form);
00203 $buttonsBox->add($button);
00204 $formsBox->add($form);
00205 }
00206
00207 public function render() {
00208 $this->layoutReviewBox();
00209 return parent::render();
00210 }
00211 }
00212
00213 ?>