Exemplo n.º 1
0
 public static function getInstance(Product $product, ProductRatingType $type = null)
 {
     $field = new ARFieldHandle(__CLASS__, 'ratingTypeID');
     $summary = $product->getRelatedRecordSet(__CLASS__, new ARSelectFilter($type ? new EqualsCond($field, $type->getID()) : new IsNullCond($field)));
     if ($summary->size()) {
         return $summary->get(0);
     } else {
         return self::getNewInstance($product, $type);
     }
 }
Exemplo n.º 2
0
 public static function getNewInstance(Product $product, ProductRatingType $type = null, User $user = null)
 {
     $instance = parent::getNewInstance(__CLASS__);
     $instance->product->set($product);
     if ($type && is_null($type->getID())) {
         $type = null;
     }
     $instance->ratingType->set($type);
     if ($user && $user->isAnonymous()) {
         $user = null;
     }
     $instance->user->set($user);
     return $instance;
 }