1: <?php
2:
3: /**
4: * ProcessWire FieldtypeComments > CommentArray
5: *
6: * Maintains an array of multiple Comment instances.
7: * Serves as the value referenced when a FieldtypeComment field is reference from a Page.
8: *
9: * ProcessWire 2.x
10: * Copyright (C) 2010 by Ryan Cramer
11: * Licensed under GNU/GPL v2, see LICENSE.TXT
12: *
13: * http://www.processwire.com
14: * http://www.ryancramer.com
15: *
16: */
17:
18: class CommentArray extends WireArray {
19:
20: /**
21: * Page that owns these comments, required to use the renderForm() or getCommentForm() methods.
22: *
23: */
24: protected $page = null;
25:
26: /**
27: * Per the WireArray interface, is the item a Comment
28: *
29: */
30: public function isValidItem($item) {
31: return $item instanceof Comment;
32: }
33:
34: /**
35: * Provides the default rendering of a comment list, which may or may not be what you want
36: *
37: * @see CommentList class and override it to serve your needs
38: *
39: */
40: public function render(array $options = array()) {
41: $commentList = $this->getCommentList($options);
42: return $commentList->render();
43: }
44:
45: /**
46: * Provides the default rendering of a comment form, which may or may not be what you want
47: *
48: * @see CommentForm class and override it to serve your needs
49: *
50: */
51: public function renderForm(array $options = array()) {
52: $form = $this->getCommentForm($options);
53: return $form->render();
54: }
55:
56: /**
57: * Return instance of CommentList object
58: *
59: */
60: public function getCommentList(array $options = array()) {
61: return new CommentList($this, $options);
62: }
63:
64: /**
65: * Return instance of CommentForm object
66: *
67: */
68: public function getCommentForm(array $options = array()) {
69: if(!$this->page) throw new WireException("You must set a page to this CommentArray before using iti.e. \$ca->setPage(\$page)");
70: return new CommentForm($this->page, $this, $options);
71: }
72:
73: /**
74: * Set the page that these comments are on
75: *
76: */
77: public function setPage(Page $page) {
78: $this->page = $page;
79: }
80:
81: }
82:
83:
84: