protected function parseParams() { $this->arParams['PATH_TO_PRODUCT_LIST'] = CrmCheckPath('PATH_TO_PRODUCT_LIST', $this->arParams['PATH_TO_PRODUCT_LIST'], $this->getApp()->GetCurPage() . '?section_id=#section_id#'); // prepare URI template $matches = array(); $curParam = $this->getApp()->GetCurParam(); $curParam = preg_replace('/(?<!\\w)list_section_id=\\d*(?=([^\\d]|$))/', 'list_section_id=#section_id#', $curParam); $curParam = preg_replace('/(^|&)tree=\\w*(?=(&|$))/', '', $curParam); $this->arParams['PAGE_URI_TEMPLATE'] = $this->arParams['PATH_TO_PRODUCT_LIST'] . (strlen($curParam) > 0 ? '?' . $curParam . '&tree=Y' : '?tree=Y'); unset($curParam); // Catalog ID if (isset($this->arParams['CATALOG_ID'])) { $this->catalogId = intval($this->arParams['CATALOG_ID']); } if ($this->catalogId <= 0) { $this->catalogId = CCrmCatalog::GetDefaultID(); } // Section ID if (isset($this->arParams['SECTION_ID'])) { $this->sectionId = intval($this->arParams['SECTION_ID']); } if ($this->sectionId < 0) { $this->sectionId = 0; } // JS events mode if (isset($this->arParams['JS_EVENTS_MODE']) && $this->arParams['JS_EVENTS_MODE'] === 'Y') { $this->jsEventsMode = true; } // JS events manager $this->jsEventsManagerId = isset($this->arParams['JS_EVENTS_MANAGER_ID']) ? strval($this->arParams['JS_EVENTS_MANAGER_ID']) : ''; return true; }
public static function formatResultValue($k, &$v, &$row, &$cInfo, $total, &$customChartValue = null) { // HACK: detect if 'report.view' component is rendering excel spreadsheet $isHtml = !(isset($_GET['EXCEL']) && $_GET['EXCEL'] === 'Y'); $field = $cInfo['field']; $fieldName = isset($cInfo['fieldName']) ? $cInfo['fieldName'] : $field->GetName(); $prcnt = isset($cInfo['prcnt']) ? $cInfo['prcnt'] : ''; if (!isset($prcnt[0]) && ($fieldName === 'DEAL_OWNER.OPPORTUNITY' || $fieldName === 'DEAL_OWNER.OPPORTUNITY_ACCOUNT' || $fieldName === 'DEAL_OWNER.RECEIVED_AMOUNT' || $fieldName === 'DEAL_OWNER.LOST_AMOUNT' || $fieldName === 'SUM_ACCOUNT' || $fieldName === 'PRICE_ACCOUNT' || $fieldName === 'DEAL_OWNER.COMPANY_BY.REVENUE')) { // unformatted value for charts $customChartValue['exist'] = true; $customChartValue['type'] = 'float'; $customChartValue['value'] = doubleval($v); $v = self::MoneyToString(doubleval($v)); } elseif ($fieldName === 'DEAL_OWNER.TITLE') { if ($isHtml && strlen($v) > 0 && self::$CURRENT_RESULT_ROW && isset(self::$CURRENT_RESULT_ROW['ID'])) { $v = self::prepareDealTitleHtml(self::$CURRENT_RESULT_ROW['ID'], $v); } } elseif ($fieldName === 'DEAL_OWNER.STAGE_ID') { if ($v !== '') { $v = self::getDealStageName($v, $isHtml); } } elseif ($fieldName === 'DEAL_OWNER.TYPE_ID') { if ($v !== '') { $v = self::getDealTypeName($v, $isHtml); } } elseif ($fieldName === 'DEAL_OWNER.CURRENCY_ID' || $fieldName === 'DEAL_OWNER.COMPANY_BY.CURRENCY_ID') { if ($v !== '') { $v = self::getCurrencyName($v, $isHtml); } } elseif ($fieldName === 'DEAL_OWNER.EVENT_ID') { if ($v !== '') { $v = self::getEventTypeName($v, $isHtml); } } elseif ($fieldName === 'DEAL_OWNER.ORIGINATOR_BY.ID') { $v = self::getDealOriginatorName($v, $isHtml); } elseif ($fieldName === 'DEAL_OWNER.CONTACT_BY.SOURCE_BY.STATUS_ID') { if ($v !== '') { $v = self::getStatusName($v, 'SOURCE', $isHtml); } } elseif (strpos($fieldName, 'DEAL_OWNER.COMPANY_BY.') === 0) { if (strlen($v) === 0 || trim($v) === '.') { if (strpos($fieldName, 'DEAL_OWNER.COMPANY_BY.COMPANY_TYPE_BY') !== 0 && strpos($fieldName, 'DEAL_OWNER.COMPANY_BY.INDUSTRY_BY') !== 0 && strpos($fieldName, 'DEAL_OWNER.COMPANY_BY.EMPLOYEES_BY') !== 0) { $v = GetMessage('CRM_DEAL_COMPANY_NOT_ASSIGNED'); } } elseif ($fieldName === 'DEAL_OWNER.COMPANY_BY.TITLE') { if ($isHtml && self::$CURRENT_RESULT_ROW && isset(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_DEAL_OWNER_COMPANY_BY_ID'])) { $v = self::prepareCompanyTitleHtml(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_DEAL_OWNER_COMPANY_BY_ID'], $v); } } elseif ($fieldName === 'DEAL_OWNER.COMPANY_BY.COMPANY_TYPE_BY.STATUS_ID') { if ($v !== '') { $v = self::getStatusName($v, 'COMPANY_TYPE', $isHtml); } } elseif ($fieldName === 'DEAL_OWNER.COMPANY_BY.INDUSTRY_BY.STATUS_ID') { if ($v !== '') { $v = self::getStatusName($v, 'INDUSTRY', $isHtml); } } elseif ($fieldName === 'DEAL_OWNER.COMPANY_BY.EMPLOYEES_BY.STATUS_ID') { if ($v !== '') { $v = self::getStatusName($v, 'EMPLOYEES', $isHtml); } } } elseif (strpos($fieldName, 'DEAL_OWNER.CONTACT_BY.') === 0) { if ($v === '' || trim($v) === '.') { if (strpos($fieldName, 'DEAL_OWNER.CONTACT_BY.TYPE_BY') !== 0) { $v = GetMessage('CRM_DEAL_CONTACT_NOT_ASSIGNED'); } } elseif ($fieldName === 'DEAL_OWNER.CONTACT_BY.TYPE_BY.STATUS_ID') { if ($v !== '') { $v = self::getStatusName($v, 'CONTACT_TYPE', $isHtml); } } elseif ($fieldName === 'DEAL_OWNER.CONTACT_BY.NAME' || $fieldName === 'DEAL_OWNER.CONTACT_BY.LAST_NAME' || $fieldName === 'DEAL_OWNER.CONTACT_BY.SECOND_NAME' || $fieldName === 'DEAL_OWNER.CONTACT_BY.ADDRESS') { if ($isHtml && self::$CURRENT_RESULT_ROW && isset(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_DEAL_OWNER_CONTACT_BY_ID'])) { $v = self::prepareContactTitleHtml(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_DEAL_OWNER_CONTACT_BY_ID'], $v); } } } elseif (strpos($fieldName, 'DEAL_OWNER.ASSIGNED_BY.') === 0) { // unset HREF for empty value if (empty($v) || trim($v) === '.' || $v === ' ') { unset($row['__HREF_' . $k]); } if (strlen($v) === 0 || trim($v) === '.') { $v = GetMessage('CRM_DEAL_RESPONSIBLE_NOT_ASSIGNED'); } elseif ($isHtml) { $v = htmlspecialcharsbx($v); } } elseif (strpos($fieldName, 'IBLOCK_ELEMENT.') === 0) { static $defaultCatalogID; if (!isset($defaultCatalogID)) { $defaultCatalogID = CCrmCatalog::GetDefaultID(); } if ($isHtml) { if ($defaultCatalogID > 0 && self::$CURRENT_RESULT_ROW) { $iblockID = isset(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_IBLOCK_ID']) ? intval(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_IBLOCK_ID']) : 0; $iblockElementID = isset(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_ID']) ? intval(self::$CURRENT_RESULT_ROW['CRM_PRODUCT_ROW_IBLOCK_ELEMENT_ID']) : 0; } else { $iblockID = 0; $iblockElementID = 0; } if ($iblockElementID > 0 && $iblockID === $defaultCatalogID) { $v = self::prepareProductNameHtml($iblockElementID, $v); } else { $v = htmlspecialcharsbx($v); } } } else { parent::formatResultValue($k, $v, $row, $cInfo, $total); } }
public static function GetByOriginID($originID, $catalogID = 0) { $catalogID = intval($catalogID); if ($catalogID <= 0) { $catalogID = CCrmCatalog::GetDefaultID(); } if ($catalogID <= 0) { return false; } $dbRes = CCrmProduct::GetList(array(), array('CATALOG_ID' => $catalogID, 'ORIGIN_ID' => $originID), array('*'), array('nTopCount' => 1)); return $dbRes->GetNext(); }
public static function processEvent(array $arParams, array $arHandler) { $eventName = $arHandler['EVENT_NAME']; switch (strtolower($eventName)) { case 'oncrmproductadd': case 'oncrmproductupdate': $ID = isset($arParams[0]) ? (int) $arParams[0] : 0; if ($ID <= 0) { throw new RestException("Could not find entity ID in fields of event \"{$eventName}\""); } $fields = CCrmProduct::GetByID($ID); $catalogID = is_array($fields) && isset($fields['CATALOG_ID']) ? (int) $fields['CATALOG_ID'] : 0; if ($catalogID !== CCrmCatalog::GetDefaultID()) { throw new RestException("Outside CRM product event is detected"); } return array('FIELDS' => array('ID' => $ID)); break; case 'oncrmproductdelete': $fields = isset($arParams[0]) && is_array($arParams[0]) ? $arParams[0] : array(); $ID = isset($fields['ID']) ? (int) $fields['ID'] : 0; if ($ID <= 0) { throw new RestException("Could not find entity ID in fields of event \"{$eventName}\""); } $catalogID = isset($fields['IBLOCK_ID']) ? (int) $fields['IBLOCK_ID'] : 0; if ($catalogID !== CCrmCatalog::GetDefaultID()) { throw new RestException("Outside CRM product event is detected"); } return array('FIELDS' => array('ID' => $ID)); break; default: throw new RestException("The Event \"{$eventName}\" is not supported in current context"); } }