Files
grzanieplus.pl/plugins/appAdsTrackerPlugin/modules/appAdsTrackerBackend/lib/appAdsTrackerValidator.class.php
2025-03-12 17:06:23 +01:00

64 lines
1.5 KiB
PHP

<?php
class appAdsTrackerValidator extends sfValidator
{
protected $regex = null;
public function execute(&$value, &$error)
{
if (empty($value))
{
$error = 'Podaj nazwę kampanii';
return false;
}
if (!$this->regex->execute($value, $error))
{
return false;
}
if (!$this->validateUnique($value, $error))
{
return false;
}
return true;
}
public function initialize($context, $parameters = array())
{
parent::initialize($context, $parameters);
$this->regex = new sfRegexValidator();
$this->regex->initialize($context, array('pattern' => '/["\']/', 'match' => false, 'match_error' => 'Kod produktu nie może zawierać znaków \' oraz "'));
return true;
}
protected function validateUnique($value, &$error)
{
$r = $this->getContext()->getRequest();
$c = new Criteria();
$c->add(AdsTrackerCampaignPeer::ADS_NAME, $value);
if ($this->getParameter('check_primary_key', true))
{
$c->add(AdsTrackerCampaignPeer::ID, $this->getParameter('primary_key', $r->getParameter(AdsTrackerCampaignPeer::translateFieldName('Id', BasePeer::TYPE_PHPNAME, BasePeer::TYPE_FIELDNAME))), Criteria::NOT_EQUAL);
}
if (AdsTrackerCampaignPeer::doCount($c))
{
$error = 'Ta nazwa kampanii jest już wykorzystywana. Podaj inną';
return false;
}
return true;
}
}