require_once(SITE_DIR."database/table.php");
class SocialDatabaseTable extends DatabaseTable {
function getRowById($ID)
{
return null;
}
function getFeed($userid = -1,$filter = '',$limit=20,$offset=0, $groupid = 0){
// $filter is not yet used
if( $limit < 1 || $limit > 20 ) {
$limit = 20;
}
if( $offset < 1 && $offset !== 0) {
$offset = 0;
}
if( $groupid >0 ) {
$sql = "SELECT s.*,IF(s.userid>0,u.name,g.title) as name FROM statuses as s LEFT JOIN users as u ON (s.userid=u.id) LEFT JOIN groups as g ON (s.groupid=g.id)";
$wh[] = " s.groupid = $groupid";
if( $userid >0 ) {
$wh[] = " s.userid = $userid";
}
} else {
$sql = "SELECT s.*,u.name FROM statuses as s LEFT JOIN users as u ON (s.userid=u.id)";
if( $userid >0 ) {
$wh[] = " s.userid = $userid";
}
// exclude closed groups
$wh[] = " (s.grouponly<>'y' OR s.groupid=0) AND s.userid > 0 ";
}
if(count($wh)>0){
$sql .= " WHERE ".implode(' AND ',$wh);
}
$sql .= " ORDER BY s.posttime DESC";
$sql .= " LIMIT $offset,$limit";
return $this->getRows($sql);
}
function getFeedTotal($userid = -1,$filter = '', $groupid = 0) {
$sql = "SELECT count(id) as c FROM statuses ";
$wh = array();
if( $userid >0 ) {
$wh[] = " userid = $userid";
}
if( $groupid >0 ) {
$wh[] = " groupid = $groupid";
} else {
// exclude closed groups
$wh[] = " (grouponly<>'y' OR groupid=0) AND userid > 0 ";
}
if(count($wh)>0){
$sql .= " WHERE ".implode(' AND ',$wh);
}
$c = $this->getRow($sql);
return $c['c'];
}
function getTimeline($userid,$filter = '',$limit=20,$offset=0){
// $filter is not yet used
if( $limit < 1 || $limit > 20 ) {
$limit = 20;
}
if( $offset < 1 && $offset !== 0) {
$offset = 0;
}
$sql = "(SELECT s.*,u.name FROM followers as f ".
" JOIN statuses as s ON (f.userid=s.userid) ".
" LEFT JOIN users as u ON (s.userid=u.id)";
$sql .= " WHERE f.followby = $userid AND (s.grouponly<>'y' OR s.groupid=0) AND s.userid>0)";
$sql .= " UNION ";
$sql .= "(SELECT s.*,u.name FROM statuses as s ".
" LEFT JOIN users as u ON (s.userid=u.id)";
$sql .= " WHERE s.userid = $userid AND (s.grouponly<>'y' OR s.groupid=0) AND s.userid>0)";
$sql .= " UNION DISTINCT ";
$sql .= "(SELECT s.*,IF(s.userid>0,u.name,g.title) as name FROM statuses as s ".
" LEFT JOIN users as u ON (s.userid=u.id) LEFT JOIN groups as g ON (s.groupid=g.id)";
$sql .= " WHERE s.groupid>0 AND s.groupid IN (SELECT groupid FROM groups_members WHERE userid=$userid))";
$sql .= " ORDER BY posttime DESC";
$sql .= " LIMIT $offset,$limit";
return $this->getRows($sql);
}
function getTimelineTotal($userid ,$filter = '') {
$sql = "SELECT count(s.id) as c FROM followers as f JOIN statuses as s ON (f.userid=s.userid) ";
$sql .= " WHERE f.followby = $userid AND (s.grouponly<>'y' OR s.groupid=0) AND s.userid>0";
$c = $this->getValue($sql);
$sql = "SELECT count(id) as c FROM statuses WHERE userid = $userid AND (grouponly<>'y' OR groupid=0) AND userid>0";
$c += $this->getValue($sql);
$sql = "SELECT count(id) as c FROM statuses WHERE groupid>0 AND groupid IN (SELECT groupid FROM groups_members WHERE userid=$userid) ".
"AND userid NOT IN (SELECT userid FROM followers WHERE followby = $userid)";
$c += $this->getValue($sql);
return $c;
}
function getGroupTimeline($groupid,$filter = '',$limit=20,$offset=0){
// $filter is not yet used
if( $limit < 1 || $limit > 20 ) {
$limit = 20;
}
if( $offset < 1 && $offset !== 0) {
$offset = 0;
}
$sql = "SELECT s.*,u.name FROM statuses as s ".
" LEFT JOIN users as u ON (s.userid=u.id)";
$sql .= " WHERE s.groupid = $groupid ";
$sql .= " ORDER BY posttime DESC";
$sql .= " LIMIT $offset,$limit";
return $this->getRows($sql);
}
function getGroupTimelineTotal($groupid ,$filter = '') {
$sql = "SELECT count(id) as c FROM statuses WHERE groupid = $groupid ";
$c = $this->getValue($sql);
return $c;
}
function getStatus( $id ) {
return $this->getRow("SELECT * FROM statuses WHERE id=".getCorrectInteger($id));
}
function addStatus($userid, $text, $parentid = 0, $posttime = '', $groupid = 0, $grouponly = 'n') {
if( $posttime == '' ){
$posttime = date("Y-m-d H:i:s");
}
$sql = "INSERT INTO statuses (userid,status,posttime,repostid,groupid,grouponly) VALUES ".
" ( ".
$userid.",".
"'".$this->quote($text)."',".
"'$posttime',".
$parentid.",".
getCorrectInteger($groupid).",".
"'$grouponly'".
" ) ";
$this->dbExecQuery($sql);
return $this->dbInsertedId();
}
function removeStatus( $statusid ) {
$sql = "DELETE FROM statuses WHERE id=".getCorrectInteger($statusid);
$this->dbExecQuery($sql);
return true;
}
function addFollowing( $userid, $followby) {
$sql = "INSERT INTO followers (userid,followby,whensubscribed) VALUES ".
" ( ".
$userid.",".
$followby.",".
"UTC_TIMESTAMP()".
" ) ";
$this->dbExecQuery($sql);
return true;
}
function removeFollowing( $userid,$followby ) {
$sql = "DELETE FROM followers WHERE userid=".getCorrectInteger($userid)." AND followby=".getCorrectInteger($followby);
$this->dbExecQuery($sql);
return true;
}
// who follows the user
function getFollowers( $userid, $limit = 0, $offset = 0 ) {
if( $limit < 1 || $limit > 20 ) {
$limit = 20;
}
if( $offset < 1 && $offset !== 0) {
$offset = 0;
}
$sql = "SELECT u.id,u.name,u.resume FROM followers as f LEFT JOIN users as u ON (u.id=f.followby) WHERE f.userid=$userid";
$sql .= " ORDER BY u.name LIMIT $offset,$limit";
return $this->getRows($sql);
}
function getFollowersCount( $userid ) {
$sql = "SELECT count(followby) FROM followers WHERE userid=$userid";
return $this->dbGetValue($sql);
}
// who the user is folowing
function getFollowing( $userid, $limit = 0, $offset = 0 ) {
if( $limit < 1 || $limit > 20 ) {
$limit = 20;
}
if( $offset < 1 && $offset !== 0) {
$offset = 0;
}
$sql = "SELECT u.id,u.name,u.resume FROM followers as f LEFT JOIN users as u ON (u.id=f.userid) WHERE f.followby=$userid";
$sql .= " ORDER BY u.name LIMIT $offset,$limit";
return $this->getRows($sql);
}
function getFollowingCount( $userid ) {
$sql = "SELECT count(userid) FROM followers WHERE followby=$userid";
return $this->dbGetValue($sql);
}
function userFollowsUser($userid1,$userid2){
if( $userid1 ==0 || $userid2 == 0 ) {
return false;
}
$sql = "SELECT count(userid) FROM followers WHERE followby=$userid1 and userid=$userid2";
$c = $this->dbGetValue($sql);
if( $c > 0 ){
return true;
}
return false;
}
function checkRecentStatusExists( $userid, $text, $timeminutes){
$sql = "SELECT * FROM statuses WHERE userid = $userid AND status = '".$this->quote($text)."'
AND posttime > date_sub('".date("Y-m-d H:i:s")."', INTERVAL $timeminutes MINUTE)";
$status = $this->getRow($sql);
if(isset($status['id'])) {
return true;
}
return false;
}
function addNotification($type,$userid,$objectid,$objecttype,$groupid,$raisedbyid,$statusid) {
$sql = "INSERT INTO `notifications` ".
"(`eventtime`, `groupid`, `objectid`, `objecttype`, `raisedbyid`, `type`, `statusid`) ".
" VALUES (UTC_TIMESTAMP(), '$groupid', '$objectid', '$objecttype', '$raisedbyid',".
" '".$this->quote($type)."', '$statusid');";
$this->dbExecQuery($sql);
$notid = $this->dbInsertedId();
$this->assignNotification($notid,$userid);
return $notid;
}
function assignNotification($notid,$userid) {
$sql = "INSERT INTO `notifications_users` ".
"(`notid`, `userid`, `read`) ".
" VALUES ('$notid', '$userid', 0);";
$this->dbExecQuery($sql);
}
function getNotification($notid) {
$sql = "SELECT * FROM notifications WHERE id=$notid";
return $this->getRow($sql);
}
function deleteNotification($notid) {
$sql = "DELETE FROM `notifications_users` WHERE `notid`=$notid ";
$this->dbExecQuery($sql);
$sql = "DELETE FROM `notifications` WHERE `id`=$notid ";
$this->dbExecQuery($sql);
return true;
}
function readNotification($notid,$userid) {
// mark also all related notifications for this user
$not_rec = $this->getNotification($notid);
if (!$not_rec) {
return false;
}
$sql = "SELECT id FROM notifications ".
" WHERE objectid=".$not_rec['objectid'].
" AND objecttype='".$not_rec['objecttype']."' ".
" AND `type`='".$this->quote($not_rec['type'])."' ";
$notids = array();
foreach( $this->getRows($sql) as $n) {
$notids[] = $n['id'];
}
if (count($notids)>0) {
$sql = "UPDATE `notifications_users` SET `read`=1 WHERE `notid` IN (".implode(',',$notids).") AND `userid`=$userid";
$this->dbExecQuery($sql);
}
return true;
}
function setReadAllNotificationsForObject($objecttype,$objectid,$type,$userid) {
$sql = "SELECT id FROM notifications ".
" WHERE objectid=".$objectid.
" AND objecttype='".$objecttype."' ";
if ($type!='') {
" AND `type`='".$this->quote($type)."' ";
}
$notids = array();
foreach( $this->getRows($sql) as $n) {
$notids[] = $n['id'];
}
if (count($notids)>0) {
$sql = "UPDATE `notifications_users` SET `read`=1 WHERE `notid` IN (".implode(',',$notids).") AND `userid`=$userid";
$this->dbExecQuery($sql);
}
return true;
}
function getUserNotifications($userid,$limit = 50, $offset = 0) {
$sql = "SELECT n.*, count(n.id) as count ".
" FROM notifications_users as u LEFT JOIN notifications as n ON (u.notid=n.id) ".
" WHERE u.userid=$userid AND u.read=0 ".
" GROUP BY objectid, objecttype,type";
$sql .= " ORDER BY eventtime DESC ".
" LIMIT $offset,$limit";
logIt($sql);
return $this->getRows($sql);
}
function getUserNotificationsCount($userid) {
$sql = "SELECT count( DISTINCT objectid, objecttype, type) as c ".
" FROM notifications_users as u LEFT JOIN notifications as n ON (u.notid=n.id) ".
" WHERE u.userid=$userid AND u.read=0 ";
logIt($sql);
return $this->getValue($sql);
}
function getUserNotificationsGroupCount($groupid,$userid) {
$sql = "SELECT count( DISTINCT objectid, objecttype, type) as c ".
" FROM notifications_users as u LEFT JOIN notifications as n ON (u.notid=n.id) ".
" WHERE u.userid=$userid AND u.read=0 and n.groupid=$groupid";
logIt($sql);
return $this->getValue($sql);
}
}
?>
Fatal error: Class 'SocialDatabaseTable' not found in /home/myedu/domains/myeducationpath.com/html/include/factory.php on line 157
Unexpected error! |
Fatal Error: Class 'SocialDatabaseTable' not found in line: 157 in the file: /home/myedu/domains/myeducationpath.com/html/include/factory.php. We are notified and will solve the problem as soon as possible. |
#0 [internal function]: Gelembjuk\Logger\ErrorScreen->fatalsHandler() #1 {main} |