Esempio n. 1
0
 /**
  * create for PriceMatchRecord
  * 
  * @param PriceMatchCompany $company
  * @param PriceMatchMin $min
  * @param string $price
  * @param string $url
  * @param string $name
  * @throws Exception
  */
 public static function create(PriceMatchCompany $company, PriceMatchMin $min, $price, $url = '', $name = '')
 {
     if (abs(doubleval($price)) === 0.0 || doubleval($price) < 0.0 || trim($price) === '') {
         throw new Exception('price must be positive, "' . $price . '" given');
     }
     $price = doubleval($price);
     $from_date = UDate::now('Australia/Melbourne')->setTime(0, 0, 0)->setTimeZone('UTC');
     $to_date = UDate::now('Australia/Melbourne')->setTime(23, 59, 59)->setTimeZone('UTC');
     if (count($i = self::getAllByCriteria('companyId = ? and minId = ? and created >= ? and created <= ?', array($company->getId(), $min->getId(), $from_date, $to_date), true, 1, 1, array('id' => 'desc'))) > 0) {
         $entity = $i[0];
     } else {
         $entity = new self();
     }
     $entity->setCompany($company)->setMin($min)->setPrice($price)->setUrl(trim($url))->setName(trim($name))->save();
     return $entity;
 }