| 1 |
# sfDoctrineTreePlugin - Manage doctrine's nested set with a DHTML tree # |
|---|
| 2 |
*Updated Jan 2 2010 for Symfony 1.3 compatibility* |
|---|
| 3 |
|
|---|
| 4 |
## Author ## |
|---|
| 5 |
|
|---|
| 6 |
Copyright (C) 2008-2010 Jacques Philip. |
|---|
| 7 |
Using a modified version of Drag and drop folder tree: |
|---|
| 8 |
Copyright (C) 2006 DTHMLGoodies.com, Alf Magne Kalleland |
|---|
| 9 |
|
|---|
| 10 |
## License ## |
|---|
| 11 |
|
|---|
| 12 |
LGPL |
|---|
| 13 |
|
|---|
| 14 |
## Prerequisites ## |
|---|
| 15 |
|
|---|
| 16 |
PHP v 5.2.0+ |
|---|
| 17 |
**Prototype v 1.6+ is required** |
|---|
| 18 |
Of course sfDoctrinePlugin |
|---|
| 19 |
|
|---|
| 20 |
## Features ## |
|---|
| 21 |
|
|---|
| 22 |
- **Display a doctrine nested set and insert, rename and delete nodes through a context menu and ajax:** |
|---|
| 23 |
|
|---|
| 24 |
![screen shot][1] |
|---|
| 25 |
|
|---|
| 26 |
- **Move complete branches of the tree through drag-drop and save the |
|---|
| 27 |
history of changes in a single ajax |
|---|
| 28 |
call:** |
|---|
| 29 |
|
|---|
| 30 |
![screen shot][2] |
|---|
| 31 |
|
|---|
| 32 |
- **Customize the node links through a template to integrate the tree in multiple situations.** |
|---|
| 33 |
Simple link here, but could be a remote link too: |
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 |
<?php echo link_to($record->get($field), "$model/edit?id=$identifier"); ?> |
|---|
| 37 |
|
|---|
| 38 |
## Browser compatibility ## |
|---|
| 39 |
|
|---|
| 40 |
Tested on IE 6, 7 and 8, Firefox 2 and 3 Opera 9 on Windows. |
|---|
| 41 |
Let me know if you find compatibility problems on other platforms. |
|---|
| 42 |
|
|---|
| 43 |
## Installation ## |
|---|
| 44 |
|
|---|
| 45 |
Install plugin as usual. |
|---|
| 46 |
For Symfony 1.2 and 1.3, enable plugins sfDoctineTreePlugin and sfProtoculousPlugin. |
|---|
| 47 |
For Symfony 1.0, update the Prototype js files to version 1.6 minimum. |
|---|
| 48 |
Create a nested set model according to Doctrine documentation. |
|---|
| 49 |
You must enable the module sfDoctrineTree in your application settings.yml: |
|---|
| 50 |
|
|---|
| 51 |
all: |
|---|
| 52 |
.settings: |
|---|
| 53 |
enabled_modules: [default, sfDoctrineTree] |
|---|
| 54 |
|
|---|
| 55 |
Create a link or virtual directory called sfDoctrineTreePlugin, pointing to the web folder of the plugin. |
|---|
| 56 |
|
|---|
| 57 |
## Settings and customization ## |
|---|
| 58 |
|
|---|
| 59 |
### Callbacks ### |
|---|
| 60 |
|
|---|
| 61 |
You can override the way sfDoctrineTreePlugin renames and deletes records by including callback methods in the table class of the model. |
|---|
| 62 |
These methods are: customizeTreeUpdateQuery and customizeTreeSelectForDeleteQuery, they take a query object as a parameter and return a query object, so you can either add to the query or replace it in the method. |
|---|
| 63 |
For example, for a model called Category, you would add the following method to add a where clause. (For security or other) This method will be called to get the update query: |
|---|
| 64 |
|
|---|
| 65 |
public function customizeTreeUpdateQuery($q) |
|---|
| 66 |
{ |
|---|
| 67 |
$securityField = Utils::getSecurityField(); |
|---|
| 68 |
return $q->addWhere('security_field = ?', $securityField); |
|---|
| 69 |
} |
|---|
| 70 |
|
|---|
| 71 |
Similarly the callback method customizeChildToAdd gives you a chance to update properties of a record before it is inserted as a child: |
|---|
| 72 |
|
|---|
| 73 |
public function customizeChildToAdd($child) |
|---|
| 74 |
{ |
|---|
| 75 |
$child->security_field = Utils::getSecurityField(); |
|---|
| 76 |
return $child; |
|---|
| 77 |
} |
|---|
| 78 |
|
|---|
| 79 |
###Setting in app.yml### |
|---|
| 80 |
|
|---|
| 81 |
You can change the following setting by defining them in app.yml: |
|---|
| 82 |
|
|---|
| 83 |
app_doctrine_tree_rename_url default: sfDoctrineTree/rename |
|---|
| 84 |
app_doctrine_tree_delete_url default: sfDoctrineTree/delete |
|---|
| 85 |
app_doctrine_tree_add_child_url default: sfDoctrineTree/add_child |
|---|
| 86 |
app_doctrine_tree_save_tree_url default: sfDoctrineTree/save_tree |
|---|
| 87 |
|
|---|
| 88 |
These setting will be applied to all trees in the application |
|---|
| 89 |
|
|---|
| 90 |
### Options in the helper function ### |
|---|
| 91 |
|
|---|
| 92 |
The helper include_doctrine_tree takes several options that modify the behavior of the tree. |
|---|
| 93 |
This gives you the ability to set different options for each tree. |
|---|
| 94 |
|
|---|
| 95 |
* link_partial: Allows you to change the default link template for the nodes. (default is: 'yourmodel/edit') |
|---|
| 96 |
* max_depth: Limits the depth where people can add or drop nodes |
|---|
| 97 |
* no_help: Hides the help link and div |
|---|
| 98 |
* no_root_rename: Hides the Rename context menu for the root |
|---|
| 99 |
|
|---|
| 100 |
All other options will be passed as HTML attributes of the nodes. (not the root) |
|---|
| 101 |
Some of them will be interpreted by the js tree object: |
|---|
| 102 |
|
|---|
| 103 |
* noAdd: Hides the Add node context menu |
|---|
| 104 |
* noRename: Hides the Rename context menu |
|---|
| 105 |
* noDelete: Hides the Delete context menu |
|---|
| 106 |
* noDrag: Keeps the nodes from being moved |
|---|
| 107 |
* noSiblings: Keeps the nodes from being dropped between 2 nodes |
|---|
| 108 |
|
|---|
| 109 |
## Limitations ## |
|---|
| 110 |
|
|---|
| 111 |
sfDoctrineTreePlugin will not work with tables having composite keys. |
|---|
| 112 |
It is the responsibility of your application to create the root(s) of the tree. |
|---|
| 113 |
Context menus do not work with Right Click on Opera, Ctrl + Left Click is used instead. |
|---|
| 114 |
|
|---|
| 115 |
## Usage ## |
|---|
| 116 |
|
|---|
| 117 |
<?php |
|---|
| 118 |
use_helper('DoctrineTree'); |
|---|
| 119 |
|
|---|
| 120 |
// Category nested set with 1 root |
|---|
| 121 |
// include_doctrine_tree('Category', 'name'); |
|---|
| 122 |
|
|---|
| 123 |
// Comments nested set with multiple roots |
|---|
| 124 |
// include_doctrine_tree('Comment', 'title', 1); // 3rd argument is the root id of the nested set tree |
|---|
| 125 |
|
|---|
| 126 |
// Comments nested set with one root, using options and custom base query |
|---|
| 127 |
// include_doctrine_tree('Comment', 'title', 0, array('link_partial' => 'my_module/my_partial', 'max_depth' => 8, 'no_root_rename' => 'true', 'noRename' => 'true', 'noDelete' => 'true', 'noSiblings' => 'true'), CommentTable::getTreeBaseQuery); |
|---|
| 128 |
|
|---|
| 129 |
// |
|---|
| 130 |
?> |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
[1]: http://svn.symfony-project.com/plugins/sfDoctrineTreePlugin/web/images/scr1.png |
|---|
| 134 |
[2]: http://svn.symfony-project.com/plugins/sfDoctrineTreePlugin/web/images/scr2.png |
|---|