Fix for issue #291
[openemr.git] / library / classes / CategoryTree.class.php
blobdaf24e33bc689bce6d4ff85e8561b918b284f7ea
1 <?php
3 require_once("Tree.class.php");
5 /**
6 * class CategoryTree
7 * This is a class for storing document categories using the MPTT implementation
8 */
10 class CategoryTree extends Tree {
14 * This just sits on top of the parent constructor, only a shell so that the _table var gets set
16 function __construct($root,$root_type = ROOT_TYPE_ID) {
17 $this->_table = "categories";
18 parent::__construct($root,$root_type);
21 function _get_categories_array($patient_id) {
22 $categories = array();
23 $sql = "SELECT c.id, c.name, d.id AS document_id, d.type, d.url, d.docdate"
24 . " FROM categories AS c, documents AS d, categories_to_documents AS c2d"
25 . " WHERE c.id = c2d.category_id"
26 . " AND c2d.document_id = d.id";
28 if (is_numeric($patient_id)) {
29 if ($patient_id == "00") {
30 // Collect documents that are not assigned to a patient
31 $sql .= " AND (d.foreign_id = 0 OR d.foreign_id IS NULL) ";
33 else {
34 // Collect documents for a specific patient
35 $sql .= " AND d.foreign_id = '" . $patient_id . "'";
38 $sql .= " ORDER BY c.id ASC, d.docdate DESC, d.url ASC";
40 //echo $sql;
41 $result = $this->_db->Execute($sql);
43 while ($result && !$result->EOF) {
44 $categories[$result->fields['id']][$result->fields['document_id']] = $result->fields;
45 $result->MoveNext();
48 return $categories;