2017 © Pedro Peláez
 

library wtrating

A Zend Framework 2 module that provides functionality to rate or like something.

image

waltertamboer/wtrating

A Zend Framework 2 module that provides functionality to rate or like something.

  • Sunday, November 4, 2012
  • by waltertamboer
  • Repository
  • 1 Watchers
  • 6 Stars
  • 39 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

WtRating

Version 0.0.1, (*1)

Build Status, (*2)

Introduction

This is a Zend Framework 2 module that provides functionality to rate or like something., (*3)

Requirements

Installation

Add this repository as a submodule to your repository or install using Composer:, (*4)

{
    "require": {
        "waltertamboer/wtrating": "*"
    }
}

Usage

Setup

Setup the mapper that you want to use. By default this module only comes with a Zend\Db mapper., (*5)

'service_manager' => array(
    'factories' => array(
        'wtrating.mapper' => function ($sm) {
            $dbAdapter = $sm->get('... db adapter ...');
            return new \WtRating\Mapper\ZendDbMapper($dbAdapter);
        }
    ),
)

Rate something

To add a rating you could do the following:, (*6)

public function indexAction()
{
    // The id of the user that is currently logged in or null if there is no user:
    $userId = ...;

    // The type that identifies the rating:
    $typeId = 'my-article-163';

    // The rating to set, make something up:
    $rating = rand();

    $serviceLocator = $this->getServiceLocator();

    // Create a new rating:
    $rating = $serviceLocator->create('wtrating.rating');
    $rating->setTypeId($typeId);
    $rating->setUserId($userId);
    $rating->setRating($rating);

    // Save the rating to the storage device:
    $ratingService = $serviceLocator->get('wtrating.service');
    $ratingService->persist($rating);

    // Retrieve the rating set that contains information like avarage rating,
    // amount of rates, etc.
    return new ViewModel(array(
        'ratingSet' => $ratingService->getRatingSet($typeId)
    ));
}

Show ratings

There is a view helper that can be invoked:, (*7)

$this->wtRating($ratingSet);

It's possible to add attributes as well:, (*8)

$this->wtRating($this->ratingSet, array(
    'class' => 'rating'
));

If you want to change the HTML element you can use the third parameter:, (*9)

$this->wtRating($this->ratingSet, array(), 'div');

The Versions

04/11 2012

dev-master

9999999-dev https://github.com/WalterTamboer/WtRating

A Zend Framework 2 module that provides functionality to rate or like something.

  Sources   Download

The Requires

 

zf2 rating like