1: <?php
2:
3: /**
4: * This file contains CONTENIDO Category API functions.
5: *
6: * If you are planning to add a function, please make sure that:
7: * 1.) The function is in the correct place
8: * 2.) The function is documented
9: * 3.) The function makes sense and is generically usable
10: *
11: * @package Core
12: * @subpackage Backend
13: * @version SVN Revision $Rev:$
14: *
15: * @author Timo Hummel
16: * @copyright four for business AG <www.4fb.de>
17: * @license http://www.contenido.org/license/LIZENZ.txt
18: * @link http://www.4fb.de
19: * @link http://www.contenido.org
20: */
21:
22: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
23:
24: /**
25: * Seeks through the category tree and returns the node on a specific level.
26: *
27: * Example:
28: * + Category A (15)
29: * |-+ News (16)
30: * | |- News A (17)
31: * + Category B (18)
32: * |-+ Internal (19)
33: *
34: * Given you are in the leaf "News A" (idcat 17), and you want to get out in which
35: * "main" tree you are, you can call the function like this:
36: *
37: * cApiCatGetLevelNode(17,1);
38: *
39: * The example would return "Category A" (idcat 15). If you specify an invalid level,
40: * the results are undefined.
41: *
42: * @deprecated [2015-05-21]
43: * This method is no longer supported (no replacement)
44: * @param int $idcat
45: * The category number
46: * @param int $minLevel
47: * The level to extract
48: * @return int
49: * The category node on a specific level
50: */
51: function cApiCatGetLevelNode($idcat, $minLevel = 0) {
52: global $cfg, $client, $lang;
53:
54: cDeprecated('This method is deprecated and is not needed any longer');
55:
56: $db = cRegistry::getDb();
57:
58: $sql = "SELECT
59: a.name AS name,
60: a.idcat AS idcat,
61: b.parentid AS parentid,
62: c.level AS level
63: FROM
64: " . $cfg['tab']['cat_lang'] . " AS a,
65: " . $cfg['tab']['cat'] . " AS b,
66: " . $cfg['tab']['cat_tree'] . " AS c
67: WHERE
68: a.idlang = " . (int) $lang . " AND
69: b.idclient = " . (int) $client . " AND
70: b.idcat = " . (int) $idcat . " AND
71: c.idcat = b.idcat AND
72: a.idcat = b.idcat";
73:
74: $db->query($sql);
75: $db->nextRecord();
76:
77: $parentid = $db->f('parentid');
78: $thislevel = $db->f('level');
79:
80: if ($parentid != 0 && $thislevel >= $minLevel) {
81: return cApiCatGetLevelNode($parentid, $minLevel);
82: } else {
83: return $idcat;
84: }
85: }
86: