示例#1
0
文件: functions.php 项目: kudin/crm
function trackStartedTask($stopStartedTask = true)
{
    CModule::IncludeModule('iblock');
    $res = CIBlockElement::GetList(array(), array("IBLOCK_ID" => TASKS_IBLOCK_ID, 'ACTIVE' => 'Y', "PROPERTY_PROGRAMMER" => CUser::GetID(), "PROPERTY_STATUS" => STATUS_LIST_WORK), false, false, array('ID', 'NAME', 'PROPERTY_PROJECT', 'PROPERTY_STATUS_DATE'));
    if ($taskArr = $res->Fetch()) {
        if ($stopStartedTask) {
            CIBlockElement::SetPropertyValuesEx($taskArr['ID'], TASKS_IBLOCK_ID, array('STATUS' => STATUS_LIST_PAUSE));
        }
        $link = TASKS_LIST_URL . $taskArr["PROPERTY_PROJECT_VALUE"] . '/' . $taskArr['ID'] . '/';
        $date = new DateTime($taskArr["PROPERTY_STATUS_DATE_VALUE"]);
        $curdate = new DateTime();
        $diff = $date->diff($curdate);
        $h = $diff->format('%h');
        $i = $diff->format('%i');
        if ($h || $i) {
            $timingText = '';
            if ($h) {
                $timingText = "{$h} ч, ";
            }
            if ($i) {
                $timingText = $timingText . "{$i} мин. ";
            }
            $decTime = $h + $i / 60;
            $decTime = round($decTime, 2);
            $el = new CIBlockElement();
            if ($el->Add(array("DATE_ACTIVE_FROM" => ConvertTimeStamp(time(), "SHORT"), "MODIFIED_BY" => CUser::GetID(), "IBLOCK_SECTION_ID" => false, "IBLOCK_ID" => TRACKING_IBLOCK_ID, "NAME" => 'Без названия' . ' (' . $decTime . 'ч.)', "ACTIVE" => "Y", "PROPERTY_VALUES" => array("HOURS" => $decTime, "TASK" => $taskArr['ID'])))) {
                crmEntitiesHelper::recalcTaskTracking($taskArr['ID']);
                ToolTip::Add("+ {$timingText} в трекер задачи \"<a target=\"_blank\" href=\"{$link}\">{$taskArr['ID']} {$taskArr['NAME']}</a>\"");
            } else {
                ToolTip::AddError($el->LAST_ERROR);
            }
        }
    }
}
示例#2
0
 function executeComponent()
 {
     $arFilter = array('IBLOCK_ID' => $this->arParams['IBLOCK_ID'], 'ACTIVE' => 'Y');
     if (true || $this->StartResultCache()) {
         $CIBlockElement = new CIBlockElement();
         $CFile = new \CFile();
         $aElts = array();
         $eltsSelectFields = array_merge(array('ID', 'NAME', 'CODE', 'PREVIEW_PICTURE', 'DETAIL_PICTURE', 'DETAIL_PAGE_URL'), $this->getIBlockProperties($this->arParams['IBLOCK_ID']));
         $rsElts = $CIBlockElement->GetList(array('SORT' => 'asc', 'date_active_from' => 'DESC'), $arFilter, false, false, array('ID', 'NAME'));
         if (intval($rsElts->SelectedRowsCount())) {
             while ($arElt = $rsElts->Fetch()) {
                 $aElts[] = array('ID' => $arElt['ID'], 'NAME' => $arElt['NAME']);
             }
             $arElt = $CIBlockElement->GetList(array('SORT' => 'asc', 'ID' => 'DESC'), array_merge($arFilter, array('ID' => $aElts[0]['ID'])), false, false, $eltsSelectFields)->GetNext();
             if ($arElt['DETAIL_PICTURE']) {
                 $arElt['DETAIL_PICTURE'] = $CFile->GetPath($arElt['DETAIL_PICTURE']);
             } elseif ($arElt['PREVIEW_PICTURE']) {
                 $arElt['DETAIL_PICTURE'] = $CFile->GetPath($arElt['PREVIEW_PICTURE']);
             }
             $arPrice = CPrice::GetList(array(), array("PRODUCT_ID" => $arElt['ID']))->Fetch();
             $arElt['PRICE'] = $arPrice['PRICE'];
             $this->arResult['ITEMS'] = $aElts;
             $this->arResult['ITEM'] = $arElt;
             $this->IncludeComponentTemplate();
         }
     }
 }
 /**
  * Получает результат запроса для поиска списка элементов
  *
  * @param array $filter
  * @param array $orderBy
  * @param array $selectedFields
  * @param mixed $navStartParams
  *
  * @return \CIBlockResult
  */
 public function rawFindBy(array $filter = array(), array $orderBy = array('sort' => 'asc'), array $selectedFields = array('*', 'PROPERTY_*'), $navStartParams = null)
 {
     if (!isset($filter['IBLOCK_ID']) && $this->iBlockId) {
         $filter['IBLOCK_ID'] = $this->iBlockId;
     }
     return $this->iBEGateway->GetList($orderBy, $filter, false, is_null($navStartParams) ? false : $navStartParams, $selectedFields);
 }
 public function transformTags($aOldTags, $aNewTags, $bSaveOldTags = false, $sOperation = false)
 {
     $aElements = $this->getMaterialsByTags($aOldTags);
     $mResult = array('iTotalElements' => count($aElements), 'iProcessedElements' => 0, 'aErrorElementID' => array());
     if (!empty($aElements)) {
         $oElement = new CIBlockElement();
         foreach ($aElements as $aElement) {
             $aTags = explode(',', $aElement['TAGS']);
             $aNewTags = array_map('trim', array_unique(array_merge($aTags, $aNewTags)));
             if (!$bSaveOldTags) {
                 foreach ($aNewTags as $iKey => &$sTag) {
                     $sTag = trim($sTag);
                     if (in_array($sTag, $aOldTags)) {
                         unset($aNewTags[$iKey]);
                     }
                 }
             }
             //var_dump($aElement['TAGS'],implode( ', ', $aNewTags ) );
             $bResult = $oElement->Update($aElement['ID'], array('TAGS' => implode(', ', $aNewTags)));
             if ($bResult) {
                 $mResult['iProcessedElements']++;
             } else {
                 $mResult['aErrorElementID'][] = array('ID' => $aElement['ID'], 'IBLOCK_ID' => $aElement['IBLOCK_ID'], 'FORMATTED_LINK' => $this->getElementLink($aElement));
             }
         }
     }
     return $mResult;
 }
