Permalink
Browse files

changed from Cakes HABTM to hasMany trough to enable sort on joined m…

…odels
  • Loading branch information...
1 parent 68ed4d3 commit d74b710e866e041b159d3becbe1c36324fff0ad5 @bartcc bartcc committed Jan 22, 2012
Showing with 504 additions and 181 deletions.
  1. +1 −1 app/config/routes.php
  2. +0 −3 app/controllers/albums_controller.php
  3. +79 −0 app/controllers/albums_photos_controller.php
  4. +79 −0 app/controllers/galleries_albums_controller.php
  5. +10 −8 app/controllers/galleries_controller.php
  6. +55 −48 app/models/album.php
  7. +47 −0 app/models/albums_photo.php
  8. +47 −0 app/models/galleries_album.php
  9. +24 −20 app/models/gallery.php
  10. +13 −7 app/models/photo.php
  11. +4 −1 app/views/layouts/director_layout.ctp
  12. +7 −7 app/webroot/js/spine/app/director/controllers/albums_view.coffee
  13. +14 −15 app/webroot/js/spine/app/director/controllers/albums_view.js
  14. +2 −2 app/webroot/js/spine/app/director/controllers/photos_view.coffee
  15. +9 −10 app/webroot/js/spine/app/director/controllers/photos_view.js
  16. +1 −1 app/webroot/js/spine/app/director/controllers/sidebar.js
  17. +4 −1 app/webroot/js/spine/app/director/models/albums_photo.coffee
  18. +6 −2 app/webroot/js/spine/app/director/models/albums_photo.js
  19. +5 −2 app/webroot/js/spine/app/director/models/galleries_album.coffee
  20. +7 −3 app/webroot/js/spine/app/director/models/galleries_album.js
  21. +13 −11 app/webroot/js/spine/app/director/plugins/ajax_relations.coffee
  22. +25 −22 app/webroot/js/spine/app/director/plugins/ajax_relations.js
  23. +0 −8 app/webroot/js/spine/app/director/plugins/drag.coffee
  24. +1 −8 app/webroot/js/spine/app/director/plugins/drag.js
  25. +17 −0 app/webroot/js/spine/app/director/plugins/model_extender.coffee
  26. +34 −1 app/webroot/js/spine/app/director/plugins/model_extender.js
