Ejemplo n.º 1
0
 /**
  * Adds a new location
  *
  * @param mixed[] $data to be added. Additional data keys could be passed:
  *
  *	<ul>
  *		<li>
  *			NAME string[] : add name string to a newly created location
  *		</li>
  *		<li>
  *			EXTERNAL string[] : add external data records to a newly created location
  *		</li>
  *	</ul>
  *
  * @param mixed[] $additional an additional behaviour flags:
  *
  *	<ul>
  *		<li>
  *			REBALANCE boolean (default: true) : do rebalance after add
  *		</li>
  *	</ul>
  *
  * @return \Bitrix\Main\Entity\AddResult the result of add operation
  */
 public static function addExtended(array $data, array $additional = array())
 {
     $resetLegacy = !isset($additional['RESET_LEGACY']) || $additional['RESET_LEGACY'] !== false;
     if (isset($data['EXTERNAL'])) {
         $external = $data['EXTERNAL'];
         unset($data['EXTERNAL']);
     }
     if (isset($data['NAME'])) {
         $name = $data['NAME'];
         unset($data['NAME']);
     }
     // force code to lowercase
     if (isset($data['CODE'])) {
         $data['CODE'] = ToLower($data['CODE']);
     }
     // you are not allowed to modify tree data over LocationTable::add()
     self::applyRestrictions($data);
     // store tree data and basic
     $addResult = parent::addExtended($data, $additional);
     // add connected data
     if ($addResult->isSuccess()) {
         $primary = $addResult->getId();
         // external
         if (isset($external)) {
             ExternalTable::addMultipleForOwner($primary, $external);
         }
         // names
         if (isset($name)) {
             Name\LocationTable::addMultipleForOwner($primary, $name);
         }
         if (intval($data['TYPE_ID']) > 0 && $resetLegacy) {
             self::resetLegacy(intval($data['TYPE_ID']));
         }
         Search\Finder::setIndexInvalid();
         $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data');
     }
     return $addResult;
 }
Ejemplo n.º 2
0
 /**
  * Adds a new location
  *
  * @param mixed[] $data to be added. Additional data keys could be passed:
  *
  *	<ul>
  *		<li>
  *			NAME string[] : add name string to a newly created location
  *		</li>
  *		<li>
  *			EXTERNAL string[] : add external data records to a newly created location
  *		</li>
  *	</ul>
  *
  * @param mixed[] $behaviour an additional behaviour flags:
  *
  *	<ul>
  *		<li>
  *			REBALANCE boolean (default: true) : do rebalance after add
  *		</li>
  *	</ul>
  *
  * @return Bitrix\Main\Entity\AddResult the result of add operation
  */
 public static function add($data = array(), $behaviour = array('REBALANCE' => true, 'RESET_LEGACY' => true))
 {
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['REBALANCE'])) {
         $behaviour['REBALANCE'] = true;
     }
     if (!isset($behaviour['RESET_LEGACY'])) {
         $behaviour['RESET_LEGACY'] = true;
     }
     if (isset($data['EXTERNAL'])) {
         $external = $data['EXTERNAL'];
         unset($data['EXTERNAL']);
     }
     if (isset($data['NAME'])) {
         $name = $data['NAME'];
         unset($data['NAME']);
     }
     // force code to lowercase
     if (isset($data['CODE'])) {
         $data['CODE'] = ToLower($data['CODE']);
     }
     // you are not allowed to modify tree data over LocationTable::add()
     self::applyRestrictions($data);
     // store tree data and basic
     $addResult = parent::add($data, $behaviour);
     // add connected data
     if ($addResult->isSuccess()) {
         $primary = $addResult->getId();
         // external
         if (isset($external)) {
             ExternalTable::addMultipleForOwner($primary, $external);
         }
         // names
         if (isset($name)) {
             Name\LocationTable::addMultipleForOwner($primary, $name);
         }
         if ($behaviour['RESET_LEGACY'] && intval($data['TYPE_ID'])) {
             $type = TypeTable::getList(array('filter' => array('=ID' => $data['TYPE_ID']), 'select' => array('CODE')))->fetch();
             if (strlen($type['CODE']) && in_array($type['CODE'], array('COUNTRY', 'REGION', 'CITY'))) {
                 static::resetLegacyPath();
             }
         }
         Search\Finder::setIndexInvalid();
         $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data');
     }
     return $addResult;
 }
Ejemplo n.º 3
0
 /**
  * Adds a new location
  *
  * @param mixed[] $data to be added. Additional data keys could be passed:
  *
  *	<ul>
  *		<li>
  *			NAME string[] : add name string to a newly created location
  *		</li>
  *		<li>
  *			EXTERNAL string[] : add external data records to a newly created location
  *		</li>
  *	</ul>
  *
  * @param mixed[] $behaviour an additional behaviour flags:
  *
  *	<ul>
  *		<li>
  *			REBALANCE boolean (default: true) : do rebalancing after add
  *		</li>
  *	</ul>
  *
  * @return Bitrix\Main\Entity\AddResult the result of add operation
  */
 public static function add($data = array(), $behaviour = array('REBALANCE' => true))
 {
     if (isset($data['EXTERNAL'])) {
         $external = $data['EXTERNAL'];
         unset($data['EXTERNAL']);
     }
     if (isset($data['NAME'])) {
         $name = $data['NAME'];
         unset($data['NAME']);
     }
     // force code to lowercase
     if (isset($data['CODE'])) {
         $data['CODE'] = ToLower($data['CODE']);
     }
     // you are not allowed to modify tree data over LocationTable::add()
     self::applyRestrictions($data);
     // store tree data and basic
     $addResult = parent::add($data, $behaviour);
     // add connected data
     if ($addResult->isSuccess()) {
         $primary = $addResult->getId();
         // external
         if (isset($external)) {
             ExternalTable::addMultipleForOwner($primary, $external);
         }
         // names
         if (isset($name)) {
             Name\LocationTable::addMultipleForOwner($primary, $name);
         }
     }
     $GLOBALS['CACHE_MANAGER']->ClearByTag('sale-location-data');
     return $addResult;
 }