function storeResult($arResult, $arParams) {
    $iblock = CIBlock::GetList(
        array(),
        array(
            'TYPE' => $arParams['IBLOCK_TYPE'],
            'CODE' => $arParams['IBLOCK_CODE'],
        )
    );
    $iblock = $iblock->Fetch();
    
    $el = new CIBlockElement;

    $props = array();
    foreach ($arResult['FIELDS_LIST'] as $arField) {
        if ($arField['FIELD_TYPE'] == 'TEXT' || $arField['FIELD_TYPE'] == 'NUMBER') {
            $props[$arField['CODE']] = array(
                'VALUE' => $arResult['POST_DATA']['~'.$arField['CODE']],
            );
        } elseif ($arField['FIELD_TYPE'] == 'TEXTAREA') {
            $props[$arField['CODE']] = array(
                'VALUE' => array(
                    'TYPE' => 'text',
                    'TEXT' => $arResult['POST_DATA']['~'.$arField['CODE']],
                ),
            );
        } elseif ($arField['FIELD_TYPE'] == 'LIST') {
            $propEnum = CIBlockPropertyEnum::GetList(
                array(),
                array(
                    'XML_ID' => $arResult['POST_DATA']['~'.$arField['CODE']],
                    'CODE' => $arField['CODE'],
                    'IBLOCK_ID' => $iblock['ID'],
                )
            );
            $propEnum = $propEnum->Fetch();
            if ( ! $propEnum) return false;

            $props[$arField['CODE']] = array(
                'VALUE' => $propEnum['ID'],
            );
        }
    }

    $res = $el->Add(array(
        'IBLOCK_TYPE' => $arParams['IBLOCK_TYPE'],
        'IBLOCK_ID' => $iblock['ID'],
        'ACTIVE' => 'Y',
        'PROPERTY_VALUES' => $props,
        'ACTIVE_FROM' => ConvertTimeStamp(time()+CTimeZone::GetOffset(), 'FULL'),
        'NAME' => 'Form result', # !!! NEED TO REPLACE TO DEFAULT VALUE
    ));

    if (!$res) {
        return array(
            'MESSAGE' => $el->LAST_ERROR,
        );
    }

    return true;
}
 function AddProduct($NAME)
 {
     $iblock_permission = CIBlock::GetPermission(IBLOCK_ID);
     if ($iblock_permission < "W") {
         $GLOBALS["USER"]->RequiredHTTPAuthBasic();
         return new CSOAPFault('Server Error', 'Unable to authorize user.');
     }
     $code = self::translit($NAME);
     $i = 1;
     while (true) {
         $res = CIBlockElement::Getlist(array(), array("CODE" => $code), false, array("CODE"));
         if ($res->Fetch()) {
             $code = self::translit($NAME) . $i;
         } else {
             break;
         }
         $i++;
     }
     $arFields = array("IBLOCK_ID" => IBLOCK_ID, "NAME" => $NAME);
     $ib_element = new CIBlockElement();
     $result = $ib_element->Add($arFields);
     if ($result > 0) {
         return $result;
     }
     return new CSOAPFault('Server Error', 'Error: ' . $ib_element->LAST_ERROR);
 }
 public function Execute()
 {
     if (!CModule::IncludeModule("intranet")) {
         return CBPActivityExecutionStatus::Closed;
     }
     $absenceIblockId = COption::GetOptionInt("intranet", 'iblock_absence', 0);
     if ($absenceIblockId <= 0) {
         return CBPActivityExecutionStatus::Closed;
     }
     $rootActivity = $this->GetRootActivity();
     $documentId = $rootActivity->GetDocumentId();
     $documentService = $this->workflow->GetService("DocumentService");
     $arAbsenceUserTmp = $this->AbsenceUser;
     $arAbsenceUser = CBPHelper::ExtractUsers($arAbsenceUserTmp, $documentId, false);
     $arAbsenceTypes = array();
     $dbTypeRes = CIBlockPropertyEnum::GetList(array("SORT" => "ASC", "VALUE" => "ASC"), array('IBLOCK_ID' => $absenceIblockId, 'PROPERTY_ID' => 'ABSENCE_TYPE'));
     while ($arTypeValue = $dbTypeRes->GetNext()) {
         $arAbsenceTypes[$arTypeValue['XML_ID']] = $arTypeValue['ID'];
     }
     foreach ($arAbsenceUser as $absenceUser) {
         $arFields = array("ACTIVE" => "Y", "IBLOCK_ID" => $absenceIblockId, 'ACTIVE_FROM' => $this->AbsenceFrom, 'ACTIVE_TO' => $this->AbsenceTo, "NAME" => $this->AbsenceName, "PREVIEW_TEXT" => $this->AbsenceDesrc, "PREVIEW_TEXT_TYPE" => "text", "PROPERTY_VALUES" => array("USER" => $absenceUser, "STATE" => $this->AbsenceState, "FINISH_STATE" => $this->AbsenceFinishState, "ABSENCE_TYPE" => $arAbsenceTypes[$this->AbsenceType]));
         $el = new CIBlockElement();
         $el->Add($arFields);
     }
     return CBPActivityExecutionStatus::Closed;
 }
