Skip to content
Snippets Groups Projects
EntryValues.php 1.43 KiB
Newer Older
  • Learn to ignore specific revisions
  • Josh Pollock's avatar
    Josh Pollock committed
    <?php
    
    
    namespace calderawp\CalderaFormsQuery\Select;
    
    class EntryValues extends SelectQueryBuilder
    {
    
    
    	/**
    	 * Create query by entry ID
    	 *
    	 * @param $entryId
    	 * @return $this
    	 */
    
    Josh Pollock's avatar
    Josh Pollock committed
    	public function queryByEntryId($entryId)
    
    Josh Pollock's avatar
    Josh Pollock committed
    	{
    		 $this
    			->getSelectQuery()
    			->where()
    
    Josh Pollock's avatar
    Josh Pollock committed
    			->equals('entry_id', $entryId)
    
    Josh Pollock's avatar
    Josh Pollock committed
    			;
    		 return $this;
    	}
    
    	/**
    	 * Create query for entry values with a field whose value equals, doesn't equal or is like (SQL LIKE) a value
    	 *
    	 * @param string $fieldSlug Field slug
    	 * @param string $fieldValue Field value
    	 * @param string $type Optional. Type of comparison. Values: equals|notEquals|like Default: 'equals'
    
    Josh Pollock's avatar
    Josh Pollock committed
    	 * @param string $whereOperator Optional. Type of where. Default is 'AND'. Any valid WHERE operator is accepted
    
    Josh Pollock's avatar
    Josh Pollock committed
    	 * @return $this
    	 */
    
    Josh Pollock's avatar
    Josh Pollock committed
    	public function queryByFieldValue($fieldSlug, $fieldValue, $type = 'equals', $whereOperator = 'AND')
    
    Josh Pollock's avatar
    Josh Pollock committed
    	{
    
    Josh Pollock's avatar
    Josh Pollock committed
    		switch ($type) {
    
    Josh Pollock's avatar
    Josh Pollock committed
    			case 'equals':
    				$this
    					->getSelectQuery()
    
    Josh Pollock's avatar
    Josh Pollock committed
    					->where($whereOperator)
    					->equals('value', $fieldValue)
    
    Josh Pollock's avatar
    Josh Pollock committed
    				;
    				break;
    			case 'notEquals':
    				$this->
    				getSelectQuery()
    
    Josh Pollock's avatar
    Josh Pollock committed
    					->where($whereOperator)
    					->notEquals('value', $fieldValue);
    
    Josh Pollock's avatar
    Josh Pollock committed
    				break;
    			case 'like':
    				$this->
    				getSelectQuery()
    
    Josh Pollock's avatar
    Josh Pollock committed
    					->where($whereOperator)
    					->like('value', $fieldValue);
    
    Josh Pollock's avatar
    Josh Pollock committed
    				break;
    		}
    
    		$this->isLike = 'like' === $type ? true : false;
    
    		if (!$this->isLike) {
    			$this->getSelectQuery()->where('AND')->equals('slug', $fieldSlug);
    		}
    
    		return $this;
    	}
    
    Josh Pollock's avatar
    Josh Pollock committed
    }