コード例 #1
14
 private static function loadBulk($entityTypeID, array &$entityIDs, array &$itemMap, array $options = null)
 {
     /** @var DuplicateEntityRanking[] $itemMap */
     if ($entityTypeID !== \CCrmOwnerType::Contact && $entityTypeID !== \CCrmOwnerType::Company && $entityTypeID !== \CCrmOwnerType::Lead) {
         return;
     }
     if (!is_array($options)) {
         $options = array();
     }
     $checkPermissions = isset($options['CHECK_PERMISSIONS']) ? (bool) $options['CHECK_PERMISSIONS'] : false;
     $userID = isset($options['USER_ID']) ? (int) $options['USER_ID'] : 0;
     $permissions = $checkPermissions ? \CCrmPerms::GetUserPermissions($userID) : null;
     $limit = isset($options['LIMIT']) ? (int) $options['LIMIT'] : 3000;
     if ($limit <= 0) {
         $limit = 3000;
     }
     $length = count($entityIDs);
     if ($length === 0) {
         return;
     }
     while ($length > 0) {
         if ($length <= $limit) {
             $ids = $entityIDs;
             unset($entityIDs);
             $entityIDs = array();
         } else {
             $ids = array_splice($entityIDs, 0, $limit);
         }
         $length = count($entityIDs);
         if (empty($ids)) {
             continue;
         }
         if ($entityTypeID === \CCrmOwnerType::Lead) {
             $dbResult = Entity\DuplicateEntityStatisticsTable::getList(array('select' => array('ENTITY_ID', 'RANKING_DATA'), 'filter' => array('ENTITY_TYPE_ID' => \CCrmOwnerType::Lead, 'ENTITY_ID' => $ids)));
             while ($fields = $dbResult->fetch()) {
                 $entityID = intval($fields['ENTITY_ID']);
                 $key = "{$entityTypeID}_{$entityID}";
                 if (!isset($itemMap[$key])) {
                     continue;
                 }
                 if (isset($fields['RANKING_DATA']) && $fields['RANKING_DATA'] !== '') {
                     $data = unserialize($fields['RANKING_DATA']);
                     /** @var DuplicateEntityRanking $ranking */
                     $ranking = $itemMap[$key];
                     $ranking->lastChanged = isset($data['LAST_CHANGED']) ? $data['LAST_CHANGED'] : 0;
                     $ranking->completeness = isset($data['COMPLETENESS']) ? $data['COMPLETENESS'] : 0;
                     if ($checkPermissions) {
                         $ranking->editable = \CCrmLead::CheckUpdatePermission($entityID, $permissions);
                         $ranking->deleteable = \CCrmLead::CheckDeletePermission($entityID, $permissions);
                     }
                 }
             }
         } else {
             $query = new Main\Entity\Query(Entity\DuplicateEntityStatisticsTable::getEntity());
             $query->addSelect('ENTITY_ID');
             $query->addSelect('RANKING_DATA');
             $query->addFilter('ENTITY_ID', $ids);
             $query->addFilter('ENTITY_TYPE_ID', $entityTypeID);
             if ($entityTypeID === \CCrmOwnerType::Contact) {
                 $subQuery = new Main\Entity\Query(DealTable::getEntity());
                 $subQuery->addSelect('CONTACT_ID');
                 $subQuery->addFilter('CONTACT_ID', $ids);
                 $subQuery->addSelect('QTY');
                 $subQuery->registerRuntimeField('', new Main\Entity\ExpressionField('QTY', 'COUNT(*)'));
                 $referenceField = new Main\Entity\ReferenceField('D', Main\Entity\Base::getInstanceByQuery($subQuery), array('=this.ENTITY_ID' => 'ref.CONTACT_ID'), array('join_type' => 'LEFT'));
             } else {
                 $subQuery = new Main\Entity\Query(DealTable::getEntity());
                 $subQuery->addSelect('COMPANY_ID');
                 $subQuery->addFilter('COMPANY_ID', $ids);
                 $subQuery->addSelect('QTY');
                 $subQuery->registerRuntimeField('', new Main\Entity\ExpressionField('QTY', 'COUNT(*)'));
                 $referenceField = new Main\Entity\ReferenceField('D', Main\Entity\Base::getInstanceByQuery($subQuery), array('=this.ENTITY_ID' => 'ref.COMPANY_ID'), array('join_type' => 'LEFT'));
             }
             $query->registerRuntimeField('', $referenceField);
             $query->addSelect('D.QTY', 'QTY');
             $dbResult = $query->exec();
             while ($fields = $dbResult->fetch()) {
                 $entityID = intval($fields['ENTITY_ID']);
                 $key = "{$entityTypeID}_{$entityID}";
                 if (!isset($itemMap[$key])) {
                     continue;
                 }
                 $itemMap[$key]->referenceCount = isset($fields['QTY']) ? intval($fields['QTY']) : 0;
                 if (isset($fields['RANKING_DATA']) && $fields['RANKING_DATA'] !== '') {
                     $data = unserialize($fields['RANKING_DATA']);
                     /** @var DuplicateEntityRanking $ranking */
                     $ranking = $itemMap[$key];
                     $ranking->lastChanged = isset($data['LAST_CHANGED']) ? $data['LAST_CHANGED'] : 0;
                     $ranking->completeness = isset($data['COMPLETENESS']) ? $data['COMPLETENESS'] : 0;
                     if ($checkPermissions) {
                         if ($entityTypeID === \CCrmOwnerType::Contact) {
                             $ranking->editable = \CCrmContact::CheckUpdatePermission($entityID, $permissions);
                             $ranking->deleteable = \CCrmContact::CheckDeletePermission($entityID, $permissions);
                         } else {
                             $ranking->editable = \CCrmCompany::CheckUpdatePermission($entityID, $permissions);
                             $ranking->deleteable = \CCrmCompany::CheckDeletePermission($entityID, $permissions);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: component.php プロジェクト: mrdeadmouse/u136006
    $contextID = $_REQUEST['context_id'];
}
if ($contextID === '') {
    $contextID = "{$uid}_{$entityID}";
}
$arResult['CONTEXT_ID'] = $arParams['CONTEXT_ID'] = $contextID;
//<-- CONTEXT_ID
$serviceURLTemplate = $arParams["SERVICE_URL_TEMPLATE"] ? $arParams["SERVICE_URL_TEMPLATE"] : '#SITE_DIR#bitrix/components/bitrix/mobile.crm.lead.edit/ajax.php?site_id=#SITE#&sessid=#SID#';
$arResult['SERVICE_URL'] = CComponentEngine::makePathFromTemplate($serviceURLTemplate, array('SID' => bitrix_sessid()));
$dbFields = CCrmLead::GetListEx(array(), array('ID' => $entityID));
$arFields = $dbFields->GetNext();
if (!$arFields) {
    ShowError(GetMessage('CRM_LEAD_VIEW_NOT_FOUND', array('#ID#' => $arParams['ENTITY_ID'])));
    return;
}
$arResult['PERMISSIONS'] = array('EDIT' => CCrmLead::CheckUpdatePermission($entityID, $userPerms) && $arFields['STATUS_ID'] !== 'CONVERTED', 'DELETE' => CCrmLead::CheckDeletePermission($entityID, $userPerms));
$arResult['STATUS_LIST'] = CCrmStatus::GetStatusList('STATUS');
$arResult['SOURCE_LIST'] = CCrmStatus::GetStatusList('SOURCE');
$arResult['CURRENCY_LIST'] = CCrmCurrencyHelper::PrepareListItems();
CCrmMobileHelper::PrepareLeadItem($arFields, $arParams, array('STATUS_LIST' => $arResult['STATUS_LIST'], 'SOURCE_LIST' => $arResult['SOURCE_LIST']));
$arFields['FM'] = array();
$dbMultiFields = CCrmFieldMulti::GetList(array('ID' => 'asc'), array('ENTITY_ID' => 'LEAD', 'ELEMENT_ID' => $entityID));
if ($dbMultiFields) {
    while ($multiFields = $dbMultiFields->Fetch()) {
        $arFields['FM'][$multiFields['TYPE_ID']][] = array('VALUE' => $multiFields['VALUE'], 'VALUE_TYPE' => $multiFields['VALUE_TYPE']);
    }
}
$arResult['CALLTO'] = CCrmMobileHelper::PrepareCalltoParams(array('COMMUNICATION_LIST_URL_TEMPLATE' => $arParams['COMMUNICATION_LIST_URL_TEMPLATE'], 'ENTITY_TYPE_ID' => CCrmOwnerType::Lead, 'ENTITY_ID' => $entityID, 'FM' => $arFields['FM']));
$arResult['MAILTO'] = CCrmMobileHelper::PrepareMailtoParams(array('COMMUNICATION_LIST_URL_TEMPLATE' => $arParams['COMMUNICATION_LIST_URL_TEMPLATE'], 'ENTITY_TYPE_ID' => CCrmOwnerType::Lead, 'ENTITY_ID' => $entityID, 'FM' => $arFields['FM']));
$arFields['PRODUCT_ROWS_QUANTITY'] = CAllCrmProductRow::GetRowQuantity(CCrmOwnerTypeAbbr::ResolveByTypeID(CCrmOwnerType::Lead), $entityID);
$arFields['PRODUCT_ROWS_URL'] = $arParams['PRODUCT_ROW_LIST_URL_TEMPLATE'] !== '' ? CComponentEngine::MakePathFromTemplate($arParams['PRODUCT_ROW_LIST_URL_TEMPLATE'], array('entity_type_id' => CCrmOwnerType::Lead, 'entity_id' => $entityID)) : '';
コード例 #3
0
ファイル: ajax.php プロジェクト: mrdeadmouse/u136006
        } else {
            //$DB->Rollback();
            __CrmMobileLeadEditEndResonse(array('ERROR' => strip_tags(preg_replace("/<br[^>]*>/", "\n", $fields['RESULT_MESSAGE']))));
        }
    }
} elseif ($action === 'DELETE_ENTITY') {
    __IncludeLang(dirname(__FILE__) . '/lang/' . LANGUAGE_ID . '/' . basename(__FILE__));
    $typeName = isset($_REQUEST['ENTITY_TYPE_NAME']) ? $_REQUEST['ENTITY_TYPE_NAME'] : '';
    if ($typeName !== CCrmOwnerType::LeadName) {
        __CrmMobileLeadEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_TYPE_NOT_SUPPORTED', array('#ENTITY_TYPE#' => $typeName))));
    }
    $ID = isset($_REQUEST['ENTITY_ID']) ? intval($_REQUEST['ENTITY_ID']) : 0;
    if ($ID <= 0) {
        __CrmMobileLeadEditEndResonse(array('ERROR' => GetMessage('CRM_ENTITY_ID_NOT_FOUND')));
    }
    if (!CCrmLead::CheckDeletePermission($ID)) {
        __CrmMobileLeadEditEndResonse(array('ERROR' => GetMessage('CRM_ACCESS_DENIED')));
    }
    $entity = new CCrmLead(false);
    //$DB->StartTransaction();
    $successed = $entity->Delete($ID);
    if ($successed) {
        //$DB->Commit();
        __CrmMobileLeadEditEndResonse(array('DELETED_ENTITY_ID' => $ID));
    } else {
        //$DB->Rollback();
        __CrmMobileLeadEditEndResonse(array('ERROR' => GetMessage('CRM_LEAD_COULD_NOT_DELETE')));
    }
} elseif ($action === 'GET_ENTITY') {
    __IncludeLang(dirname(__FILE__) . '/lang/' . LANGUAGE_ID . '/' . basename(__FILE__));
    $typeName = isset($_REQUEST['ENTITY_TYPE_NAME']) ? $_REQUEST['ENTITY_TYPE_NAME'] : '';
コード例 #4
0
ファイル: leadmerger.php プロジェクト: DarneoStudio/bitrix
 protected function checkEntityDeletePermission($entityID, $userPermissions)
 {
     return \CCrmLead::CheckDeletePermission($entityID, $userPermissions);
 }
コード例 #5
0
ファイル: component.php プロジェクト: mrdeadmouse/u136006
            } elseif (isset($_POST['saveAndAdd'])) {
                LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_EDIT'], array('lead_id' => 0)));
            } elseif (isset($_POST['saveAndView'])) {
                if (CCrmLead::CheckReadPermission($ID)) {
                    LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_SHOW'], array('lead_id' => $ID)));
                }
            }
            // save
            LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_LIST'], array()));
        }
    }
} else {
    if (isset($_GET['delete']) && check_bitrix_sessid()) {
        if ($bEdit) {
            $arResult['ERROR_MESSAGE'] = '';
            if (!CCrmLead::CheckDeletePermission($arParams['ELEMENT_ID'], $userPermissions)) {
                $arResult['ERROR_MESSAGE'] .= GetMessage('CRM_PERMISSION_DENIED') . '<br />';
            }
            $bDeleteError = !$CCrmBizProc->Delete($arResult['ELEMENT']['ID'], $arEntityAttr[$arParams['ELEMENT_ID']]);
            if ($bDeleteError) {
                $arResult['ERROR_MESSAGE'] .= $CCrmBizProc->LAST_ERROR;
            }
            if ($arResult['ERROR_MESSAGE'] === '' && !$CCrmLead->Delete($arResult['ELEMENT']['ID'], array('CHECK_DEPENDENCIES' => true, 'PROCESS_BIZPROC' => false))) {
                $arResult['ERROR_MESSAGE'] = $CCrmLead->LAST_ERROR !== '' ? $CCrmLead->LAST_ERROR : GetMessage('CRM_DELETE_ERROR');
            }
        } else {
            $arResult['ERROR_MESSAGE'] = GetMessage('CRM_DELETE_ERROR');
        }
        if ($arResult['ERROR_MESSAGE'] === '') {
            LocalRedirect(CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_LIST']));
        } else {
コード例 #6
0
ファイル: restservice.php プロジェクト: mrdeadmouse/u136006
 protected function innerDelete($ID, &$errors)
 {
     if (!CCrmLead::CheckDeletePermission($ID)) {
         $errors[] = 'Access denied.';
         return false;
     }
     $entity = self::getEntity();
     $result = $entity->Delete($ID, array('CHECK_DEPENDENCIES' => true));
     if ($result !== true) {
         $errors[] = $entity->LAST_ERROR;
     }
     return $result;
 }
コード例 #7
0
ファイル: component.php プロジェクト: mrdeadmouse/u136006
if ($arParams['TYPE'] == 'list') {
    $bRead = !$CrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'READ');
    $bExport = !$CrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'EXPORT');
    $bImport = !$CrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'IMPORT');
    $bAdd = !$CrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'ADD');
    $bWrite = !$CrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'WRITE');
    $bDelete = false;
    $bDedupe = !$CrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'WRITE') && !$CrmPerms->HavePerm('LEAD', BX_CRM_PERM_NONE, 'DELETE');
} else {
    $bExport = false;
    $bImport = false;
    $bDedupe = false;
    $bRead = CCrmLead::CheckReadPermission($arParams['ELEMENT_ID'], $CrmPerms);
    $bAdd = CCrmLead::CheckCreatePermission($CrmPerms);
    $bWrite = CCrmLead::CheckUpdatePermission($arParams['ELEMENT_ID'], $CrmPerms);
    $bDelete = CCrmLead::CheckDeletePermission($arParams['ELEMENT_ID'], $CrmPerms);
}
if (!$bRead && !$bAdd && !$bWrite) {
    return false;
}
if ($arParams['TYPE'] === 'list') {
    if ($bAdd) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('LEAD_ADD'), 'TITLE' => GetMessage('LEAD_ADD_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_EDIT'], array('lead_id' => 0)), 'HIGHLIGHT' => true);
    }
    if ($bImport) {
        $arResult['BUTTONS'][] = array('TEXT' => GetMessage('LEAD_IMPORT'), 'TITLE' => GetMessage('LEAD_IMPORT_TITLE'), 'LINK' => CComponentEngine::MakePathFromTemplate($arParams['PATH_TO_LEAD_IMPORT'], array()), 'ICON' => 'btn-import');
    }
    if ($bExport) {
        $arResult['BUTTONS'][] = array('TITLE' => GetMessage('LEAD_EXPORT_CSV_TITLE'), 'TEXT' => GetMessage('LEAD_EXPORT_CSV'), 'LINK' => CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($APPLICATION->GetCurPage(), array()), array('type' => 'csv', 'ncc' => '1')), 'ICON' => 'btn-export');
        $arResult['BUTTONS'][] = array('TITLE' => GetMessage('LEAD_EXPORT_EXCEL_TITLE'), 'TEXT' => GetMessage('LEAD_EXPORT_EXCEL'), 'LINK' => CHTTP::urlAddParams(CComponentEngine::MakePathFromTemplate($APPLICATION->GetCurPage(), array()), array('type' => 'excel', 'ncc' => '1')), 'ICON' => 'btn-export');
    }