Find parent category by external ID and set parent_id
163367
protected function initParentCategory()
    {
        if (!array_key_exists('parent_id', $this->arImportData)) {
            return;
        }

        $iParentID = array_get($this->arImportData, 'parent_id');
        array_forget($this->arImportData, 'parent_id');
        if (empty($iParentID)) {
            $this->obParentCategory = false;

            return;
        }

        //Find parent category
        $this->obParentCategory = Category::getByExternalID($iParentID)->first();
    }
1034816
def find_parent_id_for_component(self, slug):
        
        response = self.get_record(slug)

        if "parent" in response:
            return response["parent"]
        # resource was passed in, which has no higher-up record;
        # return the same ID
        else:
            return slug
570963
private function RecursiveMarkCategoryRead($CategoryModel, $UnprocessedCategories, $ParentIDs) {
		$CurrentUnprocessedCategories = array();
		$CurrentParentIDs = $ParentIDs;
		foreach ($UnprocessedCategories as $Category) {
			if (in_array($Category["ParentCategoryID"], $ParentIDs)) {
				$this->MarkCategoryRead($CategoryModel, $Category["CategoryID"]);
				// Don't add duplicate ParentIDs
				if (!in_array($Category["CategoryID"], $CurrentParentIDs)) {
					$CurrentParentIDs[] = $Category["CategoryID"];
				}
			} else {
				// This keeps track of categories that we still need to check on recurse
				$CurrentUnprocessedCategories[] = $Category;
			}
		}
		// Base case: if we have not found any new parent ids, we don't need to recurse
		if (count($ParentIDs) != count($CurrentParentIDs)) {
			$this->RecursiveMarkCategoryRead($CategoryModel, $CurrentUnprocessedCategories, $CurrentParentIDs);
		}
	}
870235
public function getAllChildren($parentID)
    {
        $children = $this->getChildren($parentID);
        foreach ($children as $key => $child){
            $this->categoriesToBeDeleted[$child->categoryID] = $child;
            $this->getAllChildren($child->categoryID);
        }
    }
1086986
public function findAssociationCategoryByID($id)
    {
        $categories = $this->findAssociationCategories()->getCategories();

        $categories->rewind();

        while ($categories->valid()) {
            $category = $categories->current();
            if ($category->getID() == $id) {
                return $category;
            }

            $categories->next();
        }
    }
1119456
def get_parent_id(self):
        ''''''
        parent_id = parsers.get_parent_id(self.__chebi_id)
        return None if math.isnan(parent_id) else 'CHEBI:' + str(parent_id)
219745
protected function setTitleEditCategory()
    {
        if (isset($this->data_category['category_id'])) {
            $title = $this->text('Edit %name', array('%name' => $this->data_category['title']));
        } else {

            $parent_category_id = $this->getQuery('parent_id');

            $parent_category = array();
            if (!empty($parent_category_id)) {
                $parent_category = $this->category->get($parent_category_id);
            }

            $vars = array('%name' => $this->data_category_group['title']);

            if (isset($parent_category['title'])) {
                $vars['%category'] = $parent_category['title'];
                $title = $this->text('Add sub-category to %name / %category', $vars);
            } else {
                $title = $this->text('Add category to %name', $vars);
            }
        }

        $this->setTitle($title);
    }
540663
private function categoryEndpoint($id = null)
    {
        return $id === null ? $this->categoryEndpoint : $this->categoryEndpoint . '/' . $id;
    }
784530
def clean_parent(self):
        
        data = self.cleaned_data['parent']
        if data == self.instance:
            raise forms.ValidationError(
                _('A category cannot be parent of itself.'),
                code='self_parenting')
        return data
275227
public static function find($id)
    {
        $category = json_decode(self::get("/categories/{$id}")->getBody(), true);

        return new self($category);
    }
1277319
def parent(self):
        # type: () -> Any
        
        if self.parent_id:
            return self._client.part(pk=self.parent_id, category=self.category)
        else:
            return None
1108276
function resolve(parent, id) {
	if (/^\.\.?\//.test(id) && parent) { // is a relative id
		id = parent.replace(/[^\/]+$/, id); // prepend parent's dirname
	}
	var terms = [];
	id.split('/').forEach(function(term) {
		if ('..' === term) { terms.pop(); } // remove previous, don't add ..
		else if ('.' !== term) { terms.push(term); } // add term
		// else if ('.' === term) // ignore .
	});
	return terms.join('/');
}
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
1221569
public function indexCategory($category_id)
    {
        $this->setCategory($category_id);
        $this->setTitleIndexCategory();
        $this->setBreadcrumbIndexCategory();
        $this->setHtmlFilterIndexCategory();
        $this->setTotalIndexCategory();
        $this->setFilterIndexCategory();
        $this->setPagerIndexCategory();
        $this->setListProductCategory();
        $this->setChildrenCategory();

        $this->setData('category', $this->data_category);

        $this->setDataMenuIndexCategory();
        $this->setDataImagesIndexCategory();
        $this->setDataNavbarIndexCategory();
        $this->setDataProductsIndexCategory();
        $this->setDataChildrenIndexCategory();

        $this->setMetaIndexCategory();
        $this->outputIndexCategory();
    }
208925
public static function findByParentCartId( $parentId, $parentType, $orderId ) {

		return self::find()->where( 'parentId=:pid AND parentType=:ptype AND orderId=:oid', [ ':pid' => $parentId, ':ptype' => $parentType, ':oid' => $orderId ] )->one();
	}
975230
function getCategory($id)
    {
        $result = $this->db->query('SELECT * FROM category WHERE id = :id', [':id'=>(0+$id)]);
        if (isset($result[0])) {
            return ['name'=>$result[0]->get('name'),
                'description'=>$result[0]->get('description')];
        }
        return false;
    }
764595
def admin_add
      return unless user_is_allowed('categories', 'add')
      
      if params[:parent_id].nil? or params[:parent_id].empty?
        render :json => { :error => 'Please select a parent category.' }
      elsif params[:name].nil? or params[:name].empty?
        render :json => { :error => 'This title cannot be empty' }
      else
        category           = Category.new
        category.parent_id = params[:parent_id]
        category.name      = params[:name]
        category.slug      = category.generate_slug
        category.url       = "#{Category.find(params[:parent_id]).url}/#{category.slug}"
        
        if category.save
          render :json => { :success => true, :redirect => "/admin/categories/#{category.id}/edit" }
        else
          render :json => { :error => 'There was an error saving the category.' }
        end
      end
    end