示例#8
0
 /**
  * {@inheritdoc}
  */
 public function getFiles($insertId, array $attachFields)
 {
     $filesList = array();
     $iblockElement = new \CIBlockElement();
     $builderData = $this->builder->getBuilderData();
     $filter = array('ID' => $insertId, 'IBLOCK_ID' => $builderData['DATA']['ID']);
     $elementDb = $iblockElement->getList(array(), $filter, false, false, array());
     if (!($element = $elementDb->getNextElement())) {
         return $filesList;
     }
     $fields = $element->getFields();
     foreach ($fields as $key => $value) {
         if (in_array($key, $attachFields) && is_numeric($value)) {
             $filesList[] = $value;
         }
     }
     $propertyList = $element->getProperties();
     foreach ($propertyList as $key => $property) {
         if (!in_array($key, $attachFields)) {
             continue;
         }
         if (is_numeric($property['VALUE'])) {
             $filesList[] = $property['VALUE'];
         } elseif (is_array($property['VALUE'])) {
             $filesList = array_merge_recursive($filesList, $property['VALUE']);
         }
     }
     return $filesList;
 }
示例#9
0
 /**
  * TASK performs with ACTION = INSERT
  *
  * @param int $limit
  * @return string
  */
 public static function taskInsertElement($limit = 500)
 {
     if (($limit = (int) $limit) < 0) {
         return;
     }
     $iblockElement = new \CIBlockElement();
     $connection = \Bitrix\Main\Application::getConnection();
     $sqlHelper = $connection->getSqlHelper();
     // We get a task with the `ACTION` of `INSERT`
     $sql = "\n            SELECT t1.ID as TASK_ID, t1.PARAMS, t1.FILTER_USER_ID, t3.*\n            FROM b_citfact_filter_subscribe_stack as t1\n            LEFT JOIN b_citfact_filter_subscribe_user as t2 ON t2.ID = t1.FILTER_USER_ID\n            LEFT JOIN b_citfact_filter_subscribe as t3 ON t3.ID = t2.FILTER_USER\n            WHERE t1.ACTION = 'INSERT' AND t3.ACTIVE = 'N'\n            LIMIT 1\n        ";
     $task = (array) $connection->query($sql)->fetch();
     if (!empty($task)) {
         $filter['IBLOCK_ID'] = $task['IBLOCK_ID'];
         if ($task['SECTION_ID'] > 0) {
             $filter['SECTION_ID'] = $task['SECTION_ID'];
         }
         $filter = array_merge($filter, unserialize($task['FILTER']));
         $elementResult = $iblockElement->GetList(array('ID' => 'ASC'), $filter, false, array('nTopCount' => $limit), array('ID'));
         while ($element = $elementResult->fetch()) {
             Model\SubscribeNotifyTable::add(array('FILTER_USER_ID' => $task['FILTER_USER_ID'], 'ELEMENT_ID' => $element['ID']));
         }
         Model\SubscribeStackTable::delete(array('ID' => $task['TASK_ID']));
     }
     return "Citfact\\FilterSubscribe\\Agent::taskInsertElement({$limit})";
 }
示例#10
0
/**
 * Created by JetBrains PhpStorm.
 * User: oleg
 * Date: 01.10.12
 * Time: 21:06
 * To change this template use File | Settings | File Templates.
 */
