[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/PriceBooks/models/ -> RelationListView.php (source)

   1  <?php
   2  /*+***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   *************************************************************************************/
  10  
  11  class PriceBooks_RelationListView_Model extends Vtiger_RelationListView_Model {
  12  
  13  	public function getHeaders() {
  14          $headerFields = parent::getHeaders();
  15  
  16          //Added to support List Price
  17          $field = new Vtiger_Field_Model();
  18          $field->set('name', 'listprice');
  19          $field->set('column', 'listprice');
  20          $field->set('label', 'List Price');
  21          $headerFields['listprice'] = $field;
  22  
  23          return $headerFields;
  24      }
  25  
  26  	public function getEntries($pagingModel) {
  27          $db = PearDatabase::getInstance();
  28          $parentModule = $this->getParentRecordModel()->getModule();
  29          $relationModule = $this->getRelationModel()->getRelationModuleModel();
  30          $relatedColumnFieldMapping = $relationModule->getConfigureRelatedListFields();
  31          if(count($relatedColumnFieldMapping) <= 0){
  32              $relatedColumnFieldMapping = $relationModule->getRelatedListFields();
  33          }
  34  
  35          $query = $this->getRelationQuery();
  36  
  37          $startIndex = $pagingModel->getStartIndex();
  38          $pageLimit = $pagingModel->getPageLimit();
  39  
  40          $orderBy = $this->getForSql('orderby');
  41          $sortOrder = $this->getForSql('sortorder');
  42          if($orderBy) {
  43              $query = "$query ORDER BY $orderBy $sortOrder";
  44          }
  45  
  46          $limitQuery = $query .' LIMIT '.$startIndex.','.$pageLimit;
  47          $result = $db->pquery($limitQuery, array());
  48          $relatedRecordList = array();
  49  
  50          for($i=0; $i< $db->num_rows($result); $i++ ) {
  51              $row = $db->fetch_row($result,$i);
  52              $newRow = array();
  53              foreach($row as $col=>$val){
  54                  if(array_key_exists($col,$relatedColumnFieldMapping))
  55                      $newRow[$relatedColumnFieldMapping[$col]] = $val;
  56              }
  57              
  58              $recordId = $row['crmid'];
  59              $newRow['id'] = $recordId;
  60              //Added to support List Price
  61              $newRow['listprice'] = CurrencyField::convertToUserFormat($row['listprice'], null, true);
  62  
  63              $record = Vtiger_Record_Model::getCleanInstance($relationModule->get('name'));
  64              $relatedRecordList[$recordId] = $record->setData($newRow)->setModuleFromInstance($relationModule);
  65          }
  66          $pagingModel->calculatePageRange($relatedRecordList);
  67  
  68          $nextLimitQuery = $query. ' LIMIT '.($startIndex+$pageLimit).' , 1';
  69          $nextPageLimitResult = $db->pquery($nextLimitQuery, array());
  70          if($db->num_rows($nextPageLimitResult) > 0){
  71              $pagingModel->set('nextPageExists', true);
  72          }else{
  73              $pagingModel->set('nextPageExists', false);
  74          }
  75          return $relatedRecordList;
  76      }
  77  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1