TYPO3, select from localized table - localization

I just created a localized table. When adding translations they go into the table with a new uid. I have checked with other localized extension, so this seems to be right.
Example: Localized entries in a table gives not just translations but also extra entries in the table with new uid
Tysk (uid 1, Danish and default language)
-- German (uid 7, English translation of "Tysk")
-- Deutch (uid 13, German translation of "Tysk")
Now I have a concern:
When tre persons from Denmark, England and Germany all sign up for something in German, they will sign up for uid 1, uid 7 and uid 13... I would prefer if they all signed up for the default language.
Else it will be difficult to generate a list of users that signed up for a language if each language will exist with own uid for each translation.
What have I missed? Som exec_select_localized function?

You are 100% correct that every translation is a new record (= new uid) in the same table. So you have done everything right.
For the frontend you can use
$GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_mytable', array('uid' => 1));
with the original record (with the result of a record in exec_SELECTquery()),
or in the TYPO3 Backend look at
BackendUtility::getRecordLocalization('tx_mytable', 4)
to get the localized record.

Related

How can I write a Rails query to find phone number which are all saved with various formats

I'm using Rails 5.2.0
I am trying to write a query to find a phone number based off user input. However, the format of phone numbers saved in the database varies (e.g. (123)-456-7890, +1(123)-456-7890, +1 123456789, and so on). Is there any way I can format the records saved in my database in this query? I've thought of adding a second column to the table that would simply be formatted_telephone, but I have tens of thousands of records. Can I add a method in the User controller to update these records when they are fetched?
Here is what I have so far:
User.where("REGEXP_REPLACE(telephone, '[^[:digit:]]', '') ~* ?", "%#{input}%")
Right now this is still only returning phone numbers with this format: 1234567890.
Am I on the right track with this? Or is it not possible to format columns when querying?
Normally with a where clause and a regexp we are asking something like "find me everything that matches this regexp" but you are asking the DB for a phone number that matches "12035551212" and want the where clause to apply a regexp to every single phone number in the table while searching to match it. I guess you try something like (this can be streamlined but I'm breaking it down to make it easier to follow):
my_phone = '12035551212'
phone_arr = my_phone.split('')
#=> ["1", "2", "0", "3", "5", "5", "5", "1", "2", "1", "2"]
regx = '^\D?' + phone_arr[0] + '?' + '\D*' + phone_arr[1..-1].join('\D*') + '$'
#=> '^\D?1?\D*2\D*0\D*3\D*5\D*5\D*5\D*1\D*2\D*1\D*2$'
now you have a regexp that matches only your phone number regardless of format. So now you can try:
User.where('phone_number ~* ?', regx)
this should ask Postgres to match your very specific regexp based on the phone number you are searching for. This should get you what you need. But I would look at refactoring it.
In the long run I would standardize all numbers in the DB. You could add a phone_number_e164 column to Users and convert every one to the E164 format using a regexp. Then remove the old phone number column and rename the new one to phone_number. You would also need to add code to standardize any new numbers coming into the DB.
As a stop-gap measure you could also create a Postgres view that grabs the User records and applies regexp to the phone number to transform it to E164 format, and access that view instead of the User table.

Searching for matching records in a field saved as a hash in PostgreSQL?

I have an active record SearchSuggestion that has a title:text field for storing values for different languages in a single hash that looks like so:
#<SearchSuggestion :id 1, link: "/search/shoes", title: {"en"=>"Women's shoes", "ko"=>"여성 신발", "ru"=>"Женская Обувь", "fr"=>"Chaussures De Femme"}>
and I'm fetching records that match the given input in the following way: all of the given words contained in all records' title fields, starting only from the start of each word the following way:
query = params[:q].split(" ").map{|s| s.prepend('(?:.*\m')}.map{|s| s.concat(')')}.join('')
SearchSuggestion.where("title ~* ?", query).limit(10).pluck(:title)
The problem is that this gives me matches from the whole field, and I want just the ones for the current selected language. So if I have languages that are using the same alphabet - I get unrelated results e.g - if I start typing "cha" this will return "Women's shoes" by finding the French suggestion as a match. Also if I type "en" - I get all of the existing records as a result, because they match the key for "en" language.
Is there any way I can specify the hash's key that I only want to search within?

Summary of Results Based on Members of File

I am not quite sure how to word this so I've also included some poorly formatted example :) Basically I have a report exported from Cognos. The report contains a list of cases and the people that are associated to those cases, along with additional information about their First Language and Religion (as an example). What I would like to do is create a summary and/or chart of the results based on the unique case.
Any ideas? Example data below:
Case Reference - Name - First Language - Religion
1234 - Name1 - English - Catholic
1234 - Name2 - French - Protestant
4321 - Name3 - Tamil - Unknown
3345 - Name4 - English - Hindu
So for a summary I'd like to see that for languages there is 1 for Tamil and 1 for French (English would be the default if no other languages are present - so for file 1234 it would have been English if there was no French speaking person). For religions I'd like to be able to see that out of the 3 files, 1 is unknown, 1 is Hindu and also that the 3rd file is actually 2 religions (Catholic and Protestant).
I am not sure if any of this is making sense but hopefully one of you can shed some light on a possible solution. I'd like to template it out so that on line one of the case it would have an x under each heading, but do it automatically instead of manually. Basically, for each unique case are there any members that are French, any that are Tamil, any that are Catholic, any that are Christian, etc...
Thanks!
I hope I'm following correctly. It seems you want to show for each language, how many cases they are associated with and for every case, how many religions are associated with it.
For language, add a column to your report's query called Language Count with the following expression:
count(distinct [Case Reference] for [First Language])
This will count the number of unique cases for each language.
For religions, add a column to your report's query called Religion Count with the following expression:
count(distinct [Religion] for [Case Reference])
This will count the number of unique religions for each case.

How to sort a list of 1million records by the first letter of the title

I have a table with 1 million+ records that contain names. I would like to be able to sort the list by the first letter in the name.
.. ABCDEFGHIJKLMNOPQRSTUVWXYZ
What is the most efficient way to setup the db table to allow for searching by the first character in the table.name field?
The best idea right now is to add an extra field which stores the first character of the name as an observer, index that field and then sort by that field. Problem is it's no longer necessarily alphabetical.
Any suggestions?
You said in a comment:
so lets ignore the first letter part. How can I all records that start with A? All A's no B...z ? Thanks – AnApprentice Feb 21 at 15:30
I issume you meant How can I RETURN all records...
This is the answer:
select * from t
where substr(name, 1, 1) = 'A'
I agree with the questions above as to why you would want to do this -- a regular index on the whole field is functionally equivalent. PostgreSQL (with some new ones in v. 9) has some rather powerful indexing capabilities for special cases which you might want to read about here http://www.postgresql.org/docs/9.1/interactive/sql-createindex.html

Translates Models(table names, column names) with gettext in rails

How may i translate model name and column name with gettext in rails ?
Gettext has provided rake task gettext:store_model_attributes. This rake task will create model_attribute.rb file in locale folder.
Example of model_attribute.rb. In your case result will be different.
_('sales rep phone')
_('SalesRepPhone|Sales rep id')
_('SalesRepPhone|Phone type id')
_('SalesRepPhone|Phone no')
_('SalesRepPhone|Compact phone no')
_('SalesRepPhone|Lock version')
Here sales rep phone is model. And Sales rep id, Phone type id are my fields of sales rep phone.
Now run rake task(makepot).It will create msgid for all the rows of model_attribute.rb in app.po.
After modified po file with proper translation.
Run the gettext:pack to create new mo files.
Now you will get all the column and model names translated.

Resources