Alpha Framework alpha--view
[ class tree: alpha--view ] [ index: alpha--view ] [ all elements ]

Source for file ArticleCommentView.inc

Documentation is available at ArticleCommentView.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/model/ArticleCommentObject.inc';
  4. require_once $config->get('sysRoot').'alpha/model/PersonObject.inc';
  5. require_once $config->get('sysRoot').'alpha/view/AlphaView.inc';
  6. require_once $config->get('sysRoot').'alpha/util/MarkdownFacade.inc';
  7.  
  8. /**
  9.  *
  10.  * The rendering class for the ArticleCommentObject class
  11.  * 
  12.  * @package alpha::view
  13.  * @since 1.0
  14.  * @author John Collins <dev@alphaframework.org>
  15.  * @version $Id: ArticleCommentView.inc 1453 2011-12-04 15:12:54Z johnc $
  16.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  17.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  18.  *  All rights reserved.
  19.  * 
  20.  *  <pre>
  21.  *  Redistribution and use in source and binary forms, with or
  22.  *  without modification, are permitted provided that the
  23.  *  following conditions are met:
  24.  * 
  25.  *  * Redistributions of source code must retain the above
  26.  *    copyright notice, this list of conditions and the
  27.  *    following disclaimer.
  28.  *  * Redistributions in binary form must reproduce the above
  29.  *    copyright notice, this list of conditions and the
  30.  *    following disclaimer in the documentation and/or other
  31.  *    materials provided with the distribution.
  32.  *  * Neither the name of the Alpha Framework nor the names
  33.  *    of its contributors may be used to endorse or promote
  34.  *    products derived from this software without specific
  35.  *    prior written permission.
  36.  *   
  37.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  38.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  39.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  40.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  41.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  42.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  43.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  44.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  45.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  46.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  47.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  48.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  49.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  50.  *  </pre>
  51.  *  
  52.  */
  53. class ArticleCommentView extends AlphaView {    
  54.     /**
  55.      * Method to generate the markdown HTML render of the ArticleComment content
  56.      * 
  57.      * @since 1.0
  58.      */
  59.     public function markdownView({
  60.         global $config;
  61.         
  62.         $markdown new MarkdownFacade($this->BO);
  63.         $author new PersonObject();
  64.         $id $this->BO->getCreatorID();
  65.         $author->load($id->getValue());
  66.         
  67.         echo '<blockquote class="usercomment">';
  68.         
  69.         $createTS $this->BO->getCreateTS();
  70.         $updateTS $this->BO->getUpdateTS();
  71.  
  72.         echo '<p>Posted by '.($author->get('URL'== ''$author->get('displayname''<a href="'.$author->get('URL').'" target="new window">'.$author->get('displayname').'</a>').' at '.$createTS->getValue().'.';
  73.         echo '&nbsp;'.$author->get('displayname').' has posted ['.$author->getCommentCount().'] comments on articles since joining.';
  74.         echo '</p>';
  75.         if($config->get('sysCMSCommentsAllowed'&& isset($_SESSION['currentUser']&& $_SESSION['currentUser']->getID(== $author->getID())
  76.             $this->editView();
  77.         else
  78.             echo $markdown->getContent();
  79.         
  80.         if($createTS->getValue(!= $updateTS->getValue()) {
  81.             $updator new PersonObject();
  82.             $id $this->BO->getCreatorID();
  83.             $updator->load($id->getValue());
  84.             echo '<p>Updated by '.($updator->get('URL'== ''$updator->get('displayname''<a href="'.$updator->get('URL').'" target="new window">'.$updator->get('displayname').'</a>').' at '.$updateTS->getValue().'.</p>';
  85.         }
  86.         echo '</blockquote>';
  87.     }
  88.     
  89.     /**
  90.      * Renders the custom create view
  91.      * 
  92.      * @param array $fields hash array of HTML fields to pass to the template
  93.      * @since 1.0
  94.      */
  95.     public function createView($fields=array()) {
  96.         echo '<h2>Post a new comment:</h2>';
  97.  
  98.         echo '<table cols="2" class="create_view">';
  99.         echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST">';
  100.         
  101.         $textBox new textBox($this->BO->getPropObject('content')$this->BO->getDataLabel('content')'content'''10);
  102.         echo $textBox->render();        
  103.         
  104.         echo '<input type="hidden" name="articleOID" value="'.$this->BO->get('articleOID').'"/>';
  105.         echo '<tr><td colspan="2">';
  106.         
  107.         $button new button('submit''Post Comment''createBut');
  108.         echo $button->render();
  109.             
  110.         echo '</td></tr>';
  111.  
  112.         echo AlphaView::renderSecurityFields();
  113.         
  114.         echo '</form></table>';
  115.         echo '<p class="warning">Please note that any comment you post may be moderated for spam or offensive material.</p>';
  116.     }
  117.     
  118.     /**
  119.      * Custom edit view
  120.      * 
  121.      * @param array $fields Hash array of HTML fields to pass to the template.
  122.      * @since 1.0
  123.      */
  124.     public function editView($fields=array()) {
  125.         global $config;
  126.  
  127.         echo '<table cols="2" class="edit_view" style="width:100%; margin:0px">';
  128.         echo '<form action="'.$_SERVER['REQUEST_URI'].'" method="POST">';
  129.         
  130.         $textBox new TextBox($this->BO->getPropObject('content')$this->BO->getDataLabel('content')'content'''5$this->BO->getID());
  131.         echo $textBox->render();        
  132.  
  133.         echo '<input type="hidden" name="version_num" value="'.$this->BO->getVersion().'"/>';
  134.         echo '<input type="hidden" name="article_comment_id" value="'.$this->BO->getID().'"/>';
  135.         
  136.         // render special buttons for admins only
  137.         if ($_SESSION['currentUser']->inGroup('Admin'&& strpos($_SERVER['REQUEST_URI']'/tk/'!== false{
  138.             echo '<tr><td colspan="2">';
  139.             
  140.             $temp new button('submit''Save''saveBut');
  141.             echo $temp->render();
  142.             echo '&nbsp;&nbsp;';
  143.             $js "$('#dialogDiv').text('Are you sure you wish to delete this item?');
  144.                 $('#dialogDiv').dialog({
  145.                 buttons: {
  146.                     'OK': function(event, ui) {                        
  147.                         $('#deleteOID').attr('value', '".$this->BO->getOID()."');
  148.                         $('#deleteForm').submit();
  149.                     },
  150.                     'Cancel': function(event, ui) {
  151.                         $(this).dialog('close');
  152.                     }
  153.                 }
  154.             })
  155.             $('#dialogDiv').dialog('open');
  156.             return false;";
  157.             $temp new Button($js"Delete""deleteBut");
  158.             echo $temp->render();
  159.             echo '&nbsp;&nbsp;';
  160.             $temp new button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'",'Back to List','cancelBut');
  161.             echo $temp->render();
  162.             echo '</td></tr>';
  163.             
  164.             echo AlphaView::renderSecurityFields();
  165.         
  166.             echo '</form></table>';
  167.         }else{
  168.             echo '</table>';
  169.             
  170.             echo '<div align="center">';
  171.             $temp new button('submit''Update Your Comment''saveBut'.$this->BO->getID());
  172.             echo $temp->render();
  173.             echo '</div>';
  174.             
  175.             echo AlphaView::renderSecurityFields();
  176.             
  177.             echo '</form>';
  178.         }        
  179.     }
  180. }
  181.  
  182. ?>

Documentation generated on Tue, 13 Dec 2011 20:26:25 +0000 by phpDocumentor 1.4.3