price_actual))
$this->price_actual = $this->price_start;
}
public function preUpdate($event)
{
if (empty($this->price_actual))
$this->price_actual = $this->price_start;
if ($this->price_actual < $this->price_start)
{
$this->price_actual = $this->price_start;
}
elseif ($this->price_start < $this->price_actual)
{
// if (count($this->Bids) == 0) {
// $this->price_actual = $this->price_start;
// }
}
}
public function getFinalPrice()
{
if(!$this->getFinalBid())
{
return null;
}
return $this->getFinalBid()->getPriceBid();
}
public function getFinalUser()
{
if(!$this->getFinalBid())
{
return false;
}
if(is_null($this->final_user))
{
$this->final_user = $this->getFinalBid()->getUser();
}
return $this->final_user;
}
public function getFinalBid()
{
if(is_null($this->final_bid))
{
$this->final_bid = Doctrine::getTable('Bid')
->createQuery('b')
->where('item_id = ?', $this->id)
->orderBy('price_bid DESC')
->fetchOne();
}
return $this->final_bid;
}
public function getFinalUserInfo()
{
if(!$this->getFinalBid())
{
return '';
}
return $this->getFinalUser()->name . "
" .
$this->getFinalUser()->email . "
" .
$this->getFinalUser()->tel . "
" .
$this->getFinalUser()->street . "
" .
$this->getFinalUser()->city . "
" .
$this->getFinalUser()->zip . "
" .
$this->getFinalUser()->state . "
";
}
public function getuser()
{
$bid = Doctrine::getTable('Bid')->createQuery("a")->where("a.item_id = " . $this->getId())
->orderBy('price_bid DESC')->limit(1)->execute();
$user = Doctrine::getTable('User')->find($bid[0]->getUserId());
return $user;
}
/*
* Lucene fulltext
*/
public function updateLuceneIndex()
{
$index = $this->getTable()->getLuceneIndex();
// remove existing entries
foreach ($index->find('pk:' . $this->getId()) as $hit)
{
$index->delete($hit->id);
}
$doc = new Zend_Search_Lucene_Document();
// store job primary key to identify it in the search results
$doc->addField(Zend_Search_Lucene_Field::Keyword('pk', $this->getId()));
// index job fields
$doc->addField(Zend_Search_Lucene_Field::UnStored('name', $this->name, 'UTF-8'));
$doc->addField(Zend_Search_Lucene_Field::UnStored('description', $this->description, 'UTF-8'));
// add job to the index
$index->addDocument($doc);
$index->commit();
}
// pretizeni ukladani pro zpracovani indexu
public function save(Doctrine_Connection $conn = null)
{
$ret = parent::save($conn);
$this->updateLuceneIndex();
return $ret;
}
public function isSold()
{
return $this->getIsFinished() && $this->hasBids();
}
public function getImageSrc($type = 'preview')
{
return '/uploads/items/' . $type . '/' . $this->getImage();
}
public function hasBids()
{
return count($this->getBids()) > 0;
}
public function getMinBidPrice()
{
if ($this->getPriceActual() == 0)
{
return $this->getPriceStart();
}
elseif (!$this->hasBids())
{
return $this->getPriceActual();
}
else
{
return round(($this->getPriceActual() * (1 + (sfConfig::get('app_minimalni_limit_procent') / 100))));
}
}
public function getBidLimitByUser($user)
{
return Doctrine::getTable('Bid_limit')->createQuery("a")
->where("a.user_id = ?", $user->getId())
->andWhere("a.item_id = ?", $this->getId())
->fetchOne();
}
public function hasAuthor()
{
if(is_null($this->getAuthorId()))
return false;
return !is_null($this->getAuthor()->getId());
}
}