class CategoryRepository extends NestedTreeRepository implements AbstractBlockElementRepositoryInterface

Class CategoryRepository is injected as alligator.category_repository service. CategoryRepository is used for crud operation for managed entity.

Use this class to work with database.

Traits

Trait JQGridTrait

Constants

CATEGORY_BLOCKS_RESULT_CACHE

Category block cache key

CATEGORY_TREE_QUERY__RESULT_CACHE

Category tree query result cache key

CATEGORY_TREE_QUERY__RESULT_CACHE_BACKEND_EDIT

Category tree query backend edit result cache key

PRODUCT_ALIAS

Product alias

ALIAS

Category alias

NUMBER_OF_MEGAMENU_ROOT_CATS

Number of megamenu root categories

NUMBER_OF_MEGAMENU_SUB_CATS

Number of megamenu subcategories

PRODUCTS_PER_CATEGORY

Number of products per category

Methods

jQGridJoinFields(QueryBuilder $qb, JQGridWrapper $jqGridWrapper)

All joins used in select.

jQGridGroupByFields(QueryBuilder $qb, JQGridWrapper $jqGridWrapper)

Should contain group by which jqgrid uses.

array
findAllForJQGRID(int $page, int $offset, array $sortParams, array $additionalParams, JQGridWrapper $jqGridWrapper)

JQGrid function

array
searchForJQGRID(array $searchParams, array $sortParams, bool $isCountSearch = false, array $additionalParams = array(), JQGridWrapper $jqGridWrapper = null)

JQGrid function

getByPrimaryKey(Category $category)

Get Category object by primary key

array
getCategoryAndParentDBInstance(Category $category)

Get Category object and its parent object

getDBParent(Category $category)

Get parent object for requested Category

getDBCategory(Category $category)

Get Category from db or null if not found

getCategoryByName(String $categoryName)

Get Category by name

getDBCategoryByCode(String $categoryCode)

Get Category by code or null if not found

getDBCategoryForCategoryPage(Category $category)

Get Category from db for category page

array
getAggregatorCategories()

Get all visible root categories

array
getFeaturedCats(int $max = 6)

Get featured categories

array
getAllCats(null $rootCats = null)

Get all categories

array
getCatsIds()

Get category ids

array
turnIntoSimpleIdsArray(mixed $arrayOfArrays)

Helper function convert to simple array of ids

array
getAllCategoriesForCSV()

Get all categories for CSV

array
getAllCategories()

Get all categories order by id descending

array
getAllCategoriesIdAndName()

Get all categories names, ids and slugs

array
getAllCategoriesIdNameAndDescription()

Get all categories names, ids, descriptions and permalink

array
getAllCategoriesForProductAdd()

Get all categories for product add order by id descending

beginCustomTransaction()

Begin transaction

flush()

Flush entity manager

commitCustomTransaction()

Commit transaction

mixed
saveCSV(mixed $objectList)

Save object list from CSV

ArrayCollection
getCategoriesFromCollection(mixed $array)

Get categories from collection

QueryBuilder
getRootCategories(null $limit = null)

Get root categories

mixed
getRootFromDb()

Get root category id and code

mixed
getRootObjFromDb()

Get root category

array|null|string
getCategoryTreePagination(array $options, string|int $id, bool $firstLoad, bool $withRoot, array $additionalCategories)

No description

array|string
getCategoryTree(array $options, boolean $displayNonVisible = false)

Get Category tree

array|string
getCategoryTreeForEditBackend(array $options, boolean $displayNonVisible = false)

Get category tree for backend edit

object
saveTreeCategory(Category $category, boolean $isCmdAdd = false)

Save category tree can be used from console command(isCmdAdd should be true than)

save(Category $entity)

Save Category entity

saveCSVSingleFile(Category $entity)

Save entity form CSV single file

mixed
editFields(Category $category)

Edit category fields

