Git Product home page Git Product logo

csdoctrineactassortableplugin's Introduction

csDoctrineActAsSortablePlugin

Build Status

The csDoctrineActAsSortablePlugin is a symfony plugin that allows use of the doctrine behavior actAsSortable.

This behavior provides methods on your model for setting display order/position.

This plugin also contains images to implement for ordering.

Installation

With git

git submodule add git://github.com/bshaffer/csDoctrineActAsSortablePlugin.git plugins/csDoctrineActAsSortablePlugin
git submodule init
git submodule update

With subversion

svn propedit svn:externals plugins

In the editor that's displayed, add the following entry and then save

csDoctrineActAsSortablePlugin https://svn.github.com/bshaffer/csDoctrineActAsSortablePlugin.git

Finally, update:

svn up

Setup

In your config/ProjectConfiguration.class.php file, make sure you have the plugin enabled.

$this->enablePlugins('csDoctrineActAsSortablePlugin');

Apply the behavior to your model in your schema file config/doctrine/schema.yml

MyModel:
  actAs: [Sortable]

Optionally accepts a UniqueBy attribute which will be used on a model with a one-to-many relationship

MyModel:
  actAs:    
    Sortable:
      uniqueBy: [parent_id]

Rebuild your models and database

./symfony doctrine:build --all --and-load

Publish your assets

./symfony plugin:publish-assets

Clear your cache

./symfony cc

#Available Record Methods

  • promote

    $record->promote();
    
  • demote

    $record->demote();
    
  • moveToFirst

    $record->moveToFirst();
    
  • moveToLast

    $record->moveToLast();
    
  • moveToPosition

    $record->moveToPosition($newPosition);
    

#Available Table Methods

  • sort - accepts the array created by the symfony/prototype sortableElement tag

    Doctrine_Core::getTable('MyModel')->sort($order);
    
  • findAllSorted - Accepts sort order (asc, desc)

    Doctrine_Core::getTable('Model')->findAllSorted('asc');
    
  • findAllSortedWithParent - accepts the parent column name, the value, and sort order (asc, desc)

    Doctrine_Core::getTable('MyModel')->findAllSortedWithParent($fk_value, $fk_name, 'asc');
    

#Example Usage With Admin Generator

In your module, edit config/generator.yml, and under list, object actions, add:

object_actions:
  promote:
    action: promote
  demote:
    action: demote
  _edit:        -
  _delete:      -

In your module, edit actions/actions.class.php, Add the following actions:

public function executePromote()
{
  $object=Doctrine_Core::getTable('MyModel')->findOneById($this->getRequestParameter('id'));


  $object->promote();
  $this->redirect("@moduleIndexRoute");
}

public function executeDemote()
{
  $object=Doctrine_Core::getTable('MyModel')->findOneById($this->getRequestParameter('id'));

  $object->demote();
  $this->redirect("@moduleIndexRoute");
}

Running Unit Tests

This plugin comes with a fully functional test suite. If you'd like to run this against the symfony version used in your project, export the $symfony environment variable as follows:

export SYMFONY=/usr/share/php/symfony

The above is where PEAR installs symfony on an Ubuntu/Debian-system.
Be sure to point this at your symfony lib directory!

By default, this will run against a sqlite database. If you'd like to run against postgres or mysql, export the environmental $DB variable as follows:

# Running against mysql:
export DB=mysql; php ./test/bin/prove.php

#Running against postgre:
export DB=postgre; php ./test/bin/prove.php

Database connection data

  • mySQL uses root with no password per default
  • postgreSQL uses postgres with no password per default

Database-Configuration can be changed in /test/fixtures/project/config/database-*.yml

csdoctrineactassortableplugin's People

Contributors

bshaffer avatar ck-1 avatar ericroge avatar jkm9000 avatar m14t avatar miamibc avatar robo47 avatar shouze avatar yceforp avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.