How to create custom User Group programmatically in Joomla 3.x? - joomla

I am writing a custom Component in Joomla 3.x.
At a certain point of the component I need to create a Custom User Group under 'Registered' group in Joomla.
After searching the web a lot, I found no solution of this problem.

You can add it to the #__usergroups table programmatically, ensuring the user group is not there already; or get an instance of JTableUsergroup (declared in libraries/joomla/table/usergroup.php). Since it extends JTable you can use its save() method, passing an array with the values you wish to store.
Then in order to have proper lft and rgt values, you need to invoke the rebuild() method on JTableUsergroup.
Please ensure adding it programmatically is really necessary, it may cause issues on sites that already make heavy use of usergroups.

Related

Where do I put "extra" default fields for a Laravel model?

This question is about the "correct" design pattern, not about functional code. I want to adhere to best-practices and use the right feature in Laravel.
I have a model called Order which contains users' product orders.
Order has several columns, like which product, quantity, etc, and is stored in mysql, with a belongsTo() call to the User model.
When I place an order using the OrderController, I call an outside API that I set up using a Service class.
Here's the main part of the question:
I need to add certain fields that the API requires, but on my end are always the same, so it would make sense to me to pack these into an object of their own and just append that object to the end of my Order data before submission.
So where is the "Best" place to put this extra data? In my model? In a Service class? I'm leaning toward the service class, but that just doesn't feel right.
You have an action that gives a single or a collection of a model. So the best practice for adding some extra data to those results is using JsonResource and ResourceCollection. By using them you can easily add anything you want in the ToArray method.
Lumen doesn't have Illuminate\Http by default but you can add it to your project.
Official Http package of laravel
Eloquent: API Resources Documentation.

Extract Order information and customer information from new order email

I want to extract Order information and customer information from new order email which is sent to the customer after purchasing any product from Magento Website.
I have tried a lot but not getting any results as such.
Is this possible in Magento, I am stuck up in this problem since days.Does any one have a solution to this?
The sending of new order emails is handled in Mage_Sales_Model_Order.
Most Magento model classes (all which extend Mage_Core_Model_Abstract) implement the Template Method pattern - not to be confused with view templates. The template methods can be used to hook in to save, load, and delete workflows in two ways:
Method rewrites via config-based class overrides (another Magento treat)
Observe events dispatched in the template methods.
By far the preferred technique for hooking into model execution is the event-observer system. Additionally, there are hundreds of events dispatched throughout Magento for any given execution.

Magento - Correct Place to store values to be used for attributes

I have an dropdown attribute that I am creating during my module setup.
I want to pre-populate this attribute with some values while my module is installing. I can do this no problem, currently by simply storing the values in an array and then creating adding the options to the attribute in the install script.
Where would be the correct place to store these values - in a model? If so would it be a source model utilizing the toOptionArray method? This is technically used for forms so it doesnt seem right. But neither does just storing the values in the setup script.
Any ideas?
Yes, the toOptionArray method would be in line with standard Magento practices.
Typically the toOptionArray() is found in Helpers, if that is what you are asking. Helpers extend far fewer classes, and therefore inherit far fewer methods than models. This makes them much lighter weight for simple tasks like setting up an array of options, provided that they are static.
If the values are stored in a new DB table, and can be expanded upon by the user, it may make more sense to put this in a Model that has direct access to your DB table.

Inserting a ModelValidator into a Model's Validators in ASP.NET MVC3

I'm currently trying to programmatically insert a ModelClientValidationStringLengthRule ModelValidator via a custom attribute, and wishing to avoid adding to the AdditionalValues dictionary in order to make use of existing functionality.
This is due to using a CMS, and wanting to control the length of the string via the CMS rather than within a model.
I assume I would do this in the OnMetadataCreated event in the custom attribute, however I cannot see how to add to the ModelValidator collection, only get them via GetValidators...
Anyone have any ideas?
Thanks in advance,
Dave
Rather than adding a custom attribute, you want to inject a validator based upon a condition.
You can use the class I detail in this answer to inject your validator based upon the conditions in your CMS.

Validate a Collection Has at Least One Item using Validation Application Block

Using the Enterprise Library 4.1 Validation Application Block, how can I validate that a collection property contains at least one item?
I'm assuming you mean out of the box. If so, then I don't think there is way to validate directly the number of items in a collection.
These are some other ways that you could try:
Decree that you only deal with null collections and not empty collections and use a Not Null Validator. Not practical, though.
Use self validation and have the object validate in code that the collection(s) have the correct number of items. Will work but it's nice to have the validation in the configuration file.
Expose the collection count as a property. This could be done, assuming an employee collection for example, with an EmployeeCount property on your object that contains the collection or you could create your own custom collections that expose a count property. Then you could use a Range Validator to validate on the Count property.
Create a custom validator that can validate the number of items in a collection -- something like CollectionCountRangeValidator.
If I wanted to develop something quickly, I would probably go with option 3. However, option 4 fits in well with the Enterprise Library approach and also allows your class design to be independent of the validation requirements. Plus you could always reuse it on your next project. :) And does anyone really miss creating their own collections when a List will do nicely?
This is already implemented in the EntLib Contrib.
This is called CollectionCountValidator.

Resources