Esempio n. 1
0
 /**
  * @return array
  * @throws \Bitrix\Main\ArgumentException
  */
 protected function getLocationGroups()
 {
     $result = array();
     $res = GroupTable::getList(array('select' => array('ID', 'CODE', 'LNAME' => 'NAME.NAME'), 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)));
     while ($group = $res->fetch()) {
         $result[$group['ID']] = $group['LNAME'];
     }
     return $result;
 }
Esempio n. 2
0
 protected function obtainDataGroups(&$cachedData)
 {
     $groups = array();
     if ($this->useGroups) {
         $res = Location\GroupTable::getList(array('select' => array('ID', 'CODE', 'LNAME' => 'NAME.NAME'), 'filter' => array('NAME.LANGUAGE_ID' => LANGUAGE_ID)));
         $res->addReplacedAliases(array('LNAME' => 'NAME'));
         while ($item = $res->fetch()) {
             $item['ID'] = intval($item['ID']);
             $groups[$item['ID']] = $item;
         }
     }
     $cachedData['GROUPS'] = $groups;
 }
Esempio n. 3
0
 public static function getGroupUsage()
 {
     $isUsing = !!GroupTable::getList(array('limit' => 1, 'select' => array('ID')))->fetch();
     Config\Option::set("sale", self::PROJECT_USES_GROUPS_OPT, $isUsing ? 'Y' : 'N', '');
     return $isUsing;
 }
Esempio n. 4
0
 public function getStatistics($type = 'TOTAL')
 {
     if (empty($this->stat)) {
         $types = \Bitrix\Sale\Location\Admin\TypeHelper::getTypes(array('LANGUAGE_ID' => $this->getLanguageId()));
         $res = Location\LocationTable::getList(array('select' => array('CNT', 'TCODE' => 'TYPE.CODE'), 'group' => array('TYPE_ID')));
         $total = 0;
         $stat = array();
         while ($item = $res->fetch()) {
             $total += intval($item['CNT']);
             $stat[$item['TCODE']] = $item['CNT'];
         }
         foreach ($types as $code => $data) {
             $this->stat[$code] = array('NAME' => $data['NAME_CURRENT'], 'CODE' => $code, 'CNT' => isset($stat[$code]) ? intval($stat[$code]) : 0);
         }
         $this->stat['TOTAL'] = array('CNT' => $total, 'CODE' => 'TOTAL');
         $res = Location\GroupTable::getList(array('runtime' => array('CNT' => array('data_type' => 'integer', 'expression' => array('COUNT(*)'))), 'select' => array('CNT')))->fetch();
         $this->stat['GROUPS'] = array('CNT' => intval($res['CNT']), 'CODE' => 'GROUPS');
     }
     return intval($this->stat[$type]['CNT']);
 }
Esempio n. 5
0
 /**
  * <p>Метод удаляет все местоположения из базы. Метод динамичный.</p> <br><br>
  *
  *
  * @return mixed 
  *
  * @static
  * @link http://dev.1c-bitrix.ru/api_help/sale/classes/csalelocation/csalelocation__deleteall.1cda6559.php
  * @author Bitrix
  */
 public static function DeleteAll()
 {
     global $DB;
     foreach (GetModuleEvents("sale", "OnBeforeLocationDeleteAll", true) as $arEvent) {
         if (ExecuteModuleEventEx($arEvent) === false) {
             return false;
         }
     }
     if (self::isLocationProMigrated()) {
         //main
         $DB->Query("DELETE FROM " . Location\LocationTable::getTableName());
         $DB->Query("DELETE FROM " . Location\GroupTable::getTableName());
         $DB->Query("DELETE FROM " . Location\TypeTable::getTableName());
         //names
         $DB->Query("DELETE FROM " . Location\Name\LocationTable::getTableName());
         $DB->Query("DELETE FROM " . Location\Name\GroupTable::getTableName());
         $DB->Query("DELETE FROM " . Location\Name\TypeTable::getTableName());
         //links
         $DB->Query("DELETE FROM " . Location\GroupLocationTable::getTableName());
         $DB->Query("DELETE FROM " . Location\SiteLocationTable::getTableName());
         $DB->Query("DELETE FROM " . Delivery\DeliveryLocationTable::getTableName());
         //other
         $DB->Query("DELETE FROM " . Location\DefaultSiteTable::getTableName());
         $DB->Query("DELETE FROM " . Location\ExternalTable::getTableName());
         $DB->Query("DELETE FROM " . Location\ExternalServiceTable::getTableName());
     }
     $DB->Query("DELETE FROM b_sale_location2location_group");
     $DB->Query("DELETE FROM b_sale_location_group_lang");
     $DB->Query("DELETE FROM b_sale_location_group");
     $DB->Query("DELETE FROM b_sale_delivery2location");
     $DB->Query("DELETE FROM b_sale_location");
     $DB->Query("DELETE FROM b_sale_location_city_lang");
     $DB->Query("DELETE FROM b_sale_location_city");
     $DB->Query("DELETE FROM b_sale_location_country_lang");
     $DB->Query("DELETE FROM b_sale_location_country");
     $DB->Query("DELETE FROM b_sale_location_region_lang");
     $DB->Query("DELETE FROM b_sale_location_region");
     $DB->Query("DELETE FROM b_sale_location_zip");
     foreach (GetModuleEvents("sale", "OnLocationDeleteAll", true) as $arEvent) {
         ExecuteModuleEventEx($arEvent);
     }
 }
