Newer
Older
function getQueryForDuplicates($module, $tableColumns, $selectedColumns = '', $ignoreEmpty = false,$requiredTables = array()) {
if(is_array($tableColumns)) {
$tableColumnsString = implode(',', $tableColumns);
}
$selectClause = "SELECT " . $this->table_name . "." . $this->table_index . " AS recordid," . $tableColumnsString;
// Select Custom Field Table Columns if present
if (isset($this->customFieldTable))
$query .= ", " . $this->customFieldTable[0] . ".* ";
$fromClause .= " INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = $this->table_name.$this->table_index";
if($this->tab_name) {
foreach($this->tab_name as $tableName) {
if($tableName != 'vtiger_crmentity' && $tableName != $this->table_name && $tableName != 'vtiger_inventoryproductrel' && in_array($tableName,$requiredTables)) {
if($this->tab_name_index[$tableName]) {
$fromClause .= " INNER JOIN " . $tableName . " ON " . $tableName . '.' . $this->tab_name_index[$tableName] .
" = $this->table_name.$this->table_index";
}
}
}
}
$whereClause = " WHERE vtiger_crmentity.deleted = 0";
$whereClause .= $this->getListViewSecurityParameter($module);
if($ignoreEmpty) {
foreach($tableColumns as $tableColumn){
$whereClause .= " AND ($tableColumn IS NOT NULL AND $tableColumn != '') ";
}
}
if (isset($selectedColumns) && trim($selectedColumns) != '') {
$sub_query = "SELECT $selectedColumns FROM $this->table_name AS t " .
" INNER JOIN vtiger_crmentity AS crm ON crm.crmid = t." . $this->table_index;
// Consider custom table join as well.
if (isset($this->customFieldTable)) {
$sub_query .= " LEFT JOIN " . $this->customFieldTable[0] . " tcf ON tcf." . $this->customFieldTable[1] . " = t.$this->table_index";
}
$sub_query .= " WHERE crm.deleted=0 GROUP BY $selectedColumns HAVING COUNT(*)>1";
} else {
$sub_query = "SELECT $tableColumnsString $fromClause $whereClause GROUP BY $tableColumnsString HAVING COUNT(*)>1";
}
$i = 1;
foreach($tableColumns as $tableColumn){
$tableInfo = explode('.', $tableColumn);
$duplicateCheckClause .= " ifnull($tableColumn,'null') = ifnull(temp.$tableInfo[1],'null')";
if (count($tableColumns) != $i++) $duplicateCheckClause .= " AND ";
}
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
$query = $selectClause . $fromClause .
" LEFT JOIN vtiger_users_last_import ON vtiger_users_last_import.bean_id=" . $this->table_name . "." . $this->table_index .
" INNER JOIN (" . $sub_query . ") AS temp ON " . $duplicateCheckClause .
$whereClause .
" ORDER BY $tableColumnsString," . $this->table_name . "." . $this->table_index . " ASC";
return $query;
}
/**
* Function to get relation query for get_activities
*/
function get_activities($id, $cur_tab_id, $rel_tab_id, $actions=false) {
global $currentModule;
$this_module = $currentModule;
$related_module = vtlib_getModuleNameById($rel_tab_id);
$userNameSql = getSqlForNameInDisplayFormat(array('first_name' => 'vtiger_users.first_name', 'last_name' => 'vtiger_users.last_name'), 'Users');
$query = "SELECT CASE WHEN (vtiger_users.user_name not like '') THEN $userNameSql ELSE vtiger_groups.groupname END AS user_name,
vtiger_crmentity.*, vtiger_activity.activitytype, vtiger_activity.subject, vtiger_activity.date_start, vtiger_activity.time_start,
vtiger_activity.recurringtype, vtiger_activity.due_date, vtiger_activity.time_end, vtiger_activity.visibility, vtiger_seactivityrel.crmid AS parent_id,
CASE WHEN (vtiger_activity.activitytype = 'Task') THEN (vtiger_activity.status) ELSE (vtiger_activity.eventstatus) END AS status
FROM vtiger_activity
INNER JOIN vtiger_crmentity ON vtiger_crmentity.crmid = vtiger_activity.activityid
LEFT JOIN vtiger_seactivityrel ON vtiger_seactivityrel.activityid = vtiger_activity.activityid
LEFT JOIN vtiger_cntactivityrel ON vtiger_cntactivityrel.activityid = vtiger_activity.activityid
LEFT JOIN vtiger_users ON vtiger_users.id = vtiger_crmentity.smownerid
LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid
WHERE vtiger_crmentity.deleted = 0 AND vtiger_activity.activitytype <> 'Emails'
AND vtiger_seactivityrel.crmid = ".$id;
$return_value = GetRelatedList($this_module, $related_module, '', $query, '', '');
if($return_value == null) $return_value = Array();
return $return_value;
}
function get_comments($relatedRecordId = false) {
$current_user = vglobal('current_user');
$moduleName = $this->moduleName;
if($moduleName != 'ModComments') {
return false;
}
$queryGenerator = new EnhancedQueryGenerator($moduleName, $current_user);
if(is_object($this->column_fields)) {
$fields = $this->column_fields->getColumnFieldNames();
} else if(is_array($this->column_fields)) {
$fields = array_keys($this->column_fields);
}
array_push($fields, 'id');
$queryGenerator->setFields($fields);
$query = $queryGenerator->getQuery();
if($relatedRecordId){
$query .= " AND related_to = ".$relatedRecordId." ORDER BY vtiger_crmentity.createdtime DESC";
}
return $query;
}
class TrackableObject implements ArrayAccess, IteratorAggregate {
private $storage;
private $trackingEnabled = true;
function __construct($value = array()) {
$this->storage = $value;
}
function offsetExists($key) {
return isset($this->storage[$key]);
}
function offsetSet($key, $value) {
if($this->tracking && $this->trackingEnabled) {
$olderValue = $this->offsetGet($key);
// decode_html only expects string
$olderValue = is_string($olderValue) ? decode_html($olderValue) : $olderValue ;
//same logic is used in vtEntityDelta to check for delta
if((empty($olderValue) && !empty($value)) || ($olderValue !== $value)) {
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
$this->changed[] = $key;
}
}
$this->storage[$key] = $value;
}
public function offsetUnset($key) {
unset($this->storage[$key]);
}
public function offsetGet($key) {
return isset($this->storage[$key]) ? $this->storage[$key] : null;
}
public function getIterator() {
$iterator = new ArrayObject($this->storage);
return $iterator->getIterator();
}
function getChanged() {
return $this->changed;
}
function startTracking() {
if($this->tracking && $this->trackingEnabled) return;
$this->tracking = true;
$this->changed = array();
}
function restartTracking() {
$this->tracking = true;
$this->startTracking();
}
function pauseTracking() {
$this->tracking = false;
}
function resumeTracking() {
if($this->trackingEnabled)
$this->tracking = true;
}
function getColumnFields() {
return $this->storage;
}
function getColumnFieldNames(){
return array_keys($this->storage);
}