function agent_kingcoupon_pars()
{
    require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
    CModule::IncludeModule("iblock");
    CModule::IncludeModule("mytb");
    $content = file_get_contents("http://kingcoupon.ru/offer/category/Food/");
    preg_match_all("#kingcoupon\\.ru/offer/([0-9]+)/#is", $content, $arr);
    $xml = file_get_contents("http://kingcoupon.ru/offer/export/?refId=100132540459877345");
    $svg = new SimpleXMLElement($xml);
    $clubListID = array();
    foreach ($arr[1] as $var) {
        $clubListID[$var] = $var;
    }
    foreach ($svg->offers->offer as $var) {
        $R = array();
        if (in_array($var->id, $arr[1])) {
            $R['clubName'] = (string) $var->supplier->name;
            foreach ((array) $var->supplier->addresses as $address) {
                if (is_array($address)) {
                    foreach ((array) $address as $var1) {
                        $R['clubAdress'][] = (string) $var1->name;
                    }
                } else {
                    $R['clubAdress'][] = $address->name;
                }
            }
            foreach ((array) $var->supplier->tel as $tel) {
                $R['clubPhone'][] = $tel;
            }
            $id = $var->id;
            $url = preg_replace("#http://#i", "", $var->supplier->url);
            $url = preg_replace("#^([^/]+)/.*#i", "\\1", $url);
            $url = str_replace("www.", "", $url);
            $R['url'] = $url;
            $arSelect = array("ID", "NAME");
            $arFilter = array("IBLOCK_ID" => IB_CLUB_ID, "PROPERTY_SITE" => "%" . $url . "%");
            $res = CIBlockElement::GetList(array("SORT" => "DESC"), $arFilter, FALSE, FALSE, $arSelect);
            if (!$res->Fetch()) {
                $PROP = array();
                //                $PROP["PHONE"]   = $R['clubPhone'];
                //                $PROP["ADDRESS"] = $R['clubAdress'];
                $PROP["SITE"] = $R['url'];
                $PROP["LIST"] = array(54);
                $el = new CIBlockElement();
                $arLoadProductArray = array("IBLOCK_ID" => IB_CLUB_ID, "PROPERTY_VALUES" => $PROP, "NAME" => $R['clubName'], "TAGS" => "kingcoupon", "ACTIVE" => "Y", "SORT" => "0");
                if ($PRODUCT_ID = $el->Add($arLoadProductArray)) {
                    foreach ($R['clubAdress'] as $addressItem) {
                        MyTbCore::Add(array("CLUB_ID" => $PRODUCT_ID, "SITY_ID" => 1, "ADDRESS" => $addressItem, "PHONE" => serialize($R['clubPhone'])), "address");
                        printAr($addressItem);
                    }
                } else {
                    echo "Error: " . $el->LAST_ERROR;
                }
            }
        }
    }
    return "agent_kingcoupon_pars();";
}
 function executeDown()
 {
     CModule::IncludeModule('iblock');
     $obj_ib_element = new CIBlockElement();
     $r = $obj_ib_element->Delete(2);
     if (!$r) {
         throw new \Exception('Fail do remove element with id = 1');
     }
     return true;
 }
示例#12
0
 public static function connectToUser($userID, $providerName, $userProfile)
 {
     CModule::IncludeModule("iblock");
     $el = new \CIBlockElement();
     $PROP = array();
     $PROP["USER_ID"] = $userID;
     $PROP["SOCIAL_PROVIDER"] = $providerName;
     $PROP["SOCIAL_ID"] = $userProfile["identifier"];
     $arLoadProductArray = array("IBLOCK_SECTION_ID" => false, "IBLOCK_ID" => USER_SOCIAL_IB, "PROPERTY_VALUES" => $PROP, "NAME" => trim("Пользователь №" . $userID), "ACTIVE" => "Y");
     $el->Add($arLoadProductArray);
     \CUserEx::capacityAdd($userID, 1);
 }
 public function save()
 {
     \Bitrix\Main\Loader::includeModule("iblock");
     $errors =& $this->arResult["forms"][$this->request->getPost("id")]["errors"];
     $el = new CIBlockElement();
     $this->element_id = $el->Add(array("IBLOCK_ID" => 4, "NAME" => "({$this->arResult["forms"][$this->request->getPost("id")]["title"]})Обращение от {$this->request->getPost("first_name")} {$this->request->getPost("last_name")}", "PREVIEW_TEXT" => $this->request->getPost("comment"), "PROPERTY_VALUES" => array("TREATMENT_REASON" => $this->request->getPost("reason_for_treatment"), "PHONE" => $this->request->getPost("phone"), "EMAIL" => $this->request->getPost("email"), "FILE" => $this->request->getFile("file"))));
     if ($this->element_id !== false) {
         return true;
     }
     $errors[] = $res->LAST_ERROR;
     return false;
 }
 /**
  * Метод вернет массив параметров из инфоблока "Параметры Автонаценки".
  *
  * @return array
  */
 function getOptions()
 {
     $filterParams = array('ACTIVE' => 'Y', 'IBLOCK_CODE' => 'autoprice_options');
     $orderParams = array('SORT' => 'ASC');
     $selectParams = array('ID', 'IBLOCK_SECTION_ID', 'NAME', 'CODE', 'PROPERTY_PARAM', 'PROPERTY_MARKUP');
     $result = array();
     $iBlockElement = new CIBlockElement();
     $dbElements = $iBlockElement->GetList($orderParams, $filterParams, false, false, $selectParams);
     while ($element = $dbElements->GetNext()) {
         $result[] = $element;
     }
     return $result;
 }