array
getAllTreeCategoriesForDelete(array $ids)

Get all categories by ids array for delete

array
getImagesIdsForDelete(int $categoryId)

Function that returns ids of all images that categories 'children' contains

array
getImagesIdsForDeleteFromExternalLinks(int $categoryId)

Get images id for delete from external links

int
deleteTreeCategories(array $objects)

if you want not to delete subcategories use $this->removeFromTree($cat); method

ArrayCollection
getCategoryObjectsById(array $array)

Get category objects by ids array

array
getDBCategoryIDBySlug(Category $category)

Get category id by slug

array
getDBCategoryFilterDataBySlug(Category $category)

Get category left, right and id from db by slug

mixed
findAllCategoriesWithContainingBrands(int $categoryId)

Get all categories and brands for category id

array
findAllCategoriesIds()

Get all category ids

mixed
findAllParentCategories(int $id, int $lft, int $rgt)

Find all category ids that have children categories

array
findCategoriesForCatAdd()

Get all categories id and name

updateFromCMD()

Update number of products in category

array
getSuggestedPrices(int $categoryId, int|null $lft = null, int|null $rgt = null)

Get suggested prices for category filter min and max

array
getSuggestedBrandsIds(int $categoryId)

Get brands for category id for category filter

boolean
updateDisplayForSubCats(Category $rootCategory)

Update visibility for categories

array
getCategoriesSlugs()

Get all category slugs for not deleted categories

mixed
getCategoryReference(int $id)

Get Category reference

mixed
getCategoryMetadata()

Get Category metadata

mixed
getCustomCategoryFieldsForExport(array $fields)

Get custom category fields for export

array
getParentImageWebPathForCategory(int $id)

Get parent image path for category with provided id

array
getExternalImageByCatId(int $id)

Get external image by category id

array
getExternalParentImageByCatId(int $id)

Get external parent image by category id

array
getEntitiesForBlockElementsExtension(array $ids)

Get entities from database by ids Tis method is used to for block elements extension Make sure you order data by ids - ids is array of elements and it is sorted by priority - so add this to select -> ' FIELD('.self::ALIAS.'.id'.', '.implode(', ', $ids).') AS sort_col'); - and order by this field Also make sure you cache this data -> qb->useQueryCache(true)->useResultCache(true, 3600)

array
searchCategories(Filter $filter, int $page, int $offset, bool $isCountSearch = false)

Search categories using Filter, page and offset, if only count is required pass $isCountSearch = true

array
getAllCategoriesIdAndCode()

Get category id and category code

mixed
getAllCategoriesIdNameAndParentId()

Get all categories id, name and parent id

bool|string
saveMultiple(array $categories, int $flushNumber = 30, bool $hasNewCategory = false)

Save multiple categories accepts flush number as parameter for optimisation purposes

bool
mergeMultiple(array $array = array())

Merge multiple categories from provided array

array
getEntityNamesForIds(array $ids)

Get id and name (field must be name so change it in select) of entity Used in event for block element edit Make sure you order data by ids - ids is array of elements and it is sorted by priority - so add this to select -> ' FIELD('.self::ALIAS.'.id'.', '.implode(', ', $ids).') AS sort_col'); - and order by this field

deleteResultCaches()

Delete all cached results

bool
updateProductPermissionsForCategories(string $categories)

Param $categories is a string, example "1,2,4,15"

array
getLftRgtData(mixed $category)

Get left and right data for category

deleteTreeQueryResultResultCaches()

delete all cached results

mixed
getParentCategorySlug(string $slug = '')

Get slug of parent category

mixed
getHighestLevelParent(Category $category)

Get highest level parent category for provided category

hideCategoriesForSlug(string $slug, bool $hide)

Update hide from menu property to provided state on categories that match provided slug

Details

in JQGridTrait at line 27
jQGridJoinFields(QueryBuilder $qb, JQGridWrapper $jqGridWrapper)

