73 class CommentFieldRenderer
extends FieldRenderer
79 var $publishedFormat =
"published/unpublished";
80 var $publishRoles =
"admin";
86 $this->parent->add($this,
$field);
91 $this->list = $this->buildCommentList($comments);
92 $this->comment = $this->createComment();
93 $this->addField($this->
field);
95 $this->addCommentFields();
97 $this->getPublishedFormat();
100 function addCommentFields()
102 $this->addTitleField();
103 $this->addAuthorField();
104 $this->addCommentField();
107 function createComment()
112 if(!checkRole(
"admin"))
125 function addTitleField()
129 $this->parent->add(
new StringFieldRenderer($this->parent),
$field);
138 function subjectSelectField(
$options, $label =
"Subject")
142 $this->parent->override(
$field, $label,
new SelectFieldRenderer($this->parent,
$field, $label,
$options));
153 $filter = $this->parent->data->filter;
156 if(
$filter->type ==
"InclusionFilter")
167 function addCommentField()
169 $field =
"comment_message";
170 $this->parent->add(
new TextFieldRenderer($this->parent),
$field);
171 $this->parent->alias(
$field,
"Comment");
175 function addAuthorField()
177 $field =
"comment_author";
182 $this->parent->add(
new StringFieldRenderer($this->parent,
$field));
187 function addPublishedField($label =
"Publish")
189 $rend =
new BooleanFieldRenderer($this->parent);
190 $this->parent->add($rend,
"comment_published");
191 $this->parent->override(
"comment_published", $label, $rend);
192 $this->addField(
"comment_published");
195 function addGroup(
$title =
"")
198 $this->parent->group(
"Comments", $this->
field,
"comment_title",
"comment_message",
"comment_published");
201 function getCommentDialog()
203 return "comment_dialog";
206 function buildCommentList($comments)
208 if(!is_array($comments))
210 $comments = $this->getComments();
214 $list =
new PagedList($comments,
"{$this->parent->id}_{$field}", array($this, formatComment));
215 $list->styles =
"clear: both";
216 $list->CSSclass =
"comment";
217 $list->paginate =
false;
222 function getComments()
224 if(!checkRole(
"admin"))
228 return $this->parent->data->Comments(
"$constraint ORDER BY date_posted DESC");
234 function getPublishedFormat()
236 $fn = array($this->xrefClass, getPublishedFormat);
239 $this->publishedFormat = call_user_func($fn);
243 function getPublishRoles()
245 $fn = array($this->xrefClass, getPublishRoles);
248 $this->publishRoles = call_user_func($fn);
255 $author = (
$comment->user_id) ?
"{User.first_name} {User.last_name}" :
"{author}";
257 $class = (
$comment->published) ?
"message" :
"message_unpublished";
258 $out .=
"<div id='comment_{comment_id}' class='$class'>\n";
259 $out .=
" <div class='title'>";
263 $out .=
"<strong><span id='comment_{comment_id}_title'>{title:prettify}</span></strong><br/>\n";
266 $published = (checkRole($this->publishRoles)) ?
"{published:{$this->publishedFormat}}" :
"";
267 $out .=
"<span class='small'>Posted by $author at {date_posted:short}</span>  {$published} \n </div>\n";
268 $out .=
"<div class='message_content'><span id='comment_{comment_id}_message'>{description:stripHTML}</span>";
272 $out .=
" <a href='#' onclick=\"commentMgr.showCommentDialog({comment_id}); return false\">(edit)</a>";
275 $out .=
"</div></div>";
282 function renderScript(
$field)
284 if ($this->parent->readOnlyForm || $this->parent->isReadOnly(
$field) || array_key_exists(
$field, $this->parent->hidden))
return "";
288 $commentDialog = $this->getCommentDialog();
291 <script type=
"text/javascript" src=
"/components/comment/js/comment_manager.js"></script>
292 <script type=
"text/javascript">
295 window.addEvent(
'domready',
function()
298 '<?php echo $this->component ?>',
299 '<?php echo $commentDialog ?>'
307 function renderField(
$field)
309 $this->list->listCSS = $this->listCSS;
311 if(count($this->list->items) > 0)
313 $this->list->drawList();
318 function getMatchingPK($xref,
$obj)
320 $pks =
$obj->getPrimaryKeyList();
323 if ($xref->hasField(
$pk))
return $pk;
326 throw new DataItemException(
"No matching foreign key in xref table");
331 $commentField =
"comment_message";
332 $titleField =
"comment_title";
333 $authorField =
"comment_author";
334 trace(
"CommentFieldRenderer postProcess title field $titleField value ".
$_POST[$titleField], 3);
336 if ($this->parent->readOnlyForm || $this->parent->isReadOnly($commentField) || array_key_exists($commentField, $this->parent->hidden))
return "";
340 $obj = $this->parent->data;
341 $pk = $this->getMatchingPK($xref,
$obj);
343 $commentMessage =
$_POST[$commentField];
347 trace(
"CommentFieldRenderer no comment entered in comment field {$commentField}", 3);
352 $comment->description = $commentMessage;
354 if(isset(
$_POST[
"comment_published"]))
363 $author =
$_POST[$authorField];
371 $xref->set(
"comment_id",
$comment->comment_id);
377 $this->readOnly =
true;
378 $this->renderField($this->
field);
static usingFile()
Uses the specified framework file(s) from the framework directory.