示例#15
0
function addElementReview($arResult, $ID_SECTION, $IBLOCK_ID)
{
    CModule::IncludeModule('iblock');
    $property_enums = CIBlockPropertyEnum::GetList(array("DEF" => "DESC", "SORT" => "ASC"), array("IBLOCK_ID" => $IBLOCK_ID, "CODE" => "RATING", "VALUE" => $arResult['RATING']));
    while ($rating = $property_enums->GetNext()) {
        $arRating = $rating["ID"];
    }
    $current_date = dateActiveFrom(date('d.m.Y'));
    $NAME = $current_date . ' ' . $arResult['NAME'];
    $arFields = array("ACTIVE" => "N", "IBLOCK_ID" => $IBLOCK_ID, "IBLOCK_SECTION_ID" => $ID_SECTION, "NAME" => $NAME, "DETAIL_TEXT" => "Описание элемента", "PROPERTY_VALUES" => array("NAME" => $arResult['NAME'], "EMAIL" => $arResult['EMAIL'], "RATING" => array('VALUE' => $arRating), "BENEFITS" => $arResult['BENEFITS'], "DISADVANTAGES" => $arResult['DISADVANTAGES'], "COMMENT" => $arResult['COMMENT']));
    $oElement = new CIBlockElement();
    $idElement = $oElement->Add($arFields, false, false, true);
    return $idElement;
}
示例#16
0
/**
 * Выключает прошедшие акции
 * User: Tabota Oleg (sForge.ru)
 * Date: 18.11.12 16:20
 * File name: no_active_stock.php
 */
function no_active_stock()
{
    require_once $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php";
    CModule::IncludeModule("iblock");
    $sort = array("SORT" => "ASC");
    $filter = array("ACTIVE" => "Y", "IBLOCK_ID" => IB_SUB_STOCK_ID, "<DATE_ACTIVE_TO" => date("d.m.Y"));
    $select = array("ID", "IBLOCK_ID");
    $ob = CIBlockElement::GetList($sort, $filter, FALSE, FALSE, $select);
    while ($row = $ob->Fetch()) {
        $el = new CIBlockElement();
        $el->Update(intval($row['ID']), array("ACTIVE" => "N"));
    }
    return "no_active_stock();";
}
示例#17
0
function OnAfterUserAddHandler(&$arFields)
{
    if (intval($arFields["ID"]) > 0) {
        global $USER;
        $noticeDefault = array("day" => array(1, 2, 3, 4, 5, 6, 7), "metod" => array("sms", "email"));
        $PROP['USER'] = $arFields["ID"];
        $PROP["NOTICE"] = serialize($noticeDefault);
        $arLoadProductArray = array("MODIFIED_BY" => $USER->GetID(), "IBLOCK_ID" => IB_USER_PROPS, "PROPERTY_VALUES" => $PROP, "NAME" => $arFields["LOGIN"], "ACTIVE" => "Y");
        $el = new CIBlockElement();
        $el->Add($arLoadProductArray);
        return true;
    } else {
        return TRUE;
    }
}
示例#18
0
 public static function GetElementID($element_id, $element_code, $section_id, $section_code, $arFilter)
 {
     $element_id = (int) $element_id;
     $element_code = (string) $element_code;
     if ($element_id > 0) {
         return $element_id;
     } elseif ($element_code != '') {
         if (!is_array($arFilter)) {
             $arFilter = array();
         }
         $arFilter['=CODE'] = $element_code;
         $section_id = (int) $section_id;
         $section_code = (string) $section_code;
         if ($section_id > 0) {
             $arFilter['SECTION_ID'] = $section_id;
         } elseif ($section_code != '') {
             $arFilter["SECTION_CODE"] = $section_code;
         }
         $rsElement = CIBlockElement::GetList(array(), $arFilter, false, false, array("ID"));
         if ($arElement = $rsElement->Fetch()) {
             return (int) $arElement["ID"];
         }
     }
     return 0;
 }
示例#19
0
 function getItem()
 {
     $arSelect = array();
     $arFilter = array("IBLOCK_ID" => (int) $GLOBALS['AQW_BRANDS']['IBLOCK_ID'], "ID" => $this->getItemID(), "GLOBAL_ACTIVE" => "Y");
     $res = CIBlockElement::GetList(array("DATE_CREATE" => "DESC"), $arFilter, false, array("nPageSize" => $this->limit), $arSelect);
     return $res->GetNext();
 }
示例#20
0
文件: News.php 项目: nProfessor/Mytb
 /**
  * Воззвращаем список новостей клуба
  * @return mixed
  */
 function getList($filter = array())
 {
     $filter['IBLOCK_ID'] = IB_SUB_NEWS_ID;
     $filter['PROPERTY_CLUB_ID'] = $this->clubID;
     $ob = CIBlockElement::GetList(array("ACTIVE_FROM" => "DESC"), $filter, false, FALSE, array("ID", "NAME", "ACTIVE_FROM", "DETAIL_TEXT", "PREVIEW_PICTURE"));
     return $ob;
 }
