first commit
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
<?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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user