199 lines
5.6 KiB
PHP
199 lines
5.6 KiB
PHP
<?php
|
|
/**
|
|
* SOTESHOP/stWebpagePlugin
|
|
*
|
|
* Ten plik należy do aplikacji stWebpagePlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stWebpagePlugin
|
|
* @subpackage libs
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
|
* @version $Id: WebpagePeer.php 16781 2012-01-19 08:48:13Z michal $
|
|
* @author Krzysztof Bebło <krzysztof.beblo@sote.pl>
|
|
*/
|
|
|
|
/**
|
|
* Klasa WebpagePeer
|
|
*
|
|
* @package stWebpagePlugin
|
|
* @subpackage libs
|
|
*/
|
|
class WebpagePeer extends BaseWebpagePeer
|
|
{
|
|
protected static $urlPool = array();
|
|
|
|
protected static $states = null;
|
|
|
|
public static function getStates(?sfI18N $i18n = null)
|
|
{
|
|
if (null === self::$states)
|
|
{
|
|
if (null === $i18n)
|
|
{
|
|
$i18n = sfContext::getInstance()->getI18N();
|
|
}
|
|
|
|
$states = [
|
|
'PRIVACY' => $i18n->__('Polityka prywatności'),
|
|
'TERMS' => $i18n->__('Regulamin'),
|
|
'SHIPPING' => $i18n->__('Informacje o wysyłce'),
|
|
'RIGHT2CANCEL' => $i18n->__('Prawo do odstąpienia od umowy'),
|
|
'CONTACT' => $i18n->__('Kontakt'),
|
|
];
|
|
|
|
$results = stEventDispatcher::getInstance()->filter(new sfEvent(null, 'WebpagePeer.filterStates', ['i18n' => $i18n]), $states)->getReturnValue();
|
|
|
|
if (null !== $results)
|
|
{
|
|
$states = $results;
|
|
}
|
|
|
|
self::$states = $states;
|
|
}
|
|
|
|
return self::$states;
|
|
}
|
|
|
|
public static function retrieveByUrl($url)
|
|
{
|
|
if (!isset(self::$urlPool[$url]) && !array_key_exists($url, self::$urlPool))
|
|
{
|
|
$c = new Criteria();
|
|
$c->addSelectColumn(WebpageI18nPeer::ID);
|
|
$c->add(WebpageI18nPeer::URL, $url);
|
|
$c->setLimit(1);
|
|
$rs = WebpageI18nPeer::doSelectRS($c);
|
|
|
|
if ($rs->next())
|
|
{
|
|
$row = $rs->getRow();
|
|
$c = new Criteria();
|
|
$c->add(self::ID, $row[0]);
|
|
$c->setLimit(1);
|
|
$tmp = self::doSelectWithI18n($c);
|
|
self::$urlPool[$url] = $tmp ? $tmp[0] : null;
|
|
}
|
|
}
|
|
|
|
return self::$urlPool[$url];
|
|
}
|
|
|
|
/**
|
|
* Przeciążenie metody pobierającej strony www w odpowiedniej wersji jezykowej
|
|
*
|
|
* @param Criteria $c Kryteria
|
|
* @param mixed $culture Wersja językowa
|
|
* @param CreoleConnection $con Połączenie z bazą danych
|
|
* @return array Produkty
|
|
*/
|
|
public static function doSelectWithI18n(Criteria $c, $culture = null, $con = null)
|
|
{
|
|
if ($culture === null)
|
|
{
|
|
$culture = stLanguage::getHydrateCulture();
|
|
}
|
|
|
|
return parent::doSelectWithI18n($c, $culture, $con);
|
|
}
|
|
|
|
|
|
public static function doCountWithI18n(Criteria $c, $con = null)
|
|
{
|
|
$c = clone $c;
|
|
|
|
$c->addJoin(WebpageI18nPeer::ID, WebpagePeer::ID);
|
|
|
|
$c->add(WebpageI18nPeer::CULTURE, stLanguage::getHydrateCulture());
|
|
|
|
return self::doCount($c, $con);
|
|
}
|
|
|
|
/**
|
|
* Zwraca strone o podanym typie
|
|
*
|
|
* @param string $state Typ strony
|
|
* @param bool $createIfMissing Tworzy nową stronę w przypadku jej braku
|
|
* @return Webpage
|
|
* @throws PropelException
|
|
*/
|
|
public static function retrieveByState(string $state, bool $createIfMissing = false)
|
|
{
|
|
$c = new Criteria();
|
|
$c->add(self::STATE, $state);
|
|
$webpage = self::doSelectOne($c);
|
|
|
|
$states = self::getStates();
|
|
|
|
if ($createIfMissing && !isset($states[$state]))
|
|
{
|
|
throw new PropelException(sprintf('State %s does not exist', $state));
|
|
}
|
|
|
|
if (null === $webpage)
|
|
{
|
|
$webpage = new Webpage();
|
|
$webpage->setActive(true);
|
|
$webpage->setCulture(stLanguage::getOptLanguage());
|
|
$webpage->setName($states[$state]);
|
|
$webpage->setState($state);
|
|
$webpage->setContent('Lorem ipsum');
|
|
$webpage->save();
|
|
}
|
|
|
|
return $webpage;
|
|
}
|
|
|
|
public static function getPrivacyWebpage()
|
|
{
|
|
return self::retrieveByState("PRIVACY");
|
|
}
|
|
|
|
public static function getTermsWebpage()
|
|
{
|
|
return self::retrieveByState("TERMS");
|
|
}
|
|
|
|
public static function getShippingWebpage()
|
|
{
|
|
return self::retrieveByState("SHIPPING");
|
|
}
|
|
|
|
public static function getRight2CancelWebpage()
|
|
{
|
|
return self::retrieveByState("RIGHT2CANCEL");
|
|
}
|
|
|
|
public static function getContactWebpage()
|
|
{
|
|
return self::retrieveByState("CONTACT");
|
|
}
|
|
|
|
public static function getAppTermsWebpage()
|
|
{
|
|
return self::retrieveByState("APP_TERMS");
|
|
}
|
|
|
|
public static function getAppPrivacyWebpage()
|
|
{
|
|
return self::retrieveByState("APP_PRIVACY");
|
|
}
|
|
|
|
public static function getAppRight2cancelWebpage()
|
|
{
|
|
return self::retrieveByState("APP_RIGHT2CANCEL");
|
|
}
|
|
|
|
public static function clearCache()
|
|
{
|
|
if (sfContext::hasInstance())
|
|
{
|
|
stPartialCache::clear('stWebpageFrontend', '_footerWebpage', array('app' => 'frontend'));
|
|
stPartialCache::clear('stWebpageFrontend', '_headerWebpage', array('app' => 'frontend'));
|
|
}
|
|
}
|
|
|
|
}
|