Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //include_once "http.php";
- class Service{
- public $dbh;
- public $host='localhost';
- public $dbname='tutor';
- public $username='root';
- public $password='';
- //connect to database , initiates the handler
- public function connect($host='localhost',$dbname='irelandt_ireland',$username='irelandt_vlat',$password='vlat@123'){
- try {
- $this->dbh=new PDO('mysql:host='.$host.';dbname='.$dbname.";charset=utf8",$username,$password);
- $this->dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
- } catch (Exception $e) {
- die("this site in under maintenance");
- }
- }
- /*
- public function connect(){
- $this->dbh=new PDO('mysql:host=localhost','irelandt_vlat','vlat@123');
- }*/
- public function disconnect(){
- $this->dbh=null;
- }
- public function splitAndAddStars($var){
- if(strlen($var)>0){
- $tab = explode(" ", $var);
- $n=count($tab);
- $res="";
- for($i=0;$i<$n;$i++){
- if(strlen($tab[$i])>0)
- $res=$res.'+'.$tab[$i].'* ';
- }
- return $res;
- }else{
- return '';
- }
- }
- public function getAllCourses(){
- $this->connect();
- $stm = $this->dbh->prepare("select * from courses");
- $stm->execute();
- $courses = $stm->fetchAll();
- return $courses;
- }
- /*public function getTutors($x,$courseid){
- $this->connect();
- $q="SELECT *, match(firstname,lastname,email,telephone,address,title,description) against(:var in boolean mode)
- as relevance1
- from users left join tutorscourses on users.userid = tutorscourses.tutorid where tutor = 1 AND
- (:courseid=0 OR tutorscourses.courseid=:courseid) AND
- match(firstname,lastname,email,telephone,address,title,description) against(:var in boolean mode)
- order by relevance1";
- $emptyQ="select * from users left join
- tutorscourses on users.userid = tutorscourses.tutorid
- where tutor = 1 AND
- (:courseid=0 OR tutorscourses.courseid=:courseid)
- order by firstname,lastname";
- $r=$q;
- if(empty($x)){
- $r=$emptyQ;
- }
- $sth=$this->dbh->prepare($r);
- $var=$this->splitAndAddStars($x);
- $sth->bindParam(':var',$var);
- $sth->bindParam(':courseid',$courseid);
- $sth->execute();
- $users=$sth->fetchAll();
- $this->disconnect();
- return $users;
- }*/
- public function getTutors($x,$courseid){
- $this->connect();
- $q="SELECT *,(SELECT avg(rating) FROM ratings WHERE ratings.tutorid=users.userid) rating, match(firstname,lastname,email,telephone,address,descriptionStudent) against(:var in boolean mode)
- as relevance1
- from users where tutor = 1 and
- match(firstname,lastname,email,telephone,address,descriptionStudent) against(:var in boolean mode)
- order by relevance1";
- $emptyQ="SELECT *,(SELECT avg(rating) FROM ratings WHERE ratings.tutorid=users.userid) as rating from users where tutor=1 order by firstname,lastname";
- $r=$q;
- if(empty($x)){
- $r=$emptyQ;
- }
- $sth=$this->dbh->prepare($r);
- $var=$this->splitAndAddStars($x);
- $sth->bindParam(':var',$var);
- $sth->bindParam(':courseid',$courseid);
- $sth->execute();
- $users=$sth->fetchAll();
- $this->disconnect();
- return $users;
- }
- public function getStudents($x){
- $this->connect();
- $q="SELECT *, match(firstname,lastname,email,telephone,address,descriptionStudent) against(:var in boolean mode)
- as relevance1
- from users where
- match(firstname,lastname,email,telephone,address,descriptionStudent) against(:var in boolean mode)
- order by relevance1";
- $emptyQ="select * from users order by firstname,lastname";
- $r=$q;
- if(empty($x)){
- $r=$emptyQ;
- }
- $sth=$this->dbh->prepare($r);
- $var=$this->splitAndAddStars($x);
- $sth->bindParam(':var',$var);
- $sth->execute();
- $users=$sth->fetchAll();
- $this->disconnect();
- return $users;
- }
- public function findWord($str,$x){
- $split = explode(" ",$str);
- for($i=0;$i<Count($split);$i++){
- if(strlen($split[$i]) > 2 && stripos($split[$i],$x) !== false){
- return $split[$i];
- }
- }
- return false;
- }
- public function predictStudents($x){
- $users = $this->getStudents($x);
- $split = explode(" ", $x);
- $n = Count($split);
- $resArr=array();
- foreach ($users as $row) {
- $res="";
- for($i=0;$i<$n;$i++){
- $found=$this->findWord($row['firstname'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- $found=$this->findWord($row['lastname'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- $found=$this->findWord($row['address'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- $found=$this->findWord($row['title'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- $found=$this->findWord($row['descriptionStudent'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- }
- array_push($resArr, $res);
- }
- return json_encode(array_unique($resArr));
- }
- public function predictTutors($x){
- $users = $this->getTutors($x,0);
- $split = explode(" ", $x);
- $n = Count($split);
- $resArr=array();
- foreach ($users as $row) {
- $res="";
- for($i=0;$i<$n;$i++){
- $found=$this->findWord($row['firstname'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- $found=$this->findWord($row['lastname'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- $found=$this->findWord($row['address'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- $found=$this->findWord($row['title'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- $found=$this->findWord($row['descriptionStudent'],$split[$i]);
- if($found!==false){
- if(stripos($res,$found) ===false)
- $res = $res." ".$found;
- }
- }
- array_push($resArr, $res);
- }
- return json_encode(array_unique($resArr));
- }
- public function getTutorsForRating($studentid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT tutors.* from users tutors
- JOIN bookings
- ON tutors.userid = bookings.tutorid
- WHERE bookings.studentid=:studentid
- AND bookings.status = 'Approved'
- ");
- $sth->bindParam(':studentid', $studentid);
- $sth->execute();
- $tutors=$sth->fetchAll();
- $this->disconnect();
- return $tutors;
- }
- public function getRatingTutorStudent($studentid,$tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * FROM ratings WHERE tutorid=:tutorid and studentid=:studentid
- ");
- $sth->bindParam(':studentid', $studentid);
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $rating=$sth->fetchAll();
- $this->disconnect();
- return $rating;
- }
- public function getRating($tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT avg(rating) FROM ratings WHERE tutorid=:tutorid
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $rating=$sth->fetchAll();
- $this->disconnect();
- return $rating[0][0];
- }
- public function checkIfTutorCanBeRatedByUser($userid,$tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT count(*) as cnt FROM bookings WHERE tutorid=:tutorid and studentid=:studentid
- AND status IN ('Booked','Done')
- ");
- $sth->bindParam(':studentid', $userid);
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $res=$sth->fetchAll();
- if($res[0]['cnt']==0){
- $this->disconnect();
- return false;
- }
- $this->disconnect();
- return true;
- }
- public function insertRating($studentid,$tutorid,$description,$rating,$title){
- $this->connect();
- $sth = $this->dbh->prepare("
- INSERT INTO ratings VALUES(null,:tutorid,:studentid,:description,:rating,:title)
- ");
- $sth->bindParam(':studentid', $studentid);
- $sth->bindParam(':tutorid', $tutorid);
- $sth->bindParam(':description', $description);
- $sth->bindParam(':rating', $rating);
- $sth->bindParam(':title', $title);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- public function updateRating($studentid,$tutorid,$description,$rating,$title){
- $this->connect();
- $sth = $this->dbh->prepare("
- UPDATE ratings SET
- description=:description,
- rating=:rating,
- title=:title
- WHERE tutorid=:tutorid
- AND studentid=:studentid
- ");
- $sth->bindParam(':studentid', $studentid);
- $sth->bindParam(':tutorid', $tutorid);
- $sth->bindParam(':description', $description);
- $sth->bindParam(':rating', $rating);
- $sth->bindParam(':title', $title);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- public function checkIfRatingExist($studentid,$tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT COUNT(*) AS numOfRatings FROM ratings
- WHERE studentid=:studentid
- AND tutorid=:tutorid
- ");
- $sth->bindParam(':studentid', $studentid);
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $row=$sth->fetch();
- if($row["numOfRatings"]==0){
- $this->disconnect();
- return false;
- }else {
- $this->disconnect();
- return true;
- }
- }
- public function addRating($studentid,$tutorid,$description,$rating,$title){
- $var = $this->checkIfRatingExist($studentid,$tutorid);
- if($var==false){
- return $this->insertRating($studentid,$tutorid,$description,$rating,$title);
- }else{
- return $this->updateRating($studentid,$tutorid,$description,$rating,$title);
- }
- }
- public function getSchedule($tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * from schedule
- WHERE tutorid=:tutorid
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $tutors=$sth->fetchAll();
- $this->disconnect();
- return $tutors;
- }
- public function getFreeSchedule($tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * from schedule
- WHERE tutorid=:tutorid
- AND status='Free'
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $tutors=$sth->fetchAll();
- $this->disconnect();
- return $tutors;
- }
- public function checkIfFreeTimeExists($tutorid,$day,$timefrom,$timetill){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT COUNT(*) as numOfFree FROM schedule
- WHERE tutorid=:tutorid
- AND day=:day
- AND ( (:timefrom >=timefrom AND :timefrom<timetill)
- OR (:timetill >timefrom AND :timetill<=timetill))
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->bindParam(':day', $day);
- $sth->bindParam(':timefrom', $timefrom);
- $sth->bindParam(':timetill', $timetill);
- $sth->execute();
- $row=$sth->fetch();
- if($row["numOfFree"]==0){
- $this->disconnect();
- return false;
- }else {
- $this->disconnect();
- return true;
- }
- }
- public function insertFreeTime($tutorid,$day,$timefrom,$timetill){
- $var = $this->checkIfFreeTimeExists($tutorid,$day,$timefrom,$timetill);
- if($var==false){
- $this->connect();
- $sth = $this->dbh->prepare("
- INSERT INTO schedule values(null,:tutorid,:day,:timefrom,:timetill,'free')
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->bindParam(':day', $day);
- $sth->bindParam(':timefrom', $timefrom);
- $sth->bindParam(':timetill', $timetill);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- return false;
- }
- public function checkIfTimeIsFree($scheduleid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT COUNT(*) as numOfFree FROM schedule
- WHERE scheduleid=:scheduleid
- AND status='Free'
- ");
- $sth->bindParam(':scheduleid', $scheduleid);
- $sth->execute();
- $row=$sth->fetch();
- if($row["numOfFree"]==0){
- $this->disconnect();
- return false;
- }else {
- $this->disconnect();
- return true;
- }
- }
- public function deleteFreeTime($tutorid,$day,$timefrom){
- if(true){
- $this->connect();
- $sth = $this->dbh->prepare("
- DELETE FROM schedule WHERE tutorid=:tutorid AND day=:day AND timefrom=:timefrom
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->bindParam(':day', $day);
- $sth->bindParam(':timefrom', $timefrom);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- return false;
- }
- public function checkIfHasBookingPending($studentid,$tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT COUNT(*) as numOfBookings FROM bookings
- WHERE studentid=:studentid
- AND tutorid=:tutorid
- AND status='Pending'
- ");
- $sth->bindParam(':studentid', $studentid);
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $row=$sth->fetch();
- if($row["numOfBookings"]==0){
- $this->disconnect();
- return false;
- }else {
- $this->disconnect();
- return true;
- }
- }
- public function getBookIdPending($studentid,$tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT bookid FROM bookings
- WHERE studentid=:studentid
- AND tutorid=:tutorid
- AND status='Pending'
- ");
- $sth->bindParam(':studentid', $studentid);
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $row=$sth->fetch();
- return $row["bookid"];
- }
- public function insertBooking($studentid,$tutorid){//returns bookid when inserted and 0 if cannot insert because already has pending book
- $var = $this->checkIfHasBookingPending($studentid,$tutorid);
- if($var==false){
- $this->connect();
- $sth = $this->dbh->prepare("
- INSERT INTO bookings VALUES(null,:studentid,:tutorid,'Pending')
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->bindParam(':studentid', $studentid);
- $sth->execute();
- $this->disconnect();
- return $this->getBookIdPending($studentid,$tutorid);
- }
- return 0;
- }
- public function checkIfBookTimeExists($bookid,$day,$timefrom,$timetill){//check if booking has conflict
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT COUNT(*) as numOfBookings FROM bookingdetails
- WHERE bookid=:bookid
- AND day=:day
- AND ( (:timefrom >=timefrom AND :timefrom<timetill)
- OR (:timetill >timefrom AND :timetill<=timetill))
- ");
- $sth->bindParam(':bookid', $bookid);
- $sth->bindParam(':day', $day);
- $sth->bindParam(':courseid', $courseid);
- $sth->bindParam(':timefrom', $timefrom);
- $sth->bindParam(':timetill', $timetill);
- $sth->execute();
- $row=$sth->fetch();
- if($row["numOfBookings"]==0){
- $this->disconnect();
- return false;
- }else {
- $this->disconnect();
- return true;
- }
- }
- public function insertBookingDetails($bookid,$day,$timefrom,$timetill,$courseid){//returns true if no conflict and insert successful
- $var = $this->checkIfBookTimeExists($bookid,$day,$timefrom,$timetill);
- if($var==false){
- $this->connect();
- $sth = $this->dbh->prepare("
- INSERT INTO bookingdetails VALUES(null,:bookid,:day,:timefrom,:timetill,:courseid)
- ");
- $sth->bindParam(':bookid', $bookid);
- $sth->bindParam(':day', $day);
- $sth->bindParam(':courseid', $courseid);
- $sth->bindParam(':timefrom', $timefrom);
- $sth->bindParam(':timetill', $timetill);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- return false;
- }
- /*
- public function getPendingBookingsForTutor($tutorid){//returns all pending booking for a tutor
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * FROM bookings JOIN bookingdetails
- ON bookingdetails.bookid=bookings.bookid
- WHERE tutorid=:tutorid
- AND status='Pending'
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $tutors=$sth->fetchAll();
- $this->disconnect();
- return $tutors;
- }*/
- public function getPendingBookingsForTutor($tutorid){//returns all pending booking for a tutor
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * FROM bookings
- WHERE tutorid=:tutorid
- AND status='Pending'
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $tutors=$sth->fetchAll();
- $this->disconnect();
- return $tutors;
- }
- public function getBookingDetails($bookid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * FROM bookingdetails bd JOIN bookings b
- ON bd.bookid=b.bookid
- WHERE bd.bookid=:bookid
- ");
- $sth->bindParam(':bookid', $bookid);
- $sth->execute();
- $res=$sth->fetchAll();
- $this->disconnect();
- return $res;
- }
- public function compareWithSchedule($tutorid,$day,$timefrom,$timetill){//returns true if there is no conflict with schedule
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT COUNT(*) as num FROM schedule
- WHERE tutorid=:tutorid
- AND day=:day
- AND (:timefrom >=timefrom AND :timetill<=timetill)
- AND status='Free'
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->bindParam(':day', $day);
- $sth->bindParam(':timefrom', $timefrom);
- $sth->bindParam(':timetill', $timetill);
- $sth->execute();
- $row=$sth->fetch();
- if($row["num"]==0){
- $this->disconnect();
- return false;
- }else{
- $this->disconnect();
- return true;
- }
- }
- public function checkIfApprovingBookingCreatesConflictWithSchedule($bookid){//return true if the bookingdetails presents a conflict with shcedule
- $bookingDetails=$this->getBookingDetails($bookid);
- foreach($bookingDetails as $details){
- $var = $this->compareWithSchedule($details["tutorid"],$details["day"],$details["timefrom"],$details["timetill"]);
- if($var==false){
- return true;
- }
- }
- return false;
- }
- public function setScheduleStatusToBooked($tutorid,$day,$timefrom,$timetill){
- $this->connect();
- $sth = $this->dbh->prepare("
- UPDATE schedule SET status='Booked' WHERE tutorid=:tutorid AND day=:day AND timefrom=:timefrom AND timetill=:timetill
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->bindParam(':day', $day);
- $sth->bindParam(':timefrom', $timefrom);
- $sth->bindParam(':timetill', $timetill);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- public function updateBookingStatus($bookid,$status){
- $this->connect();
- $sth = $this->dbh->prepare("
- UPDATE bookings SET
- status=:status
- WHERE bookid=:bookid
- ");
- $sth->bindParam(':bookid', $bookid);
- $sth->bindParam(':status', $status);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- public function approveBooking($bookid){
- $var = $this->checkIfApprovingBookingCreatesConflictWithSchedule($bookid);
- $bookingDetails=$this->getBookingDetails($bookid);
- if($var==false){
- foreach($bookingDetails as $details){
- $this->setScheduleStatusToBooked($details["tutorid"],$details["day"],$details["timefrom"],$details["timetill"]);
- }
- $this->updateBookingStatus($bookid,'Approved');
- return true;
- }
- return false;
- }
- public function signIn($email,$password){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT userid FROM users
- WHERE email= :email
- AND password= :password
- ");
- $sth->bindParam(':email', $email);
- $sth->bindParam(':password', $password);
- $sth->execute();
- $user=$sth->fetch();
- $this->disconnect();
- $_SESSION['userid']=$user['userid'];
- $_SESSION['type']=$user['tutor'];
- return $user;
- }
- public function checkIfEmailExists($email){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT COUNT(*) as num FROM users
- WHERE email=:email
- ");
- $sth->bindParam(':email', $email);
- $sth->execute();
- $row=$sth->fetch();
- if($row["num"]==0){
- $this->disconnect();
- return false;
- }else{
- $this->disconnect();
- return true;
- }
- }
- public function signUp($firstname,$lastname,$email,$password,$telephone,$address,$descriptionStudent,$dateOfBirth,$tutor,$coordinates,$icon,$courses){
- if($this->checkIfEmailExists($email)){
- return -1;
- }
- $this->connect();
- $sth = $this->dbh->prepare("
- INSERT INTO users (firstname,lastname,email,password,telephone,address,descriptionStudent,dateOfBirth,tutor,coordinates) VALUES(:firstname,:lastname,:email,:password,:telephone,:address,:descriptionStudent,:dateOfBirth,:tutor,:coordinates)
- ");
- $sth->bindParam(':firstname', $firstname);
- $sth->bindParam(':lastname', $lastname);
- $sth->bindParam(':email', $email);
- $sth->bindParam(':password', $password);
- $sth->bindParam(':telephone', $telephone);
- $sth->bindParam(':address', $address);
- $sth->bindParam(':descriptionStudent', $descriptionStudent);
- $sth->bindParam(':dateOfBirth', $dateOfBirth);
- $sth->bindParam(':tutor', $tutor);
- $sth->bindParam(':coordinates', $coordinates);
- try{
- $sth->execute();
- }catch (PDOException $e) {
- print "Error!: " . $e->getMessage() . "<br/>";
- die();
- }
- $userid = $this->dbh->lastInsertId();
- //var_dump($courses);
- foreach ($courses as $courseid) {
- $sth = $this->dbh->prepare("
- insert into studentscourses select * from (select :courseid, :userid ) as tmp where not exists (select * from studentscourses where courseid = :courseid and userid = :userid);
- ");
- $sth->bindParam(":courseid",$courseid);
- $sth->bindParam(":userid",$userid);
- $sth->execute();
- }
- if($icon){
- $imageName = md5(date("").time(""));
- $data = $icon;
- /*list($type, $data) = explode(';', $data);
- list(, $data) = explode(',', $data);*/
- $data = base64_decode($data);
- file_put_contents('./icons/'.$imageName.".png", $data);
- $stm = $this->dbh->prepare("update users set icon = :icon where userid = :userid");
- $stm->bindParam(":userid",$userid);
- $stm->bindParam(":icon",$imageName);
- $stm->execute();
- }
- $this->disconnect();
- //echo "userid<br>";
- //var_dump($userid);
- return $userid;
- }
- public function getCourses(){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * FROM courses
- ");
- $sth->execute();
- $res=$sth->fetchAll();
- $this->disconnect();
- return $res;
- }
- public function getCoursesOfTutor($tutorid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * FROM courses c join tutorscourses t on c.courseid = t.courseid where t.tutorid = :tutorid
- ");
- $sth->bindParam(':tutorid', $tutorid);
- $sth->execute();
- $res=$sth->fetchAll();
- $this->disconnect();
- return $res;
- }
- public function getCoursesOfStudent($studentId){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * FROM courses as c , studentscourses as t where c.courseid = t.courseid and t.userid = :studentId
- ");
- $sth->bindParam(':studentId', $studentId);
- $sth->execute();
- $res=$sth->fetchAll();
- $this->disconnect();
- return $res;
- }
- public function sendMessage($receiver,$sender,$title,$message){
- $this->connect();
- $sth = $this->dbh->prepare("
- INSERT INTO messages VALUES(null,:receiver,:sender,:title,:message,0,'',0)
- ");
- $sth->bindParam(':receiver', $receiver);
- $sth->bindParam(':sender', $sender);
- $sth->bindParam(':title', $title);
- $sth->bindParam(':message', $message);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- public function getNotViewedMessagesOfUser($userid){
- $this->connect();
- $sth = $this->dbh->prepare("
- SELECT * FROM messages where
- receiver=:receiver AND
- viewed=0
- ");
- $sth->bindParam(':receiver', $userid);
- $sth->execute();
- $res=$sth->fetchAll();
- $this->disconnect();
- return $res;
- }
- public function setMessageViewed($messageid){
- $this->connect();
- $sth = $this->dbh->prepare("
- UPDATE messages SET viewed=1 WHERE
- messageid=:messageid
- ");
- $sth->bindParam(':messageid', $messageid);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- public function replyTo($replyToMessageid,$message){
- $this->connect();
- $sth = $this->dbh->prepare("
- INSERT INTO messages VALUES(null,0,0,'',:message,:replyToMessageid,'',0)
- ");
- $sth->bindParam(':message', $message);
- $sth->bindParam(':replyToMessageid', $replyToMessageid);
- $sth->execute();
- $this->disconnect();
- return true;
- }
- public function getUserAddress($userid){
- $this->connect();
- $sth = $this->dbh->prepare("select coordinates from users where userid = :userid");
- $sth->bindParam(':userid', $userid);
- $sth->execute();
- $res=$sth->fetchAll();
- $this->disconnect();
- return $res;
- }
- public function getUserById($userid){
- $this->connect();
- $sth = $this->dbh->prepare("select * from users where userid = :userid");
- $sth->bindParam(':userid', $userid);
- $sth->execute();
- $res=$sth->fetchAll();
- $this->disconnect();
- return $res;
- }
- /*
- public function addressToXY($address){
- $str = "https://maps.googleapis.com/maps/api/geocode/json?address=";
- $arr = explode(" ",$address);
- $n = count($arr);
- for($i=0;$i<$n;$i++){
- $str = $str.$arr[$i];
- if($i<$n-1){
- $str=$str."+";
- }
- }
- $str=$str."&key=AIzaSyAUmZlPZBk2GEPF-cMg_mROsuECPNGwXlo";
- $r = new HttpRequest($str, "GET");
- try {
- $r->send();
- if ($r->getResponseCode() == 200) {
- echo $r->getResponseBody();
- }
- } catch (HttpException $ex) {
- // echo $ex;
- }
- }*/
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement