Advertisement
AmourSpirit

Joomla example load second model into view

Aug 26th, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.50 KB | None | 0 0
  1. <?php
  2. /**
  3.  * @version     $Id$
  4.  * @package     com_cn_reports
  5.  * @copyright   Copyright (C) 2015. All rights reserved.
  6.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  7.  * @author      
  8.  */
  9.  // No direct access
  10. defined('_JEXEC') or die;
  11.  
  12. jimport('joomla.application.component.view');
  13. JLoader::register('Cn_reportsDateHelper', JPATH_COMPONENT_ADMINISTRATOR .'/helpers/cn_reportsdatehelper.php');
  14.  
  15. /**
  16.  * View class for a list of Cn_reports.
  17.  */
  18. class Cn_reportsViewArchivecommissionsales extends JViewLegacy
  19. {
  20.     protected $items;
  21.     protected $pagination;
  22.     protected $state;
  23.  
  24.      /**
  25.      * Display the view
  26.      */
  27.     public function display($tpl = null) {
  28.         $this->state = $this->get('State');
  29.         $this->items = $this->get('Items');
  30.         $this->pagination = $this->get('Pagination');
  31.  
  32.  
  33.         // Check for errors.
  34.         if (count($errors = $this->get('Errors'))) {
  35.             throw new Exception(implode("\n", $errors));
  36.         }
  37.  
  38.         Cn_reportsHelper::addSubmenu('archivecommissionsales');
  39.  
  40.         // assign the server timezone as object
  41.         $jtz = Cn_reportsDateHelper::getTimeZone();
  42.         $this->assignRef('serverTz', $jtz);
  43.  
  44.        // Load second Model Named Cn_reportsModelArchivecommission
  45.         $aModel = JModelLegacy::getInstance('Archivecommission', 'Cn_reportsModel');
  46.         // load current state into model
  47.         foreach ($this->state as $key => $value) {
  48.             $aModel->setState($key,$value);
  49.         }
  50.         // assigne the model nto a referecne to us in other parts of the view
  51.         $this->assignRef('archiveModel', $aModel);
  52.  
  53.         $this->addToolbar();
  54.  
  55.         $this->sidebar = JHtmlSidebar::render();
  56.         parent::display($tpl);
  57.     }
  58.  
  59.     /**
  60.      * Add the page title and toolbar.
  61.      *
  62.      * @since   1.6
  63.      */
  64.     protected function addToolbar() {
  65.         //TODO: Confirm Security on backend view.html.php in administrator/com_cn_reports/view/archivecommissionsales\view.html.php addToolbar() method
  66.         JLoader::register('Cn_reportsHelper', JPATH_COMPONENT_ADMINISTRATOR .'/helpers/cn_reportshelper.php');
  67.         $state = $this->get('State');
  68.         $canDo = Cn_reportsHelper::getActions();
  69.  
  70.         JToolBarHelper::title(JText::_('COM_CN_REPORTS_TITLE_ARCHIVECOMMISSIONSALE'), 'rtreports.png');
  71.  
  72.         if ($canDo->get('core.admin')) {
  73.             JToolBarHelper::preferences('com_cn_reports');
  74.         }
  75.          //Set sidebar action - New in 3.0
  76.         JHtmlSidebar::setAction('index.php?option=com_cn_reports&view=archivecommissionsales');
  77.  
  78.         $this->extra_sidebar = '';
  79.  
  80.         //TODO: Add any filter custom Filters here. See: http://pastebin.com/w4CAhpgQ for example
  81.     }
  82.     /**
  83.      * Gets the sort fields used in the display and for possible filters
  84.      * @return multitype:string associative array with key of field and value from en-GB.com_cn_reports.ini file
  85.      */
  86.     protected function getSortFields()
  87.     {
  88.         // this array will show in the order created int he drop down coloum list.
  89.         return array(
  90.             'arc.id' => JText::_('JGRID_HEADING_ID'),
  91.             'arc.order_id' => JText::_('COM_CN_REPORTS_FORM_LBL_ORDERID'),
  92.             'override_type_name' => JText::_('COM_CN_REPORTS_ARCHIVECOMMISSIONSALES_COLUMNS_OVERRIDETYPENAME'),
  93.             'retail_partner_name' => JText::_('COM_CN_REPORTS_ARCHIVECOMMISSIONSALES_COLUMNS_RETAILPARTNERNAME'),
  94.             'arc.order_count' => JText::_('COM_CN_REPORTS_ARCHIVECOMMISSIONSALES_COLUMNS_ORDERCOUNT'),
  95.             'arc.order_voucher' => JText::_('COM_CN_REPORTS_FORM_LBL_VOUCHER'),
  96.             'arc.order_coupon' => JText::_('COM_CN_REPORTS_FORM_LBL_COUPON'),
  97.             'arc.order_shipping' => JText::_('COM_CN_REPORTS_FORM_LBL_SHIPPING'),
  98.             'arc.order_tax' => JText::_('COM_CN_REPORTS_FORM_LBL_TAX'),
  99.             'order_total' => JText::_('COM_CN_REPORTS_FORM_LBL_OT_TOTAL'),
  100.             'wholesale_price' => JText::_('COM_CN_REPORTS_FORM_LBL_WHOLESALE'),
  101.             'arc.wholesale_markup_amount' => JText::_('COM_CN_REPORTS_ARCHIVECOMMISSIONSALES_COLUMNS_WHOLESALEMARKUPAMOUNT'),
  102.             'arc.profit_margin_actual' => JText::_('COM_CN_REPORTS_FORM_LBL_APM'),
  103.             'arc.commission_rate' => JText::_('COM_CN_REPORTS_ARCHIVECOMMISSIONSALES_COLUMNS_COMMISSIONRATE'),
  104.             'arc.commission_amount' => JText::_('COM_CN_REPORTS_FORM_LBL_COMMISSION'),
  105.             'arc.date_start' => JText::_('COM_CN_REPORTS_ARCHIVECOMMISSIONSALES_COLUMNS_DATESTART'),
  106.             'arc.date_end' => JText::_('COM_CN_REPORTS_ARCHIVECOMMISSIONSALES_COLUMNS_DATEEND'),
  107.             'created_by_name' => JText::_('COM_CN_REPORTS_ARCHIVECOMMISSIONSALES_COLUMNS_CREATEDBYNAME')
  108.             );
  109.     }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement