Beispiel #1
0
 public function ApiUserSharesAddAction()
 {
     if (!$this->IsLoggedIn()) {
         return $this->ResponseNotLoggedIn();
     }
     $Name = $this->Request->GetGET('name');
     if (empty($Name)) {
         return $this->ResponseWrongData();
     }
     $UsersModelTable = ModelTable::Get('Users');
     /* @var $UserModelTable \Dashbird\Model\ModelTables\Users */
     $User = $UsersModelTable->FindByName($Name);
     if ($User == null || $User->UserId == $this->GetUserId()) {
         return $this->ResponseWrongData();
     }
     if ($this->GetUser()->UserShares->HasValue('ConnectedUserId', $User->UserId)) {
         return $this->ResponseWrongData();
     }
     $UserShare = new \Dashbird\Model\Entities\UserShare();
     $UserShare->UserId = $this->GetUserId();
     $UserShare->ConnectedUserId = $User->UserId;
     $UserShare->Insert();
     $Post = new \Dashbird\Model\Entities\Post();
     $Post->Text = 'Hello ' . $User->Name . ",\nI started sharing with you!";
     $Post->SearchHelper = '';
     $Post->UserId = $this->GetUserId();
     $Post->Insert();
     $Post->SetPostShares(array($User->UserId));
     $Post->Update();
     return $this->ResponseSuccess(array('user' => $User->ToArraySimple()));
 }
Beispiel #2
0
 public function ApiPostCommentDeleteAction()
 {
     if (!$this->IsLoggedIn()) {
         return $this->ResponseNotLoggedIn();
     }
     $CommentId = $this->Request->GetGET('commentId');
     if ($CommentId == null || !is_numeric($CommentId)) {
         return $this->ResponseWrongData();
     }
     $Comment = \Pvik\Database\Generic\ModelTable::Get('Comments')->LoadByPrimaryKey($CommentId);
     /* @var $Comment \Dashbird\Model\Entities\Comment */
     if ($Comment == null || $Comment->UserId !== $this->GetUserId()) {
         return $this->ResponseWrongData();
     }
     $Post = $Comment->Post;
     $Comment->Delete();
     $Post->Update();
     return $this->ResponseSuccess($Post->ToArray());
 }
Beispiel #3
0
 public function ApiPluginDataSaveAction()
 {
     if (!$this->IsLoggedIn()) {
         return $this->ResponseNotLoggedIn();
     }
     $Name = $this->Request->GetPOST('name');
     $Data = $this->Request->GetPOST('data');
     if ($Name == null || $Data == null) {
         return $this->ResponseWrongData();
     }
     $PluginDatasModelTable = \Pvik\Database\Generic\ModelTable::Get('PluginDatas');
     /* @var $PluginDatasModelTable \Dashbird\Model\ModelTables\PluginDatas */
     $PluginData = $PluginDatasModelTable->FindByNameAndUserId($Name, $this->GetUserId());
     if ($PluginData == null) {
         $PluginData = new \Dashbird\Model\Entities\PluginData();
         $PluginData->Name = $Name;
         $PluginData->Data = '{}';
         $PluginData->UserId = $this->GetUserId();
         $PluginData->Insert();
     }
     $PluginData->Data = $Data;
     $PluginData->Update();
     $this->ResponseSuccess($PluginData->ToArray());
 }
Beispiel #4
0
 /**
  * 
  * @return \Dashbird\Model\Entities\User
  */
 public function GetUser()
 {
     return \Pvik\Database\Generic\ModelTable::Get('Users')->LoadByPrimaryKey($this->GetUserId());
 }
Beispiel #5
0
 public function ApiPostLastViewSetAction()
 {
     if (!$this->IsLoggedIn()) {
         return $this->ResponseNotLoggedIn();
     }
     $PostId = $this->Request->GetGET('postId');
     $LastView = $this->Request->GetGET('lastView');
     if ($PostId == null || $LastView == null) {
         return $this->ResponseWrongData();
     }
     $Post = ModelTable::Get('Posts')->LoadByPrimaryKey($PostId);
     /* @var $Post \Dashbird\Model\Entities\Post */
     if ($Post == null || !$Post->CurrentUserIsAllowedToSee()) {
         return $this->ResponseWrongData();
     }
     foreach ($Post->PostShares as $PostShare) {
         if ($PostShare->UserId == $this->GetUserId()) {
             $PostShare->LastView = $LastView;
             $PostShare->Update();
             break;
         }
     }
     return $this->ResponseSuccess($Post->ToArray());
 }
Beispiel #6
0
 public function SetPostShares($UserIds)
 {
     \Pvik\Database\SQL\Manager::GetInstance()->DeleteWithParameters('DELETE FROM PostShares WHERE PostShares.PostId = %s', array($this->PostId));
     // CAUTION: PostShares in the cache maybe still have a reference to this object
     // manually delete cache posts
     $CachePostShares = \Pvik\Database\Generic\ModelTable::Get('PostShares')->GetCache()->GetAllCacheInstances();
     foreach ($CachePostShares as $CachePostShare) {
         /* @var $CachePostShare PostShare */
         if ($CachePostShare->PostId == $this->PostId) {
             \Pvik\Database\Generic\ModelTable::Get('PostShares')->GetCache()->Delete($CachePostShare);
         }
     }
     // clear all reference keys
     $this->SetFieldData('PostShares', null);
     // validate userIds
     $UserShares = \Dashbird\Library\Services\UserService::Instance()->GetUser()->UserShares;
     $FilteredUserIds = array();
     foreach ($UserIds as $UserId) {
         if ($UserShares->HasValue('ConnectedUserId', $UserId) && !in_array($UserId, $FilteredUserIds)) {
             $FilteredUserIds[] = $UserId;
         }
     }
     $UserIds = $FilteredUserIds;
     $UserIds[] = $this->UserId;
     // add him self to shared
     foreach ($UserIds as $UserId) {
         $PostShare = new \Dashbird\Model\Entities\PostShare();
         $PostShare->PostId = $this->PostId;
         $PostShare->UserId = $UserId;
         $PostShare->Insert();
     }
 }