I'm trying to turn a huge configuration array in PHP, that looks like this
$config['festival'] =
array
(
'title' => 'USF Tango Festival',
'tableLayout' => array
(
'registration' => array
(
array('firstName','text'),
array('lastName','text'),
array('phone','text'),
array('email','text'),
array('hearAboutFestival','text'),
array('danceAs','enum(\'Leader\', \'Follower\', \'Both\')'),
array('student','tinyint(1)')
),
'experience' => array
(
array('options','text'),
array('lunchMeat','enum(\'Ham\',\'Turkey\',\'Vegetarian\')'),
array('lunchBread','enum(\'White\',\'Wheat\')'),
array('dinnerPref','enum(\'Chicken\',\'Beef\',\'Vegetarian\')')
)
),
'pageLayout' => array
(
'registration' => array
(
'jqueryRules' =>
<<<EOT
'firstName': 'required',
'lastName': 'required',
'phone': {
required: true,
phoneUS: true
},
'email': {
required: true,
email: true
},
'danceAs': 'required',
'partner': 'required',
'partnerMatching': {
required: function() {
return $("input[name='partner']").val() == 0;
}
},
'partnerName': {
required: function() {
return $("input[name='partner']").val() == 1;
}
}
EOT
,
'inputs' => array
(
array
(
'type' => 'text',
'name' => 'firstName',
'fullName' => 'First Name',
'required' => true,
'separateDiv' => false
),
array
(
'type' => 'text',
'name' => 'lastName',
'fullName' => 'Last Name',
'required' => true,
'separateDiv' => false
),
array
(
'type' => 'text',
'name' => 'phone',
'fullName' => 'Phone number',
'required' => true,
'separateDiv' => false
),
array
(
'type' => 'text',
'name' => 'email',
'fullName' => 'Email address',
'required' => true,
'separateDiv' => false
),
array
(
'type' => 'text',
'name' => 'hearAboutFestival',
'separateDiv' => false,
'fullName' => 'How did you hear about the festival?',
'required' => false
),
array
(
'type' => 'select',
'name' => 'danceAs',
'fullName' => 'You dance as a...',
'required' => true,
'separateDiv' => false,
'options' => array(array('leader','Leader'),array('follower','Follower'),array('both','Both'))
),
array
(
'type' => 'checkbox',
'name' => 'student',
'value' => '1',
'separateDiv' => false,
'fullName' => 'I am a student',
'required' => false
)
)
)
and
'options' => array
(
'busMilonga' => array
(
'price' => 20,
'student' => false,
'name' => 'Tango on the Town Bus milonga',
'description' => 'A bus milonga!'
),
'thursdayMilonga' => array
(
'price' => 10,
'student' => false,
'name' => 'Thursday Kickoff Milonga',
'description' => 'The un-official kick off milonga!'
),
'saturdayPass' => array
(
'price' => 90,
'student' => true,
'name' => 'Saturday pass',
'description' => 'Includes all Saturday workshops and milongas'
),
'sundayPass' => array
(
'price' => 80,
'student' => true,
'name' => 'Sunday pass',
'description' => 'Includes all Sunday workshops, the jam session, and milonga'
),
'milongaPass' => array
(
'price' => 70,
'earlyBird' => 50, //array(50,60),
'student' => true,
'name' => 'Milonga Pass',
'description' => 'Includes entrance to all night milongas'
),
'dinnerPass' => array
(
'price' => 20,
'student' => false,
'name' => 'Dinner pass',
'description' => 'Includes Saturday dinner'
),
'lunchPass' => array
(
'price' => 10,
'student' => false,
'name' => 'Saturday lunch',
'description' => 'Includes lunch on Saturday'
)
),
'info' => array
(
'instructors' => array('Instructors'),
'hour' => array('10','11','12','01','02','03'),
'min' => array('15','30','45','00'),
'tod' => array('AM','PM'),
'day' => array('Friday','Saturday','Sunday'),
'level' => array('Beginner','Intermediate','Advanced'),
'place' => array('REC 107','REC 033','REC 005'),
'sessions' => array
(
3, // days
array
(
'Friday', // day name
3, // sessions on this day
array
(
3, // workshops in session
'1100AM' // time
),
array
(
3,
'0100PM'
),
array
(
1,
'0230PM'
) // 1,4
),
array('Saturday', // 2,0
3, // 2,1
array(1,'1030AM'), //2,2
array(3,'1145AM'), // 2,3
array(3,'0145PM') // 2,4
),
array
(
'Sunday', // 3,0
3, // 3,1
array(1,'1115AM'), // 3,2
array(3,'1230PM'), // 3,3
array(3,'0230PM') // 3,4
)
)
)
into a database. I'm thinking I could make a few tables, titled something like config.event.festival but then it would get cumbersome since I would have to create a table for each array under the array...
I want to avoid using JSON encoding or serializing, so that I keep the data all relational and clean looking but I don't know any other way other than just keeping one big configuration file rather than a database.
Assuming the sample you provided represents a truncated view of your whole data structure, this could be done with three tables.
festival
festival_id
title
layout
layout_id
festival_id
layout_type_id
type
name
fullName
required
separateDiv
layout_type
layout_type_id
name
The festival table would keep your high-level meta data about the event page. The layout table would contain meta data about each of the elements on the page. And finally, the layout_type table would allow you to identify different element types that should be on a given page.
This should get you started and allow you to modify as necessary.
Try this:
// To save multidimensional array into database:
$confIn = serialize($config);
// Save serialized config into database
// To get it from database, query the database and get serialized value
$confOut = serialize($confIn);
// Check if its ok
var_export($confOut);
More about serialize function: Serialize
The good thing with this approach is you can use only one column in database.
Hope this helps!
Related
I get passed an array in a callback function. Now I want access a value of this array.
I can dump this array into a file with var_export($fields[1], True)
Here is the content of the export:
helper_plugin_bureaucracy_fieldtextbox::__set_state(array(
'mandatory_args' => 2,
'opt' =>
array (
'cmd' => 'textbox',
'label' => 'Kunde',
'display' => 'Kunde',
'value' => 'myimportantdata',
),
'tpl' =>
array (
'_elem' => 'textfield',
'_text' => '##DISPLAY##',
'_class' => '##CLASS##',
'id' => '##ID##',
'name' => '##NAME##',
'value' => '##VALUE##',
'class' => 'edit required',
'required' => 'required',
),
'checks' =>
array (
),
'hidden' => false,
'error' => false,
'checktypes' =>
array (
'/' => 'match',
'<' => 'max',
'>' => 'min',
),
))
I want to access the value of opt->value whitch is 'myimportantdata' in this case.
How can I achieve this?
I already tried:
$mydata = $fields[1]['helper_plugin_bureaucracy_fieldtextbox']['opt'];
$mydata = $fields[1][0][2];
$mydata = $fields[1]->helper_plugin_bureaucracy_fieldtextbox['opt'];
without success :-(
fields[1] contains an object of the type 'helper_plugin_bureaucracy_fieldtextbox'. The access to the properties of the object such as 'opt' must be done with the -> operator.
$opt = $fields[1]->opt;
$opt_value = $fields[1]->opt['value']; //myimportantdata
$data = array(
'mandatory_args' => 2,
'opt' =>
array (
'cmd' => 'textbox',
'label' => 'Kunde',
'display' => 'Kunde',
'value' => 'myimportantdata',
),
'tpl' =>
array (
'_elem' => 'textfield',
'_text' => '##DISPLAY##',
'_class' => '##CLASS##',
'id' => '##ID##',
'name' => '##NAME##',
'value' => '##VALUE##',
'class' => 'edit required',
'required' => 'required',
),
'checks' =>
array (
),
'hidden' => false,
'error' => false,
'checktypes' =>
array (
'/' => 'match',
'<' => 'max',
'>' => 'min',
),
);
echo $data["opt"]["value"];
I have a simple form with 2 fields and I want to read the data from it and use it with $_POST.
This is the output when I debug the $_POST function:
file_put_contents( 'debug' . time() . '.log', var_export( $_POST, true));
OUTPUT:
array (
'form' =>
array (
'id' => '36e3113',
'name' => 'New Form',
),
'fields' =>
array (
0 =>
array (
'id' => '0',
'type' => 'text',
'title' => 'Your name',
'value' => 'John',
'raw_value' => 'John',
'required' => '1',
),
1 =>
array (
'id' => '1',
'type' => 'tel',
'title' => 'Phone number',
'value' => '12345',
'raw_value' => '12345',
'required' => '1',
),
),
)
I want to use $POST to only assign values of Your name to $name and Phone number to $number variable.
You can get it like.
$name = $_POST['fields'][0]['value'];
$number = $_POST['fields'][1]['value'];
Hopping some of you can help me with this, since a few days back I'm trying to get a list like a carousel, displayed in my FaceBook bot using the following code:
public function returnCarousel(){
$messagearray = array (
'message' =>
array (
'attachment' =>
array (
'type' => 'list',
'payload' =>
array (
'template_type' => 'list',
'top_element_style' => 'compact',
'elements' =>
array (
0 =>
array (
'title' => 'Classic T-Shirt Collection',
'subtitle' => 'See all our colors',
'image_url' => 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
'buttons' =>
array (
0 =>
array (
'title' => 'View',
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/collection',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
),
),
1 =>
array (
'title' => 'Classic White T-Shirt',
'subtitle' => 'See all our colors',
'default_action' =>
array (
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/view?item=100',
'messenger_extensions' => false,
'webview_height_ratio' => 'tall',
),
),
2 =>
array (
'title' => 'Classic Blue T-Shirt',
'image_url' => 'https://peterssendreceiveapp.ngrok.io/img/blue-t-shirt.png',
'subtitle' => '100% Cotton, 200% Comfortable',
'default_action' =>
array (
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/view?item=101',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
'buttons' =>
array (
0 =>
array (
'title' => 'Shop Now',
'type' => 'web_url',
'url' => 'https://peterssendreceiveapp.ngrok.io/shop?item=101',
'messenger_extensions' => true,
'webview_height_ratio' => 'tall',
'fallback_url' => 'https://peterssendreceiveapp.ngrok.io/',
),
),
),
),
'buttons' =>
array (
0 =>
array (
'title' => 'View More',
'type' => 'postback',
'payload' => 'payload',
),
),
),
),
),
);
$this->sendMessage($messagearray);
}
public function sendMessage($parameters) {
echo json_encode($parameters);
}
No carousel is displayed and no error is returnes intead I get in my ngrok console this:
{"message":{"attachment":{"type":"list","payload":{"template_type":"list","top_element_style":"compact","elements":[{"title":"Classic T-Shirt Collection","subtitle":"See all our colors","image_url":"https://peterssendreceiveapp.ngrok.io/img/collection.png","buttons":[{"title":"View","type":"web_url","url":"https://peterssendreceiveapp.ngrok.io/collection","messenger_extensions":true,"webview_height_ratio":"tall","fallback_url":"https://peterssendreceiveapp.ngrok.io/"}]},{"title":"Classic White T-Shirt","subtitle":"See all our colors","default_action":{"type":"web_url","url":"https://peterssendreceiveapp.ngrok.io/view?item=100","messenger_extensions":false,"webview_height_ratio":"tall"}},{"title":"Classic Blue T-Shirt","image_url":"https://peterssendreceiveapp.ngrok.io/img/blue-t-shirt.png","subtitle":"100% Cotton, 200% Comfortable","default_action":{"type":"web_url","url":"https://peterssendreceiveapp.ngrok.io/view?item=101","messenger_extensions":true,"webview_height_ratio":"tall","fallback_url":"https://peterssendreceiveapp.ngrok.io/"},"buttons":[{"title":"Shop Now","type":"web_url","url":"https://peterssendreceiveapp.ngrok.io/shop?item=101","messenger_extensions":true,"webview_height_ratio":"tall","fallback_url":"https://peterssendreceiveapp.ngrok.io/"}]}],"buttons":[{"title":"View More","type":"postback","payload":"payload"}]}}}}
if I send a single card it works, please your help
SOLVED: I formatted the array like this and I get it working.
$messagearray = array (
'speech' => 'Carousel',
'messages' => array (
0 => array (
'type' => 1,
'platform' => 'facebook',
'title' => 'Rosa Amarilla',
'imageUrl' => 'http://rosa.com/assets/imgs/rosaamarilla.jpg',
'buttons' =>
array (
0 =>array ('text' => 'Detalles de la Rosa', 'postback' => '',),
),
),
1 =>array (
'type' => 1,
'platform' => 'facebook',
'title' => 'Rosa Azul',
'imageUrl' => 'http://rosa.com/assets/imgs/rosaazul.jpg',
'buttons' =>
array (
0 => array ('text' => 'Detalles de la Rosa', 'postback' => '',),
),
),
),);
I am trying to retrieve data from "Opportunities" Reports.
This is my scenario: Opportunity module, field sales_person is a realated field from users module.
In Bids modules I have a relate field with opportunities.
During report generation, I am trying to retrieve the sales_person name in opportunities. But it is not listing in Bids report field_lists.
My dictionary in Bids
'opportunity_id_c' => array(
'required' => false,
'name' => 'opportunity_id_c',
'vname' => 'LBL_OPPORTUNITY_OPPORTUNITY_ID',
'type' => 'id',
'reportable' => true,
'calculated' => false,
'len' => 36,
'size' => '20',
),
'opportunity' => array(
'required' => false,
'source' => 'non-db',
'name' => 'opportunity',
'vname' => 'LBL_OPPORTUNITY',
'type' => 'relate',
'reportable' => true,
'unified_search' => false,
'merge_filter' => 'disabled',
'len' => '255',
'size' => '20',
'id_name' => 'opportunity_id_c',
'ext2' => 'Opportunities',
'module' => 'Opportunities',
'rname' => 'name',
'quicksearch' => 'enabled',
'studio' => 'visible',
),
Relationship:
$dictionary['Opportunity']['fields']['opportunities_procurements'] = [
'name' => 'opportunities_procurements',
'type' => 'link',
'relationship' => 'opportunities_procurements',
'module' => 'Procurement',
'bean_name' => 'Procurement',
'source' => 'non-db',
'vname' => '',
];
$dictionary['Opportunity']['relationships']['opportunities_procurements'] = [
'lhs_module' => 'Opportunities',
'lhs_table' => 'opportunities',
'lhs_key' => 'id',
'rhs_module' => 'Procurement',
'rhs_table' => 'procurement',
'rhs_key' => 'opportunity_id_c',
'relationship_type' => 'one-to-many',
];
This is what I tried: I tried to create a similar field opportunity in bids module named as opportunity_sales_userand in dictionary instead of 'rname' => 'name', I use 'rname' => 'sales_person', but I didn't get the data as the sales_person is related record.
I couldn't retrieve the vales in Reports.
How can I create a full relationship so I can get the sales_person value in Bids reports generation?
I am facing same problem so , i choose to write a simple SQL query
global $db;
$query = "Your Sql to get Reports";
$re = $db->query($query);
$data = '';
while ($row = $db->fetchByAssoc($re)) {
your code
}
How can i create one-to-many relationship with my custom module. And add subpanel to Campaign module
Campaign vardefs
$dictionary["Campaign"]["fields"]["costs"] =
array (
'name' => 'costs',
'type' => 'link',
'relationship' => 'campaign_costs',
'module'=>'Costs',
'bean_name'=>'Costs',
'source'=>'non-db',
'vname'=>'LBL_AUCTIONS',
);
$dictionary['Campaign']['relationships']['campaign_costs'] =
array (
'lhs_module'=> 'Campaigns',
'lhs_table'=> 'campaigns',
'lhs_key' => 'id',
'rhs_module'=> 'Costs',
'rhs_table'=> 'cots',
'rhs_key' => 'campaign_id',
'relationship_type'=>'one-to-many'
);
layout_defs properties
$layout_defs["Campaigns"]["subpanel_setup"]["campaign_costs"] = array (
'order' => 2,
'module' => 'Costs',
'subpanel_name' => 'default',
'sort_order' => 'desc',
'sort_by' => 'date_entered',
'title_key' => 'LBL_SUBPANEL_COSTS',
'get_subpanel_data' => 'costs', //имя поля link
'top_buttons' =>
array (
0 =>
array (
'widget_class' => 'SubPanelTopButtonQuickCreate',
),
1 =>
array (
'widget_class' => 'SubPanelTopSelectButton',
'mode' => 'MultiSelect',
),
),
);
Custom module vardefs
$dictionary['Costs']['fields']['campaign_id'] =
array (
'required' => false,
'name' => 'campaign_id',
'vname' => '',
'type' => 'id',
'massupdate' => 0,
'importable' => 'true',
'audited' => 0,
'len' => 36,
);
$dictionary['Costs']['fields']['campaign_name'] =
array (
'required' => false,
'source' => 'non-db',
'name' => 'campaign_name',
'vname' => 'LBL_CAMPAIGN_NAME',
'type' => 'relate',
'massupdate' => 0,
'comments' => '',
'help' => '',
'audited' => 1,
'len' => '100',
'id_name' => 'campaign_id',
'ext2' => 'Campaigns',
'module' => 'Campaigns',
'rname' => 'name',
'studio' => 'visible',
);
The relationship is added, but subpanel doesn't appear at campaigns module.
In your $dictionary["Campaign"]["fields"]["costs"], change bean_name from Costs to Cost.
I take it you have enabled the subpanel in the admin-menu? (index.php?module=Administration&action=ConfigureTabs)
Does your error-logs say anything?