Example #1
0
 /**
  * Drops all related to index database structures.
  *
  * @param integer $iblockId Information block identifier.
  *
  * @return void
  * @throws \Bitrix\Main\Db\SqlQueryException
  */
 public static function dropIfExists($iblockId)
 {
     $storage = new Storage($iblockId);
     if ($storage->isExists()) {
         $storage->drop();
     }
     $dictionary = new Dictionary($iblockId);
     if ($dictionary->isExists()) {
         $dictionary->drop();
     }
 }
Example #2
0
 /**
  * Returns all relevant information for the element in section context.
  *
  * @param Element $element Loaded from the database element information.
  *
  * @return array
  */
 protected function getSectionIndexEntries(Element $element)
 {
     $result = array(1 => array(array("VALUE" => 0, "VALUE_NUM" => 0.0)));
     foreach ($this->getFilterProperty(Storage::DICTIONARY) as $propertyId) {
         $facetId = $this->storage->propertyIdToFacetId($propertyId);
         $result[$facetId] = array();
         $propertyValues = $element->getPropertyValues($propertyId);
         foreach ($propertyValues as $value) {
             $value = intval($value);
             $result[$facetId][$value] = array("VALUE" => $value, "VALUE_NUM" => 0.0);
         }
     }
     foreach ($this->getFilterProperty(Storage::STRING) as $propertyId) {
         $facetId = $this->storage->propertyIdToFacetId($propertyId);
         $result[$facetId] = array();
         $propertyValues = $element->getPropertyValues($propertyId);
         foreach ($propertyValues as $value) {
             $valueId = $this->dictionary->getStringId($value);
             $result[$facetId][$valueId] = array("VALUE" => $valueId, "VALUE_NUM" => 0.0);
         }
     }
     foreach ($this->getFilterProperty(Storage::NUMERIC) as $propertyId) {
         $facetId = $this->storage->propertyIdToFacetId($propertyId);
         $result[$facetId] = array();
         $propertyValues = $element->getPropertyValues($propertyId);
         foreach ($propertyValues as $value) {
             $value = doubleval($value);
             $result[$facetId][md5($value)] = array("VALUE" => 0, "VALUE_NUM" => $value);
         }
     }
     foreach ($this->getFilterProperty(Storage::DATETIME) as $propertyId) {
         $facetId = $this->storage->propertyIdToFacetId($propertyId);
         $result[$facetId] = array();
         $propertyValues = $element->getPropertyValues($propertyId);
         foreach ($propertyValues as $value) {
             //Save date only based on server time.
             $timestamp = MakeTimeStamp($value, "YYYY-MM-DD HH:MI:SS");
             $value = date('Y-m-d', $timestamp);
             $timestamp = MakeTimeStamp($value, "YYYY-MM-DD");
             $valueId = $this->dictionary->getStringId($value);
             $result[$facetId][$valueId] = array("VALUE" => $valueId, "VALUE_NUM" => $timestamp);
         }
     }
     foreach ($this->getFilterPrices() as $priceId) {
         $facetId = $this->storage->priceIdToFacetId($priceId);
         $result[$facetId] = array();
         $elementPrices = $element->getPriceValues($priceId);
         if ($elementPrices) {
             foreach ($elementPrices as $currency => $priceValues) {
                 $currencyId = $this->dictionary->getStringId($currency);
                 foreach ($priceValues as $price) {
                     $result[$facetId][$currencyId . ":" . $price] = array("VALUE" => $currencyId, "VALUE_NUM" => $price);
                 }
             }
         }
     }
     return array_filter($result, "count");
 }
