How to manage collections
From Armarius
http://www.armarius.org/wiki/index.php/Propositions
Contents |
[edit] Database tables
The new database table will be `armarius_collections`, `armarius_pages` and `armarius_collections_content` Old tables like `prefix_collections`, `prefix_volumes`, `prefix_page_orders`, `prefix_pages` will be removed.
[edit] Structure proposition & exemples
| `armarius_collections` | `armarius_pages` | `armarius_collections_content` | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
Means that Collection 1 is composed by the pages 1 and 2.
Collection 1 is also composed by the sub collection 3.
Collection 3 is composed by the page 12 and the sub collection 5.
Finally Sub Collection 5 is empty.
The purpose of the letters p or c is only to know the type of the child element. In fact p will mean page and c will mean collection.
[edit] Querys
Example : List all the content of the Collection 1
Get the collection name SELECT col_name FROM `armarius_collections` WHERE col_id=1;
Get the collection content SELECT * FROM `armarius_collections_content` WHERE id_parent=1;
For each fetched row : If (id_child begin with p) Then take the number after the p letter, put into the $id_page variable and make a query for this page. SELECT * FROM `armarius_pages` WHERE pd_id=$id_page; Display the page information Else if (id_child begin with c) Then take the number after the c letter ant put it into the array $collections_to_scan[] (this array will contain all the sub-collections to list after)
Repeat this procedure for each row of the $collections_to_scan[] array in order to list in a recursive way all the content of the collection.
Notice that an error in the table `armarius_collections_content` can produce an infinite loop.
[edit] Functions querys
- function create_collection($collection_name)
INSERT INTO `armarius_collections` (col_name) VALUES ('$collection_name');
//Get the ID of the inserted row into $id_collection
Return $id_collection
- function edit_collection_name($id_collection, $collection_name)
UPDATE `armarius_collections` SET col_name = '$collection_name' WHERE col_id = $id_collection;
- function remove_collection($id_collection)
DELETE FROM `armarius_collections` WHERE col_id = $id_collection; //Remove data recursively
- function add_subcollection($id_collection_parent, $id_subcollection)
INSERT INTO `armarius_collections_content` (cc_col_id, cc_content) VALUES ($id_collection_parent, 'c_'+$id_subcollection);
- function import_page($url_to_page, $id_collection, optional $page_title)
INSERT INTO `armarius_pages` (pg_filename, pg_title) VALUES ('$page_filename','$page_title');
//Get the ID of the inserted row into $id_page
INSERT INTO `armarius_collections_content` (cc_col_id, cc_content) VALUES ($id_collection_parent, 'p_'+$id_page);
Return $id_page
- function edit_page($id_page, $page_title)
UPDATE `armarius_pages` SET pg_title = '$page_title' WHERE pg_id = $id_page;
- function move_page($id_page, $id_collection)
UPDATE `armarius_collections_content` SET cc_col_id = $id_collection WHERE cc_content = $id_page; //Each page has an unique ID
- function move_pages_set($array_of_id_pages, $id_collection)
For each page of the array $array_of_id_pages call move_page function.
- function delete_page($id_page)
DELETE FROM `armarius_pages` WHERE pg_id = $id_page; DELETE FROM `armarius_collections_content` WHERE cc_content = 'p_'+'$id_page';
- function delete_pages_set($array_of_id_pages)
For each page of the array $array_of_id_pages call delete_page function.
- function find_collection($id_collection)
Repeat SELECT cc_col_id FROM `armarius_collections_content` WHERE cc_content = 'c_'+'$id_collection'; //Put query result into the variable $query_result $route_from_root=$route_from_root+$query_result //Concatenate all the collections containing the searched collection in order to have the complete location to it Until the query is empty //If this query returns an empty result it means that the collections is at the root Return $route_from_root
- function locate_page($id_page)
SELECT cc_col_id FROM `armarius_collections_content` WHERE cc_content = 'p_'+'$id_page'; //Put query result into the variable $query_result Return 'c'+$query_result


