Contao DCA - How to set default value on multiple checkboxes - configuration

Let's say we have a dca array like this:
$GLOBALS['TL_DCA']['tl_member']['fields']['publicFields'] = array
(
...
'inputType' => 'checkbox',
'options' => array('value1' => "label1", 'value2' => "label2");,
'eval' => array('multiple'=>true, ...
);
Now we want to set the checkbox with value1 to checked by default.
I tried this but it does NOT work:
$GLOBALS['TL_DCA']['tl_member']['fields']['publicFields']['default'][0] = 'value1';
I found a description on https://de.contaowiki.org/Defaultwerte_vorbelegen. but it's for single value fields only not for multiple.

Use an array with your needed fieldnames for the declaration, e.g.:
$GLOBALS['TL_DCA']['tl_member']['fields']['publicFields']['default'] = array('firstname', 'lastname', 'dateOfBirth', 'street', 'postal', 'city', 'phone', 'mobile', 'email', 'website');

Related

Can't Insert an array in table column, Laravel

I need to insert an array in a table column with other non array inputs, But each time it's inserting a string "Array" ,
My codes are :
$post_data['product_category'] = "Goods";
$post_data['product_profile'] = "physical-goods";
for ($i = 1; $i < count($request->package_type_id); $i++) {
$answers[] = [
$post_data['package_type_id'] =$request->package_type_id,
];
}
$update_product = DB::table('orders')
->where('transaction_id', $post_data['tran_id'])
->updateOrInsert([
'name' => $post_data['cus_name'],
'email' => $post_data['cus_email'],
'phone' => $post_data['cus_phone'],
'amount' => $post_data['total_amount'],
'status' => 'Pending',
'address' => $post_data['cus_add1'],
'transaction_id' => $post_data['tran_id'],
'currency' => $post_data['currency'],
'package_type_id' => implode($answers,',')
]);
You have gone a long way, I think you just want to make a string from the $request->package_type_id which I assume is an array.
$post_data['product_category'] = "Goods";
$post_data['product_profile'] = "physical-goods";
$post_data['package_type_id'] = implode(',', $request->package_type_id);
$update_product = DB::table('orders')
->where('transaction_id', $post_data['tran_id'])
->updateOrInsert([
// ...
'package_type_id' => $post_data['package_type_id']
]);
Also note that the syntax for implode is implode(glue, array) not the other way around.

Group By array value from text field using mysql

I have a table 'my_data'
Table structure
and field 'input' as type text. And I stored array value in that field as follow
array (
'msisdn' => '99999999999',
'keyword' => '',
'serviceid' => '0011001100',
'productid' => '111000111',
**'mode' => '02',**
'cli' => '0000',
'txnid' => '000000403401806110710441878004',
'startdate' => '2018-06-06 14:51:45',
'enddate' => '2018-06-12 00:00:00',
'type' => 'subscription',
'renewalon' => '2018-06-12 00:00:00',
'lastrenewalon' => '2018-06-11 13:06:52',
'fee' => 2.44,
'status' => '0',
'linkid' => '',
)
Now, how can I get the values group by 'mode' from the array value using mysql
You can chain two SUBSTRING_INDEX functions to first get the substring after 'mode', and then get the substring before ,'cli':
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(a, "'mode'", -1), ",'cli'", 1) AS group_condition
Insert the field text in the place of a.
Then you can use group_condition in the GROUP BY clause.

cakephp query find_in_set on single column with multiple searched keywords not working

