add some documentation

This commit is contained in:
John Bintz 2009-11-05 21:45:27 -05:00
parent 7a98ebbad1
commit 55950e3a0a
1 changed files with 42 additions and 5 deletions

View File

@ -10,17 +10,26 @@ class ComicPressStoryline {
$this->create_structure($this->get_flattened_storyline()); $this->create_structure($this->get_flattened_storyline());
} }
/**
* Get the flattened storyline from options.
*/
function get_flattened_storyline() { function get_flattened_storyline() {
$comicpress = &ComicPress::get_instance(); $comicpress = &ComicPress::get_instance();
return $comicpress->comicpress_options['storyline_order']; return $comicpress->comicpress_options['storyline_order'];
} }
/**
* Set the global storyline as a flattened storyline.
*/
function set_flattened_storyline($storyline) { function set_flattened_storyline($storyline) {
$comicpress = &ComicPress::get_instance(); $comicpress = &ComicPress::get_instance();
$comicpress->comicpress_options['storyline_order'] = $storyline; $comicpress->comicpress_options['storyline_order'] = $storyline;
$comicpress->save(); $comicpress->save();
} }
/**
* Set the order from a flattened storyline.
*/
function set_order_via_flattened_storyline($order) { function set_order_via_flattened_storyline($order) {
$nodes = explode(',', $order); $nodes = explode(',', $order);
$original_nodes = explode(',', $this->get_flattened_storyline()); $original_nodes = explode(',', $this->get_flattened_storyline());
@ -150,10 +159,17 @@ class ComicPressStoryline {
return $result; return $result;
} }
/**
* Get all comic categories.
* @deprecated
*/
function get_comic_categories() { function get_comic_categories() {
return array_keys($this->_structure); return array_keys($this->_structure);
} }
/**
* Get a simple storyline.
*/
function get_simple_storyline() { function get_simple_storyline() {
$simple_storyline = array('0' => array()); $simple_storyline = array('0' => array());
foreach ($this->_structure as $category_id => $adjacents) { foreach ($this->_structure as $category_id => $adjacents) {
@ -168,6 +184,9 @@ class ComicPressStoryline {
return $this->_merge_simple_storyline($simple_storyline); return $this->_merge_simple_storyline($simple_storyline);
} }
/**
* Get a simple structure.
*/
function get_category_simple_structure($parent = null) { function get_category_simple_structure($parent = null) {
$structure = array(); $structure = array();
foreach (get_all_category_ids() as $category_id) { foreach (get_all_category_ids() as $category_id) {
@ -188,10 +207,16 @@ class ComicPressStoryline {
return $structure; return $structure;
} }
/**
* Get a flattened category node list.
*/
function get_category_flattened($parent = null) { function get_category_flattened($parent = null) {
return $this->flatten_simple_storyline($this->get_category_simple_structure($parent)); return $this->flatten_simple_storyline($this->get_category_simple_structure($parent));
} }
/**
* Merge a flat simple storyline into a tree.
*/
function _merge_simple_storyline($simple_storyline) { function _merge_simple_storyline($simple_storyline) {
while (count($simple_storyline) > 0) { while (count($simple_storyline) > 0) {
$merge_found = false; $merge_found = false;
@ -240,6 +265,9 @@ class ComicPressStoryline {
return $result; return $result;
} }
/**
* Sort nodes by node count.
*/
function _length_sort($parts) { function _length_sort($parts) {
$new = array(); $new = array();
foreach ($parts as $part) { foreach ($parts as $part) {
@ -257,6 +285,9 @@ class ComicPressStoryline {
return $output; return $output;
} }
/**
* Normalize a flattened storyline, inserting and removing categories from the list is necessary.
*/
function normalize_flattened_storyline($storyline, $comic_categories) { function normalize_flattened_storyline($storyline, $comic_categories) {
$storyline_nodes = explode(",", $storyline); $storyline_nodes = explode(",", $storyline);
$category_nodes = explode(",", $comic_categories); $category_nodes = explode(",", $comic_categories);
@ -295,10 +326,16 @@ class ComicPressStoryline {
return implode(',', $storyline_nodes); return implode(',', $storyline_nodes);
} }
/**
* Flatten a simple storyline.
*/
function flatten_simple_storyline($storyline) { function flatten_simple_storyline($storyline) {
return implode(',', $this->_follow_simple_storyline($storyline)); return implode(',', $this->_follow_simple_storyline($storyline));
} }
/**
* Follow the nodes of a simple storyline, creating a node list.
*/
function _follow_simple_storyline($storyline, $parent = null) { function _follow_simple_storyline($storyline, $parent = null) {
$output = array(); $output = array();
foreach ($storyline as $key => $children) { foreach ($storyline as $key => $children) {