All joins used in select.

Override in the repository class if needed. Should do nothing otherwise

Parameters

QueryBuilder $qb
JQGridWrapper $jqGridWrapper

in JQGridTrait at line 42
jQGridGroupByFields(QueryBuilder $qb, JQGridWrapper $jqGridWrapper)

Should contain group by which jqgrid uses.

Override in the repository class if needed. Should do nothing otherwise

Parameters

QueryBuilder $qb
JQGridWrapper $jqGridWrapper

in JQGridTrait at line 61
array findAllForJQGRID(int $page, int $offset, array $sortParams, array $additionalParams, JQGridWrapper $jqGridWrapper)

JQGrid function

Parameters

int $page
int $offset
array $sortParams
array $additionalParams
JQGridWrapper $jqGridWrapper

Return Value

array

in JQGridTrait at line 94
array searchForJQGRID(array $searchParams, array $sortParams, bool $isCountSearch = false, array $additionalParams = array(), JQGridWrapper $jqGridWrapper = null)

JQGrid function

Parameters

array $searchParams
array $sortParams
bool $isCountSearch
array $additionalParams
JQGridWrapper $jqGridWrapper

Return Value

array

at line 77
Category getByPrimaryKey(Category $category)

Get Category object by primary key

Parameters

Category $category

Return Value

Category

at line 88
array getCategoryAndParentDBInstance(Category $category)

Get Category object and its parent object

Parameters

Category $category

Return Value

array

at line 99
Category getDBParent(Category $category)

Get parent object for requested Category

Parameters

Category $category

Return Value

Category

at line 110
Category getDBCategory(Category $category)

Get Category from db or null if not found

Parameters

Category $category

Return Value

Category

at line 125
Category getCategoryByName(String $categoryName)

Get Category by name

Parameters

String $categoryName

Return Value

Category | null

at line 149
Category getDBCategoryByCode(String $categoryCode)

Get Category by code or null if not found

Parameters

String $categoryCode

Return Value

Category | null

Exceptions

NonUniqueResultException

at line 171
Category getDBCategoryForCategoryPage(Category $category)

Get Category from db for category page

Parameters

Category $category

Return Value

Category

Exceptions

NonUniqueResultException

at line 194
array getAggregatorCategories()

Get all visible root categories

Return Value

array

at line 213
array getFeaturedCats(int $max = 6)

Get featured categories

Parameters

int $max

Return Value

array

at line 231
array getAllCats(null $rootCats = null)

Get all categories

Parameters

null $rootCats

Return Value

array

at line 279
array getCatsIds()

Get category ids

Return Value

array

at line 334
array turnIntoSimpleIdsArray(mixed $arrayOfArrays)

Helper function convert to simple array of ids

Parameters

mixed $arrayOfArrays

Return Value

array

at line 348
array getAllCategoriesForCSV()

Get all categories for CSV

Return Value

array

at line 359
array getAllCategories()

Get all categories order by id descending

Return Value

array

at line 372
array getAllCategoriesIdAndName()

Get all categories names, ids and slugs

Return Value

array

at line 386
array getAllCategoriesIdNameAndDescription()

Get all categories names, ids, descriptions and permalink

Return Value

array

at line 398
array getAllCategoriesForProductAdd()

Get all categories for product add order by id descending

Return Value

array

at line 411
beginCustomTransaction()

Begin transaction

at line 419
flush()

Flush entity manager

at line 427
commitCustomTransaction()

Commit transaction

at line 440
mixed saveCSV(mixed $objectList)

Save object list from CSV

Parameters

mixed $objectList

Return Value

mixed

Exceptions

Exception

at line 466
ArrayCollection getCategoriesFromCollection(mixed $array)

Get categories from collection

Parameters

mixed $array

Return Value

ArrayCollection

at line 485
QueryBuilder getRootCategories(null $limit = null)

Get root categories

Parameters

