Development

Changeset 3571

You must first sign up to be able to contribute.

Changeset 3571

Show
Ignore:
Timestamp:
03/04/07 12:51:02 (6 years ago)
Author:
tristan
Message:

sfPropelNotificationPlugin :

  • wrote installation docs
  • started writing usage docs
  • deprecated sfUser::getId() / getPeerClass() in favor of getAttribute() + plugin namespace
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfPropelNotificationPlugin/README

    r3562 r3571  
    1515   
    1616{{{ 
    17   symfony plugin-install http://plugins.symfony-project.com/sfPropelNotificationPlugin 
     17#!sh 
     18symfony plugin-install http://plugins.symfony-project.com/sfPropelNotificationPlugin 
     19}}} 
     20 
     21=== Set up relationship with your model's user table === 
     22 
     23 * Update plugin's `schema.xml` : replace `@FIXME@` occurences in the `watch` table with correct values. Eg. : 
     24  
     25{{{ 
     26#!xml 
     27<?xml version="1.0" encoding="UTF-8"?> 
     28<table name="watch"> 
     29  <column name="id" type="INTEGER" required="true" primaryKey="true" autoIncrement="true" /> 
     30  <column name="user_id" type="INTEGER" required="true" /> 
     31  <column name="watch_type" type="VARCHAR" size="255" required="true" /> 
     32  <index name="watch_FKIndex2"> 
     33    <index-column name="user_id" /> 
     34  </index> 
     35  <foreign-key foreignTable="User" name="Rel_02" onDelete=""> 
     36    <reference local="user_id" foreign="id" /> 
     37  </foreign-key> 
     38</table> 
     39}}} 
     40 
     41 * Register connected user peer class and unique id in session, under the `sfPropelNotificationPlugin` namespace : 
     42 
     43For instance, when logging user in : 
     44 
     45{{{ 
     46#!php 
     47<?php 
     48$this->getUser()->setAttribute('uid', $id, 'sfPropelNotificationPlugin'); 
     49$this->getUser()->setAttribute('peer_class', 'UserPeer', 'sfPropelNotificationPlugin'); 
    1850}}} 
    1951 
    2052== Usage == 
    2153 
     54=== Defining notification types === 
     55 
     56This plugin enable users to subscribe to notification "types". Let's see how to define a notification type which will trigger notification 
     57when an (imaginary) article is reported being offensive by five users or more :  
     58 
     59 * Create a `sfPropelNotificationPlugin` directory in your application's `config` directory 
     60 * Create a `types.yml` file in this directory 
     61 * Specify a new notification type : 
     62{{{ 
     63offensive_article: 
     64  enabled: on 
     65  logic_class: myLogicProvider 
     66}}} 
     67 
     68The `myLogicProvider` class implements the logic that will tell if notification logic should be triggered : 
     69{{{ 
     70#!php 
     71<?php 
     72class myLogicProvider 
     73{ 
     74  public static function OffensiveArticle(Article $article) 
     75  { 
     76    return $article->countOffensiveReports() >= 5; 
     77  } 
     78} 
     79}}} 
     80 
     81 * Register notification behavior with your `Article` class : 
     82 
     83{{{ 
     84#!php 
     85<?php 
     86// lib/model/Article.php 
     87class Article extends BaseArticle 
     88{ 
     89  // ... 
     90} 
     91 
     92sfPropelBehavior::add('Article', array('sfPropelNotificationPlugin' =>  array('types' => array('offensive_article'))); 
     93}}} 
     94 
     95And that's it. Every time an article is modified, it will be checked against every notification type it's registered with. 
     96If type's associated logic method returns true, notification will be triggered for every user who subscribed to it, using whatever notification 
     97backend(s) they chose. 
     98 
    2299=== Enabling the notification management module === 
    23100 
    24 === Defining notification types === 
     101This module provides a `my` action, which is a way for registered user to manage their subscriptions to notifications types and backends. 
     102 
     103''insert screenshot here'' 
     104 
     105Enable it in your application's `settings.yml` : 
     106 
     107{{{ 
     108all: 
     109  .settings:   
     110    enabled_modules: [default, sfPropelNotificationPluginNotifications] 
     111}}} 
    25112 
    26113=== Using the default email backend === 
    27114 
     115The plugin comes with a default email notification backend (based on symfony's `sfMail` class). 
     116 
     117You first need to configure it for your needs : 
     118 
     119 * Copy plugin's `config/sfPropelNotificationPlugin/backends.yml` file in yout application's `config/sfPropelNotificationPlugin` directory. 
     120 * Configure it accordingly to your needs : 
     121 
     122{{{  
     123email: 
     124  enabled: on 
     125  class: sfPropelNotificationPluginSfMailBackend 
     126  params: 
     127    mailer: sendmail 
     128    charset: utf-8 
     129    sender_name: Notification bot 
     130    sender_address: noreply@example.com 
     131    subject_prefix: "[notification]" 
     132}}} 
     133 
     134You must then implement the notification emails template. Email body is provided by plugin's `sfPropelNotificationPluginBackends::SfMail` action. 
     135Enable it in your application's `settings.yml` : 
     136 
     137{{{ 
     138all: 
     139  .settings:   
     140    enabled_modules: [default, sfPropelNotificationPluginNotifications, sfPropelNotificationPluginBackends] 
     141}}} 
     142 
     143You must create one template per notification type : 
     144 
     145 * Create a module directory tree in your application : 
     146 
     147{{{ 
     148modules 
     149|-- sfPropelNotificationPluginBackends 
     150  | -- templates 
     151}}} 
     152 
     153 * Implement needed templates : 
     154 
     155Templates names correspond to notification type name (eg. `OffensiveArticleSuccess.php`) 
     156The following variables are made available to template : 
     157 
     158 * `$object` : the object which triggered notification 
     159 * `$watch` : the watch from database. It grants access database user through its `getUser` method.  
     160 
     161Here is an example template : 
     162 
     163{{{ 
     164#!php 
     165// modules/sfPropelNotificationPluginBackends/templates/OffensiveArticleSuccess.php 
     166 
     167Hello <?php echo $watch->getUser()->getFirstName() ?>, 
     168 
     169You receive this notification email because the article <?php echo $object->getTitle() ?> (<?php echo url_to('@article_view?id='.$object->getId()) ?>) 
     170has been reported offensive several times. 
     171 
     172You can : 
     173 
     174 * Delete it : <?php echo url_to('@article_delete?id='.$object->getId()) ?> 
     175 
     176or 
     177 
     178 * Reset its offensiveness status : <?php echo url_to('@article_reset?id='.$object->getId()) ?> 
     179}}} 
     180 
    28181=== Implementing a new notification backend === 
     182 
     183TODO. 
    29184 
    30185== Changelog == 
     
    32187=== trunk === 
    33188 
    34  * removed hardcoded "User" model. 
     189 * removed hardcoded "User" model 
     190 * wrote installation docs 
     191 * started writing usage docs 
     192 * deprecated sfUser::getId() / getPeerClass() in favor of getAttribute() + plugin namespace 
    35193 
    36194=== 2007-03-02 | 0.1.0 alpha === 
  • plugins/sfPropelNotificationPlugin/config/schema.xml

    r3562 r3571  
    1010        <index-column name="user_id" /> 
    1111      </index> 
    12       <foreign-key foreignTable="FIXME" name="Rel_02" onDelete=""> 
    13         <reference local="user_id" foreign="FIXME" /> 
     12      <foreign-key foreignTable="@FIXME@" name="Rel_02" onDelete=""> 
     13        <reference local="user_id" foreign="@FIXME@" /> 
    1414      </foreign-key> 
    1515    </table> 
  • plugins/sfPropelNotificationPlugin/config/sfPropelNotificationPlugin/types.yml

    r3560 r3571  
    1 new_user
     1example_type
    22  enabled: on 
    3   logic_class: sfTestLogicProvider 
    4  
    5 problematic_message: 
    6   enabled: off 
    7   logic_class: sfTestLogicProvider 
     3  logic_class: ExampleLogicProvider 
  • plugins/sfPropelNotificationPlugin/modules/sfPropelNotificationPluginNotifications/actions/actions.class.php

    r3562 r3571  
    2424  public function executeMy() 
    2525  { 
    26     // TODO : get this from yamls 
    2726    include(sfConfigCache::getInstance()->checkConfig('config/sfPropelNotificationPlugin/types.yml')); 
    2827    include(sfConfigCache::getInstance()->checkConfig('config/sfPropelNotificationPlugin/backends.yml')); 
     
    4039      } 
    4140       
    42       // TODO : document getId() and getPeerClass() being mandatory 
    43       $user = call_user_func(array($this->getUser()->getPeerClass(), 'retrieveByPk'), $this->getUser()->getId()); 
     41      // Retrieve connected user info from database 
     42      $peer_class = $this->getUser()->getAttribute('peer_class', null, 'sfPropelNotificationPlugin'); 
     43      $user_id = $this->getUser()->getAttribute('uid', null, 'sfPropelNotificationPlugin'); 
     44      $user = call_user_func(array($peer_class, 'retrieveByPk'), $user_id); 
    4445       
    4546      foreach ($user->getWatchs() as $watch)