Example #3
0
 /**
  * When called subsequent queries will use currency conversion for filtering.
  * Works only with 'currency' module installed.
  *
  * @param string $toCurrencyId Valid currency id for price value passed into addPriceFilter method.
  * @param array $convertCurrencyId Array of valid currencies ids.
  *
  * @return void
  */
 public function enableCurrencyConversion($toCurrencyId, array $convertCurrencyId)
 {
     if (\Bitrix\Main\Loader::includeModule('currency')) {
         $this->toCurrencyId = $toCurrencyId;
         $this->convertCurrencyId = array();
         foreach ($convertCurrencyId as $currency) {
             $currencyDictionaryId = $this->dictionary->getStringId($currency, false);
             if ($currency) {
                 $this->convertCurrencyId[$currency] = $currencyDictionaryId;
             }
         }
     }
 }
Example #4
0
 /**
  * Returns all relevant information for the element in section context.
  *
  * @param Element $element Loaded from the database element information.
  * @param integer $sectionId Section identifier.
  *
  * @return array
  */
 protected function getSectionIndexEntries(Element $element, $sectionId)
 {
     $result = array(1 => array(array("VALUE" => 0, "VALUE_NUM" => 0.0)));
     foreach ($this->getFilterProperty(Storage::DICTIONARY) as $propertyId) {
         $facetId = $this->storage->propertyIdToFacetId($propertyId);
         $result[$facetId] = array();
         $propertyValues = $element->getPropertyValues($propertyId);
         foreach ($propertyValues as $value) {
             $value = intval($value);
             $result[$facetId][$value] = array("VALUE" => $value, "VALUE_NUM" => 0.0);
         }
     }
     foreach ($this->getFilterProperty(Storage::STRING) as $propertyId) {
         $facetId = $this->storage->propertyIdToFacetId($propertyId);
         $result[$facetId] = array();
         $propertyValues = $element->getPropertyValues($propertyId);
         foreach ($propertyValues as $value) {
             $valueId = $this->dictionary->getStringId($value);
             $result[$facetId][$valueId] = array("VALUE" => $valueId, "VALUE_NUM" => 0.0);
         }
     }
     foreach ($this->getFilterProperty(Storage::NUMERIC) as $propertyId) {
         $facetId = $this->storage->propertyIdToFacetId($propertyId);
         $result[$facetId] = array();
         $propertyValues = $element->getPropertyValues($propertyId);
         foreach ($propertyValues as $value) {
             $value = doubleval($value);
             $result[$facetId][md5($value)] = array("VALUE" => 0, "VALUE_NUM" => $value);
         }
     }
     foreach ($this->getFilterPrices($sectionId) as $priceId) {
         $facetId = $this->storage->priceIdToFacetId($priceId);
         $result[$facetId] = array();
         $elementPrices = $element->getPriceValues($priceId);
         if ($elementPrices) {
             foreach ($elementPrices as $currency => $priceValues) {
                 $currencyId = $this->dictionary->getStringId($currency);
                 foreach ($priceValues as $price) {
                     $result[$facetId][$currencyId . ":" . $price] = array("VALUE" => $currencyId, "VALUE_NUM" => $price);
                 }
             }
         }
     }
     return array_filter($result, "count");
 }
Example #5
0
 /**
  * Returns array on integers representing values for sql query.
  *
  * @param mixed $value Value to be intvaled.
  * @param boolean $lookup Whenever to convert the value from string to dictionary or not.
  *
  * @return integer[]
  */
 protected function getInSql($value, $lookup)
 {
     $result = array();
     if (is_array($value)) {
         foreach ($value as $val) {
             if (strlen($val) > 0) {
                 if ($lookup) {
                     $result[] = $this->dictionary->getStringId($val, false);
                 } else {
                     $result[] = intval($val);
                 }
             }
         }
     } elseif (strlen($value) > 0) {
         if ($lookup) {
             $result[] = $this->dictionary->getStringId($value, false);
         } else {
             $result[] = intval($value);
         }
     }
     return $result;
 }
Example #6
0
 /**
  * Returns string by its identifier in the dictionary.
  *
  * @param integer $valueId Value identifier for dictionary lookup.
  *
  * @return string
  */
 public function lookupDictionaryValue($valueId)
 {
     return $this->dictionary->getStringById($valueId);
 }