The default category when making a query
432196
def default_value(self):
        
        if not hasattr(self, "_default_value"):
            if self.elem_type == "select":
                try:
                    # Get option marked "selected"
                    def_value = get_option_value(self.elem.select_one("[selected]"))
                except AttributeError:
                    # ...or if that one doesen't exist get the first option
                    def_value = get_option_value(self.elem.select_one("option"))

            elif self.elem_type == "checkbox":
                def_value = self.elem.get("value")

            elif self.elem_type == "radio":
                def_value = [x for x in self.elem if x.has_attr("checked")][0].get("value")

            self._default_value = def_value

            assert def_value is not None

        return self._default_value
16522
def enable_category(self, category: str) -> None:
        
        for cmd_name in list(self.disabled_commands):
            func = self.disabled_commands[cmd_name].command_function
            if hasattr(func, HELP_CATEGORY) and getattr(func, HELP_CATEGORY) == category:
                self.enable_command(cmd_name)
130983
public function setDefaultCategory($defaultCategoryId)
    {
        // Allow uncategorized products (NULL instead of 0, to bypass delete cascade constraint)
        if ($defaultCategoryId <= 0) {
            $defaultCategoryId = null;
        }

        /** @var ProductCategory $productCategory */
        $productCategory = ProductCategoryQuery::create()
            ->filterByProductId($this->getId())
            ->filterByDefaultCategory(true)
            ->findOne()
        ;

        if ($productCategory !== null && (int) $productCategory->getCategoryId() === (int) $defaultCategoryId) {
            return $this;
        }

        if ($productCategory !== null) {
            $productCategory->delete();
        }

        // checks if the product is already associated with the category and but not default
        if (null !== $productCategory = ProductCategoryQuery::create()->filterByProduct($this)->filterByCategoryId($defaultCategoryId)->findOne()) {
            $productCategory->setDefaultCategory(true)->save();
        } else {
            $position = (new ProductCategory())->setCategoryId($defaultCategoryId)->getNextPosition();

            (new ProductCategory())
                ->setProduct($this)
                ->setCategoryId($defaultCategoryId)
                ->setDefaultCategory(true)
                ->setPosition($position)
                ->save();

            $this->setPosition($position);
        }

        return $this;
    }
219834
def categories(self):
        
        if self._categories is None:
            self._categories = list()
            self.__pull_combined_properties()
        return self._categories
1018324
def get_category(self, id, **data):
        
        
        return self.get("/categories/{0}/".format(id), data=data)
557083
function getCategories (posts) {
  var categories = posts.reduce(function (categories, post) {
    if (!post.category) return categories;
    return categories.concat(post.category);
  }, []);

  return _.unique(categories).sort();
}
116021
def _to_add_with_category(self, catid):
        '''
        
        '''

        catinfo = MCategory.get_by_uid(catid)
        kwd = {
            'uid': self._gen_uid(),
            'userid': self.userinfo.user_name if self.userinfo else '',
            'gcat0': catid,
            'parentname': MCategory.get_by_uid(catinfo.pid).name,
            'catname': MCategory.get_by_uid(catid).name,
        }

        self.render('autogen/add/add_{0}.html'.format(catid),
                    userinfo=self.userinfo,
                    kwd=kwd)
929572
protected function ensure_categories_loaded() {
        global $DB;
        $this->ensure_category_loaded();
        if (!is_null(end($this->_categories))) {
            return; // Already done.
        }
        $idstoload = array_keys($this->_categories);
        array_shift($idstoload);
        $categories = $DB->get_records_list('course_categories', 'id', $idstoload);
        foreach ($idstoload as $catid) {
            $this->_categories[$catid] = $categories[$catid];
        }
    }
1040670
public static function get_all_question_types_in_categories($categories) {
        global $DB;

        list($categorysql, $params) = $DB->get_in_or_equal($categories);
        $sql = "SELECT DISTINCT q.qtype
                FROM {question} q
                WHERE q.category $categorysql";

        $qtypes = $DB->get_fieldset_sql($sql, $params);
        return $qtypes;
    }
1307098
function BasicQuery(query) {
	assign(this, query);
	if (!this.filter) {
		this.filter = set.UNIVERSAL;
	}
	if (!this.page) {
		this.page = new RecordRange();
	}
	if (!this.sort) {
		this.sort = "id";
	}
	if (typeof this.sort === "string") {
		this.sort = new DefaultSort(this.sort);
	}
}
633518
private function InitCategoryArticles()
    {
        $sql = Access::SqlBuilder();
        $tblArticle = Article::Schema()->Table();
        $orderBy = $sql->OrderList($sql->OrderDesc($tblArticle->Field('Created')));
        $where = $this->PublishedCondition()->
                And_($sql->Equals($tblArticle->Field('Category'), 
                        $sql->Value($this->category->GetID())));
        $this->articles = Article::Schema()->Fetch(false, $where, $orderBy);
        $this->articlesTotal = Article::Schema()->Count(false, $where);
    }
810405
def _set_categories(self):
        
        for column, _ in self._categories.items():
            if column in self.columns:
                self[column] = self[column].astype('category')
1366413
protected function addCriteriaToPositionQuery($query)
    {
        // Find products in the same category
        $products = ProductCategoryQuery::create()
            ->filterByCategoryId($this->getDefaultCategoryId())
            ->filterByDefaultCategory(true)
            ->select('product_id')
            ->find();

        if ($products != null) {
            $query->filterById($products, Criteria::IN);
        }
    }
873702
def getquery(self, default=None, encoding='utf-8', errors='strict'):
        
        query = self.query
        if query is None:
            return default
        else:
            return uridecode(query, encoding, errors)
425119
private function init() {
        global $DB;
        if (!$this->category = $this->get_current_category($this->cat)) {
            return;
        }
        if ($this->recurse) {
            $categoryids = question_categorylist($this->category->id);
        } else {
            $categoryids = array($this->category->id);
        }
        list($catidtest, $this->params) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED, 'cat');
        $this->where = 'q.category ' . $catidtest;
    }
364403
function pickCategories() {
  var picked = [];
  var max = Math.floor(Math.random() * maxCategories);
  while(picked.length < max) {
    var category = pickCategory();
    if (picked.indexOf(category) === -1) {
      picked.push(category);
    }
  }
  return picked;
}
161995
def make_category(self, string, parent=None, order=1):
        
        cat = Category(
            name=string.strip(),
            slug=slugify(SLUG_TRANSLITERATOR(string.strip()))[:49],
            # arent=parent,
            order=order
        )
        cat._tree_manager.insert_node(cat, parent, 'last-child', True)
        cat.save()
        if parent:
            parent.rght = cat.rght + 1
            parent.save()
        return cat