Highway to PSR2
[openemr.git] / interface / therapy_groups / therapy_groups_models / therapy_groups_model.php
blobe6113f8f94bd0338401d96769432e58ea67bab34
1 <?php
2 /**
3 * interface/therapy_groups/therapy_groups_models/therapy_groups_model.php contains the model for the therapy groups.
5 * This model fetches the therapy groups from the DB.
7 * Copyright (C) 2016 Shachar Zilbershlag <shaharzi@matrix.co.il>
8 * Copyright (C) 2016 Amiel Elboim <amielel@matrix.co.il>
10 * LICENSE: This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 3
13 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
21 * @package OpenEMR
22 * @author Shachar Zilbershlag <shaharzi@matrix.co.il>
23 * @author Amiel Elboim <amielel@matrix.co.il>
24 * @link http://www.open-emr.org
27 class Therapy_Groups
30 const TABLE = 'therapy_groups';
32 public function getAllGroups()
35 $sql = 'SELECT * FROM ' . self::TABLE . ' ORDER BY ' . self::TABLE . '.group_start_date DESC;';
37 $therapy_groups = array();
38 $result = sqlStatement($sql);
39 while ($tg = sqlFetchArray($result)) {
40 $therapy_groups[] = $tg;
43 return $therapy_groups;
46 public function getGroup($groupId)
49 $sql = "SELECT * FROM " . self::TABLE . " WHERE group_id = ?";
51 $group = sqlQuery($sql, array($groupId));
53 return $group;
56 public function saveNewGroup(array $groupData)
59 $sql = "INSERT INTO " . self::TABLE . " (group_name, group_start_date,group_type,group_participation,group_status,group_notes,group_guest_counselors) VALUES(?,?,?,?,?,?,?)";
60 $groupId = sqlInsert($sql, $groupData);
62 return $groupId;
65 public function updateGroup(array $groupData)
68 $sql = "UPDATE " . self::TABLE . " SET ";
69 foreach ($groupData as $key => $value) {
70 $sql .= $key . '=?,';
73 $sql = substr($sql, 0, -1);
74 $sql .= ' WHERE group_id = ?';
75 array_push($groupData, $groupData['group_id']);
76 $result = sqlStatement($sql, $groupData);
77 return !$result ? false :true;
80 public function existGroup($name, $startDate, $groupId = null)
83 $sql = "SELECT COUNT(*) AS count FROM " . self::TABLE . " WHERE group_name = ? AND group_start_date = ?";
84 $conditions = array($name, $startDate);
86 if (!is_null($groupId)) {
87 $sql .= " AND group_id <> ?";
88 $conditions[] = $groupId;
91 // $result = sqlStatement($sql, $conditions);
92 // $count = sqlFetchArray($result);
93 $count = sqlQuery($sql, $conditions);
94 return($count['count'] > 0) ? true : false;
97 /**
98 * Changes group status in DB.
99 * @param $group_id
100 * @param $status
102 public function changeGroupStatus($group_id, $status)
105 $sql = "UPDATE " . self::TABLE . " SET `group_status` = ? WHERE group_id = ?";
107 sqlStatement($sql, array($status, $group_id));
111 * Fetches groups data by given search parameter (used in popup search when in add_edit_event for groups).
112 * @param $search_params
113 * @param $result_columns
114 * @param $column
115 * @return array
117 public function getGroupData($search_params, $result_columns, $column, $onlyActive = true)
119 $sql = 'SELECT ' . $result_columns . ' FROM ' . self::TABLE . ' WHERE ' . $column . ' LIKE ? ';
120 // status 20 is 'deleted'
121 if ($onlyActive) {
122 $sql .= ' AND group_status = 10 ';
125 $sql .='ORDER BY group_start_date DESC;';
126 $search_params = '%' . $search_params . '%';
127 $result = sqlStatement($sql, array($search_params));
128 $final_result = array();
129 while ($row = sqlFetchArray($result)) {
130 $final_result[] = $row;
133 return $final_result;