Closed Elfangor93 closed 1 year ago
\
Get all parent categories
$model = $this->component->getMVCFactory()->createModel('Category');
$res = $model->getParents(<CATID>, <SELF>, <ROOT>);
dump($res)
Get all child categories
$model = $this->component->getMVCFactory()->createModel('Category');
$res = $model->getChildren(<CATID>, <SELF>);
dump($res)
Get all child and parent categories
$model = $this->component->getMVCFactory()->createModel('Category');
$res = $model->getTree(<CATID>, <ROOT>);
dump($res)
Get direct sibling of category
$model = $this->component->getMVCFactory()->createModel('Category');
$res = $model->getSibling(<CATID>, <SIDE>);
dump($res)
Get all siblings of category
$model = $this->component->getMVCFactory()->createModel('Category');
$res = $model->getSiblings(<CATID>, <SIDE>);
dump($res)
You should see an output like this:
\
Create Config service
$this->component->createConfig(<CONTEXT>, <ID>);
$config = $this->component->getConfig();
dump($config)
You then should see the following:
Here all possible configuration settings are listed with the correct value loaded based on the inheritance method chosen and the context and id provided.
Sorry, for me, it's too abstract. I'm not able to understand what's behind this service. So I see, I have a lot to learn.
After a few tests, I still have a few questions about config service: Perhaps I have not understood the functionality correctly? :confused:
Actual situation:
Config sets: Global config: User group=Public, id=1 For Registered: User group=Registered, id=2 For Super User: User group=Super Users, id=3
Users: Admin: User group=Super Users, id=663 Tester: User group=Registered, id=664
Categories: First: Access=Public, id=2 Second: Access=Registered, id=3
1. Attempt: Code:
$this->component->createConfig('com_joomgallery.user.id', 664);
$config = $this->component->getConfig();
dump($config);
Expected: Loading the configuration valid for the user with id 664.
Result: Correct?: The config for registered is displayed. but also the message: Error deriving settings from configurations. Provided context may be wrong. Context: com_joomgallery.user.id
2. Attempt: Code:
$this->component->createConfig('com_joomgallery', );
$config = $this->component->getConfig();
dump($config);
Expected: Load global configuration valid for current user
Result: Correct?: Configuration for super user (is current user) is displayed. No error message.
3. Attempt: Code:
$this->component->createConfig('com_joomgallery.user.id', null);
$config = $this->component->getConfig();
dump($config);
Expected: Loading of the configuration valid for public (visitors)
Result: Correct?: The config for public is displayed. but also the message: Error deriving settings from configurations. Provided context may be wrong. Context: com_joomgallery.user.id
4. Attempt: Code:
$this->component->createConfig('com_joomgallery.category.id', 2);
$config = $this->component->getConfig();
dump($config);
Expected: Loading of the configuration for category with id = 2 (public).
Result:
Wrong?: The configuration for the current user (Super user id=663) is loaded.
but also the message:
Error deriving settings from configurations. Provided context may be wrong. Context: com_joomgallery.category.id
5. Attempt: Code:
$this->component->createConfig('com_joomgallery.category.id', 3);
$config = $this->component->getConfig();
dump($config);
Expected: Loading the configuration for category with id = 3 (registered).
Result: Wrong?: The configuration for the current user (Super user id=663) is loaded. but also the message: Error deriving settings from configurations. Provided context may be wrong. Context: com_joomgallery.category.id
Test data: https://prnt.sc/cyYMX57jwgru Test ENV: https://prnt.sc/POC1XpMTIc-i
$model = $this->component->getMVCFactory()->createModel('Category'); $res = $model->getChildren(1, true); dump($res);
1 is Root category so I expected to see ALL child categories... but there is one missing ID 2 "Categorized". Also there is self = true... so Root category should be also listed?
$model = $this->component->getMVCFactory()->createModel('Category'); $res = $model->getSibling(2, 'both'); dump($res);
Category ID 2 is "Uncategorized"... with above code I expected to see both siblings... but it seems that the only sibling is ROOT. Is "Uncategorized" on the same level as ROOT or it should be child of ROOT category?
Get all siblings of category = OK
Create Config service = I can confirm issues mentioned by @MrMusic above.
Category ID 2 is "Uncategorized"... with above code I expected to see both siblings... but it seems that the only sibling is ROOT. Is "Uncategorized" on the same level as ROOT or it should be child of ROOT category?
Something seems to be weird with your categories structure. The root category is tho only category with level=0. All other categories including "Uncategorised" have levels > 0. This means that Root category does not have any siblings. You can check that by doing
$model = $this->component->getMVCFactory()->createModel('Category');
$res = $model->getSibling(1, 'both');
dump($res);
The output should be "false" since Root category (id=1) does not have any siblings.
@MrMusic and @szepty-ziemi are your found issues fixed now?
Okay, when fired code you provided I get false indeed. But I did it on new installation, without any other categories than default.
When tried to create category I get error:
I downloaded fresh branch package (few minutes ago).
When tried to create category I get error:
This issue you found to create categories already exists in the current main branch and is not related to this PR. Please open a new issue for that.
I propose to merge this PR and fix the remaining issues with new PRs. This one here is already huge. I am scared of messing up new things by fixing issues not related to the content of this PR...
Okay, the problem is that this is bloker for testing. I removed previous version and installed new one... so no categories left. I need to create them to be able to test this PR... or rather to confirm if issues I reported are fixed.
Is there a workaround I could use? Eg. creating categories straight in DB?
Since last updates a warning message is shown in the subform 'Image processing (static images)' in new configuration sets:
Warning: Undefined variable $id in ...administrator\components\com_joomgallery\layouts\joomla\form\renderfield.php on line 41
This is only in new config sets not in 'Global Configuration'.
PS: Creating new categories is possible for me without problems.
Creating new categories also for me without any problems. I am testing with mysql v5.7.37 on Windows while you (@szepty-ziemi) are testing with MariaDB v10.3.37 on Linux. When did the creation of categories stop working? I dont remember a change which could result in the error you are experiencing...
Maybe you could try using the zip file with sample data created by @MrMusic until we solved the probelm of creating categories. The zip should work anyway since it adds the categories directly into the DB by SQL queries.
I uninstalled, downloaded latest version and installed as a fresh one. Problem with category creation is gone. I retested the cases and all looks good :)
I propose to merge this PR and fix the remaining issues with new PRs...
Ok, then we do it so...
What is this service for
The Config service will be used to handle the different configurations set in the component. Based on the chosen inheritance method in the Glocal component settings, the correct set of configurations are loaded depending on the current context. The following configuration sets are taken into account:
The following contexts are available:
How does it work
When you instantiate the service, you have to provide a context and optionally an ID telling the service for which part of the component you want to have the configuration set loaded. The service then will get the configuration sets and override the settings based on the chosen inheritance method. Default inheritance method will override the settings as follows:
How to use this service
You can load the service anywhere in Joomla by doing
How to test the service
Make sure "Debug System" is "Yes" in Joomla Global configuration. Open the file
/administrator/com_joomgallery/src/View/Faulties/HtmlView.php
and insert the following code on line 62 afterthrow new \Exception(implode("\n", $errors)); }
Different test instructions see comments below...