Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions local/components/otus/currency.rate/.description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
use Bitrix\Main\Localization\Loc;

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
die();
}
Loc::loadMessages(__FILE__);

$arComponentDescription = [
'NAME' => Loc::getMessage("OTUS_CURRENCY_RATE_COMPONENT_NAME"),
'DESCRIPTION' => Loc::getMessage("OTUS_CURRENCY_RATE_COMPONENT_DESCRIPTION"),
"SORT" => 20,
'PATH' => [
'ID' => 'otus',
'NAME' => 'otus',
'CHILD' => [
'ID' => 'otus.currency.rate',
'NAME' => Loc::getMessage("OTUS_CURRENCY_RATE_COMPONENT_NAME"),
],
],
];
36 changes: 36 additions & 0 deletions local/components/otus/currency.rate/.parameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

use Bitrix\Main\Loader;
use Bitrix\Currency\CurrencyTable;
use Bitrix\Main\Localization\Loc;

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();


Loader::includeModule('currency');

$result = CurrencyTable::getList([
'select' => ['CURRENCY'],
'order' => ['SORT' => 'ASC']
]);

$listCurrencies = [];

while ($currency = $result->fetch()) {

$listCurrencies[$currency['CURRENCY']] = $currency['CURRENCY'];

}


$arComponentParameters = array(

"PARAMETERS" => array(
"CURRENCY_CODE" => array(
"PARENT" => "BASE",
"NAME"=> Loc::getMessage("OTUS_CURRENCY_RATE_LIST"),
"TYPE" => "LIST",
"VALUES" => $listCurrencies,
),
)
);
41 changes: 41 additions & 0 deletions local/components/otus/currency.rate/class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

use Bitrix\Currency\CurrencyTable;
use Bitrix\Main\Localization\Loc;

if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED !== true) {
die();
}


Loc::loadMessages(__FILE__);

if (!\Bitrix\Main\Loader::includeModule('currency'))
{
ShowError(Loc::getMessage('OTUS_ERROR_NOT_INSTALLED_CURRENCY'));
return;
}

class OtusCurrencyComponent extends \CBitrixComponent
{
public function onPrepareComponentParams($params)
{
return $params;
}



public function executeComponent()
{

if($this->arParams['CURRENCY_CODE']){
$this->arResult['CURRENCY'] = CurrencyTable::getById($this->arParams['CURRENCY_CODE'])->fetch();
}
else {
$this->arResult['CURRENCY'] = false;
}


$this->includeComponentTemplate();
}
}
3 changes: 3 additions & 0 deletions local/components/otus/currency.rate/lang/ru/.description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php
$MESS["OTUS_CURRENCY_RATE_COMPONENT_NAME"] = 'Курс выбранной валюты';
$MESS["OTUS_CURRENCY_RATE_COMPONENT_DESCRIPTION"] = 'Выводит курс выбранной валюты';
2 changes: 2 additions & 0 deletions local/components/otus/currency.rate/lang/ru/.parameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS["OTUS_CURRENCY_RATE_LIST"] = 'Выберите валюту';
2 changes: 2 additions & 0 deletions local/components/otus/currency.rate/lang/ru/class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS["OTUS_ERROR_NOT_INSTALLED_CURRENCY"] = 'Модуль валюты не установлен';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
$MESS["OTUS_CURRENCY_CAPTION"] = 'Курс выбранной валюты';
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
use Bitrix\Main\Localization\Loc;

if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true)die();
/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
/** @global CDatabase $DB */
/** @var CBitrixComponentTemplate $this */
/** @var string $templateName */
/** @var string $templateFile */
/** @var string $templateFolder */
/** @var string $componentPath */
/** @var CBitrixComponent $component */
$this->setFrameMode(true);


if($arResult['CURRENCY']){?>
<div class="currency_rate">
<?=Loc::getMessage('OTUS_CURRENCY_CAPTION')?> <?=$arResult['CURRENCY']['CURRENCY']?> - <?=$arResult['CURRENCY']['AMOUNT']?>
</div>
<?php }
20 changes: 20 additions & 0 deletions otus/currencies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* @global \CMain $APPLICATION
*/

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Валюты");
?><?$APPLICATION->IncludeComponent(
"otus:currency.rate",
".default",
[
"CACHE_TIME" => "3600",
"CACHE_TYPE" => "A",
"CURRENCY_CODE" => "EUR",
"COMPONENT_TEMPLATE" => ".default"
],
false
);?>

<?require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");?>