function OnProductCatalogHandler($ID, $arFields)
{
    Bitrix\Main\Loader::includeModule('iblock');
    Bitrix\Main\Loader::includeModule('catalog');
    define('IBLOCK_ID_PRODUCTS', 2);
    define('IBLOCK_ID_OFFERS', 3);
    $query = new \Bitrix\Main\Entity\Query(Bitrix\Iblock\ElementTable::getEntity());
    $query->setSelect(array("ID", "IBLOCK_ID"))->setFilter(array("ID" => $ID))->setOrder(array("ID" => "ASC"));
    $resElement = $query->exec()->fetch();
    if ($resElement['IBLOCK_ID'] == IBLOCK_ID_PRODUCTS) {
        CIBlockElement::SetPropertyValuesEx($ID, $resElement['IBLOCK_ID'], array("AVAILABLE_QUANTITY_CATALOG" => $arFields['QUANTITY']));
    } elseif ($resElement['IBLOCK_ID'] == IBLOCK_ID_OFFERS) {
        //1
        $rsElementOffer = CIBlockElement::GetList(array(), array("ID" => $ID), false, false, array("ID", "IBLOCK_ID", 'NAME', "PROPERTY_CML2_LINK"))->fetch();
        $resElemOfferProduct = (int) $rsElementOffer['PROPERTY_CML2_LINK_VALUE'];
        //2
        $resOffersCML2 = CIBlockElement::GetList(array(), array("PROPERTY_CML2_LINK" => $resElemOfferProduct, 'IBLOCK_ID' => IBLOCK_ID_OFFERS), false, false, array("ID", "IBLOCK_ID", 'NAME'));
        //3
        $arrOffersIDs = array();
        while ($res = $resOffersCML2->fetch()) {
            $arrOffersIDs[] = $res['ID'];
        }
        //4
        $availQuant = array();
        foreach ($arrOffersIDs as $k => $v) {
            $ar_res_cat = CCatalogProduct::GetList(array("ID" => "DESC"), array("ID" => (int) $v), false, false, array("ID", "QUANTITY", 'ELEMENT_IBLOCK_ID', 'ELEMENT_NAME'))->fetch();
            $availQuant[] = $ar_res_cat['QUANTITY'];
        }
        //5
        $minAvailQuant = (int) min($availQuant);
        //6
        $resUpdateSCU = CIBlockElement::SetPropertyValuesEx($resElemOfferProduct, IBLOCK_ID_PRODUCTS, array("AVAILABLE_QUANTITY_CATALOG" => $minAvailQuant));
    }
}
示例#22
0
function updateResult($ID_RESULT, $STEP, $RES, $MSG){
	if (!CModule::IncludeModule("iblock")):
		return false;
	endif;
	global $USER;
	$actionStr = getActionStr($STEP);
	if ($RES == "success"):
		$STATUS = "success";
		$MESSAGE = "Успешно";
	elseif ($RES == "fail"):
		$STATUS = "fail";
		$MESSAGE = "Ошибка";
	else:
		$STATUS = "processed";
		$MESSAGE = "Исполняется";
	endif;
	if ($MSG):
		$MESSAGE = $MSG;
	endif;
	$PROP = array();
	$PROP = array(
		"ACTION" => $actionStr,
		"STATUS" => $STATUS,
		"MESSAGE" => $MESSAGE,
		"OFF_TIME" => mktime(),
		"TYPE" => $STEP
		);
	foreach ($PROP as $code => $value) :
		CIBlockElement::SetPropertyValues($ID_RESULT, 23, $value, $code);
	endforeach;
	return $ID_RESULT;
}
示例#23
0
 /**
  * Delete
  * @param $IblockTypeCode
  * @return bool
  * @throws \Exception
  */
 public static function Delete($IblockTypeCode)
 {
     $Iblock = new \CIBlock();
     $iblockEl = new \CIBlockElement();
     $dbIblock = $Iblock->GetList(array(), array('TYPE' => $IblockTypeCode));
     while ($dbRow = $dbIblock->Fetch()) {
         $iblockElDbRes = $iblockEl->GetList(array(), array('IBLOCK_ID' => $dbRow['ID']));
         if ($iblockElDbRes !== false && $iblockElDbRes->SelectedRowsCount()) {
             throw new BimException('Can not delete iblock type: iblock id =' . $dbRow['ID'] . ' have elements');
         }
     }
     if (!\CIBlockType::Delete($IblockTypeCode)) {
         throw new BimException('Delete iblock type error!');
     }
     return true;
 }
示例#24
0
 /** @return \CDBResult */
 public function getData()
 {
     $iblockId = $this->getFieldValue('IBLOCK', null);
     $propertyNameId = $this->getFieldValue('PROPERTY_NAME', null);
     $propertyEmailId = $this->getFieldValue('PROPERTY_EMAIL', null);
     if ($iblockId && $propertyEmailId) {
         // if property is property with code like '123'
         $propertyNameValue = null;
         $propertyEmailValue = null;
         if (is_numeric($propertyEmailId)) {
             $propertyEmailId = "PROPERTY_" . $propertyEmailId;
             $propertyEmailValue = $propertyEmailId . "_VALUE";
         }
         $selectFields = array($propertyEmailValue);
         if ($propertyNameId) {
             if (is_numeric($propertyNameId)) {
                 $propertyNameId = "PROPERTY_" . $propertyNameId;
                 $propertyNameValue = $propertyNameId . "_VALUE";
             }
             $selectFields[] = $propertyNameValue;
         }
         $filter = array('IBLOCK_ID' => $iblockId, '!' . $propertyEmailId => false);
         $iblockElementListDb = \CIBlockElement::getList(array('id' => 'asc'), $filter, false, false, $selectFields);
         // replace property names from PROPERTY_123_VALUE to EMAIL, NAME
         $iblockElementDb = new CDBResultSenderConnector($iblockElementListDb);
         $iblockElementDb->senderConnectorFieldEmail = $propertyEmailValue;
         $iblockElementDb->senderConnectorFieldName = $propertyNameValue;
     } else {
         $iblockElementDb = new \CDBResult();
         $iblockElementDb->InitFromArray(array());
     }
     return $iblockElementDb;
 }
