/[drupal]/contributions/modules/skeleton/skeleton_common.inc
ViewVC logotype

Contents of /contributions/modules/skeleton/skeleton_common.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.5 - (show annotations) (download) (as text)
Wed Jan 7 01:45:12 2009 UTC (10 months, 3 weeks ago) by deviantintegral
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-ALPHA1, HEAD
Changes since 1.4: +1 -31 lines
File MIME type: text/x-php
#352258: agentrickard, Remove include_once('skeleton_common.inc');.
1 <?php
2
3 // $Id: skeleton_common.inc,v 1.4 2008/12/08 22:07:31 deviantintegral Exp $
4
5 /**
6 * @file
7 * Common functions for the skeleton module
8 */
9
10 /**
11 * Get the data for a skeleton from a title
12 * @param $skeleton
13 * The name of the outline to act upon
14 * @return $result
15 * An object containing elements from the {skeleton} table
16 */
17 function skeleton_get_by_name($skeleton) {
18 $result = db_fetch_object(db_query("SELECT * FROM {skeleton} WHERE skeleton = '%s'", $skeleton));
19 return $result;
20 }
21
22 /**
23 * Get the data for a skeleton template from a title
24 *
25 * @param $template
26 * The name of the template to act upon
27 * @return $result
28 * An object containing elements from the {skeleton_template} table
29 */
30 function skeleton_get_template_by_name($template) {
31 $result = db_fetch_object(db_query("SELECT * FROM {skeleton_template} WHERE template = '%s'", $template));
32 if ($result->node_data) {
33 // node data is a complex serialized array
34 $result->node_data = unserialize($result->node_data);
35 }
36 return $result;
37 }
38
39 /**
40 * Get the tree structure for a skeleton outline
41 * Function cirbbed from taxonomy_get_tree().
42 *
43 * @param $skeleton_id
44 * The id number of the skeleton outline being acted upon.
45 * @param $parent
46 * The parent id of an item in the outline
47 * @param $depth
48 * The depth of iterations through the parent-child relationship
49 * @param $max_depth
50 * The maximum depth to traverse.
51 * @return $tree
52 * A weighted array of templates assigned to this outline.
53 */
54 function skeleton_get_tree($skeleton_id, $parent = 0, $depth = -1, $max_depth = NULL) {
55 static $children, $parents, $templates, $storage;
56 $depth++;
57 // We cache trees, so it's not CPU-intensive to call get_tree() on a template
58 // and its children, too.
59 if (!isset($children[$skeleton_id][$parent])) {
60 $children[$skeleton_id][$parent] = array();
61 $result = db_query("SELECT sd.template_id, st.template, st.node_type, st.node_data, sd.parent, sd.weight FROM {skeleton_data} sd INNER JOIN {skeleton_template} st
62 ON sd.template_id = st.template_id WHERE sd.skeleton_id = %d ORDER BY sd.parent, sd.weight, st.template, sd.template_id DESC", $skeleton_id, $parent);
63 while ($template = db_fetch_object($result)) {
64 $children[$skeleton_id][$template->parent][] = $template->template_id;
65 $parents[$skeleton_id][$template->template_id][] = $template->parent;
66 // because we don't have a hierachy table like taxonomy, we run this query and store
67 // children in a separate array to prevent duplication of terms
68 $parental = 0;
69 if ($template->parent) {
70 $parental = db_result(db_query("SELECT parent FROM {skeleton_data} WHERE skeleton_id = %d AND template_id = %d", $skeleton_id, $template->parent));
71 }
72 if ($parental) {
73 $storage[$skeleton_id][$parental][] = $template->template_id;
74 $parents[$skeleton_id][$template->template_id][] = $parental;
75 }
76 $storage[$skeleton_id][$template->parent][] = $template->template_id;
77 $templates[$skeleton_id][$template->template_id] = $template;
78 }
79 }
80 // this section needs work, without the {taxonomy_hierarchy} table, the logic
81 // for taxonomy_get_tree() isn't fully supported. This seems to work.
82 if ($parent && !empty($storage[$skeleton_id][$parent])) {
83 foreach ($storage[$skeleton_id][$parent] as $key => $temp) {
84 if (!empty($storage[$skeleton_id][$temp])) {
85 foreach ($storage[$skeleton_id][$temp] as $t) {
86 if (!in_array($t, $storage[$skeleton_id][$parent])) {
87 $storage[$skeleton_id][$parent][] = $t;
88 }
89 }
90 }
91 }
92 }
93 $max_depth = (is_null($max_depth)) ? count($children[$skeleton_id]) : $max_depth;
94 if ($children[$skeleton_id][$parent]) {
95 foreach ($children[$skeleton_id][$parent] as $child) {
96 if ($max_depth > $depth) {
97 $template = drupal_clone($templates[$skeleton_id][$child]);
98 $template->depth = $depth;
99 $template->parents = $parents[$skeleton_id][$child];
100 $tree[] = $template;
101 // iterate again, if needed
102 if ($children[$skeleton_id][$child]) {
103 $tree = array_merge($tree, skeleton_get_tree($skeleton_id, $child, $depth, $max_depth));
104 }
105 }
106 }
107 }
108 // kluge, see note at line 110.
109 if (!empty($tree)) {
110 foreach ($tree as $i => $element) {
111 $tree[$i]->children = $storage[$skeleton_id][$element->template_id];
112 }
113 }
114 return $tree ? $tree : array();
115 }

  ViewVC Help
Powered by ViewVC 1.1.2