<commit_before>WtRating
========

A module for Zend Framework 2 that provides functionality to rate or like something.<commit_msg>Updated the README with installation information<commit_after># WtRating

Version 0.0.1

[![Build Status](https://travis-ci.org/WalterTamboer/WtRating.png)](https://travis-ci.org/WalterTamboer/WtRating)

## Introduction

This is a Zend Framework 2 module that provides functionality to rate or like something.

## Requirements

* [Zend Framework 2](https://github.com/zendframework/zf2)

## Installation

Add this repository as a submodule to your repository or install using Composer:

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

## Usage

### Setup

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

```
'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:

```
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:

```
$this->wtRating($ratingSet);
```

It's possible to add attributes as well:

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

If you want to change the HTML element you can use the third parameter:

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

{'fraction_non_alphanumeric': 0.14140558848433532, 'fraction_numerical': 0.004233700254022015, 'mean_word_length': 3.4250936329588013, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '547878', 'n_tokens_mistral': 758, 'n_tokens_neox': 714, 'n_words': 224}