Query scope for posts published within the given year and month number.

@param $query
@param $year
@param $month
@return mixed
764915
public function scopeByYearMonth($query, $year, $month)
	{
		return $query->where(\DB::raw('DATE_FORMAT(published_date, "%Y%m")'), '=', $year.$month);
	}
274746
public function scopeActiveOn($query, $period)
    {
        return $query->whereHas('periods', function($query) use ($period){
            $query->where('academic_periods_id', $period);
        });
    }
467898
public function scopeRecent($query)
    {
        $time = time();
        $age = strtotime(config('forum.preferences.old_thread_threshold'), 0);
        $cutoff = $time - $age;

        return $query->where('updated_at', '>', date('Y-m-d H:i:s', $cutoff))->orderBy('updated_at', 'desc');
    }
1306093
public function scopeOrderByViews(Builder $query, string $direction = 'desc', $period = null): Builder
    {
        return $query->withCount(['views' => function ($query) use ($period) {
            if ($period) {
                $query->withinPeriod($period);
            }
        }])->orderBy('views_count', $direction);
    }
214591
public function scopeOfDate($query, Carbon $date)
    {
        $date->timezone('UTC');

        return $query->whereRaw('date(`start_at`) = ?', [$date->toDateString()]);
    }
846846
public function doPostTaxonomyFiltering($query)
    {
        if (is_admin()) {
            return $query;
        }

        $postType = $this->postType;
        $filterable = $this->getEnabledTaxonomies($postType);

        if (empty($filterable)) {
            return $query;
        }

        $taxQuery = array('relation' => 'AND');

        foreach ($filterable as $key => $value) {
            if (!isset($_GET['filter'][$key]) || empty($_GET['filter'][$key]) || $_GET['filter'][$key] === '-1') {
                continue;
            }

            $terms = (array)$_GET['filter'][$key];

            $taxQuery[] = array(
                'taxonomy' => $key,
                'field' => 'slug',
                'terms' => $terms,
                'operator' => 'IN'
            );
        }

        if (is_tax() || is_category() || is_tag()) {
            $taxQuery = array(
                'relation' => 'AND',
                array(
                    'relation' => 'AND',
                    array(
                        'taxonomy' => get_queried_object()->taxonomy,
                        'field' => 'slug',
                        'terms' => (array)get_queried_object()->slug,
                        'operator' => 'IN'
                    )
                ),
                $taxQuery
            );
        }

        $query->set('tax_query', $taxQuery);
        $query->set('post_type', get_field('posts_data_post_type', $this->moduleId));

        return $query;
    }
312990
public function scopePublished($query, $languageSlug = '')
    {
        if(!$languageSlug) {
            $languageSlug = App::getLocale();
        }

        return $query
            ->where('status->'.$languageSlug, 'published')
            ->where('published_at', '<=', date('Y-m-d H:i:s'));
    }
424128
public static function GetDaysInMonth( int $year, int $month ) : int
   {

      $dt = new \DateTime();
      $dt->setDate( $year, $month, 2 );
      $dt->setTime( 0, 0, 2 );

      return \intval( $dt->format( 't' ) );

   }
1256290
public function visit($query, $node, string $context)
    {
        if ($node instanceof $this->node) {
            $bindings = [];
            $sql = [];

            $child0 = $node->getChildByIndex(0);
            $child1 = $node->getChildByIndex(1);

            if ($child0 instanceof Nodes\KeyNode) {
                $context === Nodes\OrNode::class && $query->orWhereNotNull($this->parseKey($child0->getValue()));
                $context === Nodes\AndNode::class && $query->whereNotNull($this->parseKey($child0->getValue()));
            }
        }
    }
1183639
public function doPostDateFiltering($where, $query)
    {
        if (is_admin() || $query->is_main_query()) {
            return $where;
        }

        global $wpdb;

        $from = null;
        $to = null;

        if (isset($_GET[$this->moduleId . 'f']) && !empty($_GET[$this->moduleId . 'f'])) {
            $from = sanitize_text_field($_GET[$this->moduleId . 'f']);
        }

        if (isset($_GET[$this->moduleId . 't']) && !empty($_GET[$this->moduleId . 't'])) {
            $to = sanitize_text_field($_GET[$this->moduleId . 't']);
        }

        if (!is_null($from) && !is_null($to)) {
            $where .= " AND ($wpdb->posts.post_date >= '$from' AND $wpdb->posts.post_date <= '$to')";
        } elseif (!is_null($from) && is_null($to)) {
            $where .= " AND ($wpdb->posts.post_date >= '$from')";
        } elseif (is_null($from) && !is_null($to)) {
            $where .= " AND ($wpdb->posts.post_date <= '$to')";
        }

        return $where;
    }
897903
public function setDate($year, $month, $day)
    {
        return parent::setDate(self::$yearMustAlwaysBe, self::$monthMustAlwaysBe, self::$dayMustAlwaysBe);
    }
919677
public static function gregorianToJd($month, $day, $year)
    {
        if ($year == 0) {
            return 0;
        } else {
            return self::$gregorian_calendar->ymdToJd($year, $month, $day);
        }
    }
495097
public function scopeFromWeeksAgo(Builder $query, $ago, $endDateTime = null)
    {
        return $this->scopeFromDateTimeRange(DateTime::getWeeksAgo($ago, $endDateTime));
    }
1192706
public function scope(Query $query, $bundle = null)
    {
        $whereClause = $query->clause('where');
        if (!$whereClause) {
            return $query;
        }

        $whereClause->traverse(function (&$expression) use ($bundle, $query) {
            if ($expression instanceof ExpressionInterface) {
                $expression = $this->_inspectExpression($expression, $bundle, $query);
            }
        });

        return $query;
    }
310950
public function scopeClients(Builder $query)
    {
        $query->with('roles')->whereNotNull('tbl_users.id')->whereHas('roles', function ($query) {
            $query->whereIn('tbl_roles.name', ['member', 'users', 'user']);
        });


        return $query;
    }
1195173
public function daysInMonth($year, $month)
    {
        if ($year <= 0) {
            throw new InvalidArgumentException('Year ' . $year . ' is invalid for this calendar');
        } elseif ($month < 1 || $month > 13) {
            throw new InvalidArgumentException('Month ' . $month . ' is invalid for this calendar');
        } elseif ($month !== 13) {
            return 30;
        } elseif ($this->isLeapYear($year)) {
            return 6;
        } else {
            return 5;
        }
    }
1069960
public function scopeActive($query)
    {
        return $this->scopeActiveOn($query,
                AcademicPeriod::current()->get()->first()->id);
    }