/** * Set the opening times to null if nothing was set * @param DataContainer $dc */ public function clearOpeningTimes(DataContainer $dc) { $arrOpeningTimes = deserialize($dc->activeRecord->opening_times); if (empty($arrOpeningTimes[0]['from']) && empty($arrOpeningTimes[0]['isClosed'])) { $objStore = AnyStoresModel::findByPk($dc->id); $objStore->opening_times = null; $objStore->save(); } }
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'); }