Esempio n. 6
0
 public static function resetLocationsForEntity($entityId, $locations, $entityName, $expectCodes = false)
 {
     $locList = array();
     if (is_array($locations) && !empty($locations)) {
         foreach ($locations as $loc) {
             if ($loc['LOCATION_TYPE'] == 'L') {
                 $locList[Location\Connector::DB_LOCATION_FLAG][] = $loc['LOCATION_ID'];
             } elseif ($loc['LOCATION_TYPE'] == 'G') {
                 $locList[Location\Connector::DB_GROUP_FLAG][] = $loc['LOCATION_ID'];
             }
         }
     }
     $entityClass = $entityName . 'Table';
     try {
         if (!empty($locList) && !$expectCodes) {
             $locList[Location\Connector::DB_LOCATION_FLAG] = $entityClass::normalizeLocationList($locList[Location\Connector::DB_LOCATION_FLAG]);
             $gf = Location\Connector::DB_GROUP_FLAG;
             if (!empty($locList[$gf])) {
                 $groupCodes = array();
                 $locList[$gf] = array_flip($locList[$gf]);
                 // here we must get codes by ids for groups. There will be no thousands of groups, so we can do the following:
                 $res = Location\GroupTable::getList(array('select' => array('ID', 'CODE')));
                 while ($item = $res->fetch()) {
                     if (isset($locList[$gf][$item['ID']])) {
                         $groupCodes[$item['CODE']] = 1;
                     }
                 }
                 $locList[$gf] = array_keys($groupCodes);
             }
         }
         $entityClass::resetMultipleForOwner($entityId, $locList);
     } catch (Exception $e) {
     }
 }
Esempio n. 7
0
 protected static function getConnectedEntitiesByCondition($locationPrimary, $linkType = 'id', $parameters = array())
 {
     $useGroups = GroupTable::checkGroupUsage() && static::getUseGroups();
     // check if we have groups in project and entity uses groups
     $sql = static::getConnectedEntitiesQuery($locationPrimary, $linkType, $parameters);
     $res = static::queryPage($sql, $parameters['limit'], $parameters['offset']);
     return $res;
 }
	public function getStatistics($type = 'TOTAL')
	{
		if(empty($this->stat))
		{
			$types = $this->getTypes();

			$res = Location\LocationTable::getList(array(
				'runtime' => array(
					'CNT' => array(
						'data_type' => 'integer',
						'expression' => array(
							'COUNT(*)'
						)
					)
				),
				'select' => array(
					'CNT',
					'TCODE' => 'TYPE.CODE',
					'TNAME' => 'TYPE.NAME'
				),
				'filter' => array(
					'TYPE.NAME.LANGUAGE_ID' => LANGUAGE_ID
				),
				'group' => array(
					'TYPE_ID'
				)
			));
			$total = 0;
			$stat = array();
			while($item = $res->fetch())
			{
				$total += intval($item['CNT']);
				$stat[$item['TCODE']] = $item['CNT'];
			}

			foreach($types as $code => $name)
			{
				$this->stat[$code] = array(
					'NAME' => $name,
					'CODE' => $code,
					'CNT' => isset($stat[$code]) ? intval($stat[$code]) : 0,
				);
			}

			$this->stat['TOTAL'] = array('CNT' => $total, 'CODE' => 'TOTAL');

			$res = Location\GroupTable::getList(array(
				'runtime' => array(
					'CNT' => array(
						'data_type' => 'integer',
						'expression' => array(
							'COUNT(*)'
						)
					)
				),
				'select' => array(
					'CNT'
				)
			))->fetch();

			$this->stat['GROUPS'] = array('CNT' => intval($res['CNT']), 'CODE' => 'GROUPS');
		}

		return intval($this->stat[$type]['CNT']);
	}