示例#25
0
文件: Table.php 项目: nProfessor/Mytb
 /**
  * Возвращаем данные столика
  * @param $arData
  * @return CDBResult|CIBlockResult|string
  */
 function getInfo($tableID, $arData = false, $GetNext = false)
 {
     $arFilterTable = array("IBLOCK_ID" => IB_TABLE_ID, "PROPERTY_CLUB" => $this->clubID, "ID" => intval($tableID));
     $arSelectTable = array("ID");
     $arOrderTable = array();
     $arOrder = is_array($arData["arSelect"]) ? array_merge($arData["arOrder"], $arOrderTable) : $arOrderTable;
     $arGroupBy = is_array($arData["arGroupBy"]) ? array_merge($arData["arGroupBy"], array()) : false;
     $arNavStartParams = is_array($arData["arGroupBy"]) ? array_merge($arData["arNavStartParams"], array()) : false;
     $arSelect = is_array($arData["arSelect"]) ? array_merge($arData["arSelect"], $arSelectTable) : $arSelectTable;
     $arFilter = is_array($arData["arFilter"]) ? array_merge($arData["arFilter"], $arFilterTable) : $arFilterTable;
     $res = CIBlockElement::GetList($arOrder, $arFilter, $arGroupBy, $arNavStartParams, $arSelect);
     if (!$res) {
         return Errors::run("404");
     }
     $ob = $GetNext ? $res->GetNext() : $res->Fetch();
     if (isset($ob["PREVIEW_PICTURE"])) {
         $arFile = CFile::GetFileArray($ob["PREVIEW_PICTURE"]);
         $ob["PREVIEW_PICTURE"] = $arFile["SRC"];
     }
     if (isset($ob["PROPERTY_PRICE_GROUP_VALUE"])) {
         $res = CIBlockElement::GetList(array(), array("ID" => intval($ob["PROPERTY_PRICE_GROUP_VALUE"]), "IBLOCK_ID" => IB_PRICE_GROUP), false, false, array("NAME", "ID", "PROPERTY_PRICE"));
         $ob["PROPERTY_PRICE_GROUP"] = $res->Fetch();
     }
     return $ob;
 }
示例#26
0
 /**
  * ’эндлер, отслеживающий изменени¤ в инфоблоках
  * @param $arFields
  * @return bool
  */
 static function getCradoBaners()
 {
     //$arResult = array();
     CModule::IncludeModule('iblock');
     global $DB;
     $result = $DB->Query('SELECT * FROM b_cradobaners');
     $arResult = array();
     $i = 0;
     while ($res = $result->fetch()) {
         $arResult[$i]['ID'] = $res['ID'];
         $arResult[$i]['COUNT_CLICK'] = $res['UF_COUNTCLICK'];
         $arResult[$i]['COUNT_VIEW'] = $res['UF_COUNTVIEW'];
         $arResult[$i]['DATE_LAST_CLICK'] = $res['UF_DATECLICK'];
         $obElement = CIBlockElement::GetByID($res['UF_IDBANERS']);
         if ($arEl = $obElement->GetNext()) {
             //$arResult[$i]['BANNER'] = $arEl;
             $arResult[$i]['BANNER']['ID'] = $arEl['ID'];
             $arResult[$i]['BANNER']['NAME'] = $arEl['NAME'];
             //Баннер в категории
             if ($arEl['PREVIEW_PICTURE'] != '') {
                 $arResult[$i]['BANNER']['BANNER_CATEGORY'] = CFile::ResizeImageGet($arEl['PREVIEW_PICTURE'], array('width' => 140, 'height' => 95), BX_RESIZE_IMAGE_PROPORTIONAL, true);
             }
             if ($arEl['DETAIL_PICTURE'] != '') {
                 $arResult[$i]['BANNER']['BANNER_ELEMENT'] = CFile::ResizeImageGet($arEl['DETAIL_PICTURE'], array('width' => 82, 'height' => 140), BX_RESIZE_IMAGE_PROPORTIONAL, true);
             }
         }
         $i++;
     }
     return $arResult;
 }
示例#27
0
 /** Returns an array, containing information about the product block on its ID.
  * @param $elementId
  * @return array|string
  */
 public static function getProductInfo($elementId)
 {
     $elementId = intval($elementId);
     $result = "";
     if ($elementId <= 0) {
         return $result;
     }
     $dbProduct = CIBlockElement::GetList(array(), array("ID" => $elementId), false, false, array('ID', 'IBLOCK_ID', 'IBLOCK_SECTION_ID', 'DETAIL_PICTURE', 'PREVIEW_PICTURE', 'NAME', 'XML_ID'));
     while ($arProduct = $dbProduct->GetNext()) {
         $imgCode = "";
         if ($arProduct["IBLOCK_ID"] > 0) {
             $arProduct["EDIT_PAGE_URL"] = CIBlock::GetAdminElementEditLink($arProduct["IBLOCK_ID"], $elementId, array("find_section_section" => $arProduct["IBLOCK_SECTION_ID"]));
         }
         if ($arProduct["DETAIL_PICTURE"] > 0) {
             $imgCode = $arProduct["DETAIL_PICTURE"];
         } elseif ($arProduct["PREVIEW_PICTURE"] > 0) {
             $imgCode = $arProduct["PREVIEW_PICTURE"];
         }
         $arProduct["NAME"] = $arProduct["NAME"];
         $arProduct["DETAIL_PAGE_URL"] = htmlspecialcharsex($arProduct["DETAIL_PAGE_URL"]);
         if ($imgCode > 0) {
             $arFile = CFile::GetFileArray($imgCode);
             $arImgProduct = CFile::ResizeImageGet($arFile, array('width' => 80, 'height' => 80), BX_RESIZE_IMAGE_PROPORTIONAL, false, false);
             $arProduct["IMG_URL"] = $arImgProduct['src'];
         }
         return $arProduct;
     }
     return $result;
 }
