Exemplo n.º 1
0
 private static function PrepareUpdateEvent($fieldName, $arNewRow, $arOldRow, &$arEvents)
 {
     $fieldName = strtoupper(strval($fieldName));
     if ($fieldName === '') {
         return false;
     }
     $typeID = isset($arNewRow['TYPE_ID']) ? intval($arNewRow['TYPE_ID']) : CCrmActivityType::Undefined;
     $changed = false;
     $oldText = $newText = '';
     if ($fieldName === 'NOTIFY') {
         $oldType = isset($arOldRow['NOTIFY_TYPE']) ? intval($arOldRow['NOTIFY_TYPE']) : CCrmActivityNotifyType::None;
         $newType = isset($arNewRow['NOTIFY_TYPE']) ? intval($arNewRow['NOTIFY_TYPE']) : CCrmActivityNotifyType::None;
         $oldVal = isset($arOldRow['NOTIFY_VALUE']) ? intval($arOldRow['NOTIFY_VALUE']) : 0;
         $newVal = isset($arNewRow['NOTIFY_VALUE']) ? intval($arNewRow['NOTIFY_VALUE']) : 0;
         if ($oldType !== $newType || $oldVal !== $newVal) {
             $changed = true;
             $oldText = $oldType === CCrmActivityNotifyType::None ? CCrmActivityNotifyType::ResolveDescription(CCrmActivityNotifyType::None) : strval($oldVal) . ' ' . CCrmActivityNotifyType::ResolveDescription($oldType);
             $newText = $newType === CCrmActivityNotifyType::None ? CCrmActivityNotifyType::ResolveDescription(CCrmActivityNotifyType::None) : strval($newVal) . ' ' . CCrmActivityNotifyType::ResolveDescription($newType);
         }
     } else {
         $old = isset($arOldRow[$fieldName]) ? strval($arOldRow[$fieldName]) : '';
         $new = isset($arNewRow[$fieldName]) ? strval($arNewRow[$fieldName]) : '';
         if (strcmp($old, $new) !== 0) {
             $changed = true;
             $oldText = $old;
             $newText = $new;
             if ($fieldName === 'COMPLETED') {
                 $oldText = CCrmActivityStatus::ResolveDescription($old === 'Y' ? CCrmActivityStatus::Completed : CCrmActivityStatus::Waiting, isset($arOldRow['TYPE_ID']) ? intval($arOldRow['TYPE_ID']) : CCrmActivityType::Undefined);
                 $newText = CCrmActivityStatus::ResolveDescription($new === 'Y' ? CCrmActivityStatus::Completed : CCrmActivityStatus::Waiting, isset($arNewRow['TYPE_ID']) ? intval($arNewRow['TYPE_ID']) : CCrmActivityType::Undefined);
             } elseif ($fieldName === 'PRIORITY') {
                 $oldText = CCrmActivityPriority::ResolveDescription($old);
                 $newText = CCrmActivityPriority::ResolveDescription($new);
             } elseif ($fieldName === 'DIRECTION') {
                 $oldText = CCrmActivityDirection::ResolveDescription($old, $typeID);
                 $newText = CCrmActivityDirection::ResolveDescription($new, $typeID);
             } elseif ($fieldName === 'RESPONSIBLE_ID') {
                 $oldID = intval($old);
                 $arOldUser = array();
                 $newID = intval($new);
                 $arNewUser = array();
                 $dbUser = CUser::GetList($by = 'id', $order = 'asc', array('ID' => "{$oldID}|{$newID}"), array('FIELDS' => array('ID', 'LOGIN', 'EMAIL', 'NAME', 'LAST_NAME', 'SECOND_NAME')));
                 while (is_array($arUser = $dbUser->Fetch())) {
                     $userID = intval($arUser['ID']);
                     if ($userID === $oldID) {
                         $arOldUser = $arUser;
                     } elseif ($userID === $newID) {
                         $arNewUser = $arUser;
                     }
                 }
                 $template = CSite::GetNameFormat(false);
                 $oldText = CUser::FormatName($template, $arOldUser);
                 $newText = CUser::FormatName($template, $arNewUser);
             }
         }
     }
     if ($changed) {
         $typeName = self::ResolveEventTypeName($typeID);
         $name = isset($arNewRow['SUBJECT']) ? strval($arNewRow['SUBJECT']) : '';
         if ($name === '') {
             $name = "[{$arNewRow['ID']}]";
         }
         $arEvents[] = array('EVENT_NAME' => GetMessage("CRM_ACTIVITY_CHANGE_{$typeName}_{$fieldName}", array('#NAME#' => $name)), 'EVENT_TEXT_1' => $oldText !== '' ? $oldText : GetMessage('CRM_ACTIVITY_FIELD_COMPARE_EMPTY'), 'EVENT_TEXT_2' => $newText !== '' ? $newText : GetMessage('CRM_ACTIVITY_FIELD_COMPARE_EMPTY'), 'USER_ID' => isset($arNewRow['EDITOR_ID']) ? $arNewRow['EDITOR_ID'] : 0);
     }
     return $changed;
 }