3 * interface/therapy_groups/therapy_groups_models/therapy_groups_counselors_model.php contains the model for therapy group counselors.
5 * This model fetches the counselors for the therapy group 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>;.
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_Counselors
30 const TABLE
= 'therapy_groups_counselors';
32 public function getAllCounselors()
35 $sql = 'SELECT * FROM ' . SELf
::TABLE
;
37 $counselors = array();
38 $result = sqlStatement($sql);
39 while ($c = sqlFetchArray($result)) {
46 public function getCounselors($groupId)
49 $sql = 'SELECT user_id FROM ' . self
::TABLE
. ' WHERE group_id = ?';
51 $counselors = array();
52 $result = sqlStatement($sql, array($groupId));
53 while ($c = sqlFetchArray($result)) {
54 $counselors[] = $c['user_id'];
61 public function save($groupId, $userId)
64 $sql = "INSERT INTO " . self
::TABLE
. " (group_id, user_id) VALUES(?,?)";
65 sqlStatement($sql, array($groupId, $userId));
68 public function remove($groupId, $userId = null)
71 $sql = "DELETE FROM " . self
::TABLE
. " WHERE group_id = ?";
72 $condition[] = $groupId;
74 if (!is_null($userId)) {
75 $sql .= ' AND user_id = ?';
76 $condition[]= $userId;
79 sqlStatement($sql, $condition);
82 public function getAllCounselorsNames($groupId)
85 $counselors = $this->getCounselors($groupId);
86 $userModel = new Users();
88 foreach ($counselors as $counselor) {
89 $counselorName = $userModel->getUserNameById($counselor);
90 $result[] = $counselorName;