/[drupal]/contributions/modules/helpdesk/misc.php
ViewVC logotype

Contents of /contributions/modules/helpdesk/misc.php

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


Revision 1.1 - (show annotations) (download) (as text)
Tue Jan 17 19:55:10 2006 UTC (3 years, 10 months ago) by fgm
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-4-6
File MIME type: text/x-php
First version under CVS control: not yet a working version: only performs a minimal subset of the functionality designed for the module.
1 <?php
2 /**
3 * Useful ancillary functions, not helpdesk-specific
4 * Copyright OSI 2005. Licensed under GPL version 2.
5 * $Id$
6 *
7 * @package helpdesk
8 * 20050920
9 * - Added _helpdesk_notempty()
10 */
11
12 define('HELPDESKUNIMPLEMENTED', t('To be implemented')) ;
13
14 /**
15 * Returns the type of a node, because Drupal uses two
16 * conventions for this: either node passed as its type or as an object
17 * @param mixed $node The node
18 * @return string The node type
19 */
20 function _helpdesk_node_type ($node)
21 {
22 return is_string ($node) ? $node : $node->type ;
23 }
24
25 /**
26 * A safer way of accessing a node's properties
27 *
28 * @param mixed $node
29 * @param string $prop
30 * @return string
31 */
32 function _helpdesk_get_node_property ($node, $prop)
33 {
34 if (!isset($node))
35 $ret = '(node not set)' ;
36 elseif (is_object($node))
37 $ret = isset($node->$prop) ? $node->$prop : '(property not set)' ;
38 elseif (is_array($node))
39 $ret = array_key_exists($prop, $node) ? $node[$prop] : '(array key not found)' ;
40 else
41 $ret = $node ;
42 return $ret ;
43 }
44
45 /**
46 * Returns a non empty string for anything passed to it.
47 *
48 * @param mixed $var The var to be displayed.
49 * @param string $default Value to be returned if variable is empty or non scalar
50 * @param bool $debug Provides detailed output for non-scalar types instead of defaulting
51 * @return string HTML code
52 */
53 function _helpdesk_notempty ($var, $default = '&nbsp;', $debug = FALSE)
54 {
55 if (!isset($var))
56 return $default ;
57
58 if (is_scalar($var))
59 return ($var <> '') ? $var : $default ;
60
61 if (is_resource($var))
62 return $debug
63 ? get_resource_type($var)
64 : $default ;
65
66 if (is_object($var))
67 {
68 if ($debug)
69 {
70 $ret = ' ';
71 print_r ($var, $ret) ;
72 $ret = "<pre>$ret</pre>" ;
73 }
74 else
75 $ret = $default ;
76 return $ret ;
77 }
78
79 if (is_array($var))
80 {
81 if ($debug)
82 {
83 $ret = '' ;
84 print_r ($var, $ret) ;
85 $ret = "<pre>$ret</pre>" ;
86 }
87 else
88 $ret = $default ;
89 return $ret ;
90 }
91
92 // No other type is supposed to exist
93 return "Error in _helpdesk_notempty(): variable of unknown type '" . gettype($var) . "' passed. Cannot process." ;
94 }
95 ?>
96

  ViewVC Help
Powered by ViewVC 1.1.2