null $limit

Return Value

QueryBuilder

at line 503
mixed getRootFromDb()

Get root category id and code

Return Value

mixed

Exceptions

NoResultException
NonUniqueResultException

at line 521
mixed getRootObjFromDb()

Get root category

Return Value

mixed

Exceptions

NoResultException
NonUniqueResultException

at line 541
array|null|string getCategoryTreePagination(array $options, string|int $id, bool $firstLoad, bool $withRoot, array $additionalCategories)

Parameters

array $options
string|int $id
bool $firstLoad
bool $withRoot
array $additionalCategories

Return Value

array|null|string

at line 587
array|string getCategoryTree(array $options, boolean $displayNonVisible = false)

Get Category tree

Parameters

array $options
boolean $displayNonVisible

Return Value

array|string

at line 667
array|string getCategoryTreeForEditBackend(array $options, boolean $displayNonVisible = false)

Get category tree for backend edit

Parameters

array $options
boolean $displayNonVisible

Return Value

array|string

at line 715
object saveTreeCategory(Category $category, boolean $isCmdAdd = false)

Save category tree can be used from console command(isCmdAdd should be true than)

Parameters

Category $category
boolean $isCmdAdd

Return Value

object

at line 762
Category save(Category $entity)

Save Category entity

Parameters

Category $entity

Return Value

Category

Exceptions

Exception

at line 782
Category saveCSVSingleFile(Category $entity)

Save entity form CSV single file

Parameters

Category $entity

Return Value

Category

Exceptions

Exception

at line 803
mixed editFields(Category $category)

Edit category fields

Parameters

Category $category

Return Value

mixed

at line 847
array getAllTreeCategoriesForDelete(array $ids)

Get all categories by ids array for delete

Parameters

array $ids

Return Value

array

at line 867
array getImagesIdsForDelete(int $categoryId)

Function that returns ids of all images that categories 'children' contains

Parameters

int $categoryId

Return Value

array

Get images id for delete from external links

Parameters

int $categoryId

Return Value

array

at line 907
int deleteTreeCategories(array $objects)

if you want not to delete subcategories use $this->removeFromTree($cat); method

Parameters

array $objects

Return Value

int

Exceptions

Exception

at line 930
ArrayCollection getCategoryObjectsById(array $array)

Get category objects by ids array

Parameters

array $array

Return Value

ArrayCollection

at line 950
array getDBCategoryIDBySlug(Category $category)

Get category id by slug

Parameters

Category $category

Return Value

array

Exceptions

NoResultException
NonUniqueResultException

at line 969
array getDBCategoryFilterDataBySlug(Category $category)

Get category left, right and id from db by slug

Parameters

Category $category

Return Value

array

Exceptions

NoResultException
NonUniqueResultException

at line 988
mixed findAllCategoriesWithContainingBrands(int $categoryId)

Get all categories and brands for category id

Parameters

int $categoryId

Return Value

mixed

Exceptions

NoResultException
NonUniqueResultException

at line 1031
array findAllCategoriesIds()

Get all category ids

Return Value

array

at line 1047
mixed findAllParentCategories(int $id, int $lft, int $rgt)

Find all category ids that have children categories

Parameters

int $id
int $lft
int $rgt

Return Value

mixed

at line 1064
array findCategoriesForCatAdd()

Get all categories id and name

Return Value

array

at line 1075
updateFromCMD()

Update number of products in category

at line 1120
array getSuggestedPrices(int $categoryId, int|null $lft = null, int|null $rgt = null)

Get suggested prices for category filter min and max

Parameters

int $categoryId
int|null $lft
int|null $rgt

Return Value

array

at line 1149
array getSuggestedBrandsIds(int $categoryId)

Get brands for category id for category filter

Parameters

int $categoryId

Return Value

array

at line 1170
boolean updateDisplayForSubCats(Category $rootCategory)

Update visibility for categories

