public function NewBlog()
 {
     //Returns true if the user has no blogs. Returns false otherwise.
     $userID = BusinessLogic_User_User::GetInstance()->GetUserID();
     $query = 'select Count(*) from [0] where UserID=[1] AND Auth="Owner"';
     $arguments = array('User_Auth', $userID);
     $DataAccess = DataAccess_DataAccessFactory::GetInstance();
     $result = $DataAccess->Select($query, $arguments);
     $numOfBlogs = $result[0]["Count(*)"];
     return $numOfBlogs == 0;
 }
Example #2
0
 public function CanDeleteUser($blogID, $userID)
 {
     $permission = $this->GetPermissionForBlog($blogID);
     if ($permission == 'Owner' or $permission == 'Editor') {
         $DataAccess = DataAccess_DataAccessFactory::GetInstance();
         //get rank of user in blog
         $query = 'select Auth from [0] where UserID="[1]" and BlogID="[2]"';
         $arguments = array('User_Auth', $userID, $blogID);
         $result = $DataAccess->Select($query, $arguments);
         if (count($result) > 0) {
             $userAuth = $result[0]['Auth'];
             switch ($userAuth) {
                 case 'Editor':
                     if ($permission == 'Owner') {
                         return true;
                     } else {
                         return false;
                     }
                     break;
                 case 'Author':
                     if ($permission == 'Owner' or $permission == 'Editor') {
                         return true;
                     } else {
                         return false;
                     }
                     break;
                 default:
                     return false;
                     break;
             }
         } else {
             throw new Exception('User is not part of blog.');
         }
     } else {
         throw new Exception('Access Denied.');
     }
 }
 public function GetCommentCounts($postIDs)
 {
     //Given an array of postIDs to look at, returns an array of comment counts in the same array indices.
     if (count($postIDs) < 1) {
         return array();
     }
     $DataAccess = DataAccess_DataAccessFactory::GetInstance();
     $arguments = array();
     $insertme = '0';
     //just to stick into OR statement
     foreach ($postIDs as $key => $value) {
         $insertme = $insertme . ' or PostID="[' . $key . ']"';
         array_push($arguments, $value);
     }
     $query = 'select count(CommentID),PostID from Comments where ' . $insertme . ' group by PostID';
     $response = $DataAccess->Select($query, $arguments);
     $returnme = array();
     //extract contents of response:
     foreach ($postIDs as $key => $postID) {
         foreach ($response as $responsekey => $responsedata) {
             if ($responsedata['PostID'] == $postID) {
                 $returnme[$key] = $responsedata['count(CommentID)'];
                 unset($response[$responsekey]);
                 break;
             }
         }
     }
     //fill in 0's for slots that aren't currently filled:
     foreach ($postIDs as $key => $value) {
         if (!isset($returnme[$key])) {
             $returnme[$key] = 0;
         }
     }
     return $returnme;
 }
 public function ProcessSearch($blog_title)
 {
     $query = 'select BlogID, Title, About from Blogs where Title like "%[0]%" or About like "%[0]%"';
     $arguments = array($blog_title);
     $DataAccess = DataAccess_DataAccessFactory::GetInstance();
     $result = $DataAccess->Select($query, $arguments);
     //there is no matching record in the DB
     if (count($result) < 1) {
         return new Presentation_View_ViewSearchBlogCollectionView(0, $blog_title);
     } else {
         foreach ($result as $key => $value) {
             $blogsID[$key] = new Presentation_View_ViewSearchBlogView($value['BlogID'], $value['Title'], $value['About']);
         }
         return new Presentation_View_ViewSearchBlogCollectionView($blogsID, $blog_title);
     }
 }
 public function GetPostAuthorID($postID)
 {
     //Returns the authorid of a given post.
     //Used by PostSecurity to determine if an Author can mess with a post.
     $query = 'select UserID from Posts where PostID="[0]" order by Timestamp desc';
     $arguments = array($postID);
     $DataAccess = DataAccess_DataAccessFactory::GetInstance();
     $response = $DataAccess->Select($query, $arguments);
     return $response[0]['UserID'];
 }