Example #1
0
 protected function identifyLinkType(&$items)
 {
     if ($this->filterBySite && is_array($items) && !empty($items)) {
         try {
             $linkTypeMap = Location\SiteLocationTable::getLinkStatusForMultipleNodes($items, $this->arParams['FILTER_SITE_ID'], $this->dbResult['TEMP']['CONNECTORS']);
             foreach ($linkTypeMap as $id => $linkType) {
                 $items[$id]['LINK_TYPE'] = $linkType;
             }
         } catch (\Bitrix\Main\ArgumentException $e) {
             LocationHelper::informAdminLocationDatabaseFailure();
             foreach ($items as $id => &$item) {
                 $items['LINK_TYPE'] = Location\SiteLocationTable::LSTAT_IN_NOT_CONNECTED_BRANCH;
             }
         }
     }
 }
Example #2
0
 protected function obtainDataConnectors()
 {
     if (!$this->arParams['LINK_ENTITY_NAME']) {
         $this->errors['FATAL'][] = Loc::getMessage('SALE_SLSS_LINK_ENTITY_NAME_NOT_SET');
         return;
     }
     $class = $this->entityClass;
     $parameters = array('select' => array('ID', 'CODE', 'LEFT_MARGIN', 'RIGHT_MARGIN', 'SORT', 'TYPE_ID', 'LNAME' => 'NAME.NAME'), 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID));
     $linkFld = $this->useCodes ? 'CODE' : 'ID';
     $res = false;
     $points = array();
     // get locations to display
     if ($this->locationsFromRequest !== false) {
         // get from request when form save fails or smth
         $res = self::getEntityListByListOfPrimary(self::LOCATION_ENTITY_NAME, $this->locationsFromRequest, $parameters, $linkFld);
     } elseif (strlen($this->arParams['ENTITY_PRIMARY'])) {
         // get from database, if entity exists
         $res = $class::getConnectedLocations($this->arParams['ENTITY_PRIMARY'], $parameters);
     }
     if ($res !== false) {
         $res->addReplacedAliases(array('LNAME' => 'NAME'));
         while ($item = $res->fetch()) {
             $points[$item['ID']] = $item;
         }
     }
     if (!empty($points)) {
         // same algorythm repeated on client side - fetch PATH for only visible items
         if (count($points) - static::PAGE_SIZE > static::HUGE_TAIL_LEN) {
             $pointsToGetPath = array_slice($points, 0, static::PAGE_SIZE);
         } else {
             $pointsToGetPath = $points;
         }
         try {
             $res = Location\LocationTable::getPathToMultipleNodes($pointsToGetPath, array('select' => array('LNAME' => 'NAME.NAME'), 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)));
             while ($item = $res->Fetch()) {
                 $item['ID'] = intval($item['ID']);
                 if (!is_array($item['PATH']) || empty($item['PATH'])) {
                     // we got empty PATH. This is not a normal case, item without a path is not sutable for displaying. Skip.
                     unset($points[$item['ID']]);
                 } else {
                     foreach ($item['PATH'] as &$node) {
                         $node['NAME'] = $node['LNAME'];
                         unset($node['LNAME']);
                     }
                     $points[$item['ID']]['PATH'] = $item['PATH'];
                 }
             }
         } catch (\Bitrix\Main\ArgumentException $e) {
             LocationHelper::informAdminLocationDatabaseFailure();
         }
         // clean up some fields
         foreach ($points as $i => &$location) {
             unset($location['LEFT_MARGIN']);
             // system fields should not figure in $arResult
             unset($location['RIGHT_MARGIN']);
             // same
         }
         unset($location);
     }
     $this->dbResult['CONNECTIONS']['LOCATION'] = $points;
     if ($this->useGroups) {
         $parameters = array('select' => array('ID', 'CODE', 'LNAME' => 'NAME.NAME'), 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID));
         $res = false;
         $points = array();
         if ($this->groupsFromRequest !== false) {
             $res = self::getEntityListByListOfPrimary('Bitrix\\Sale\\Location\\GroupTable', $this->groupsFromRequest, $parameters, $linkFld);
         } elseif (strlen($this->arParams['ENTITY_PRIMARY'])) {
             $res = $class::getConnectedGroups($this->arParams['ENTITY_PRIMARY'], $parameters);
         }
         if ($res !== false) {
             $res->addReplacedAliases(array('LNAME' => 'NAME'));
             while ($item = $res->fetch()) {
                 $item['ID'] = intval($item['ID']);
                 $points[$item['ID']] = $item;
             }
         }
         $this->dbResult['CONNECTIONS']['GROUP'] = $points;
     }
 }
Example #3
0
 protected static function getPathToNodesV2($list, $parameters = array())
 {
     $select = static::getPathNodesSelect();
     if (is_array($parameters['select'])) {
         $select = $parameters['select'];
         // orm wont return a correct result in case of array("ID", "VALUE" => "ID") select passed, so orm fix required
         unset($select['VALUE']);
         $select[] = 'ID';
     }
     $result = array('ITEM_NAMES' => array(), 'PATH_ITEMS' => array());
     try {
         $res = Location\LocationTable::getPathToMultipleNodes($list, array('select' => $select, 'filter' => array('=NAME.LANGUAGE_ID' => (string) $parameters['filter']['=NAME.LANGUAGE_ID'] != '' ? $parameters['filter']['=NAME.LANGUAGE_ID'] : LANGUAGE_ID)));
     } catch (\Bitrix\Main\ArgumentException $e) {
         LocationHelper::informAdminLocationDatabaseFailure();
         return $result;
     }
     $pathItems = array();
     while ($path = $res->fetch()) {
         // format path as required for JSON responce
         $chain = array();
         $itemId = false;
         $i = -1;
         foreach ($path['PATH'] as $id => $pItem) {
             $i++;
             if (!$i) {
                 $itemId = $id;
                 $result['ITEM_NAMES'][$id] = $pItem['DISPLAY'];
                 continue;
             }
             // orm fix, return everything back
             if (isset($pItem['ID'])) {
                 $pItem['VALUE'] = intval($pItem['ID']);
             }
             $chain[] = intval($pItem['VALUE']);
             $id = $pItem['VALUE'];
             unset($pItem['ID']);
             $pathItems[$id] = $pItem;
         }
         $result['PATH'][$itemId] = $chain;
     }
     $result['PATH_ITEMS'] = $pathItems;
     return $result;
 }