How to find out the Joomla components base table name - joomla

I want to know in which table a joomla component stores its data and I want to achieve this programmatically. (I already know through phpmyadmin the relevant tables a component stores data in.) For eg. if I know that the base component is com_content then how can the Joomla 3.1 platform a.p.i tell me that it stores its data in #__content table.

The content types table provides information on this if your component has stored rows there. Using this you can programmatically get both the db table as well as the JTable data. In 3.2. there are a couple of places where this is used nicely such as in the ordering field and in versioning.

Related

Store Umbraco Member Properties in Separate Table

I want to create a membership based site in Umbraco 7, following the umbraco.tv videos and reading through the docs have got me quite far.
My members will have custom properties, firstname, lastname, favourite colours, hats owned etc. I have been adding each of these as custom properties and then assigning them to the tab I want. This works fine and I can then access them from code using:
Members.GetCurrentMember().GetProperty("lastname").Value.ToString();
When I looked in my database I noticed that each of these custom properties is a row in the cmsPropertyData table, linked to the cmsMember table by the nodeId column. Is there a way I can set all of this information to store in it's own table?
Ideally, I want each Member to have a one to many relationship with favourite colours, as well as one to many relationships with other tables; each member might have 100 hats for example. What is the best way for me to set this up? Shall I create custom tables in my Umbraco database for HatsOwned and FavouriteColours, then assign each Member a unique ID so I can set my foreign keys up correctly? That way I would only need to store the Members Unique Id in the cmsPropertyTable. Is there a better way to let Umbraco deal with it? Would I have difficulty retrieving Members using either the Umbraco orm, or EF?
Any help or pointers greatly appreciated!
I would store all data in the PROFILE of the member, in the umbraco membership. E.g. timezone, hair color, ... This makes sense for other developers to find back the data.
For all other data, you have a few options:
Relationships
If you want to link nodes to members, or nodes to nodes, or... Relations link 2 umbraco entities and can be one way or two way. If you have a color node, you can link all members to this node. Just create a "favoriteColor" relationship on the developer section, linking up nodes to members. Do some programming and you are done. Don't forget that a relation is a database record linking 2 umbraco entities. So think of some caching if you use this in your front end to take off some database load. Read more on the Relationship Api in the umbraco documentation.
Content
It's pretty easy to create new nodes using code to store e.g. comments on an article. Because you are republishing the xml cache every time you create (and publish) a node, don't use content nodes for stroring your data if you have a lot of updates.
External data
It is perfectly legit to store data outside of umbraco. Just create your own tables (or content to any service you created). You could use every ORM you want to, but I would recommend PetaPoco. The reason is obvious. Umbraco uses it also. And it will make you a better Umbraco developer. There is a detailed post on stackoverflow on how to work with external data in umbraco.

Store translated versions in database for Joomla component

I'm currently developing my first MVC component for Joomla 3.x. All in all I'm bit struggling with language/translation issues in database.
My problem is that I need to store translated content of user generated content which comes from the backend. For example someone enters a new item in German (stored in database) and needs a translation in another language. How to accomplish that in Joomla? I don't like to generate a new item for every different language when the rest is all the same.
I thought about a table "item" and a table "item_language" with that structure (strongly simplified for viewing purposes):
item
id PRIMARY INT
price DOUBLE(4,2)
item_language
itemid PRIMARY INT
language PRIMARY CHAR(5)
name VARCHAR(50)
In item_language I would like to store the different translated versions. In the language field there would be the region code (eg. de-DE) to identify the language.
My problems:
How to display the different (translated) versions in backend?
Is this the right database model?
Any help is appreciated!
You have really found yourself a nice task for a first component in Joomla!
A rather generalist answer:
The database model seems right. Alternatively you could encode in JSON the language data, but this could make later query operations potentially difficult. This way you will only have one table to work with.
As far as I know (if you are using JModel / JTable to manipulate the data) can't do this directly, as JTable is really only designed to manipulate single tables.
What you can do:
For editing: figure a way to represent this graphically ( for your users to see and edit this one to many relationship) and to post this data (language texts as an array) to JModel. In the model you can maintain the desired relationships and save the data using JTable.
Viewing (without editing) shouldn't be an issue, it would be a simple JOIN.
If you are willing to create a basic component on github, I might even give you a hand with JModel / JTable.
I found a way to deal with the things I needed.
Thanks Valentin Despa for guiding me in the right direction :-).
Here the whole procedure (simplified - validations and exact steps omitted):
Define the form fields in the models/forms/site.xml as normal.
In views/site/tmpl/edit.php add self coded Javascript (based on jQuery) to deal with the fields which have content in multiple languages stored as JSON in database.
Clone the original form element and modify the needed attributes (id, name, ...) to display a special version just for the defined languages. As content - extract the JSON for the needed language from original field content and display.
Hide the original field with Javascript and append the customized versions to DOM.
Afterwards in tables/site.php I read the dynamically generated content withJInput and build together the original field by generating JSON and saving to database.
It's working like expected.

Is it upgrade safe to add custom address attributes

currently i am developing a Magento extension, that needs to add several custom attributes to customer address.
I've found several tutorials on the topic that describe precisely what i need to build
http://www.unexpectedit.com/magento/add-new-customer-attribute-onepage-magento-checkout
http://www.excellencemagentoblog.com/magento-adding-custom-field-to-customer-address
They all use ALTER TABLE to add columns to several db tables.My question is :
Is it upgrade safe to do this?
Thanks in advance
They're using the magento framework method addAttribute() not pure SQL queries. They're using it in an upgrade script and it's its purpose : to upgrade safely a database..
Note that the EAV mechanims of the customer entity is built in order to not alter the table definition but add data in it. So in the background customer::addAttribute doesn't do a single ALTER TABLE. On the contrary, the now flated-tables sales_flat_order/quote addAttribute method does alter the tables cause it's no more an EAV entity.
They're doing it right.
I don't really understand your question.

Import url rewrites to magento

I often get to the point in building a new Magento site where 301 rewrites need creating for all the items on the old site. Is there a way of importing them directly?
Programmatically via a urlCreate() type Magento function would be fine as then I could just cycle through a csv.
Generally it's a good idea to stick with Magento's ORM for interacting with entity data, as there may be both business logic and storage logic which is baked into the entity ORM stack (this is notoriously true for EAV entities). But, depending on the number of records to be entered, a direct-to-db approach should be fine, especially if it's a one-off import. This is because URL rewrites are flat entities stored in the core_url_rewrite table (link), and the table itself has the necessary storage logic as part of its structure (mainly, unique request_path + store_id and an FK for core_store table). In other words, manipulating this data outside of the ORM tier is okay because the logic is part of the table definition itself.
Beyond this information, it's possible to load up a core/url_rewrite collection, create core/url_rewrite instances from the CSV and add them, and then call save() on the collection, but note that each item is saved individually. It might do to refer to the convert adapters for catalog entities and for customers, which is how dataflow works.

how to join arbitrary view in tableMethod

I have a doctrine data model with a table Person, however my Symfony application is only part of a bigger web application, which is build in Joomla. For a module, I need to add a number of fields from a view, which spans 8 tables with the person table. The view is already established for the Joomla part of things.
Short of creating a schema for all the tables involved, is there a way to arbitrarily join the view in my tableMethod? As another shortcut I am thinking of creating a minimal schema.yml table to just represent the field of the view that I need.
another solution would be to use native sql with doctrine

Resources