public static function retrieveByPKs($pks, $con = null) { if ($con === null) { $con = Propel::getConnection(self::DATABASE_NAME); } $objs = null; if (empty($pks)) { $objs = array(); } else { $criteria = new Criteria(); $criteria->add(sfRatingPeer::ID, $pks, Criteria::IN); $objs = sfRatingPeer::doSelect($criteria, $con); } return $objs; }
/* * This file is part of the sfPropelActAsRatableBehavior package. * * (c) 2009 Kasper Garnæs <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * The unit test assumes that sfGuardPlugin is installed and that the model * class Item is defined. */ include dirname(__FILE__) . '/../bootstrap/unit.php'; sfPropelBehavior::add('sfGuardUser', array('sfPropelActAsSlopeOneRaterBehavior')); //Setup values sfRatingPeer::doDeleteAll(); sfGuardUserPeer::doDeleteAll(); $users = array(); for ($i = 0; $i < 3; $i++) { $users[$i] = new sfGuardUser(); $users[$i]->setUsername(rand()); $users[$i]->save(); } $items = ItemPeer::doSelect(new Criteria()); $items[0]->setRating(5, $users[0]->getId()); $items[1]->setRating(3, $users[0]->getId()); $items[2]->setRating(2, $users[0]->getId()); $items[0]->setRating(3, $users[1]->getId()); $items[1]->setRating(4, $users[1]->getId()); $items[1]->setRating(2, $users[2]->getId()); $items[2]->setRating(5, $users[2]->getId());
public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME) { $keys = sfRatingPeer::getFieldNames($keyType); if (array_key_exists($keys[0], $arr)) { $this->setId($arr[$keys[0]]); } if (array_key_exists($keys[1], $arr)) { $this->setRatableModel($arr[$keys[1]]); } if (array_key_exists($keys[2], $arr)) { $this->setRatableId($arr[$keys[2]]); } if (array_key_exists($keys[3], $arr)) { $this->setUserId($arr[$keys[3]]); } if (array_key_exists($keys[4], $arr)) { $this->setRating($arr[$keys[4]]); } if (array_key_exists($keys[5], $arr)) { $this->setComment($arr[$keys[5]]); } if (array_key_exists($keys[6], $arr)) { $this->setStatus($arr[$keys[6]]); } }
/** * Deletes all rating for a ratable object (delete cascade emulation) * * @param BaseObject $object */ public function preDelete(BaseObject $object) { try { $c = new Criteria(); $c->add(sfRatingPeer::RATABLE_ID, $object->getReferenceKey()); sfRatingPeer::doDelete($c); } catch (Exception $e) { throw new sfPropelActAsRatableException('Unable to delete ratable object related ratings records'); } }
$obj->clearRatings(); $obj2->clearRatings(); sfConfig::set(sprintf('propel_behavior_sfPropelActAsRatableBehavior_%s_max_rating', get_class($obj)), 12); $obj->setRating(6, $user_1_id); $obj->setRating(6, $user_2_id); $t->is($obj->getRating(), 6, 'getRating() base12 ok'); $obj->setRating(12, $user_2_id); $t->is($obj->getRating(), 9, 'getRating() base12 ok'); $obj->setRating(3, $user_1_id); $t->is($obj->getRating(), 7.5, 'getRating() base12 ok'); // Testing ratings details retrieval $obj->setRating(6, $user_1_id); $obj->setRating(6, $user_2_id); $obj->setRating(7, $user_3_id); $details = $obj->getRatingDetails(); $t->is(count($details), 2, 'getRatingDetails() count ok'); $t->is_deeply($details, array(6 => 2, 7 => 1), 'getRatingDetails() results are conform'); $full_details = $obj->getRatingDetails(true); $t->is(count($full_details), 12, 'getRatingDetails(true) count ok'); $expected = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 2, 7 => 1, 8 => 0, 9 => 0, 10 => 0, 11 => 0, 12 => 0); $t->is_deeply($full_details, $expected, 'getRatingDetails(true) results are conform'); // Testing cascade deletion $obj_key = $obj->getPrimaryKey(); $obj->delete(); $c = new Criteria(); $c->add(sfRatingPeer::RATABLE_ID, $obj_key); $count = sfRatingPeer::doCount($c); $t->is($count, 0, 'doCount() No more rating records for deleted object'); // Delete remaining object $obj2->delete(); $t->diag('Tests are now terminated');