Exemplo 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;
 }
Exemplo 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;
 }
Exemplo 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;
 }
Exemplo 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']);
 }
Exemplo n.º 5
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) {
     }
 }
Exemplo n.º 6
0
 /**
  * Returns a set of location groups that connected with a given entity.
  *
  * @param mixed $entityPrimary primary key for an entity
  * @param mixed[] $parameters for ORM getList()
  *
  * @throws ArgumentNullException
  * @throws NotImplementedException
  *
  * @return Bitrix\Main\DB\Result list of locations
  */
 public static function getConnectedGroups($entityPrimary, $parameters = array())
 {
     $entityPrimary = Assert::expectStringNotNull($entityPrimary, Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_PRIMARY_FLD_NAME'));
     if (!static::getUseGroups()) {
         Assert::announceNotSupported(Loc::getMessage('SALE_LOCATION_CONNECTOR_ENTITY_DOESNT_SUPPORT_GROUPS'));
     }
     if (!is_array($parameters)) {
         $parameters = array();
     }
     $parameters['runtime']['C'] = array('data_type' => static::getEntity()->getFullName(), 'reference' => array('=ref.' . static::getLinkField() => array('?', $entityPrimary), '=ref.' . static::getTypeField() => array('?', 'G')), 'join_type' => 'inner');
     $parameters['runtime']['C']['reference']['=ref.' . static::getLocationLinkField()] = static::getConnectType() == self::LINK_CODE ? 'this.CODE' : 'this.ID';
     return GroupTable::getList($parameters);
 }
Exemplo n.º 7
0
	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']);
	}