I've got a Document model that's used for uploading various files by
an admin that can then be downloaded by users. The client wanted to be
able to specify a section/category for these files and so I've
included a DocumentSection model. The index page lists all Sections,
with each Document below. So far, so good.
Now, the client has expressed a desire to be able to re-order the
documents within each section and this has me stumped. I've done re-
ordering in Cake in the past, using MPTT (tree) model [1] and some
nifty jQuery drag & drop. However, because these documents are not all
in a single "list" (ie. they have different sections) I'm having some
difficulty figuring out how to proceed. Perhaps I've just missed
something so I'd like to throw it out there in case anyone has an
idea.
Just to clarify, I need to be able to re-order the list of Documents
within a given Section. Normally, I'd simply rely on the moveUp() &
moveDown() methods that TreeBehavior provides. But that presupposes
that we're dealing with a single list, not several, one for each
section.
Right now, I'm using the following simple method in the Document
model:
public function fetchAll()
{
return $this->DocumentSection->find(
'all',
array(
'contain' => array(
'Document'
)
)
);
}
... which gives me a list of Sections, each with their own list of
Documents.
Here's the current schema, without re-ordering:
CREATE TABLE document_sections
(
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(64) NOT NULL,
description text DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE TABLE documents
(
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL,
section_id INT(10) NOT NULL,
title VARCHAR(64) NOT NULL,
description text DEFAULT NULL,
directory VARCHAR(255) NOT NULL,
basename VARCHAR(64) NOT NULL,
extension VARCHAR(4) NOT NULL,
type VARCHAR(64) NOT NULL,
size INT(11) UNSIGNED NOT NULL,
FOREIGN KEY (section_id) REFERENCES document_sections (id)
) ENGINE=MyISAM DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Ideas?
[1] Modified Preorder Tree Traversal
http://articles.sitepoint.com/article/hierarchical-data-database
http://dev.mysql.com/tech-resources/articles/hierarchical-data.html
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment