Download the PHP package marcanuy/popularity without Composer

On this page you can find all versions of the php package marcanuy/popularity. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package popularity

Laravel 4 Popularity Package

Laravel 4 Popularity Package tracks your most popular Eloquent models based on hits in a date range and lets you display them.


Table of contents

Features

How to install

Setup

In the require key of composer.json file add the following

"marcanuy/popularity": "1.0.x"

Run the Composer update comand

$ composer update

In your config/app.php add 'Marcanuy\Popularity\PopularityServiceProvider' to the end of the $providers array

'providers' => array(

    'Illuminate\Foundation\Providers\ArtisanServiceProvider',
    'Illuminate\Auth\AuthServiceProvider',
    ...
    'Marcanuy\Popularity\PopularityServiceProvider',

),

It also automatically registers the following aliases to have them available in the app container

'aliases' => array(
    ..
    'Stats'      => 'Marcanuy\Popularity\Stats',
    'Popularity' => 'Marcanuy\Popularity\Facades\Popularity',
..
),

Run package migrations

Generate the table that will contain hits for each Eloquent model

php artisan migrate --package=marcanuy/popularity

Configuration

For each Eloquent model you want to track, you need to implement src/models/PopularityInterface.php contract like this:

#e.g. in models/ExamplePost.php

class ExamplePost implements \Marcanuy\Popularity\PopularityInterface
{
    public function popularityStats()
    {
        return $this->morphOne('Stats', 'trackable');
    }

    public function hit()
    {
        //check if a polymorphic relation can be set
        if($this->exists){
            $stats = $this->popularityStats()->first();
            if( empty( $stats ) ){
                //associates a new Stats instance for this instance
                $stats = new Stats();
                $this->popularityStats()->save($stats);
            }
            return $stats->updateStats();
        }
            return false;            
        }
    }

Usage

It makes use of Eloquent's polymorphic relations, so each tracked model has its own stats.

Tracking hits

For each model instance that has already been saved into the db (or already has an id), call hit() method to increase count for each time frame, e.g. in routes.php each time a post or an article is viewed, or an Eloquent event is fired.

Route::get('post/{id}', function($id)
{
    $post = ExamplePost::find($id);
    $post->hit();
    ...
}

Retrieving most popular elements

By default it register the route popularity, popularity/day, etc, where you can see an example of its usage. It is based on the following views that can be easily modified.

//copy package views into your app
php artisan view:publish marcanuy/popularity

You can include this views as subviews or adapt them to your project needs

app/views/packages/marcanuy/popularity/item_list.blade.php
app/views/packages/marcanuy/popularity/widget.blade.php

Then use them like

$items = Popularity::getStats('one_day_stats', 'DESC', '\Marcanuy\Popularity\ExamplePost')->paginate();
View::make('popularity::item_list')->with(array('items' => $items));

$topItems = Popularity::getStats('one_day_stats', 'DESC', '', 3)->get();
View::make('popularity::widget')->with(array('topItems' => $topItems));

License

This is free software distributed under the terms of the MIT license

Additional information

Inspired by and based on WP-Most-Popular

Any questions, post an issue or feel free to contact me.


All versions of popularity with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.0
illuminate/support Version 4.1.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package marcanuy/popularity contains the following files

Loading the files please wait ....