Esempio n. 9
0
 function Add($arFields)
 {
     global $DB;
     if (!CSaleLocationGroup::CheckFields("ADD", $arFields)) {
         return false;
     }
     // make IX_B_SALE_LOC_GROUP_CODE feel happy
     $arFields['CODE'] = 'randstr' . rand(999, 999999);
     $db_events = GetModuleEvents("sale", "OnBeforeLocationGroupAdd");
     while ($arEvent = $db_events->Fetch()) {
         if (ExecuteModuleEventEx($arEvent, array($arFields)) === false) {
             return false;
         }
     }
     $arInsert = $DB->PrepareInsert("b_sale_location_group", $arFields);
     $strSql = "INSERT INTO b_sale_location_group(" . $arInsert[0] . ") " . "VALUES(" . $arInsert[1] . ")";
     $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     $ID = IntVal($DB->LastID());
     // make IX_B_SALE_LOC_CODE feel happy
     Location\GroupTable::update($ID, array('CODE' => $ID));
     $countFieldLang = count($arFields["LANG"]);
     for ($i = 0; $i < $countFieldLang; $i++) {
         $arInsert = $DB->PrepareInsert("b_sale_location_group_lang", $arFields["LANG"][$i]);
         $strSql = "INSERT INTO b_sale_location_group_lang(LOCATION_GROUP_ID, " . $arInsert[0] . ") " . "VALUES(" . $ID . ", " . $arInsert[1] . ")";
         $DB->Query($strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
     }
     if (CSaleLocation::isLocationProMigrated()) {
         try {
             $entityClass = self::CONN_ENTITY_NAME . 'Table';
             $entityClass::resetMultipleForOwner($ID, array(Location\Connector::DB_LOCATION_FLAG => $entityClass::normalizeLocationList($arFields["LOCATION_ID"])));
         } catch (Exception $e) {
         }
     } else {
         $strSqlHead = "INSERT INTO b_sale_location2location_group (LOCATION_ID, LOCATION_GROUP_ID) VALUES ";
         $strSqlHeadLength = strlen($strSqlHead);
         $res = $DB->Query('SHOW VARIABLES LIKE \'max_allowed_packet\'');
         $maxPack = $res->Fetch();
         if (isset($maxPack["Value"])) {
             $max_allowed_packet = $maxPack["Value"] - $strSqlHeadLength - 100;
         } else {
             $max_allowed_packet = 0;
         }
         $tmpSql = '';
         $strSql = '';
         $countFieldLoc = count($arFields["LOCATION_ID"]);
         for ($i = 0; $i < $countFieldLoc; $i++) {
             $tmpSql = "(" . $arFields["LOCATION_ID"][$i] . ", " . $ID . ")";
             $strSqlLen = strlen($strSql);
             if ($strSqlHeadLength + $strSqlLen + strlen($tmpSql) < $max_allowed_packet || $max_allowed_packet <= 0) {
                 if ($strSqlLen > 0) {
                     $strSql .= ",";
                 }
                 $strSql .= $tmpSql;
             } else {
                 $DB->Query($strSqlHead . $strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
                 $strSql = $tmpSql;
             }
         }
         if (strlen($strSql) > 0) {
             $DB->Query($strSqlHead . $strSql, false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
         }
     }
     $events = GetModuleEvents("sale", "OnLocationGroupAdd");
     while ($arEvent = $events->Fetch()) {
         ExecuteModuleEventEx($arEvent, array($ID, $arFields));
     }
     return $ID;
 }