[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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 Vtiger_FindDuplicate_Model extends Vtiger_Base_Model { 12 13 public function setModule($moduleModel) { 14 $this->module = $moduleModel; 15 } 16 17 public function getModule() { 18 return $this->module; 19 } 20 21 function getListViewHeaders() { 22 $db = PearDatabase::getInstance(); 23 $moduleModel = $this->getModule(); 24 $listViewHeaders = array(); 25 $listViewHeaders[] = new Vtiger_Base_Model(array('name' => 'recordid', 'label' => 'Record Id')); 26 $headers = $db->getFieldsArray($this->result); 27 foreach($headers as $header) { 28 $fieldModel = $moduleModel->getFieldByColumn($header); 29 if($fieldModel) { 30 $listViewHeaders[] = $fieldModel; 31 } 32 } 33 return $listViewHeaders; 34 } 35 36 function getListViewEntries(Vtiger_Paging_Model $paging) { 37 $db = PearDatabase::getInstance(); 38 $moduleModel = $this->getModule(); 39 $module = $moduleModel->getName(); 40 41 $fields = $this->get('fields'); 42 $fieldModels = $moduleModel->getFields(); 43 if(is_array($fields)) { 44 foreach($fields as $fieldName) { 45 $fieldModel = $fieldModels[$fieldName]; 46 $tableColumns[] = $fieldModel->get('table').'.'.$fieldModel->get('column'); 47 } 48 } 49 50 $startIndex = $paging->getStartIndex(); 51 $pageLimit = $paging->getPageLimit(); 52 $ignoreEmpty = $this->get('ignoreEmpty'); 53 54 $focus = CRMEntity::getInstance($module); 55 $query = $focus->getQueryForDuplicates($module, $tableColumns, '', $ignoreEmpty); 56 57 $query .= " LIMIT $startIndex, ". ($pageLimit+1); 58 59 $result = $db->pquery($query, array()); 60 $rows = $db->num_rows($result); 61 $this->result = $result; 62 63 $group = 'group0'; 64 $temp = $fieldValues = array(); $groupCount = 0; 65 $groupRecordCount = 0; 66 $entries = array(); 67 for($i=0; $i<$rows; $i++) { 68 $entries[] = $db->query_result_rowdata($result, $i); 69 } 70 71 $paging->calculatePageRange($entries); 72 73 if ($rows > $pageLimit) { 74 array_pop($entries); 75 $paging->set('nextPageExists', true); 76 } else { 77 $paging->set('nextPageExists', false); 78 } 79 $rows = count($entries); 80 81 for ($i=0; $i<$rows; $i++) { 82 $row = $entries[$i]; 83 if($i != 0) { 84 $slicedArray = array_slice($row, 2); 85 array_walk($temp, 'lower_array'); 86 array_walk($slicedArray, 'lower_array'); 87 $arrDiff = array_diff($temp, $slicedArray); 88 if(count($arrDiff) > 0) { 89 $groupCount++; 90 $temp = $slicedArray; 91 $groupRecordCount = 0; 92 } 93 $group = "group".$groupCount; 94 } 95 $fieldValues[$group][$groupRecordCount]['recordid'] = $row['recordid']; 96 foreach($row as $field => $value) { 97 if($i == 0 && $field != 'recordid') $temp[$field] = $value; 98 $fieldModel = $fieldModels[$field]; 99 $resultRow[$field] = $value; 100 } 101 $fieldValues[$group][$groupRecordCount++] = $resultRow; 102 } 103 104 return $fieldValues; 105 } 106 107 public static function getInstance($module) { 108 $self = new self(); 109 $moduleModel = Vtiger_Module_Model::getInstance($module); 110 $self->setModule($moduleModel); 111 return $self; 112 } 113 114 public function getRecordCount() { 115 if($this->rows) { 116 $rows = $this->rows; 117 } else { 118 $db = PearDatabase::getInstance(); 119 120 $moduleModel = $this->getModule(); 121 $module = $moduleModel->getName(); 122 $fields = $this->get('fields'); 123 $fieldModels = $moduleModel->getFields(); 124 if(is_array($fields)) { 125 foreach($fields as $fieldName) { 126 $fieldModel = $fieldModels[$fieldName]; 127 $tableColumns[] = $fieldModel->get('table').'.'.$fieldModel->get('column'); 128 } 129 } 130 $focus = CRMEntity::getInstance($module); 131 $ignoreEmpty = $this->get('ignoreEmpty'); 132 $query = $focus->getQueryForDuplicates($module, $tableColumns, '', $ignoreEmpty); 133 134 $position = stripos($query, 'from'); 135 if ($position) { 136 $split = spliti('from ', $query); 137 $splitCount = count($split); 138 $query = 'SELECT count(*) AS count '; 139 for ($i=1; $i<$splitCount; $i++) { 140 $query = $query. ' FROM ' .$split[$i]; 141 } 142 } 143 $result = $db->pquery($query, array()); 144 $rows = $db->query_result($result, 0, 'count'); 145 146 } 147 return $rows; 148 } 149 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |