/** * * @param string $Name * @return \Dashbird\Model\Entities\User */ public function FindByName($Name) { $Query = new \Pvik\Database\Generic\Query('Users'); $Query->SetConditions('WHERE Users.Name = "%s"'); $Query->AddParameter($Name); return $Query->SelectSingle(); }
/** * * @param string $Name * @return \Dashbird\Model\Entities\Plugin */ public function FindByNameAndUserId($Name, $UserId) { $Query = new \Pvik\Database\Generic\Query('PluginDatas'); $Query->SetConditions('WHERE PluginDatas.Name = "%s" AND PluginDatas.UserId = "%s"'); $Query->AddParameter($Name); $Query->AddParameter($UserId); return $Query->SelectSingle(); }
public function ApiPostsSearchAction() { if (!$this->IsLoggedIn()) { return $this->ResponseNotLoggedIn(); } $Search = $this->Request->GetGET('search'); if (!is_array($Search) || !isset($Search['keywords'])) { return $this->ResponseWrongData(); } $PostCount = $this->Request->GetGET('post-count'); if ($PostCount == null) { $PostCount = 9999999999.0; } $Query = new \Pvik\Database\Generic\Query('Posts'); $ConditionString = 'LEFT JOIN PostShares as PostShares ON PostShares.PostId = Posts.PostId'; $ConditionString .= ' WHERE PostShares.UserId = "%s"'; $Query->AddParameter($this->GetUserId()); foreach ($Search['keywords'] as $Keyword) { $Query->AddParameter('%' . $Keyword . '%'); $ConditionString .= ' AND Posts.SearchHelper LIKE "%s"'; } $Query->SetConditions($ConditionString); $Query->SetOrderBy('ORDER BY Posts.Updated DESC LIMIT 0,%s'); $Query->AddParameter($PostCount); $Posts = $Query->Select(); // optimization for tags $Posts->LoadList('PostsTags->Tag'); // optimization for postshare $Posts->LoadList('PostShares'); // optimization for comments $Posts->LoadList('Comments'); $Data = array(); $Data['posts'] = array(); foreach ($Posts as $Post) { $Data['posts'][] = $Post->ToArray(); } $this->ResponseSuccess($Data); }
public function DeleteTag($TagTitle) { $Query = new \Pvik\Database\Generic\Query('Tags'); $Query->SetConditions('WHERE Tags.Title = "%s"'); $Query->AddParameter($TagTitle); $Tag = $Query->SelectSingle(); if ($Tag != null) { foreach ($this->PostsTags as $PostsTags) { if ($PostsTags->TagId == $Tag->TagId) { $PostsTags->Delete(); break; } } } }