Your IP : 3.17.157.7


Current Path : /home/bitrix/ext_www/home-comfort.in.ua/local/modules/webprofy.offersgroup/lib/
Upload File :
Current File : /home/bitrix/ext_www/home-comfort.in.ua/local/modules/webprofy.offersgroup/lib/relationmain.php

<?php
/**
 * Created by PhpStorm.
 * User: Alya
 * Date: 06.06.2016
 * Time: 9:20
 */

namespace Webprofy\Offersgroup;


use Bitrix\Main\Loader;
use Bitrix\Iblock\ElementTable;
use Bitrix\Highloadblock\HighloadBlockTable;
use Bitrix\Main\Entity\Query;


/**
 * Class RelationMain
 * @package Webprofy\Offersgroup
 */
class RelationMain
{
    /**
     * @param $relationID
     * @return array|false
     * @throws \Bitrix\Main\ArgumentException
     * Поиск группы по ID
     */
    public static function getRelationByID($relationID)
    {
        return RelationTable::getList(
            array(
                'filter' => array(
                    'ID' => $relationID,
                ),
            )
        )->fetch();
    }


    /**
     * @return array
     * @throws \Bitrix\Main\ArgumentException
     */
    public static function getAllRelation()
    {
        $arRelation = array();

        $arResult = RelationTable::getList(
            array(
                'select' => array(
                    '*',
                ),
                'order' => array(
                    'ID' => 'ASC'
                )
            )
        )->fetchAll();

        if (!empty($arResult)) {
            foreach ($arResult as $item) {
                $arRelation[$item['ID']] = $item;
            }
        }

        return $arRelation;
    }


    public static function getAllRelationGroupByCode()
    {
        $arRelation = array();
        $arResult = RelationTable::getList(
            array(
                'select' => array(
                    'ID',
                    'RELATION_CODE'
                ),
                'order' => array(
                    'ID' => 'ASC'
                )
            )
        )->fetchAll();

        if (!empty($arResult)) {
            foreach ($arResult as $item) {
                $arRelation[$item['RELATION_CODE']] = $item['ID'];
            }
        }
        return $arRelation;
    }


    /**
     * @return array
     * @throws \Bitrix\Main\ArgumentException
     * Выбираем справочники из таблицы связей
     */
    public static function getAllReference(){
        $arRelation = array();

        $arResult = RelationTable::getList(
            array(
                'filter' => array(
                    'RELATION_TYPE' => 'highload'
                ),
                'select' => array(
                    '*',
                ),
                'order' => array(
                    'ID' => 'ASC'
                )
            )
        )->fetchAll();

        if (!empty($arResult)) {
            foreach ($arResult as $item) {
                $arRelation[$item['ID']] = $item;
            }
        }

        return $arRelation;
    }


    /**
     * @param $highloadID
     * @return array
     * @throws \Bitrix\Main\LoaderException
     * @throws \Bitrix\Main\SystemException
     */
    public static function getReferenceDataName($highloadID){
        Loader::IncludeModule('highloadblock');

        $highloadData = array();
        $rsData = HighloadBlockTable::getById($highloadID);
        if ($arData = $rsData->fetch()) {
            $Entity = HighloadBlockTable::compileEntity($arData);
            // Создадим объект - запрос
            $Query = new Query($Entity);
            // Зададим параметры запроса
            $Query->setSelect(Array(
                'ID',
                'UF_NAME'
            ));
            // Выполним запрос
            $result = $Query->exec();
            // Получаем результат
            while ($res = $result->fetch()) {
                $highloadData[$res['ID']] = $res['UF_NAME'];
            }
        }

        return $highloadData;
    }


    /**
     * @return array|false
     * @throws \Bitrix\Main\ArgumentException
     * Возвращает информацию о торговом каталоге из настроек
     */
    public static function getProductsInfo(){
        return RelationTable::getList(
            array(
                'filter' => array(
                    'RELATION_CODE' => 'product',
                ),
                'select' => array(
                    '*'
                )
            )
        )->fetch();
    }

    /**
     * @param $id
     * @return bool
     * @throws \Exception
     */
    public static function deleteRelation($id)
    {
        return RelationTable::delete($id)->isSuccess();
    }

    /**
     * @param $fields
     * @return bool
     * @throws \Exception
     */
    public static function addRelation($fields)
    {
        return RelationTable::add($fields)->isSuccess();
    }

}