2017 © Pedro Peláez
 

symfony-bundle activity-bundle

Manages activities

image

kitpages/activity-bundle

Manages activities

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 10 % Grown

The README.md

KitpagesActivityBundle

Build Status, (*1)

SensioLabsInsight, (*2)

Records activity of a website and display notifications on some pages., (*3)

Mostly used for rapid prototyping., (*4)

Quick Start

Create an activity, (*5)

$this->get("kitpages_activity.activity_manager")->createActivity(
    "my_category",
    "my title",
    "my message content",
    "my url", //optionnal
    "my reference", //optionnal
    array("key1" => "val1", ), //optionnal
);

Display a list of activities in a twig template, (*6)

{{ render(controller('KitpagesActivityBundle:Activity:list', {
    'request': app.request, // mandatory
    'filterList': { "category": "my_category" }, // optionnal
} ) ) }}

get activities in PHP, (*7)

$activityManager = $this->get("kitpages_activity.activity_manager");
$activityList = $activityManager->getActivityList( array(
    "category" => "my category"
) );

Features :

  • record activities
  • attach activities to an object using reference
  • attach activities to categories
  • easy to display activities with a paginator and a full text filter
  • filter activities by category, title, message, reference
  • you can sort activities

Installation

Using Composer, just $ composer require kitpages/activity-bundle package or:, (*8)

{
  "require": {
    "kitpages/activity-bundle": "~1.0"
  }
}

Then add the bundle in AppKernel :, (*9)

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(),
            new Kitpages\ActivityBundle\KitpagesActivityBundle(),
            new Kitpages\DataGridBundle\KitpagesDataGridBundle(),
        );
    }

Display a list of activities in a twig template

{{ render(controller('KitpagesActivityBundle:Activity:list', {
    'request': app.request, // mandatory
    'filterList': { "category": "my_category" }, // optionnal
    'orderBy': 'id ASC' // optionnal, default to "createdAt DESC"
} ) ) }}

get activity list in PHP

get all activities

$activityManager = $this->get("kitpages_activity.activity_manager");
$activityList = $activityManager->getActivityList();

get activities for a given category

$activityManager = $this->get("kitpages_activity.activity_manager");
$activityList = $activityManager->getActivityList( array(
    "category" => "my category"
) );

get activities for all categories beginning by "payments."

$activityManager = $this->get("kitpages_activity.activity_manager");
$activityList = $activityManager->getActivityList( array(
    "category" => "payment*"
) );

principle of filter

  • You can filter the fields category, title, message, url or reference.
  • You can use "*" at the beginning or the end of your filter as a wildcard (everything with category beginning by "xxx" or ending by "xxx").
  • You can escape the wildcard by using '*'

ordering results

By default activity list is ordered by createdAt DESC. You can specify the order :, (*10)

$activityManager = $this->get("kitpages_activity.activity_manager");
$activityList = $activityManager->getActivityList(
    array("category" => "payment.*"),
    "id DESC", // sort field : id, reference, category, createdAt
);

Best practices

  • the category field is used for filtering activities by category
  • the reference field is used to represent the object linked to this activity (if there is an object). I imagine references like "company.15.user.23". We can then retrieve activities for the company or this user using wildcard in filters.
  • The data field is used to add every information you would need linked to this activity

note : category is not mandatory in filter list., (*11)

Versions

2013-12-18 : v1.0.0, (*12)

  • first version

2014-11-07 : v2.0.0, (*13)

  • upgrade to KitpagesDataGrid 2.x
  • filters on activities
  • added reference, and custom data
  • ordering of activity list
  • better unit tests

The Versions