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

Source for file ArticleView.inc

Documentation is available at ArticleView.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/model/PersonObject.inc';
  4. require_once $config->get('sysRoot').'alpha/view/AlphaView.inc';
  5. require_once $config->get('sysRoot').'alpha/util/MarkdownFacade.inc';
  6.  
  7. /**
  8.  *
  9.  * The rendering class for the ArticleObject class
  10.  * 
  11.  * @package alpha::view
  12.  * @since 1.0
  13.  * @author John Collins <dev@alphaframework.org>
  14.  * @version $Id: ArticleView.inc 1341 2011-03-17 15:02:02Z johnc $
  15.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  16.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  17.  *  All rights reserved.
  18.  * 
  19.  *  <pre>
  20.  *  Redistribution and use in source and binary forms, with or
  21.  *  without modification, are permitted provided that the
  22.  *  following conditions are met:
  23.  * 
  24.  *  * Redistributions of source code must retain the above
  25.  *    copyright notice, this list of conditions and the
  26.  *    following disclaimer.
  27.  *  * Redistributions in binary form must reproduce the above
  28.  *    copyright notice, this list of conditions and the
  29.  *    following disclaimer in the documentation and/or other
  30.  *    materials provided with the distribution.
  31.  *  * Neither the name of the Alpha Framework nor the names
  32.  *    of its contributors may be used to endorse or promote
  33.  *    products derived from this software without specific
  34.  *    prior written permission.
  35.  *   
  36.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  37.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  38.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  39.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  41.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  42.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  43.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  44.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  45.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  46.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  47.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  48.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  49.  *  </pre>
  50.  *  
  51.  */
  52. class ArticleView extends AlphaView {    
  53.     /**
  54.      * Method to generate the markdown HTML render of the article content
  55.      * 
  56.      * @param array $fields Hash array of HTML fields to pass to the template.
  57.      * @since 1.0
  58.      */
  59.     public function markdownView($fields=array()) {
  60.         global $config;
  61.         
  62.         $markdown new MarkdownFacade($this->BO);
  63.          
  64.         $fields['markdownContent'$markdown->getContent();
  65.         
  66.         $this->loadTemplate($this->BO'markdown'$fields);
  67.     }
  68.     
  69.     /**
  70.      * Adds a note to the create article screen
  71.      * 
  72.      * @since 1.0
  73.      */
  74.     protected function after_createView_callback({
  75.         echo '<p><strong>Please note</strong> that you will only be able to attach files to the article once it has been created.</p><br>';
  76.     }
  77.     
  78.     /**
  79.      * Renders the list view (adds the dateAdded field for the list template)
  80.      * 
  81.      * @param array $fields hash array of HTML fields to pass to the template
  82.      * @since 1.0
  83.      */
  84.     public function listView($fields=array()) {
  85.         $fields['dateAdded'$this->BO->getCreateTS()->getDate();
  86.         parent::listView($fields);                
  87.     }
  88.     
  89.     /**
  90.      * Renders a form to enable article editing with attachments options
  91.      * 
  92.      * @param array $fields hash array of HTML fields to pass to the template
  93.      * @since 1.0
  94.      */
  95.     public function editView($fields=array()) {
  96.         if(method_exists($this'before_editView_callback'))
  97.             $this->before_editView_callback();
  98.         
  99.         global $config;
  100.  
  101.         // the form action
  102.         $fields['formAction'$_SERVER['REQUEST_URI'];
  103.         
  104.         // the form ID
  105.         $fields['formID'get_class($this->BO).'_'.$this->BO->getID();
  106.         
  107.         // buffer form fields to $formFields
  108.         $fields['formFields'$this->renderAllFields('edit');
  109.         
  110.         // buffer HTML output for Create and Cancel buttons        
  111.         $button new button('submit''Save''saveBut');
  112.         $fields['saveButton'$button->render();
  113.         
  114.         $js "$('#dialogDiv').text('Are you sure you wish to delete this item?');
  115.                 $('#dialogDiv').dialog({
  116.                 buttons: {
  117.                     'OK': function(event, ui) {                        
  118.                         $('#deleteOID').attr('value', '".$this->BO->getOID()."');
  119.                         $('#deleteForm').submit();
  120.                     },
  121.                     'Cancel': function(event, ui) {
  122.                         $(this).dialog('close');
  123.                     }
  124.                 }
  125.             })
  126.             $('#dialogDiv').dialog('open');
  127.             return false;";
  128.         $button new Button($js"Delete""deleteBut");
  129.         $fields['deleteButton'$button->render();
  130.         
  131.         $button new button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'""Back to List""cancelBut");
  132.         $fields['cancelButton'$button->render();
  133.         
  134.         $tags $this->BO->getPropObject('tags')->getRelatedObjects();
  135.             
  136.         if(count($tags0{
  137.             $button new button("document.location = '".FrontController::generateSecureURL('act=EditTags&bo='.get_class($this->BO).'&oid='.$this->BO->getOID())."'""Edit Tags""tagsBut");
  138.             $fields['tagsButton'$button->render();
  139.         }
  140.                 
  141.         // buffer security fields to $formSecurityFields variable        
  142.         $fields['formSecurityFields'$this->renderSecurityFields();
  143.  
  144.         // OID will need to be posted for optimistic lock checking
  145.         $fields['version_num'$this->BO->getVersionNumber();
  146.         
  147.         // file attachments section
  148.         $fields['fileAttachments'$this->renderFileUploadSection();
  149.         
  150.         $this->loadTemplate($this->BO'edit'$fields);
  151.         
  152.         if(method_exists($this'after_editView_callback'))
  153.             $this->after_editView_callback();
  154.     }
  155.     
  156.     /**
  157.      * Renders the HTML for the file upload section
  158.      *
  159.      * @return string 
  160.      * @since 1.0
  161.      */
  162.     protected function renderFileUploadSection({        
  163.         $html '<tr><td colspan="2">&nbsp;</td></tr><tr><th colspan="2" style="text-align:left;">File Attachments:</th></tr>';
  164.         
  165.         if (is_dir($this->BO->getAttachmentsLocation())) {
  166.             $handle opendir($this->BO->getAttachmentsLocation());
  167.                
  168.             // loop over the attachments directory
  169.             while (false !== ($file readdir($handle))) {
  170.                 if($file != '.' && $file != '..'{
  171.                     $html .= '<tr><td>';                
  172.                     $html .= '&nbsp;'.$file.'&nbsp;<em>('.number_format(filesize($this->BO->getAttachmentsLocation().'/'.$file)/1024).' KB)</em>';
  173.                     $html .= '</td>';
  174.                     $html .= '<td>';
  175.                     $js "$('#dialogDiv').text('Are you sure you want to delete the file ".$file."');
  176.                             $('#dialogDiv').dialog({
  177.                             buttons: {
  178.                                 'OK': function(event, ui) {                        
  179.                                     $('#file_to_delete').attr('value', '".$file."');
  180.                                     $('#".get_class($this->BO).'_'.$this->BO->getID()."').submit();
  181.                                 },
  182.                                 'Cancel': function(event, ui) {
  183.                                     $(this).dialog('close');
  184.                                 }
  185.                             }
  186.                         })
  187.                         $('#dialogDiv').dialog('open');
  188.                         return false;";
  189.                     $button new Button($js"Delete""deleteBut");
  190.                     $html .= $button->render();
  191.                     $html .= '</td></tr>';
  192.                 }
  193.             }
  194.             
  195.             $html .= '<tr><td>';
  196.             $html .= 'Attachment file location';
  197.             $html .= '</td>';
  198.         }else{
  199.             // we will take this opportunity to create the attachments folder is it does
  200.             // not already exist.
  201.             $this->BO->createAttachmentsFolder();
  202.         }
  203.  
  204.         $html .= '<td>';
  205.         $html .= '<input name="userfile" type="file" value="Browse..." size="70"/>';
  206.         $html .= '</td></tr>';
  207.         
  208.         $html .= '<tr><td colspan="2">';
  209.         $temp new button('submit''Upload''uploadBut');
  210.         $html .= $temp->render();
  211.         $html .= '</td></tr>';
  212.         
  213.         $html .= '<input type="hidden" name="file_to_delete" id="file_to_delete" value=""/>';
  214.         
  215.         return $html;
  216.     }
  217. }
  218.  
  219. ?>

Documentation generated on Thu, 17 Mar 2011 16:43:52 +0000 by phpDocumentor 1.4.3