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: *
45: * @param int $idcat
46: * The category number
47: * @param int $minLevel [optional]
48: * The level to extract
49: *
50: * @return int
51: * The category node on a specific level
52: *
53: * @throws cDbException
54: * @throws cInvalidArgumentException
55: */
56: function cApiCatGetLevelNode($idcat, $minLevel = 0) {
57:
58: global $cfg, $client, $lang;
59:
60: cDeprecated('This method is deprecated and is not needed any longer');
61:
62: $db = cRegistry::getDb();
63:
64: $sql = "SELECT
65: a.name AS name,
66: a.idcat AS idcat,
67: b.parentid AS parentid,
68: c.level AS level
69: FROM
70: " . $cfg['tab']['cat_lang'] . " AS a,
71: " . $cfg['tab']['cat'] . " AS b,
72: " . $cfg['tab']['cat_tree'] . " AS c
73: WHERE
74: a.idlang = " . (int) $lang . " AND
75: b.idclient = " . (int) $client . " AND
76: b.idcat = " . (int) $idcat . " AND
77: c.idcat = b.idcat AND
78: a.idcat = b.idcat";
79:
80: $db->query($sql);
81: $db->nextRecord();
82:
83: $parentid = $db->f('parentid');
84: $thislevel = $db->f('level');
85:
86: if ($parentid != 0 && $thislevel >= $minLevel) {
87: return cApiCatGetLevelNode($parentid, $minLevel);
88: } else {
89: return $idcat;
90: }
91: }
92: