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
12 changes: 12 additions & 0 deletions doctors/code.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* @global \CMain $APPLICATION
*/

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle('Врачи');
?>

232
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/footer.php");
14 changes: 14 additions & 0 deletions doctors/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
/**
* @global \CMain $APPLICATION
*/

require($_SERVER["DOCUMENT_ROOT"]."/bitrix/header.php");
$APPLICATION->SetTitle("Врачи");
?><?$APPLICATION->IncludeComponent(
"custom:doctors.manager",
"",
Array(

)
);?><br>
14 changes: 14 additions & 0 deletions local/components/custom/doctors.manager/.description.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();

$arComponentDescription = array(
'NAME' => 'Менеджер докторов',
'DESCRIPTION' => 'Комплексный компонент для управления докторами ',
'ICON' => '/images/icon.gif',
'CACHE_PATH' => 'Y',
'PATH' => array(
'ID' => 'custom',
'NAME' => 'Кастомные компоненты'
),
'COMPLEX' => 'Y'
);
45 changes: 45 additions & 0 deletions local/components/custom/doctors.manager/.parameters.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();

$arComponentParameters = array(
'PARAMETERS' => array(

'DETAIL_URL' => array(
'PARENT' => 'URL_TEMPLATES',
'NAME' => 'URL детальной страницы',
'TYPE' => 'STRING',
'DEFAULT' => 'index.php?ID=#ELEMENT_ID#'
),
'EDIT_URL' => array(
'PARENT' => 'URL_TEMPLATES',
'NAME' => 'URL редактирования',
'TYPE' => 'STRING',
'DEFAULT' => 'index.php?ID=#ELEMENT_ID#&action=edit'
),
'ADD_URL' => array(
'PARENT' => 'URL_TEMPLATES',
'NAME' => 'URL добавления',
'TYPE' => 'STRING',
'DEFAULT' => 'index.php?action=add'
),
'LIST_URL' => array(
'PARENT' => 'URL_TEMPLATES',
'NAME' => 'URL списка',
'TYPE' => 'STRING',
'DEFAULT' => 'index.php'
),
'ADD_PROC' => array(
'PARENT' => 'URL_TEMPLATES',
'NAME' => 'Добавление процедуры',
'TYPE' => 'STRING',
'DEFAULT' => 'index.php?action=proc_add'
),
'SET_TITLE' => array(
'PARENT' => 'ADDITIONAL_SETTINGS',
'NAME' => 'Устанавливать заголовок страницы',
'TYPE' => 'CHECKBOX',
'DEFAULT' => 'Y'
),
)
);
?>
234 changes: 234 additions & 0 deletions local/components/custom/doctors.manager/class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
<?php
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();

use Otus\Models\Lists\DoctorsPropertyValuesTable as DoctorsTable;
use Otus\Models\Lists\ProcsPropertyValuesTable as ProcsTable;
use Bitrix\Main\Loader;

