/**
  * {@inheritdoc}
  */
 protected static function buildFindQuery(array $arrOptions)
 {
     $arrOptions['group'] = ($arrOptions['group'] ? $arrOptions['group'] . ', ' : '') . 'tl_iso_product_price.id';
     $query = \Model\QueryBuilder::find($arrOptions);
     $from = substr($query, strpos($query, '*') + 1);
     $query = "SELECT tl_iso_product_price.*, GROUP_CONCAT(tl_iso_product_pricetier.min) AS tier_keys, GROUP_CONCAT(tl_iso_product_pricetier.price) AS tier_values" . $from;
     $query = str_replace('FROM tl_iso_product_price', 'FROM tl_iso_product_price LEFT JOIN tl_iso_product_pricetier ON tl_iso_product_pricetier.pid = tl_iso_product_price.id', $query);
     return $query;
 }
Example #2
0
 /**
  * Build a query based on the given options to count the number of records
  *
  * @param array $arrOptions The options array
  *
  * @return string The query string
  */
 protected static function buildCountQuery(array $arrOptions)
 {
     return \Model\QueryBuilder::count($arrOptions);
 }
Example #3
0
 /**
  * Return the number of records matching certain criteria
  * 
  * @param mixed $strColumn An optional property name
  * @param mixed $varValue  An optional property value
  * 
  * @return integer The number of matching rows
  */
 public static function countBy($strColumn = null, $varValue = null)
 {
     if (static::$strTable == '') {
         return 0;
     }
     $strQuery = \Model\QueryBuilder::count(array('table' => static::$strTable, 'column' => $strColumn, 'value' => $varValue));
     return \Database::getInstance()->prepare($strQuery)->execute($varValue)->count;
 }
Example #4
0
 /**
  * Find records and return the model or model collection
  *
  * Supported options:
  *
  * * column: the field name
  * * value:  the field value
  * * limit:  the maximum number of rows
  * * offset: the number of rows to skip
  * * order:  the sorting order
  * * eager:  load all related records eagerly
  *
  * @param array $arrOptions The options array
  *
  * @return \Model|\Model\Collection|null A model, model collection or null if the result is empty
  */
 protected static function find(array $arrOptions)
 {
     if (static::$strTable == '') {
         return null;
     }
     $arrOptions['table'] = static::$strTable;
     $strQuery = \Model\QueryBuilder::find($arrOptions);
     $objStatement = \Database::getInstance()->prepare($strQuery);
     // Defaults for limit and offset
     if (!isset($arrOptions['limit'])) {
         $arrOptions['limit'] = 0;
     }
     if (!isset($arrOptions['offset'])) {
         $arrOptions['offset'] = 0;
     }
     // Limit
     if ($arrOptions['limit'] > 0 || $arrOptions['offset'] > 0) {
         $objStatement->limit($arrOptions['limit'], $arrOptions['offset']);
     }
     $objStatement = static::preFind($objStatement);
     $objResult = $objStatement->execute($arrOptions['value']);
     if ($objResult->numRows < 1) {
         return null;
     }
     $objResult = static::postFind($objResult);
     if ($arrOptions['return'] == 'Model') {
         $strPk = static::$strPk;
         $intPk = $objResult->{$strPk};
         // Try to load from the registry
         $objModel = \Model\Registry::getInstance()->fetch(static::$strTable, $intPk);
         if ($objModel !== null) {
             return $objModel->mergeRow($objResult->row());
         }
         return new static($objResult);
     } else {
         return \Isotope\Collection\ProductPrice::createFromDbResult($objResult, static::$strTable);
     }
 }
Example #5
0
 public static function findPublishedByAdressAndCountryAndCategory($strSearch, $strCountry = null, array $arrCategories, $intLimit = null, $intMaxDistance = null)
 {
     $t = static::$strTable;
     $arrCoordinates = AnyStores::getLonLat($strSearch, $strCountry);
     if (!$arrCoordinates) {
         \System::log("Can't find coordinates for '{$strSearch}'", __METHOD__, TL_ERROR);
         return;
     }
     $arrOptions = array('fields' => array("{$t}.id", "( 6371 * acos( cos( radians(?) ) * cos( radians( {$t}.latitude ) ) * cos( radians( {$t}.longitude ) - radians(?) ) + sin( radians(?) ) * sin( radians( {$t}.latitude ) ) ) ) AS distance"), 'table' => $t, 'column' => array("{$t}.pid IN(" . implode(',', array_map('intval', $arrCategories)) . ")", "({$t}.start='' OR {$t}.start<UNIX_TIMESTAMP()) AND ({$t}.stop='' OR {$t}.stop>UNIX_TIMESTAMP()) AND {$t}.published=1"), 'order' => "distance");
     // Country
     if ($strCountry) {
         $arrOptions['column'][] = "{$t}.country=?";
     }
     // Maximun distance
     if (is_numeric($intMaxDistance)) {
         $arrOptions['having'] = "distance < " . $intMaxDistance;
     }
     // Get query
     $strQuery = \Model\QueryBuilder::find($arrOptions);
     // replace * with additional fields
     $strQuery = preg_replace('/\\*/', implode(',', $arrOptions['fields']), $strQuery, 1);
     $objResult = \Database::getInstance()->prepare($strQuery)->limit($intLimit)->execute($arrCoordinates['latitude'], $arrCoordinates['longitude'], $arrCoordinates['latitude'], $strCountry ?: null);
     if (!$objResult->numRows) {
         \System::log("No results for '{$objResult->query}'", __METHOD__, TL_ERROR);
         return;
     }
     // Create store models from database result
     while ($objResult->next()) {
         $objModel = AnyStoresModel::findByPk($objResult->id);
         $objModel->distance = $objResult->distance;
         $objModel->preventSaving();
         $arrModels[] = $objModel;
     }
     // Return model collection
     return new \Model\Collection($arrModels, 'tl_anystores');
 }
Example #6
0
 /**
  * Get categories (pages) assigned to this product
  *
  * @param bool $blnPublished Only return published categories (pages)
  *
  * @return array
  */
 public function getCategories($blnPublished = false)
 {
     $key = $blnPublished ? 'published' : 'all';
     if (null === $this->arrCategories || !isset($this->arrCategories[$key])) {
         if ($blnPublished) {
             $options = ProductCategory::getFindByPidForPublishedPagesOptions($this->getProductId());
             $options['table'] = ProductCategory::getTable();
             $query = \Model\QueryBuilder::find($options);
             $values = (array) $options['value'];
         } else {
             $query = 'SELECT page_id FROM ' . ProductCategory::getTable() . ' WHERE pid=?';
             $values = array($this->getProductId());
         }
         $objCategories = \Database::getInstance()->prepare($query)->execute($values);
         $this->arrCategories[$key] = $objCategories->fetchEach('page_id');
         // Sort categories by the backend drag&drop
         $arrOrder = deserialize($this->orderPages);
         if (!empty($arrOrder) && is_array($arrOrder)) {
             $this->arrCategories[$key] = array_unique(array_merge(array_intersect($arrOrder, $this->arrCategories[$key]), $this->arrCategories[$key]));
         }
     }
     return $this->arrCategories[$key];
 }
Example #7
0
 /**
  * Build a query based on the given options
  * @param array $arrOptions The options array
  * @return string The query string
  * @deprecated this is only for BC with Contao 3.2
  */
 protected static function buildFindQuery(array $arrOptions)
 {
     if (version_compare(VERSION, '3.3', '<')) {
         return \Model\QueryBuilder::find($arrOptions);
     }
     return parent::buildFindQuery($arrOptions);
 }