<?php
require_once("../models/DataAccessHelper.php");


class group{
	
	public static function insertGroup($name){
		 $query ="insert into `groups`(gname) values('$name')";
		 $groupId=DataAccessHelper::insertQuerySpecial($query);
		 if($groupId){
				return $groupId;
		}
		return false;
	}

	public static function insertMember($groupId,$username)
	{
		 $query ="insert into members(groupId,username) values('$groupId','$username')";
		 $result=DataAccessHelper::insertQuery($query);
		 if($result===TRUE){
			return true;
		}
		return false;
	}

	public static function getAllUserGroups($username)
	{
		$query="select * from `groups` join members on members.groupId= `groups`.groupId where members.username= '$username'";
		$result=DataAccessHelper::executeQuery($query);
		return $result;
	}

	public static function getAllUsers($groupId){
		$query="select * from members join `groups` on members.groupId=`groups`.groupId where `groups`.groupId= $groupId";
		$result=DataAccessHelper::executeQuery($query);
		return $result;
	}
}

?>