Gdn_SQLDriver::whereIn PHP Метод

whereIn() публичный Метод

Adds to the $this->_WhereIns collection. Used to generate a "where field in (1,2,3)" query. Concatenated with AND.
public whereIn ( string $Field, array $Values, $Escape = true ) : Gdn_SQLDriver
$Field string The field to search in for $Values.
$Values array An array of values to look for in $Field.
Результат Gdn_SQLDriver $this
    public function whereIn($Field, $Values, $Escape = true)
    {
        return $this->_whereIn($Field, $Values, 'in', $Escape);
    }

Usage Example

Пример #1
0
 /**
  *
  *
  * @param Gdn_SQLDriver $Sql
  * @param $Tag
  * @param $Limit
  * @param int $Offset
  * @param string $Op
  * @throws Exception
  */
 protected function _setTagSql($Sql, $Tag, &$Limit, &$Offset = 0, $Op = 'or')
 {
     $SortField = 'd.DateLastComment';
     $SortDirection = 'desc';
     $TagSql = clone Gdn::sql();
     if ($DateFrom = Gdn::request()->get('DateFrom')) {
         // Find the discussion ID of the first discussion created on or after the date from.
         $DiscussionIDFrom = $TagSql->getWhere('Discussion', array('DateInserted >= ' => $DateFrom), 'DiscussionID', 'asc', 1)->value('DiscussionID');
         $SortField = 'd.DiscussionID';
     }
     $Tags = array_map('trim', explode(',', $Tag));
     $TagIDs = $TagSql->select('TagID')->from('Tag')->whereIn('Name', $Tags)->get()->resultArray();
     $TagIDs = array_column($TagIDs, 'TagID');
     if ($Op == 'and' && count($Tags) > 1) {
         $DiscussionIDs = $TagSql->select('DiscussionID')->select('TagID', 'count', 'CountTags')->from('TagDiscussion')->whereIn('TagID', $TagIDs)->groupBy('DiscussionID')->having('CountTags >=', count($Tags))->limit($Limit, $Offset)->orderBy('DiscussionID', 'desc')->get()->resultArray();
         $Limit = '';
         $Offset = 0;
         $DiscussionIDs = array_column($DiscussionIDs, 'DiscussionID');
         $Sql->whereIn('d.DiscussionID', $DiscussionIDs);
         $SortField = 'd.DiscussionID';
     } else {
         $Sql->join('TagDiscussion td', 'd.DiscussionID = td.DiscussionID')->limit($Limit, $Offset)->whereIn('td.TagID', $TagIDs);
         if ($Op == 'and') {
             $SortField = 'd.DiscussionID';
         }
     }
     // Set up the sort field and direction.
     saveToConfig(array('Vanilla.Discussions.SortField' => $SortField, 'Vanilla.Discussions.SortDirection' => $SortDirection), '', false);
 }