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 generally usable
10: *
11: * @package Core
12: * @subpackage Backend
13: * @author Timo Hummel
14: * @copyright four for business AG <www.4fb.de>
15: * @license http://www.contenido.org/license/LIZENZ.txt
16: * @link http://www.4fb.de
17: * @link http://www.contenido.org
18: */
19:
20: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
21:
22: /**
23: * Seeks through the category tree and returns the node on a specific level.
24: *
25: * Example:
26: * <pre>
27: * + Category A (15)
28: * |-+ News (16)
29: * | |- News A (17)
30: * + Category B (18)
31: * |-+ Internal (19)
32: * </pre>
33: *
34: * Given you are in the leaf "News A" (idcat 17), and you want to find
35: * out in which "main" tree you are, you can call the function like this:
36: *
37: * <code>cApiCatGetLevelNode(17, 1);</code>
38: *
39: * The example would return "Category A" (idcat 15). If you specify an
40: * invalid level 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 [optional]
47: * The level to extract
48: * @return int
49: * The category node on a specific level
50: */
51: function cApiCatGetLevelNode($idcat, $minLevel = 0) {
52:
53: global $cfg, $client, $lang;
54:
55: cDeprecated('This method is deprecated and is not needed any longer');
56:
57: $db = cRegistry::getDb();
58:
59: $sql = "SELECT
60: a.name AS name,
61: a.idcat AS idcat,
62: b.parentid AS parentid,
63: c.level AS level
64: FROM
65: " . $cfg['tab']['cat_lang'] . " AS a,
66: " . $cfg['tab']['cat'] . " AS b,
67: " . $cfg['tab']['cat_tree'] . " AS c
68: WHERE
69: a.idlang = " . (int) $lang . " AND
70: b.idclient = " . (int) $client . " AND
71: b.idcat = " . (int) $idcat . " AND
72: c.idcat = b.idcat AND
73: a.idcat = b.idcat";
74:
75: $db->query($sql);
76: $db->nextRecord();
77:
78: $parentid = $db->f('parentid');
79: $thislevel = $db->f('level');
80:
81: if ($parentid != 0 && $thislevel >= $minLevel) {
82: return cApiCatGetLevelNode($parentid, $minLevel);
83: } else {
84: return $idcat;
85: }
86: }
87: