Git Product home page Git Product logo

sfdoctrinepublishableplugin's Introduction

sfDoctrinePublishablePlugin

Introduction

A plugin which adds Publishable behaviour to a model. This behaviour adds 3 fields to a model - published_at, publish_until and is_draft. The plugin also includes preDQL which can be enabled in an application's configuration to automatically filter models based on whether they are currently published or not.

Dependencies

  • Doctrine 1.x
  • Symfony 1.3/1.4

Setup

1. Enable the plugin

In ProjectConfiguration:

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
    $this->enablePlugin('sfDoctrinePlugin','sfDoctrinePublishablePlugin');
  }
...

2. Enable preDQL callback in application configuration

All queries in this application for the models with Publishable behaviour will be restricted to those that are not draft, and whose publish dates are valid for the current date.

In %APPLICATION%Configuration:

class %APPLICATION%Configuration extends sfApplicationConfiguration
{
...

	public function configureDoctrine(Doctrine_Manager $manager)
	{
  		// This is required for the Publishable behaviour
  		$manager->setAttribute(Doctrine_Core::ATTR_USE_DQL_CALLBACKS, true);  

  		// enable predql callback on the sfDoctrinePublishable plugin in this app
  		$manager->setAttribute('publishable_enable_predql', sfConfig::get('app_publishable_enable_predql', true));
	}
	...
}

This will add the following SQL to the end of all queries that get MyModel in this application.

WHERE ((((a.publish_until IS NULL AND a.published_at <= NOW()) OR NOW() BETWEEN a.published_at AND a.publish_until) AND (a.is_draft IS NULL OR a.is_draft != 1)))

NOTE: If there are other WHERE constraints, this will be added as an AND
NOTE: a represents the root alias of MyModel

3. Add behaviour to model(s) in schema.yml

MyModel:
  actAs: [Publishable]
  ...

This behaviour adds 3 fields to MyModel - published_at, publish_until and is_draft.

  • published_at is a required field - if this not set then the model won't appear when preDQL is enabled. This sets the start date for the model to start appearing as a query result
  • publish_until sets the end date for the model to stop appearing, if this is not set (e.g NULL) then the model appears indefinitely
  • is_draft allows models to have publish dates set, but not yet appear - for example, if a model requires approval it could be set as is_draft

sfdoctrinepublishableplugin's People

Contributors

angelsk avatar

Watchers

Kolba avatar James Cloos avatar Jimmy Wong avatar  avatar Joe Harlow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.