How to search entities ?
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
How to search entities ?
My environment is the following:
Laravel Framework 5.8.26
aimeos-laravel 2019.04
PHP Version 7.2.19-1+ubuntu18.04.1+deb.sury.org+1
In the users_list table I have several rows with domain = media. In other words some user has several media attached to his.
My goal is to find all media of specific user and show it on admin tab. I created topic about it, but here I would like figure out another thing.
The code above does what I need. It returns me customer/list items like this:
Problem is there refItem is null! But actually I need this refItem, there as I know must be media object where I can get label and other. $items = $customerListsManager->searchItems($search, ['media'], $total); - here I have set media, so it must fetch media... Ideally would be if I can get exactly array of media objects.
So, such way I want to get all media from specific user. But also I want to make it work with filters in admin panel, so user can filter media by label and sort them.
Please provide correct code how to do it
Thank you a lot for the help!
Laravel Framework 5.8.26
aimeos-laravel 2019.04
PHP Version 7.2.19-1+ubuntu18.04.1+deb.sury.org+1
In the users_list table I have several rows with domain = media. In other words some user has several media attached to his.
My goal is to find all media of specific user and show it on admin tab. I created topic about it, but here I would like figure out another thing.
Code: Select all
/** @var \Aimeos\MShop\Common\Manager\Decorator\Depth $customerListsManager */
$customerListsManager = \Aimeos\MShop::create( $context, 'customer/lists' );
$search = $customerListsManager->createSearch();
$search->setConditions( $search->combine( '&&', [
$search->compare( '==', 'customer.lists.domain', 'media' ),
$search->compare( '==', 'customer.lists.parentid', Auth::id()),
] ) );
$items = $customerListsManager->searchItems($search, ['media'], $total);
dd($items);
Code: Select all
34 => Standard {#430 ▼
-prefix: "customer.lists."
-values: array:15 [▼
"customer.lists.id" => "34"
"customer.lists.siteid" => "1"
"customer.lists.parentid" => "2"
"customer.lists.type" => "default"
"customer.lists.domain" => "media"
"customer.lists.refid" => "96"
"customer.lists.datestart" => null
"customer.lists.dateend" => null
"customer.lists.config" => []
"customer.lists.position" => "0"
"customer.lists.status" => "1"
"customer.lists.mtime" => "2019-07-16 15:20:21"
"customer.lists.editor" => "aimeos:account"
"customer.lists.ctime" => "2019-07-16 15:20:21"
"date" => "2019-07-17 10:06:00"
]
-refItem: null
-bdata: array:15 [▶]
-available: true
-modified: false
-prefix: "customer.lists."
}
So, such way I want to get all media from specific user. But also I want to make it work with filters in admin panel, so user can filter media by label and sort them.
Please provide correct code how to do it
Thank you a lot for the help!
Re: How to search entities ?
Simply use this:
The second and third parameters are the type and list type of the returned items to filter for.
Code: Select all
$customer = \Aimeos\MShop::create( $context, 'customer' )->getItem( Auth::id(), 'media' );
foreach( $customer->getListItems( 'media', null, null, false ) as $listItem ) {
if( ( $refItem = $listItem->getRefItem() ) !== null ) {
// ...
}
}
// or use this if you don't need the list items:
$mediaItems = $customer->getRefItems( 'media', null, null, false );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to search entities ?
Ok, but please, take a look at the screenshot:
https://prnt.sc/og8258
This I meant about filters. I want to be able to filter and sort entities. As I understand your approach will look ugly if I want implement filtering and sorting. Because it will not create right sql query to filter entities at once. But I will need filter them in loop or using array functions.. Not good(
Do you understand what I mean ?
https://prnt.sc/og8258
This I meant about filters. I want to be able to filter and sort entities. As I understand your approach will look ugly if I want implement filtering and sorting. Because it will not create right sql query to filter entities at once. But I will need filter them in loop or using array functions.. Not good(
Do you understand what I mean ?
Re: How to search entities ?
Because of the strict data domain model, you can't sort and filter items in foreign data domains. But the list items are sorted by their positions automatically if you use getItem().
If you implement your panel similar to the catalog/product panel, you can use filtering and sorting at least for the list items:
https://github.com/aimeos/ai-admin-jqad ... andard.php
If you implement your panel similar to the catalog/product panel, you can use filtering and sorting at least for the list items:
https://github.com/aimeos/ai-admin-jqad ... andard.php
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to search entities ?
Do you mean this method ?
https://github.com/aimeos/ai-admin-jqad ... d.php#L288
Strange, why I can't get refItem from my first post in this topic
https://github.com/aimeos/ai-admin-jqad ... d.php#L288
Strange, why I can't get refItem from my first post in this topic
Re: How to search entities ?
Yes, this is the method which retrieves the items but you also have to take a look at fromArray()/toArray().
The lists manager doesn't retrieve the referenced items. This is done in the domain manager (customer manager in your case).
The lists manager doesn't retrieve the referenced items. This is done in the domain manager (customer manager in your case).
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to search entities ?
Hmm, honestly after using ActiveRecord and Repository pattern this approach is new for me and for now not very useful.
I have idea how to solve my problem. Firstly I get customer media list and then I get media ids. Then I can get exact media by their ids. Code looks like this:
As for me it is ugly solution. But I don't know another way yet. And problem that I don't know how to search media with 'in' operator. I need get all media which IDS are in $mediaIds. How can I do it ?
I have idea how to solve my problem. Firstly I get customer media list and then I get media ids. Then I can get exact media by their ids. Code looks like this:
Code: Select all
/** @var \Aimeos\MShop\Common\Manager\Decorator\Depth $customerListsManager */
$customerListsManager = \Aimeos\MShop::create( $context, 'customer/lists' );
$search = $customerListsManager->createSearch();
$search->setConditions( $search->combine( '&&', [
$search->compare( '==', 'customer.lists.domain', 'media' ),
$search->compare( '==', 'customer.lists.parentid', Auth::id()),
] ) );
$items = $customerListsManager->searchItems($search, ['media'], $total);
$mediaIds = [];
foreach ($items as $item) {
$mediaIds[] = $item->getRefId();
}
$search = $mediaManager->createSearch();
$search->setConditions( $search->compare( 'in', 'media.id', $mediaIds ));
$media = $customerListsManager->searchItems($search);
Re: How to search entities ?
Yes, your approach works, just use the "==" operator. It works for arrays too.
ActiveRecord and Respository patterns are unable to work with huge amounts of data efficiently. Thus we use DAO/DTO pattern to be able to manage and retrieve data in setups with billions of items in milliseconds.
ActiveRecord and Respository patterns are unable to work with huge amounts of data efficiently. Thus we use DAO/DTO pattern to be able to manage and retrieve data in setups with billions of items in milliseconds.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
-
- Expert
- Posts: 274
- Joined: 27 Jun 2019, 16:19
Re: How to search entities ?
Great thank you! But here I am also afraid for one thing.
The following code must collect all ids of media I need:
But is there any limit for entities count ? Because if there is, for example, limit per 100 entities, but user has 200 entities - my logic will be broken
The following code must collect all ids of media I need:
Code: Select all
$items = $customerListsManager->searchItems($search);
$mediaIds = [];
foreach ($items as $item) {
$mediaIds[] = $item->getRefId();
}
Re: How to search entities ?
There's a default limit of 100 if you use createSearch() only. If you copy/paste/adapt the catalog/product sub-panel, there's a pagination included.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star