I want to find all the records from column who have any keyword match with column data:
It works fine if searching single search keyword in column having comma separated values like below code: Cakephp 3.4 version
$posts = TableRegistry::get('Posts');
$search_keywords = array_filter(explode(' ', $search_string));
$option = [
'contain' => false,
'conditions' => [
"find_in_set('New', Posts.title)",
],
'order' => ['Posts.created DESC']
];
$allpost = $posts->find('all',$option)->toArray();
Note: i want all the words from string should be search with column title, its not mandatory to have comma separated records:
$search_keyword = "New car in new delhi";
so i want code to be like below :
$search_keyword = "New car in new delhi";
$search_keywords = array_filter(explode(' ', $search_string));
$option = [
'contain' => false,
'conditions' => [
"find_in_set({$search_keywords}, `Posts`.title)",
],
'order' => ['Posts.created DESC']
];
$allpost = $posts->find('all',$option)->toArray();
Great Thanks in advance!!!
I found the solution:
First make column fulltext index then add below code:
$search_string = "New car in new delhi";
$option = [
'contain' => false,
'conditions' => [
"MATCH (title) AGAINST ('$search_string')"
],
'order' => ['Posts.created DESC']
];
$allpost = $posts->find('all',$option)->toArray();

Get multiple array in Codeigniter and insert to database

I have multiple array to insert into database but i don't fix the field name because can select format table data and insert into database but can check field name with $id_template.
This my format table(example)
So i want to know how can i get data from multiple array to insert into database
This my code in controller
$column = $this->m_rate_template->get_column($id_template);
$colum_detail = implode(",", $column);
$column_cut = explode(",", $colum_detail); //example data get format is Array ( [0] => min [1] => max)
foreach ($column_cut as $key => $val){
$a = $this->input->post($column_cut[$key]);
foreach ($a as $key1 => $val1){
echo $val1;
$child_data = array(
'id' => $this->m_rate_template->generate_id_in_template($template_name),
'id_rate' => $id_rate,
$column_cut[$key] => $val1
);
$this->m_rate_template->insert_rate($child_data, $template_name);
}
}
My data it show like this
Array ( [id] => 4ae665037e [id_rate] => 7f881e02bb [min] => 1 )
Array ( [id] => bc3e60157f [id_rate] => 7f881e02bb [min] => 2 )
Array ( [id] => 082de3ad82 [id_rate] => 7f881e02bb [max] => 1 )
Array ( [id] => ee135ecd8a [id_rate] => 7f881e02bb [max] => 2 )
actually, data should be like this
Array ( [id] => 4ae665037e [id_rate] => 7f881e02bb [min] => 1 [max] => 2)
Array ( [id] => 082de3ad82 [id_rate] => 7f881e02bb [max] => 1 [max] => 2)
Update
$array = array(
[0] => array(
'min' => '2500',
'max' => '5000'
),
[1] => array(
'min' => '5001',
'max' => '7000'
)
)
You can use batch insert to insert multiple
$this->db->insert_batch();
first parameter is table name and second is array of arrays(records)
if you have want to insert multiple record in table then you can also use codeigniter inbuilt insert_batch function without make query in loop.
so i thing your execution will be fast.
you have want to array in below format.
$array = array(
[0] => array(
'column 1' => 'value 1',
'column 2' => 'value 1'
),
[1] => array(
'column 1' => 'value 2',
'column 2' => 'value 2'
)
)
$this->db->insert_batch('tbl_name',$array)
so please make your code and generate your array as above in loop and simply pass your array in insert_batch function.

elastic search: Advanced Filter Query

I am Working on Elastic Search for My current Project. I need a filter for users based on their industries. please look at my code once. and mySql query as follows
SELECT U.* FROM `users` `U`
JOIN `user_industries` `UI` ON `UI`.`user_id`=`U`.`id`
WHERE `UI`.`industry_id` IN('1','3','5');
$query = array("from" => $start,
"size" => $recordslimit,
"sort" => array(array('id' => 'desc')),
"query" => array(
"filtered" => array(
"query" => array("match_all" => array()),
"filter" => array(
"bool" => array(
'must' => array(array('term' => array('user_type' => 'v')),
array('term' => array('status' => 'a')),
array('term' => array('industries.id' => 1))
),
'must_not' => array(
array('term' => array('subscription_type' => 'n'))
)
))
)));
I passed one Industry Value. how can i pass multiple values of industries
Great start !! You can achieve what you want by using a terms filter instead of a term one and specifying the values 1, 3, 5 in an array():
...
array('terms' => array('industries.id' => array(1, 3, 5)))
...