salimkanoun /
GaelO
| 1 | <?php |
||
| 2 | /** |
||
| 3 | Copyright (C) 2018-2020 KANOUN Salim |
||
| 4 | This program is free software; you can redistribute it and/or modify |
||
| 5 | it under the terms of the Affero GNU General Public v.3 License as published by |
||
| 6 | the Free Software Foundation; |
||
| 7 | This program is distributed in the hope that it will be useful, |
||
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 10 | Affero GNU General Public Public for more details. |
||
| 11 | You should have received a copy of the Affero GNU General Public Public along |
||
| 12 | with this program; if not, write to the Free Software Foundation, Inc., |
||
| 13 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
||
| 14 | */ |
||
| 15 | |||
| 16 | /** |
||
| 17 | * Tracker related methods |
||
| 18 | * @author salim |
||
| 19 | * |
||
| 20 | */ |
||
| 21 | class Tracker { |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Get tracker data by Role +- Study Filter |
||
| 25 | * @param string $role |
||
| 26 | * @param PDO $linkpdo |
||
| 27 | * @param string $study |
||
| 28 | * @return array |
||
| 29 | */ |
||
| 30 | public static function getTrackerByRoleStudy(string $role, PDO $linkpdo, $study=null) { |
||
| 31 | if ($study == null) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 32 | $queryTracker=$linkpdo->prepare('SELECT * FROM tracker WHERE role=:role'); |
||
| 33 | $queryTracker->execute(array( |
||
| 34 | 'role' => $role |
||
| 35 | )); |
||
| 36 | |||
| 37 | }else { |
||
| 38 | $queryTracker=$linkpdo->prepare('SELECT * FROM tracker WHERE study = :study AND role=:role'); |
||
| 39 | $queryTracker->execute(array('study' => $study, |
||
| 40 | 'role' => $role, |
||
| 41 | )); |
||
| 42 | |||
| 43 | } |
||
| 44 | $trackerResult=$queryTracker->fetchAll(PDO::FETCH_ASSOC); |
||
| 45 | |||
| 46 | return $trackerResult; |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Return logged users messages of a study |
||
| 51 | * @param string $study |
||
| 52 | * @param PDO $linkpdo |
||
| 53 | * @return array |
||
| 54 | */ |
||
| 55 | public static function getMessageStudy(string $study, PDO $linkpdo) { |
||
| 56 | $queryTracker=$linkpdo->prepare('SELECT * FROM tracker WHERE study = :study AND action_type="Send Message"'); |
||
| 57 | $queryTracker->execute(array('study' => $study)); |
||
| 58 | $trackerResult=$queryTracker->fetchAll(PDO::FETCH_ASSOC); |
||
| 59 | return $trackerResult; |
||
| 60 | } |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Get tracker data for a specific visit |
||
| 64 | * @param string $id_visit |
||
| 65 | * @param PDO $linkpdo |
||
| 66 | * @return array |
||
| 67 | */ |
||
| 68 | public static function getTackerForVisit(string $id_visit, PDO $linkpdo) { |
||
| 69 | $queryTracker=$linkpdo->prepare('SELECT * FROM tracker WHERE id_visit = :id_visit ORDER BY date'); |
||
| 70 | $queryTracker->execute(array('id_visit' => $id_visit)); |
||
| 71 | $trackerResult=$queryTracker->fetchAll(PDO::FETCH_ASSOC); |
||
| 72 | return $trackerResult; |
||
| 73 | } |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Activity logger to log user activity in database |
||
| 77 | * Activity should be an associative key, will be JSON encoded |
||
| 78 | */ |
||
| 79 | public static function logActivity($username, $role, $study, $id_visit, $actionType, $actionDetails) { |
||
| 80 | |||
| 81 | $linkpdo=Session::getLinkpdo(); |
||
| 82 | |||
| 83 | $connecter=$linkpdo->prepare('INSERT INTO tracker (date, username, role, study, id_visit, action_type, action_details) |
||
| 84 | VALUES(:date, :username, :role, :study, :id_visit, :action_type, :action_details)' ); |
||
| 85 | |||
| 86 | $connecter->execute(array( |
||
| 87 | "username" => $username, |
||
| 88 | "role" => $role, |
||
| 89 | "date"=> date('Y-m-d H:i:s').substr((string)microtime(), 1, 6), |
||
| 90 | "study"=>$study, |
||
| 91 | "id_visit"=>$id_visit, |
||
| 92 | "action_type"=>$actionType, |
||
| 93 | "action_details"=>json_encode($actionDetails) |
||
| 94 | )); |
||
| 95 | |||
| 96 | } |
||
| 97 | |||
| 98 | } |