Deduble calendar fix
This commit is contained in:
parent
07ce316c53
commit
2b1fad8cc5
@ -41,13 +41,10 @@ if ($_SESSION['id']) {
|
||||
|
||||
$i = 0;
|
||||
while ($event = mysql_fetch_assoc($rez)) {
|
||||
// Дедупликация сделок
|
||||
// Deal-события обрабатываются отдельно во втором цикле
|
||||
if ($event['type'] == 'deal' && !empty($event['deal_id'])) {
|
||||
if (in_array($event['deal_id'], $seenDealIds)) {
|
||||
continue;
|
||||
}
|
||||
$seenDealIds[] = $event['deal_id'];
|
||||
}
|
||||
|
||||
if ($i > 0) {
|
||||
echo ',{';
|
||||
@ -57,8 +54,10 @@ if ($_SESSION['id']) {
|
||||
echo '"id" : "'.$i.'", ';
|
||||
echo '"table_id" : "'.$event['id'].'", ';
|
||||
echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", ';
|
||||
$objectId = ($event['type'] == 'deal') ? '0' : $event['object_id'];
|
||||
echo '"object_id" : "'.$objectId.'",';
|
||||
// Для сделок не выводим object_id чтобы клик шёл на client_id/req_id
|
||||
if ($event['type'] != 'deal') {
|
||||
echo '"object_id" : "'.$event['object_id'].'",';
|
||||
}
|
||||
|
||||
$event['nazv'] = str_replace('"', "'", $event['nazv']);
|
||||
$event['nazv'] = str_replace('"', "'", $event['nazv']);
|
||||
@ -198,27 +197,24 @@ if ($_SESSION['id']) {
|
||||
}
|
||||
|
||||
$sql = "SELECT *, deal_id FROM user_client_events WHERE user_id = $_SESSION[id] and schedule_date is not null and cancel=0 and $where and $startDateWhere and $endDateWhere";
|
||||
//echo $sql;
|
||||
$agencyId = User::getUserAgencyID();
|
||||
if($agencyId != 7384){
|
||||
$sql = "SELECT *, deal_id FROM user_client_events WHERE user_id = $_SESSION[id] and megafon=0 and mango=0 and telphin=0 and beeline=0 and mts=0 and tele2=0 and allo=0 and schedule_date is not null and cancel=0 and $where and $startDateWhere and $endDateWhere";
|
||||
}
|
||||
$rez = mysql_query($sql);
|
||||
|
||||
// Собираем все deal-события по deal_id
|
||||
$dealEvents = array();
|
||||
while ($event = mysql_fetch_assoc($rez)) {
|
||||
// Дедупликация сделок
|
||||
if ($event['type'] == 'deal' && !empty($event['deal_id'])) {
|
||||
if (in_array($event['deal_id'], $seenDealIds)) {
|
||||
continue;
|
||||
$did = (int)$event['deal_id'];
|
||||
if (!isset($dealEvents[$did])) {
|
||||
$dealEvents[$did] = array();
|
||||
}
|
||||
$seenDealIds[] = $event['deal_id'];
|
||||
}
|
||||
|
||||
if ($i > 0) {
|
||||
echo ',{';
|
||||
$dealEvents[$did][] = $event;
|
||||
} else {
|
||||
echo '{';
|
||||
}
|
||||
// Не сделки — выводим сразу
|
||||
if ($i > 0) { echo ',{'; } else { echo '{'; }
|
||||
$fio = '';
|
||||
if($event['client_id'] > 0){
|
||||
$sql_cl = "SELECT fio from clients WHERE id=$event[client_id]";
|
||||
@ -226,28 +222,11 @@ if ($_SESSION['id']) {
|
||||
$fio = str_replace("\\","/", mysql_fetch_assoc($q_cl)['fio']);
|
||||
} else if($event['req_id'] > 0) {
|
||||
$sql_cl = "SELECT name from requisitions WHERE id=$event[req_id]";
|
||||
|
||||
$q_cl = mysql_query($sql_cl);
|
||||
$fio = mysql_fetch_assoc($q_cl)['name'];
|
||||
}
|
||||
|
||||
// Для сделок подтягиваем название сделки
|
||||
if ($event['type'] == 'deal' && !empty($event['deal_id'])) {
|
||||
if (!isset($deals[$event['deal_id']])) {
|
||||
$q_deal = mysql_query("SELECT title FROM deals WHERE id = " . intval($event['deal_id']) . " LIMIT 1");
|
||||
if ($q_deal && mysql_num_rows($q_deal) > 0) {
|
||||
$deals[$event['deal_id']] = mysql_fetch_assoc($q_deal)['title'];
|
||||
} else {
|
||||
$deals[$event['deal_id']] = '';
|
||||
}
|
||||
}
|
||||
$fio = $deals[$event['deal_id']] ?: $fio;
|
||||
}
|
||||
|
||||
$fio = str_replace('"', "'", $fio);
|
||||
$fio = str_replace('"', "'", $fio);
|
||||
|
||||
//$fio = $event['fio'];
|
||||
echo '"id" : "'.$i.'", ';
|
||||
echo '"table_id" : "'.$event['id'].'", ';
|
||||
echo '"start" : "'.date(DateTime::ATOM, strtotime($event['schedule_date'])).'", ';
|
||||
@ -259,67 +238,121 @@ if ($_SESSION['id']) {
|
||||
}
|
||||
echo '"client_id" : "'.$event['client_id'].'",';
|
||||
echo '"req_id" : "'.$event['req_id'].'",';
|
||||
|
||||
if ($event['type'] == 'comment') {
|
||||
|
||||
$className = "comment";
|
||||
if ($event['calendar_view'] != 0) {
|
||||
$className .= " viewed";
|
||||
}
|
||||
|
||||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||||
echo '"title": "Комментарий '.$fio.'","className" : "'.$className.'"';
|
||||
}
|
||||
|
||||
if ($event['type'] == 'call') {
|
||||
|
||||
$className = "call";
|
||||
if ($event['calendar_view'] != 0) {
|
||||
$className .= " viewed";
|
||||
}
|
||||
|
||||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||||
echo '"title": "Звонок '.$fio.'","className" : "'.$className.'"';
|
||||
}
|
||||
|
||||
if ($event['type'] == 'meet') {
|
||||
|
||||
$className = "meet";
|
||||
if ($event['calendar_view'] != 0) {
|
||||
$className .= " viewed";
|
||||
}
|
||||
|
||||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||||
echo '"title": "Встреча '.$fio.'","className" : "'.$className.'"';
|
||||
}
|
||||
|
||||
if ($event['type'] == 'show') {
|
||||
|
||||
$className = "showing";
|
||||
if ($event['calendar_view'] != 0) {
|
||||
$className .= " viewed";
|
||||
}
|
||||
|
||||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||||
echo '"title": "Показ '.$fio.'","className" : "'.$className.'"';
|
||||
}
|
||||
|
||||
if ($event['type'] == 'deal') {
|
||||
|
||||
$className = "deal";
|
||||
if ($event['calendar_view'] != 0) {
|
||||
$className .= " viewed";
|
||||
}
|
||||
|
||||
echo '"title": "Сделка '.$fio.'","className" : "'.$className.'"';
|
||||
}
|
||||
|
||||
if ($event['type'] == 'even') {
|
||||
|
||||
$className = "even";
|
||||
if ($event['calendar_view'] != 0) {
|
||||
$className .= " viewed";
|
||||
}
|
||||
|
||||
if ($event['calendar_view'] != 0) { $className .= " viewed"; }
|
||||
echo '"title": "'.$event['name'].' '.$fio.'","className" : "'.$className.'"';
|
||||
}
|
||||
echo "}";
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
|
||||
// Выводим по одному событию на сделку с приоритетом
|
||||
foreach ($dealEvents as $did => $events) {
|
||||
// Подтягиваем данные сделки
|
||||
if (!isset($deals[$did])) {
|
||||
$q_deal = mysql_query("SELECT title, side_one_requisition_id, side_two_requisition_id FROM deals WHERE id = " . $did . " LIMIT 1");
|
||||
$deals[$did] = ($q_deal && mysql_num_rows($q_deal) > 0) ? mysql_fetch_assoc($q_deal) : null;
|
||||
}
|
||||
$deal = $deals[$did];
|
||||
$dealTitle = $deal ? $deal['title'] : '';
|
||||
$sideOneReqId = $deal ? (int)$deal['side_one_requisition_id'] : 0;
|
||||
$sideTwoReqId = $deal ? (int)$deal['side_two_requisition_id'] : 0;
|
||||
|
||||
// Приоритет: 1) заявка стороны 1, 2) заявка стороны 2, 3) объект
|
||||
$bestEvent = null;
|
||||
$bestType = '';
|
||||
|
||||
// 1. Ищем событие с req_id == side_one_requisition_id
|
||||
foreach ($events as $ev) {
|
||||
if ($sideOneReqId > 0 && (int)$ev['req_id'] == $sideOneReqId) {
|
||||
$bestEvent = $ev;
|
||||
$bestType = 'req_one';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Ищем событие с req_id == side_two_requisition_id
|
||||
if (!$bestEvent) {
|
||||
foreach ($events as $ev) {
|
||||
if ($sideTwoReqId > 0 && (int)$ev['req_id'] == $sideTwoReqId) {
|
||||
$bestEvent = $ev;
|
||||
$bestType = 'req_two';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Ищем событие с client_id > 0
|
||||
if (!$bestEvent) {
|
||||
foreach ($events as $ev) {
|
||||
if (!empty($ev['client_id'])) {
|
||||
$bestEvent = $ev;
|
||||
$bestType = 'client';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Ищем событие с req_id > 0
|
||||
if (!$bestEvent) {
|
||||
foreach ($events as $ev) {
|
||||
if (!empty($ev['req_id'])) {
|
||||
$bestEvent = $ev;
|
||||
$bestType = 'req';
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 5. Берём любое
|
||||
if (!$bestEvent) {
|
||||
$bestEvent = $events[0];
|
||||
$bestType = 'any';
|
||||
}
|
||||
|
||||
if ($i > 0) { echo ',{'; } else { echo '{'; }
|
||||
echo '"id" : "'.$i.'", ';
|
||||
echo '"table_id" : "'.$bestEvent['id'].'", ';
|
||||
echo '"start" : "'.date(DateTime::ATOM, strtotime($bestEvent['schedule_date'])).'", ';
|
||||
|
||||
// Для клика: передаём client_id или req_id (без object_id)
|
||||
if (!empty($bestEvent['client_id'])) {
|
||||
echo '"client_id" : "'.$bestEvent['client_id'].'",';
|
||||
echo '"req_id" : "0",';
|
||||
} else if (!empty($bestEvent['req_id'])) {
|
||||
echo '"client_id" : "0",';
|
||||
echo '"req_id" : "'.$bestEvent['req_id'].'",';
|
||||
} else {
|
||||
echo '"client_id" : "0",';
|
||||
echo '"req_id" : "0",';
|
||||
}
|
||||
|
||||
$className = "deal";
|
||||
if ($bestEvent['calendar_view'] != 0) { $className .= " viewed"; }
|
||||
|
||||
echo '"title": "'.str_replace('"', "'", $dealTitle).'","className" : "'.$className.'"';
|
||||
echo "}";
|
||||
$i++;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user