class DoctorsManagerComponent extends CBitrixComponent
{
private $errors = array();
private $iblockFields = array();
private $properties = array();


public function onPrepareComponentParams($arParams)
{
return $arParams;
}

public function executeComponent()
{
try {
$this->checkModules();
$this->determineAction();
$this->includeComponentTemplate($this->arResult['TEMPLATE_PAGE']);
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$this->arResult['ERRORS'] = $this->errors;
//$this->includeComponentTemplate('error');
}
}

private function checkModules()
{
if (!Loader::IncludeModule("iblock")) {
throw new Exception('Модуль инфоблоков не установлен');
}
}

private function determineAction()
{
$action = $this->request->get('action');
$elementId = $this->request->get('ID');

switch ($action) {
case 'add':
$this->processAdd();
$templatePage = 'add';
break;
case 'add_proc':
$this->processAddProc();
$templatePage = 'proc_add';
break;
case 'edit':
$this->processEdit($elementId);
$templatePage = 'edit';
break;
case 'detail':
$this->processDetail($elementId);
$templatePage = 'detail';
break;
default:
$this->processList();
$templatePage = 'list';
break;
}

$this->arResult['TEMPLATE_PAGE'] = $templatePage;
}

private function processList()
{

$doctors = DoctorsTable::query()
->setSelect([
'NAME' => 'ELEMENT.NAME',
'LAST_NAME',
'MIDDLE_NAME',
'ID' => 'ELEMENT.ID'

])
->fetchCollection();

$this->arResult['ITEMS'] = [];

foreach ($doctors as $doctor) {

$this->arResult['ITEMS'][] = [
'ID' => $doctor->getElement()->getId(),
'NAME' => $doctor->getElement()->getName(),
'MIDDLE_NAME' => $doctor->getMiddleName(),
'LAST_NAME' => $doctor->getLastName(),
];

}


if ($this->arParams['SET_TITLE'] === 'Y') {
$GLOBALS['APPLICATION']->SetTitle('Список врачей');
}
}

protected function getDoctorById(int $elementId) : array
{
$doctor = DoctorsTable::query()
->setSelect([
'*',
'NAME' => 'ELEMENT.NAME',
'PROC_IDS',
'ID' => 'ELEMENT.ID'
])->where("ID", $elementId)
->fetch();

if (!$doctor) {
throw new Exception('Элемент не найден');
}

if($doctor['PROC_IDS']){
$doctor["PROCS"] = ProcsTable::query()
->setSelect(['NAME' => 'ELEMENT.NAME', 'ID' => 'ELEMENT.ID'])
->where("ELEMENT.ID", 'in', $doctor['PROC_IDS'])
->fetchAll();
}

return $doctor ?: [];
}

protected function getAllProcedures() : array
{
$procs = ProcsTable::query()
->setSelect(['NAME' => 'ELEMENT.NAME', 'ID' => 'ELEMENT.ID'])
->fetchAll();

return $procs ?: [];
}



private function processDetail($elementId)
{
if (!$elementId) {
throw new Exception('Не указан ID элемента');
}

$this->arResult = $this->getDoctorById($elementId);

if ($this->arParams['SET_TITLE'] === 'Y') {
$GLOBALS['APPLICATION']->SetTitle($this->arResult['NAME']);
}
}

private function processAdd()
{

if ($this->request->isPost() && check_bitrix_sessid()) {
//$this->saveElement();

$fields['NAME'] = $this->request->getPost('NAME');
$fields['MIDDLE_NAME'] = $this->request->getPost('MIDDLE_NAME');
$fields['LAST_NAME'] = $this->request->getPost('LAST_NAME');
$fields['PROC_IDS'] = $this->request->getPost('PROC_IDS');

if( DoctorsTable::add($fields)){
header('Location: /doctors');
exit();
} else echo "Произошла ошибка";

}

$this->arResult['ALL_PROCEDURES'] = $this->getAllProcedures();

if ($this->arParams['SET_TITLE'] === 'Y') {
$GLOBALS['APPLICATION']->SetTitle('Добавление доктора');
}
}

private function processAddProc()
{

if ($this->request->isPost() && check_bitrix_sessid()) {
//$this->saveElement();

$fields['NAME'] = $this->request->getPost('NAME');


if( ProcsTable::add($fields)){
header('Location: /doctors');
exit();
} else echo "Произошла ошибка";

}

if ($this->arParams['SET_TITLE'] === 'Y') {
$GLOBALS['APPLICATION']->SetTitle('Добавление процедуры');
}
}

private function processEdit($elementId)
{
if (!$elementId) {
throw new Exception('Не указан ID элемента');
}

$this->arResult = $this->getDoctorById($elementId);

$this->arResult['ALL_PROCEDURES'] = $this->getAllProcedures();


if ($this->request->isPost() && check_bitrix_sessid()) {

//echo "<pre>"; var_dump($this->request->getPostList()); echo "</pre>"; die();

\CIBlockElement::SetPropertyValues($elementId, DoctorsTable::IBLOCK_ID, $this->request->getPost('PROC_IDS'), "PROC_IDS");

$fields['NAME'] = $this->request->getPost('NAME');
$fields['MIDDLE_NAME'] = $this->request->getPost('MIDDLE_NAME');
$fields['LAST_NAME'] = $this->request->getPost('LAST_NAME');


if(DoctorsTable::update($elementId, $fields)){
header('Location: /doctors');
exit();
}

}

if ($this->arParams['SET_TITLE'] === 'Y') {
$GLOBALS['APPLICATION']->SetTitle('Редактирование: ' . $this->arResult['NAME']);
}
}



}
38 changes: 38 additions & 0 deletions local/components/custom/doctors.manager/templates/.default/add.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();

/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
?>

<form action="" method="POST" class="doctor-edit-form">
<div class="doctor-edit-form__actions">
<a href="/doctors/" class="doctor-detail__action">← Назад к списку</a>
</div>
<h2 class="doctor-edit-form__title"> Добавление врача</h2>
<div class="doctor-edit-form__content">
<?=bitrix_sessid_post()?>


<input class="doctor-edit-form__input-text" type="text" name="NAME" placeholder="Имя врача" value="">
<input class="doctor-edit-form__input-text" type="text" name="MIDDLE_NAME" placeholder="Отчество врача" value="">
<input class="doctor-edit-form__input-text" type="text" name="LAST_NAME" placeholder="Фамилия врача" value="">

<select class="doctor-edit-form__select" multiple name="PROC_IDS[]">
<option value="" selected disabled>Процедуры</option>

<?php foreach($arResult['ALL_PROCEDURES'] as $proc):?>

<option value="<?=$proc['ID']?>">
<?=$proc['NAME']?>
</option>

<?php endforeach?>

</select>

<input class="doctor-edit-form__submit" type="submit" name="doctor-submit" value="Сохранить">
</div>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
if (!defined('B_PROLOG_INCLUDED') || B_PROLOG_INCLUDED !== true) die();

/** @var array $arParams */
/** @var array $arResult */
/** @global CMain $APPLICATION */
/** @global CUser $USER */
?>

<div class="doctor-detail">

<div class="doctor-detail__actions">
<a href="/doctors/" class="doctor-detail__action">← Назад к списку</a>
<a href="/doctors/?ID=<?=$arResult['ID']?>&action=edit" class="doctor-detail__action">Редактировать</a>
</div>

<h1 class="doctor-detail__title"><?=$arResult['LAST_NAME'] . " " . $arResult['NAME'] . " " . $arResult['MIDDLE_NAME']?></h1>

<?php if($arResult['PROCS']){?>

<ul class="doctor-detail__procedures">
<?php foreach($arResult['PROCS']as $proc):?>
<li class="doctor-detail__procedures-item"><?=$proc['NAME']?></li>
<?php endforeach?>
</ul>

<?php }?>
</div>
Loading