Example #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()));
 }
Example #2
0
 public function ApiPostAddAction()
 {
     if (!$this->IsLoggedIn()) {
         return $this->ResponseNotLoggedIn();
     }
     $Text = htmlentities(utf8_decode($this->Request->GetGET('text')));
     if (empty($Text)) {
         return $this->ResponseWrongData();
     }
     $Post = new \Dashbird\Model\Entities\Post();
     $Post->Text = $Text;
     $Post->SearchHelper = '';
     $Post->UserId = $this->GetUserId();
     $Post->Insert();
     $Tags = $this->Request->GetGET('tags');
     if (is_array($Tags)) {
         $Post->SetTags($Tags);
     } else {
         $Post->SetTags(array());
     }
     $Post->Update();
     $Shares = $this->Request->GetGET('shares');
     if (!is_array($Shares)) {
         $Shares = array();
     }
     $Post->SetPostShares($Shares);
     return $this->ResponseSuccess($Post->ToArray());
 }