| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2022-04-15 11:34:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | declare(strict_types=1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Nextcloud - Social Support | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This file is licensed under the Affero General Public License version 3 or | 
					
						
							|  |  |  |  * later. See the COPYING file. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * @author Maxence Lange <maxence@artificial-owl.com> | 
					
						
							|  |  |  |  * @copyright 2018, Maxence Lange <maxence@artificial-owl.com> | 
					
						
							|  |  |  |  * @license GNU AGPL version 3 or any later version | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is free software: you can redistribute it and/or modify | 
					
						
							|  |  |  |  * it under the terms of the GNU Affero General Public License as | 
					
						
							|  |  |  |  * published by the Free Software Foundation, either version 3 of the | 
					
						
							|  |  |  |  * License, or (at your option) any later version. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU Affero General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU Affero General Public License | 
					
						
							|  |  |  |  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-13 21:56:40 +00:00
										 |  |  | namespace OCA\Social\Db; | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2019-09-13 21:56:40 +00:00
										 |  |  |  * Class SocialQueryBuilder | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-09-29 11:39:25 +00:00
										 |  |  |  * @package OCA\Social\Db | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-09-29 11:39:25 +00:00
										 |  |  | class SocialQueryBuilder extends SocialFiltersQueryBuilder { | 
					
						
							| 
									
										
										
										
											2022-04-15 11:01:18 +00:00
										 |  |  | 	private int $format = 1; | 
					
						
							| 
									
										
										
										
											2020-08-25 03:06:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param int $format | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function setFormat(int $format) { | 
					
						
							|  |  |  | 		$this->format = $format; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @return int | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	public function getFormat(): int { | 
					
						
							|  |  |  | 		return $this->format; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-14 10:01:05 +00:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param string $id | 
					
						
							| 
									
										
										
										
											2019-09-29 11:39:25 +00:00
										 |  |  | 	 * @param string $field | 
					
						
							| 
									
										
										
										
											2019-09-14 10:01:05 +00:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-09-29 11:39:25 +00:00
										 |  |  | 	public function generatePrimaryKey(string $id, string $field = 'id_prim') { | 
					
						
							|  |  |  | 		if ($id === '') { | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-09-14 10:01:05 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-29 11:39:25 +00:00
										 |  |  | 		$this->setValue($field, $this->createNamedParameter($this->prim($id))); | 
					
						
							| 
									
										
										
										
											2019-09-14 10:01:05 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * search using username | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param string $username | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-09-29 11:39:25 +00:00
										 |  |  | 	public function searchInPreferredUsername(string $username) { | 
					
						
							| 
									
										
										
										
											2019-09-14 10:01:05 +00:00
										 |  |  | 		$dbConn = $this->getConnection(); | 
					
						
							|  |  |  | 		$this->searchInDBField('preferred_username', $dbConn->escapeLikeParameter($username) . '%'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Limit the request to the ActorId | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param string $hashtag | 
					
						
							|  |  |  | 	 * @param bool $all | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-09-29 11:39:25 +00:00
										 |  |  | 	public function searchInHashtag(string $hashtag, bool $all = false) { | 
					
						
							| 
									
										
										
										
											2019-09-14 10:01:05 +00:00
										 |  |  | 		$dbConn = $this->getConnection(); | 
					
						
							|  |  |  | 		$this->searchInDBField('hashtag', (($all) ? '%' : '') . $dbConn->escapeLikeParameter($hashtag) . '%'); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * Limit the request to the account | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param string $account | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2019-09-29 11:39:25 +00:00
										 |  |  | 	public function searchInAccount(string $account) { | 
					
						
							| 
									
										
										
										
											2019-09-14 10:01:05 +00:00
										 |  |  | 		$dbConn = $this->getConnection(); | 
					
						
							|  |  |  | 		$this->searchInDBField('account', $dbConn->escapeLikeParameter($account) . '%'); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2019-09-12 12:38:03 +00:00
										 |  |  | } |