function createSmartFilterSeoXML()
{
    if (CModule::IncludeModule("iblock")) {
        $resElDB = CIBlockElement::GetList(array("SORT" => "ASC"), array('IBLOCK_ID' => SEO_IBLOCK), false, false, array('PROPERTY_TARGET_ON', 'PROPERTY_INDEX', 'PROPERTY_FOLLOW', 'IBLOCK_ID', 'ID', 'NAME'));
        $protocol = CMain::IsHTTPS() ? "https" : "http";
        $host = $_SERVER['HTTP_HOST'];
        if ($_SERVER['SERVER_PORT'] != 80 && $_SERVER['SERVER_PORT'] != 443 && $_SERVER['SERVER_PORT'] > 0 && strpos($_SERVER['HTTP_HOST'], ":") === false) {
            $host .= ":" . $_SERVER['SERVER_PORT'];
        }
        $curDate = date("Y-m-d\\TH:i:s P");
        $strBeginSmartFilter = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
        $index = 0;
        while ($res = $resElDB->fetch()) {
            $exp = explode('*', $res['PROPERTY_TARGET_ON_VALUE']['TEXT']);
            $urlFilter = trim($exp[0]);
            //clean url of smart filter
            if ($index == 0) {
                $strBeginSmartFilter .= "\t<url>\n\t\t";
                $index++;
            } else {
                $strBeginSmartFilter .= "<url>\n\t\t";
            }
            $strBeginSmartFilter .= "<loc>" . $protocol . "://" . $host . $urlFilter . "</loc>\n\t\t";
            $strBeginSmartFilter .= "<lastmod>" . $curDate . "</lastmod>\n\t";
            $strBeginSmartFilter .= "</url>";
        }
        $strBeginSmartFilter .= "</urlset\n>";
        $smartXmlFileName = 'sitemap_iblock_' . SEO_IBLOCK . '.xml';
        $el = fopen($_SERVER['DOCUMENT_ROOT'] . '/' . $smartXmlFileName, "w");
        fwrite($el, $strBeginSmartFilter);
        fclose($el);
        return "createSmartFilterSeoXML();";
    }
}
示例#29
0
 protected function loadFromDatabase()
 {
     if (!isset($this->fields) && $this->iblock_id > 0 && is_array($this->id)) {
         $this->fields = array();
         foreach ($this->id as $id) {
             if ($id > 0) {
                 $propertyList = \CIBlockElement::getProperty($this->iblock_id, $id, array("sort" => "asc"), array("EMPTY" => "N"));
                 while ($property = $propertyList->fetch()) {
                     if ($property["VALUE_ENUM"] != "") {
                         $value = $property["VALUE_ENUM"];
                     } elseif ($property["PROPERTY_TYPE"] === "E") {
                         $value = new ElementPropertyElement($property["VALUE"]);
                     } elseif ($property["PROPERTY_TYPE"] === "G") {
                         $value = new ElementPropertySection($property["VALUE"]);
                     } else {
                         if (strlen($property["USER_TYPE"])) {
                             $value = new ElementPropertyUserField($property["VALUE"], $property);
                         } else {
                             $value = $property["VALUE"];
                         }
                     }
                     $this->fields[$property["ID"]][] = $value;
                     $this->fieldMap[$property["ID"]] = $property["ID"];
                     if ($property["CODE"] != "") {
                         $this->fieldMap[strtolower($property["CODE"])] = $property["ID"];
                     }
                 }
             }
         }
     }
     return is_array($this->fields);
 }
示例#30
0
文件: CInc.php 项目: Tvaruga/ae
 public static function getJobName($id)
 {
     if (empty($id)) {
         return false;
     }
     $result = false;
     $obCache = new CPHPCache();
     $dir = '/companies/names';
     if ($obCache->InitCache(9999999999, md5($id), $dir)) {
         $result = $obCache->GetVars();
     } elseif ($obCache->StartDataCache() && \Bitrix\Main\Loader::includeModule('iblock')) {
         if ($result = CIBlockElement::GetByID($id)->Fetch()) {
             if (defined('BX_COMP_MANAGED_CACHE')) {
                 $GLOBALS['CACHE_MANAGER']->StartTagCache($dir);
                 $GLOBALS['CACHE_MANAGER']->RegisterTag('iblock_id_' . $result['IBLOCK_ID']);
             }
             $result = $result['NAME'];
             if (defined('BX_COMP_MANAGED_CACHE')) {
                 $GLOBALS['CACHE_MANAGER']->EndTagCache();
             }
         }
         $obCache->EndDataCache($result);
     }
     return $result;
 }