@@ -39,5 +39,5 @@
*/
Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
-Router::mapResources(array('todos', 'tasks', 'contacts' ,'users', 'galleries', 'albums', 'photos'));
+Router::mapResources(array('todos', 'tasks', 'contacts' ,'users', 'galleries', 'albums', 'photos', 'galleries_albums', 'albums_photos'));
//Router::parseExtensions();
@@ -49,9 +49,6 @@ function edit($id = null) {
if (empty($this->data)) {
$this->data = $this->Album->read(null, $id);
}
- $photos = $this->Album->Photo->find('list');
- $galleries = $this->Album->Gallery->find('list');
- $this->set(compact('photos', 'galleries'));
}
function delete($id = null) {
@@ -0,0 +1,79 @@
+<?php
+
+class AlbumsPhotosController extends AppController {
+
+ var $name = 'AlbumsPhotos';
+
+ function beforeFilter() {
+ //$this->Auth->allowedActions = array('index', 'view', 'add', 'edit', 'delete');
+ parent::beforeFilter();
+ }
+
+ function index() {
+ $this->AlbumsPhoto->recursive = 0;
+ $this->set('albumsPhotos', $this->paginate());
+ }
+
+ function view($id = null) {
+ if (!$id) {
+ $this->Session->setFlash(__('Invalid albums photo', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->set('albumsPhoto', $this->AlbumsPhoto->read(null, $id));
+ }
+
+ function add() {
+ $this->log('AlbumsPhotosController::add', LOG_DEBUG);
+ if (!empty($this->data)) {
+ $this->log($this->data, LOG_DEBUG);
+ $this->AlbumsPhoto->create();
+ if ($this->AlbumsPhoto->saveAll($this->data)) {
+ $this->Session->setFlash(__('The albums photo has been saved', true));
+// $this->redirect(array('action' => 'index'));
+ $this->render(BLANK_RESPONSE);
+ } else {
+ $this->Session->setFlash(__('The albums photo could not be saved. Please, try again.', true));
+ }
+ }
+ $albums = $this->AlbumsPhoto->Album->find('list');
+ $photos = $this->AlbumsPhoto->Photo->find('list');
+ $this->set(compact('albums', 'photos'));
+ }
+
+ function edit($id = null) {
+ if (!$id && empty($this->data)) {
+ $this->Session->setFlash(__('Invalid albums photo', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ if (!empty($this->data)) {
+ if ($this->AlbumsPhoto->save($this->data)) {
+ $this->Session->setFlash(__('The albums photo has been saved', true));
+ $this->redirect(array('action' => 'index'));
+ } else {
+ $this->Session->setFlash(__('The albums photo could not be saved. Please, try again.', true));
+ }
+ }
+ if (empty($this->data)) {
+ $this->data = $this->AlbumsPhoto->read(null, $id);
+ }
+ $albums = $this->AlbumsPhoto->Album->find('list');
+ $photos = $this->AlbumsPhoto->Photo->find('list');
+ $this->set(compact('albums', 'photos'));
+ }
+
+ function delete($id = null) {
+ if (!$id) {
+ $this->Session->setFlash(__('Invalid id for albums photo', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ if ($this->AlbumsPhoto->delete($id)) {
+ $this->Session->setFlash(__('Albums photo deleted', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__('Albums photo was not deleted', true));
+ $this->redirect(array('action' => 'index'));
+ }
+
+}
+
+?>
@@ -0,0 +1,79 @@
+<?php
+
+class GalleriesAlbumsController extends AppController {
+
+ var $name = 'GalleriesAlbums';
+
+ function beforeFilter() {
+ //$this->Auth->allowedActions = array('index', 'view', 'add', 'edit', 'delete');
+ parent::beforeFilter();
+ }
+
+ function index() {
+ $this->GalleriesAlbum->recursive = 0;
+ $this->set('galleriesAlbums', $this->paginate());
+ }
+
+ function view($id = null) {
+ if (!$id) {
+ $this->Session->setFlash(__('Invalid galleries album', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->set('galleriesAlbum', $this->GalleriesAlbum->read(null, $id));
+ }
+
+ function add() {
+ $this->log('GalleriesAlbumsController::add', LOG_DEBUG);
+ if (!empty($this->data)) {
+ $this->log($this->data, LOG_DEBUG);
+ $this->GalleriesAlbum->create();
+ if ($this->GalleriesAlbum->saveAll($this->data)) {
+ $this->Session->setFlash(__('The galleries album has been saved', true));
+// $this->redirect(array('action' => 'index'));
+ $this->render(BLANK_RESPONSE);
+ } else {
+ $this->Session->setFlash(__('The galleries album could not be saved. Please, try again.', true));
+ }
+ }
+ $galleries = $this->GalleriesAlbum->Gallery->find('list');
+ $albums = $this->GalleriesAlbum->Album->find('list');
+ $this->set(compact('galleries', 'albums'));
+ }
+
+ function edit($id = null) {
+ if (!$id && empty($this->data)) {
+ $this->Session->setFlash(__('Invalid galleries album', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ if (!empty($this->data)) {
+ if ($this->GalleriesAlbum->save($this->data)) {
+ $this->Session->setFlash(__('The galleries album has been saved', true));
+ $this->redirect(array('action' => 'index'));
+ } else {
+ $this->Session->setFlash(__('The galleries album could not be saved. Please, try again.', true));
+ }
+ }
+ if (empty($this->data)) {
+ $this->data = $this->GalleriesAlbum->read(null, $id);
+ }
+ $galleries = $this->GalleriesAlbum->Gallery->find('list');
+ $albums = $this->GalleriesAlbum->Album->find('list');
+ $this->set(compact('galleries', 'albums'));
+ }
+
+ function delete($id = null) {
+ if (!$id) {
+ $this->Session->setFlash(__('Invalid id for galleries album', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ if ($this->GalleriesAlbum->delete($id)) {
+ $this->Session->setFlash(__('Galleries album deleted', true));
+ $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__('Galleries album was not deleted', true));
+ $this->redirect(array('action' => 'index'));
+ }
+
+}
+
+?>
@@ -25,15 +25,15 @@ function view($id = null) {
function add() {
if (!empty($this->data)) {
$this->Gallery->create();
+ $this->log('GalleriesController::add', LOG_DEBUG);
+ $this->log($this->data, LOG_DEBUG);
if ($this->Gallery->save($this->data)) {
$this->Session->setFlash(__('The gallery has been saved', true));
$this->render(BLANK_RESPONSE);
} else {
$this->Session->setFlash(__('The gallery could not be saved. Please, try again.', true));
}
}
- $albums = $this->Gallery->Album->find('list');
- $this->set(compact('albums'));
}
function edit($id = null) {
@@ -42,18 +42,20 @@ function edit($id = null) {
$this->redirect(array('action' => 'index'));
}
if (!empty($this->data)) {
- if ($this->Gallery->save($this->data)) {
+ $this->log('GalleriesController::edit', LOG_DEBUG) ;
+ $this->log($this->data, LOG_DEBUG) ;
+ if ($this->Gallery->saveAll($this->data)) {
$this->Session->setFlash(__('The gallery has been saved', true));
$this->render(BLANK_RESPONSE);
} else {
$this->Session->setFlash(__('The gallery could not be saved. Please, try again.', true));
}
}
- if (empty($this->data)) {
- $this->data = $this->Gallery->read(null, $id);
- }
- $albums = $this->Gallery->Album->find('list');
- $this->set(compact('albums'));
+// if (empty($this->data)) {
+// $this->data = $this->Gallery->read(null, $id);
+// }
+// $albums = $this->Gallery->Album->find('list');
+// $this->set(compact('albums'));
}
function delete($id = null) {
View
@@ -1,54 +1,61 @@
<?php
+
class Album extends AppModel {
- var $name = 'Album';
- var $useDbConfig = 'director_spine';
- var $displayField = 'title';
- var $validate = array(
- 'name' => array(
- 'notempty' => array(
- 'rule' => array('notempty'),
- //'message' => 'Your custom message here',
- //'allowEmpty' => false,
- //'required' => false,
- //'last' => false, // Stop validation after this rule
- //'on' => 'create', // Limit validation to 'create' or 'update' operations
- ),
- )
- );
- //The Associations below have been created with all possible keys, those that are not needed can be removed
- var $hasAndBelongsToMany = array(
- 'Photo' => array(
- 'className' => 'Photo',
- 'joinTable' => 'albums_photos',
- 'foreignKey' => 'album_id',
- 'associationForeignKey' => 'photo_id',
- 'unique' => true,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'finderQuery' => '',
- 'deleteQuery' => '',
- 'insertQuery' => ''
- ),
- 'Gallery' => array(
- 'className' => 'Gallery',
- 'joinTable' => 'galleries_albums',
- 'foreignKey' => 'album_id',
- 'associationForeignKey' => 'gallery_id',
- 'unique' => true,
- 'conditions' => '',
- 'fields' => '',
- 'order' => '',
- 'limit' => '',
- 'offset' => '',
- 'finderQuery' => '',
- 'deleteQuery' => '',
- 'insertQuery' => ''
- )
- );
+ var $name = 'Album';
+ var $useDbConfig = 'director_spine';
+ var $displayField = 'title';
+ var $validate = array(
+ 'name' => array(
+ 'notempty' => array(
+ 'rule' => array('notempty'),
+ //'message' => 'Your custom message here',
+ //'allowEmpty' => false,
+ //'required' => false,
+ //'last' => false, // Stop validation after this rule
+ //'on' => 'create', // Limit validation to 'create' or 'update' operations
+ ),
+ )
+ );
+
+ var $hasMany = array(
+ 'AlbumsPhoto', 'GalleriesAlbum'
+ );
+
+// The Associations below have been created with all possible keys, those that are not needed can be removed
+// var $hasAndBelongsToMany = array(
+// 'Photo' => array(
+// 'className' => 'Photo',
+// 'joinTable' => 'albums_photos',
+// 'foreignKey' => 'album_id',
+// 'associationForeignKey' => 'photo_id',
+// 'unique' => true,
+// 'conditions' => '',
+// 'fields' => '',
+// 'order' => 'AlbumsPhoto.order DESC',
+// 'limit' => '',
+// 'offset' => '',
+// 'finderQuery' => '',
+// 'deleteQuery' => '',
+// 'insertQuery' => ''
+// ),
+// 'Gallery' => array(
+// 'className' => 'Gallery',
+// 'joinTable' => 'galleries_albums',
+// 'foreignKey' => 'album_id',
+// 'associationForeignKey' => 'gallery_id',
+// 'unique' => true,
+// 'conditions' => '',
+// 'fields' => '',
+// 'order' => '',
+// 'limit' => '',
+// 'offset' => '',
+// 'finderQuery' => '',
+// 'deleteQuery' => '',
+// 'insertQuery' => ''
+// )
+// );
}
+
?>
@@ -0,0 +1,47 @@
+<?php
+
+class AlbumsPhoto extends AppModel {
+
+ var $name = 'AlbumsPhoto';
+ var $useDbConfig = 'director_spine';
+
+ var $belongsTo = array(
+ 'Album', 'Photo'
+ );
+
+ //The Associations below have been created with all possible keys, those that are not needed can be removed
+// var $hasAndBelongsToMany = array(
+// 'Album' => array(
+// 'className' => 'Album',
+// 'joinTable' => 'albums_photos',
+// 'foreignKey' => 'photo_id',
+// 'associationForeignKey' => 'album_id',
+// 'unique' => true,
+// 'conditions' => '',
+// 'fields' => '',
+// 'order' => 'AlbumsPhoto.order DESC',
+// 'limit' => '',
+// 'offset' => '',
+// 'finderQuery' => '',
+// 'deleteQuery' => '',
+// 'insertQuery' => ''
+// ),
+// 'Tag' => array(
+// 'className' => 'Tag',
+// 'joinTable' => 'photos_tags',
+// 'foreignKey' => 'photo_id',
+// 'associationForeignKey' => 'tag_id',
+// 'unique' => true,
+// 'conditions' => '',
+// 'fields' => '',
+// 'order' => '',
+// 'limit' => '',
+// 'offset' => '',
+// 'finderQuery' => '',
+// 'deleteQuery' => '',
+// 'insertQuery' => ''
+// )
+// );
+}
+
+?>
Oops, something went wrong.

0 comments on commit d74b710

Please sign in to comment.