public static function create_package() { $user = User::find_by_username('bob'); $file = FileUtils::join(NIMBLE_ROOT, 'test', 'data', 'bobs_other_package-0.0.1.tgz'); $package = Package::from_upload(array('file' => $file, 'user' => $user)); foreach (User::_find('all') as $user) { $raiting = '0.' . $user->id; PackageRating::_create(array('user_id' => $user->id, 'package_id' => $package->id, 'rating' => (double) $raiting)); } }
</div> <div class='right'> <p><?php echo link_to('Download', $package->file_url($version->version) . '.tgz', array('class' => 'download')); ?> </p> <?php if ($this->is_logged_in()) { ?> <p> <div id='rater'></div> <script type='text/javascript'>new Rater($('rater'), raterLayout.stars, {bg:'#eeeeee', ratingto:'/package/<?php echo $package->id; ?> /rate/%score%'},<?php echo PackageRating::get_rating_for_user($user->id, $package->id); ?> );</script> </p> <?php } ?> </div> <br style='clear:both;' /> </div> <p>Downloaded: <?php echo $package->num_downloads; ?> times.</p> <?php if ($this->is_logged_in() && $this->user->id == $package->user_id) {
public function rate() { $this->layout = false; $this->has_rendered = true; $this->login_user(); $score = (double) $_GET['score']; try { PackageRating::_create(array('rating' => $score, 'package_id' => $_GET['id'], 'user_id' => $this->user->id)); echo 'created'; } catch (NimbleRecordException $e) { $p = PackageRating::find('first', array('package_id' => $_GET['id'], 'user_id' => $this->user->id)); PackageRating::update($p->id, array('rating' => $score)); echo 'updated'; } }
/** * @expectedException NimbleRecordException */ public function testBobTriesToRatePackageThatsRaitedByBob() { $p = Package::find_by_name('bobs_other_package'); $user = $p->user; PackageRating::create(array('user_id' => $user->id, 'package_id' => $p->id, 'rating' => 0.1)); }
<td><?php echo link_to($version->version, url_for("VersionController", 'show', $package->user->username, $package->name, $version->version)); ?> </td> <td width='25%'><div class='small summary-right'><?php echo $version->summary; ?> </div></td> <td><?php echo $version->min_php; ?> </td> <td><span class='small'><?php echo distance_of_time_in_words(DateHelper::from_db($version->created_at), time(), true); ?> ago</span></td> <td><?php echo isset($package->rating) ? PackageRating::convert_to_human($package->rating) : 0; ?> %</td> </tr> <?php } ?> </tbody> </table> <div id='pagination'> <?php echo paginate($packages); ?> </div>