Parameters

Category $rootCategory

Return Value

boolean

at line 1195
array getCategoriesSlugs()

Get all category slugs for not deleted categories

Return Value

array

at line 1212
mixed getCategoryReference(int $id)

Get Category reference

Parameters

int $id

Return Value

mixed

Exceptions

ORMException

at line 1221
mixed getCategoryMetadata()

Get Category metadata

Return Value

mixed

at line 1232
mixed getCustomCategoryFieldsForExport(array $fields)

Get custom category fields for export

Parameters

array $fields

Return Value

mixed

at line 1273
array getParentImageWebPathForCategory(int $id)

Get parent image path for category with provided id

Parameters

int $id

Return Value

array

Exceptions

NonUniqueResultException

at line 1292
array getExternalImageByCatId(int $id)

Get external image by category id

Parameters

int $id

Return Value

array

Exceptions

NonUniqueResultException

at line 1311
array getExternalParentImageByCatId(int $id)

Get external parent image by category id

Parameters

int $id

Return Value

array

Exceptions

NonUniqueResultException

at line 1334
array getEntitiesForBlockElementsExtension(array $ids)

Get entities from database by ids Tis method is used to for block elements extension Make sure you order data by ids - ids is array of elements and it is sorted by priority - so add this to select -> ' FIELD('.self::ALIAS.'.id'.', '.implode(', ', $ids).') AS sort_col'); - and order by this field Also make sure you cache this data -> qb->useQueryCache(true)->useResultCache(true, 3600)

Parameters

array $ids

Return Value

array

at line 1376
array searchCategories(Filter $filter, int $page, int $offset, bool $isCountSearch = false)

Search categories using Filter, page and offset, if only count is required pass $isCountSearch = true

Parameters

Filter $filter
int $page
int $offset
bool $isCountSearch

Return Value

array

See also

Filter

at line 1414
array getAllCategoriesIdAndCode()

Get category id and category code

Return Value

array

at line 1427
mixed getAllCategoriesIdNameAndParentId()

Get all categories id, name and parent id

Return Value

mixed

at line 1446
bool|string saveMultiple(array $categories, int $flushNumber = 30, bool $hasNewCategory = false)

Save multiple categories accepts flush number as parameter for optimisation purposes

Parameters

array $categories
int $flushNumber
bool $hasNewCategory

Return Value

bool|string

at line 1487
bool mergeMultiple(array $array = array())

Merge multiple categories from provided array

Parameters

array $array

Return Value

bool

at line 1512
array getEntityNamesForIds(array $ids)

Get id and name (field must be name so change it in select) of entity Used in event for block element edit Make sure you order data by ids - ids is array of elements and it is sorted by priority - so add this to select -> ' FIELD('.self::ALIAS.'.id'.', '.implode(', ', $ids).') AS sort_col'); - and order by this field

Parameters

array $ids

Return Value

array

at line 1529
deleteResultCaches()

Delete all cached results

at line 1544
bool updateProductPermissionsForCategories(string $categories)

Param $categories is a string, example "1,2,4,15"

Parameters

string $categories

Return Value

bool

at line 1566
array getLftRgtData(mixed $category)

Get left and right data for category

Parameters

mixed $category

Return Value

array

Exceptions

NonUniqueResultException

at line 1582
deleteTreeQueryResultResultCaches()

delete all cached results

at line 1597
mixed getParentCategorySlug(string $slug = '')

Get slug of parent category

Parameters

string $slug

Return Value

mixed

Exceptions

DBALException

at line 1624
mixed getHighestLevelParent(Category $category)

Get highest level parent category for provided category

Parameters

Category $category

Return Value

mixed

Exceptions

NonUniqueResultException

at line 1642
hideCategoriesForSlug(string $slug, bool $hide)

Update hide from menu property to provided state on categories that match provided slug

Parameters

string $slug
bool $hide

Exceptions

DBALException