I have retrieve a view programmaticly in my module with PHP. How can retrieve the values of this view? I'm using drupal 6.
That's the view result in my PHP code:
enter code hereobject(view)#48 (22) {
["db_table"]=>
string(10) "views_view"
["base_table"]=>
string(4) "node"
["args"]=>
array(0) {
}
["use_ajax"]=>
bool(false)
["result"]=>
array(0) {
}
["pager"]=>
array(5) {
["use_pager"]=>
bool(false)
["items_per_page"]=>
int(10)
["element"]=>
int(0)
["offset"]=>
int(0)
["current_page"]=>
int(0)
}
["old_view"]=>
array(0) {
}
["vid"]=>
string(2) "48"
["name"]=>
string(7) "student"
["description"]=>
string(7) "Student"
["tag"]=>
string(0) ""
["view_php"]=>
string(0) ""
["is_cacheable"]=>
string(1) "0"
["display"]=>
array(2) {
["default"]=>
object(views_display)#11 (7) {
["db_table"]=>
string(13) "views_display"
["vid"]=>
string(2) "48"
["id"]=>
string(7) "default"
["display_title"]=>
string(8) "Defaults"
["display_plugin"]=>
string(7) "default"
["position"]=>
string(1) "1"
["display_options"]=>
array(2) {
["fields"]=>
array(5) {
["field_locatie_student_lid"]=>
array(14) {
["label"]=>
string(7) "Locatie"
["alter"]=>
array(16) {
["alter_text"]=>
int(0)
["text"]=>
string(0) ""
["make_link"]=>
int(0)
["path"]=>
string(0) ""
["link_class"]=>
string(0) ""
["alt"]=>
string(0) ""
["prefix"]=>
string(0) ""
["suffix"]=>
string(0) ""
["target"]=>
string(0) ""
["help"]=>
string(0) ""
["trim"]=>
int(0)
["max_length"]=>
string(0) ""
["word_boundary"]=>
int(1)
["ellipsis"]=>
int(1)
["html"]=>
int(0)
["strip_tags"]=>
int(0)
}
["empty"]=>
string(41) "geen overeenkomstige resultaten gevonden."
["hide_empty"]=>
int(0)
["empty_zero"]=>
int(0)
["link_to_node"]=>
int(0)
["label_type"]=>
string(6) "widget"
["format"]=>
string(7) "default"
["multiple"]=>
array(4) {
["group"]=>
bool(true)
["multiple_number"]=>
string(0) ""
["multiple_from"]=>
string(0) ""
["multiple_reversed"]=>
bool(false)
}
["exclude"]=>
int(0)
["id"]=>
string(25) "field_locatie_student_lid"
["table"]=>
string(31) "node_data_field_locatie_student"
["field"]=>
string(25) "field_locatie_student_lid"
["relationship"]=>
string(4) "none"
}
["field_naam_student_value"]=>
array(14) {
["label"]=>
string(4) "Naam"
["alter"]=>
array(16) {
["alter_text"]=>
int(0)
["text"]=>
string(0) ""
["make_link"]=>
int(0)
["path"]=>
string(0) ""
["link_class"]=>
string(0) ""
["alt"]=>
string(0) ""
["prefix"]=>
string(0) ""
["suffix"]=>
string(0) ""
["target"]=>
string(0) ""
["help"]=>
string(0) ""
["trim"]=>
int(0)
["max_length"]=>
string(0) ""
["word_boundary"]=>
int(1)
["ellipsis"]=>
int(1)
["html"]=>
int(0)
["strip_tags"]=>
int(0)
}
["empty"]=>
string(41) "geen overeenkomstige resultaten gevonden."
["hide_empty"]=>
int(0)
["empty_zero"]=>
int(0)
["link_to_node"]=>
int(0)
["label_type"]=>
string(6) "widget"
["format"]=>
string(7) "default"
["multiple"]=>
array(4) {
["group"]=>
bool(true)
["multiple_number"]=>
string(0) ""
["multiple_from"]=>
string(0) ""
["multiple_reversed"]=>
bool(false)
}
["exclude"]=>
int(0)
["id"]=>
string(24) "field_naam_student_value"
["table"]=>
string(28) "node_data_field_naam_student"
["field"]=>
string(24) "field_naam_student_value"
["relationship"]=>
string(4) "none"
}
["field_ugentid_student_value"]=>
array(14) {
["label"]=>
string(7) "UGentID"
["alter"]=>
array(16) {
["alter_text"]=>
int(0)
["text"]=>
string(0) ""
["make_link"]=>
int(0)
["path"]=>
string(0) ""
["link_class"]=>
string(0) ""
["alt"]=>
string(0) ""
["prefix"]=>
string(0) ""
["suffix"]=>
string(0) ""
["target"]=>
string(0) ""
["help"]=>
string(0) ""
["trim"]=>
int(0)
["max_length"]=>
string(0) ""
["word_boundary"]=>
int(1)
["ellipsis"]=>
int(1)
["html"]=>
int(0)
["strip_tags"]=>
int(0)
}
["empty"]=>
string(41) "geen overeenkomstige resultaten gevonden."
["hide_empty"]=>
int(0)
["empty_zero"]=>
int(0)
["link_to_node"]=>
int(0)
["label_type"]=>
string(6) "widget"
["format"]=>
string(7) "default"
["multiple"]=>
array(4) {
["group"]=>
bool(true)
["multiple_number"]=>
string(0) ""
["multiple_from"]=>
string(0) ""
["multiple_reversed"]=>
bool(false)
}
["exclude"]=>
int(0)
["id"]=>
string(27) "field_ugentid_student_value"
["table"]=>
string(31) "node_data_field_ugentid_student"
["field"]=>
string(27) "field_ugentid_student_value"
["relationship"]=>
string(4) "none"
}
["field_voornaam_student_value"]=>
array(14) {
["label"]=>
string(8) "Voornaam"
["alter"]=>
array(16) {
["alter_text"]=>
int(0)
["text"]=>
string(0) ""
["make_link"]=>
int(0)
["path"]=>
string(0) ""
["link_class"]=>
string(0) ""
["alt"]=>
string(0) ""
["prefix"]=>
string(0) ""
["suffix"]=>
string(0) ""
["target"]=>
string(0) ""
["help"]=>
string(0) ""
["trim"]=>
int(0)
["max_length"]=>
string(0) ""
["word_boundary"]=>
int(1)
["ellipsis"]=>
int(1)
["html"]=>
int(0)
["strip_tags"]=>
int(0)
}
["empty"]=>
string(41) "geen overeenkomstige resultaten gevonden."
["hide_empty"]=>
int(0)
["empty_zero"]=>
int(0)
["link_to_node"]=>
int(0)
["label_type"]=>
string(6) "widget"
["format"]=>
string(7) "default"
["multiple"]=>
array(4) {
["group"]=>
bool(true)
["multiple_number"]=>
string(0) ""
["multiple_from"]=>
string(0) ""
["multiple_reversed"]=>
bool(false)
}
["exclude"]=>
int(0)
["id"]=>
string(28) "field_voornaam_student_value"
["table"]=>
string(32) "node_data_field_voornaam_student"
["field"]=>
string(28) "field_voornaam_student_value"
["relationship"]=>
string(4) "none"
}
["field_voorkeur_student_value"]=>
array(14) {
["label"]=>
string(19) "Voorkeurstageplaats"
["alter"]=>
array(16) {
["alter_text"]=>
int(0)
["text"]=>
string(0) ""
["make_link"]=>
int(0)
["path"]=>
string(0) ""
["link_class"]=>
string(0) ""
["alt"]=>
string(0) ""
["prefix"]=>
string(0) ""
["suffix"]=>
string(0) ""
["target"]=>
string(0) ""
["help"]=>
string(0) ""
["trim"]=>
int(0)
["max_length"]=>
string(0) ""
["word_boundary"]=>
int(1)
["ellipsis"]=>
int(1)
["html"]=>
int(0)
["strip_tags"]=>
int(0)
}
["empty"]=>
string(41) "geen overeenkomstige resultaten gevonden."
["hide_empty"]=>
int(0)
["empty_zero"]=>
int(0)
["link_to_node"]=>
int(0)
["label_type"]=>
string(6) "widget"
["format"]=>
string(7) "default"
["multiple"]=>
array(4) {
["group"]=>
bool(true)
["multiple_number"]=>
string(0) ""
["multiple_from"]=>
string(0) ""
["multiple_reversed"]=>
bool(false)
}
["exclude"]=>
int(0)
["id"]=>
string(28) "field_voorkeur_student_value"
["table"]=>
string(32) "node_data_field_voorkeur_student"
["field"]=>
string(28) "field_voorkeur_student_value"
["relationship"]=>
string(4) "none"
}
}
["filters"]=>
array(2) {
["type"]=>
array(9) {
["operator"]=>
string(2) "in"
["value"]=>
array(1) {
["student"]=>
string(7) "student"
}
["group"]=>
string(1) "0"
["exposed"]=>
bool(false)
["expose"]=>
array(2) {
["operator"]=>
bool(false)
["label"]=>
string(0) ""
}
["id"]=>
string(4) "type"
["table"]=>
string(4) "node"
["field"]=>
string(4) "type"
["relationship"]=>
string(4) "none"
}
["field_ugentid_student_value"]=>
array(9) {
["operator"]=>
string(9) "not empty"
["value"]=>
array(3) {
["value"]=>
string(0) ""
["min"]=>
string(0) ""
["max"]=>
string(0) ""
}
["group"]=>
string(1) "0"
["exposed"]=>
bool(false)
["expose"]=>
array(2) {
["operator"]=>
bool(false)
["label"]=>
string(0) ""
}
["id"]=>
string(27) "field_ugentid_student_value"
["table"]=>
string(31) "node_data_field_ugentid_student"
["field"]=>
string(27) "field_ugentid_student_value"
["relationship"]=>
string(4) "none"
}
}
}
}
["page_1"]=>
object(views_display)#43 (7) {
["db_table"]=>
string(13) "views_display"
["vid"]=>
string(2) "48"
["id"]=>
string(6) "page_1"
["display_title"]=>
string(6) "Pagina"
["display_plugin"]=>
string(4) "page"
["position"]=>
string(1) "2"
["display_options"]=>
array(1) {
["path"]=>
string(17) "studentenLijstCSV"
}
}
}
["type"]=>
string(6) "Normal"
["loaded"]=>
bool(true)
["executed"]=>
bool(false)
["built"]=>
bool(false)
["build_info"]=>
array(0) {
}
["attachment_before"]=>
string(0) ""
["attachment_after"]=>
string(0) ""
["get_total_rows"]=>
bool(true)
}
<div style="display: none" id="drupalforfirebug_general"><fieldset><legend>Drupal for Firebug General Messages</legend>There were no messages sent to the general log. Please use "firep($item, $optional_title)" to output messages to this console.</div><div style="display: none" id="drupalforfirebug_sql"><fieldset><legend>Devel Module is Not Installed</legend>Please install and enable the Devel Module to display the SQL queries.</fieldset></div><div style="display: none" id="drupalforfirebug_hook_form_alter">There was no form altering.</div><div style="display: none" id="drupalforfirebug_hook_user">There was no user processing.</div><div style="display: none" id="drupalforfirebug_hook_nodeapi">There was no node processing.</div><div style="display: none" id="drupalforfirebug_hook_views">There was no views processing.</div><div style="display: none" id="drupalforfirebug_php"><object style="width:100%;frameborder=0;height=100%;margin-bottom:-3px;" type="text/html" data="http://localhost/testplanning/?q=admin/firebug/exec"></object></div><div style="display: none" id="drupalforfirebug_hook_page_alter">This feature is only available in Drupal 7.</div>
why you not using just views?
$view = view_get_view('MY_VIEW_NAME');
$view->set_display('MY_DISPLAY'); // page_1 or block_1 ... block_n, ...page_n
$view->set_items_per_page(0);
$view->execute();
$result = $view->result;
$result will contains array of values of each row
I haven't actually tried this myself. First thing to do would be to execute the views query. This can be done with the execute function.
So doing something like this:
$view->execute('display_id');
Should populate the $view object with at least some data. The data available differs through the different layers of theme functions, so you might not get what you want. But this is the best method I can think of.
Related
On my Apache ErrorLog file I see many times this warning message:
[Wed Aug 23 17:27:25.146025 2017] [:error] [pid 14989] [client 66.249.76.54:44935] PHP Warning: Illegal offset type in isset or empty in /var/www/html/blog/wp-content/plugins/ilab-media-tools/classes/tools/s3/ilab-media-s3-tool.php on line 1012
It's related to a Wordpress plugin, I tried on Github to ask help from author (as many others) but nothing.
The warning points to this function:
public function imageDownsize($fail,$id,$size) {
if (apply_filters('ilab_imgix_enabled', false)) {
return $fail;
}
$meta=wp_get_attachment_metadata($id);
// This is the line of the warning:
if (!isset($meta['sizes']) || !isset($meta['sizes'][$size])) {
return $fail;
}
$sizeMeta = $meta['sizes'][$size];
if (!isset($sizeMeta['s3'])) {
return $fail;
}
$url = $sizeMeta['s3']['url'];
$result=[
$url,
$sizeMeta['width'],
$sizeMeta['height'],
true
];
return $result;
}
Apache prints this warning every minute. Is there a way to fix this annoying message warning?
This is the output of var_dump($meta);:
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
array(7) {
["width"]=>
int(140)
["height"]=>
int(140)
["file"]=>
string(31) "2016/01/logo_retina.png"
["sizes"]=>
array(0) {
}
["image_meta"]=>
array(12) {
["aperture"]=>
int(0)
["credit"]=>
string(0) ""
["camera"]=>
string(0) ""
["caption"]=>
string(0) ""
["created_timestamp"]=>
int(0)
["copyright"]=>
string(0) ""
["focal_length"]=>
int(0)
["iso"]=>
int(0)
["shutter_speed"]=>
int(0)
["title"]=>
string(0) ""
["orientation"]=>
int(0)
["keywords"]=>
array(0) {
}
}
["ewww_image_optimizer"]=>
string(30) "Reduced by 16.3% (1.3 kB)"
["s3"]=>
array(3) {
["url"]=>
string(79) "https://s3-eu-west-1.amazonaws.com/blog-example/2016/01/logo_retina.png"
["bucket"]=>
string(12) "blog-example"
["key"]=>
string(31) "2016/01/logo_retina.png"
}
}
And the output of var_dump($size);:
string(4) "full"
array(2) {
[0]=>
int(32)
[1]=>
int(32)
}
array(2) {
[0]=>
int(192)
[1]=>
int(192)
}
array(2) {
[0]=>
int(180)
[1]=>
int(180)
}
array(2) {
[0]=>
int(270)
[1]=>
int(270)
}
So, based on the GitHub issue, it looks like this line is failing somehow
$meta=wp_get_attachment_metadata($id);
According to the WP reference it returns
Attachment meta field. False on failure.
The code mistakenly assumes it's always going to get an array back. So you could fix this by changing the following to make sure $meta isn't false
if (!$meta || !isset($meta['sizes']) || !isset($meta['sizes'][$size])) {
return $fail;
}
$result = User::where('email_add', '=', $username)->first();
Here's what shows up when I use var_dump on $result
object(User)#22 (30) { ["user_id"]=> int(0) ["fname"]=> string(0) "" ["lname"]=> string(0) "" ["mname"]=> string(0) "" ["bdate"]=> string(0) "" ["contact"]=> string(0) "" ["email_add"]=> string(0) "" ["fillable":protected]=> array(6) { [0]=> string(5) "fname" [1]=> string(5) "mname" [2]=> string(5) "lname" [3]=> string(5) "bdate" [4]=> string(7) "contact" [5]=> string(9) "email_add" } ["connection":protected]=> NULL ["table":protected]=> NULL ["primaryKey":protected]=> string(2) "id" ["keyType":protected]=> string(3) "int" ["perPage":protected]=> int(15) ["incrementing"]=> bool(true) ["timestamps"]=> bool(true) ["attributes":protected]=> array(10) { ["user_id"]=> int(33) ["fname"]=> string(6) "Robert" ["lname"]=> string(6) "Marley" ["mname"]=> string(5) "Nesta" ["bdate"]=> string(10) "0000-00-00" ["contact"]=> string(11) "09123847599" ["email_add"]=> string(40) "7c9ac9ca8543dd84f71aa541d422e2a95d3e7450" ["photo"]=> NULL ["created_at"]=> string(19) "2017-01-25 01:03:06" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } ["original":protected]=> array(10) { ["user_id"]=> int(33) ["fname"]=> string(6) "Robert" ["lname"]=> string(6) "Marley" ["mname"]=> string(5) "Nesta" ["bdate"]=> string(10) "0000-00-00" ["contact"]=> string(11) "09123847599" ["email_add"]=> string(40) "7c9ac9ca8543dd84f71aa541d422e2a95d3e7450" ["photo"]=> NULL ["created_at"]=> string(19) "2017-01-25 01:03:06" ["updated_at"]=> string(19) "0000-00-00 00:00:00" } ["relations":protected]=> array(0) { } ["hidden":protected]=> array(0) { } ["visible":protected]=> array(0) { } ["appends":protected]=> array(0) { } ["guarded":protected]=> array(1) { [0]=> string(1) "*" } ["dates":protected]=> array(0) { } ["dateFormat":protected]=> NULL ["casts":protected]=> array(0) { } ["touches":protected]=> array(0) { } ["observables":protected]=> array(0) { } ["with":protected]=> array(0) { } ["exists"]=> bool(true) ["wasRecentlyCreated"]=> bool(false) }
Here's what happens when I use foreach to var_dump each $user on the $result
int(0) string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" string(0) "" bool(true) bool(true) bool(true) bool(false)
I've been looking for a solution to this but I don't seem to find one, I was using get() at first but I read somewhere that if I'm expecting only 1 result, I should be using first() but it doesn't change anything. I can't access the Collection..
I've found a solution
This one helped me.
adding ->toArray on my ->first() was the magic, it only returns an array with the exact attributes without the unnecessary object properties.
I have this array, that is dumped from WooCommerce using these lines:
$items = $woocommerce->cart->get_cart();
foreach($items as $item => $values) {
// some code here…
}
If I make a raw output of my cart ($items) I get this:
array(1) {
["f584d8671586d336d84e8cf9ed43303c"]=>
array(11) {
["booking"]=>
array(15) {
["_year"]=>
int(2016)
["_month"]=>
int(8)
["_day"]=>
int(28)
["_persons"]=>
array(1) {
[0]=>
int(1)
}
["_date"]=>
string(9) "2016-8-28"
["date"]=>
string(13) "28 août 2016"
["_time"]=>
string(5) "21:30"
["time"]=>
string(11) "21 h 30 min"
["_qty"]=>
int(1)
["Personnes"]=>
int(1)
["_start_date"]=>
int(1472419800)
["_end_date"]=>
int(1472421600)
["_all_day"]=>
int(0)
["_cost"]=>
int(0)
["_booking_id"]=>
int(13013)
}
["product_id"]=>
int(12856)
["variation_id"]=>
int(0)
["variation"]=>
array(0) {
}
["quantity"]=>
int(1)
["line_total"]=>
float(0)
["line_tax"]=>
int(0)
["line_subtotal"]=>
int(0)
["line_subtotal_tax"]=>
int(0)
["line_tax_data"]=>
array(2) {
["total"]=>
array(0) {
}
["subtotal"]=>
array(0) {
}
}
["data"]=>
object(WC_Product_Booking)#11131 (20) {
["availability_rules":"WC_Product_Booking":private]=>
array(0) {
}
["id"]=>
int(12856)
["post"]=>
object(WP_Post)#11132 (24) {
["ID"]=>
int(12856)
["post_author"]=>
string(2) "14"
["post_date"]=>
string(19) "2016-08-16 22:04:09"
["post_date_gmt"]=>
string(19) "2016-08-16 20:04:09"
["post_content"]=>
string(0) ""
["post_title"]=>
string(10) "La Cuchara"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(4) "open"
["ping_status"]=>
string(6) "closed"
["post_password"]=>
string(0) ""
["post_name"]=>
string(12) "la-cuchara-2"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2016-08-16 22:13:52"
["post_modified_gmt"]=>
string(19) "2016-08-16 20:13:52"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
int(0)
["guid"]=>
string(59) ""
["menu_order"]=>
int(0)
["post_type"]=>
string(7) "product"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
["filter"]=>
string(3) "raw"
}
["product_type"]=>
string(7) "booking"
["shipping_class":protected]=>
string(0) ""
["shipping_class_id":protected]=>
int(0)
["total_stock"]=>
NULL
["supports":protected]=>
array(0) {
}
["price"]=>
string(1) "0"
["wc_display_cost"]=>
string(0) ""
["wc_booking_base_cost"]=>
string(0) ""
["wc_booking_min_duration"]=>
string(1) "1"
["wc_booking_cost"]=>
string(0) ""
["wc_booking_has_resources"]=>
string(2) "no"
["wc_booking_has_persons"]=>
string(3) "yes"
["wc_booking_has_person_types"]=>
string(2) "no"
["wc_booking_min_persons_group"]=>
string(1) "1"
["tax_status"]=>
string(7) "taxable"
["stock_status"]=>
string(7) "instock"
["manage_stock"]=>
string(2) "no"
}
}
}
I would like to use specific data values in php variables (the booking date, the time and the person):
["date"]=> string(13) "28 août 2016"
["_persons"]=> array(1) { [0]=> int(1) }
["time"]=> string(11) "21 h 30 min"
How can I do to get this specific values from WooCommerce cart object?
Thanks
You could try first this (but I am unsure as I think it can be an object, so may be it will not work):
echo $items[0]['booking']['date'] . '<br>';
echo $items[0]['booking']['_persons'] . '<br>';
echo $items[0]['booking']['time'] . '<br>';
If not working with a foreach loop it will:
$items = WC()->cart->get_cart();
foreach($items as $item) {
$date = $item['booking']['date'];
$person = $item['booking']['_persons'];
$time = $item['booking']['time'];
}
// displaying values for test
echo 'Booking - Date: ' . $date . '/ Person: ' . $person . '/ Time: ' . $time;
One of these will work, for sure…
I do the next SOAP call:
$soapclient = new SoapClient(self::getParameterByKey(self::$WDSL));
$response = $soapclient->getAllProductsAndOffers(array("province_id" => $province_id, "city_id" =>
$city_id, "code" => $code, "favoritos" => $favoritos, "tipo" => $tipo));
THE CONNECTIONOF MY SOAP IS GOING FINE. NO PROBLEM.
I get the result:
object(stdClass)#10 (1) { ["getAllProductsAndOffersResult"]=> object(stdClass)#9 (3) { ["data"]=> object(stdClass)#8 (1) { ["ProductsOffers"]=> array(3) { [0]=> object(stdClass)#7 (13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(10) "davidtest1" ["created_date"]=> string(19) "2014-04-30T00:15:05" ["id"]=> int(7) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(0) ["province_id"]=> int(33) ["tipo"]=> string(1) "P" ["value"]=> float(123) } [1]=> object(stdClass)#6 (13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(8) "alava-01" ["created_date"]=> string(19) "2014-04-27T01:57:18" ["id"]=> int(5) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(50) ["province_id"]=> int(33) ["tipo"]=> string(1) "O" ["value"]=> float(500) } [2]=> object(stdClass)#5 (13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(6) "da-003" ["created_date"]=> string(19) "2014-04-27T01:05:39" ["id"]=> int(4) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(0) ["province_id"]=> int(33) ["tipo"]=> string(1) "P" ["value"]=> float(2000) } } } ["err"]=> bool(false) ["message"]=> string(2) "ok" } }
The Result to convert the object to array is:
array(1) { ["getAllProductsAndOffersResult"]=> array(3) { ["data"]=> array(1) { ["ProductsOffers"]=> array(3) { [0]=> array(13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(10) "davidtest1" ["created_date"]=> string(19) "2014-04-30T00:15:05" ["id"]=> int(7) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(0) ["province_id"]=> int(33) ["tipo"]=> string(1) "P" ["value"]=> float(123) } [1]=> array(13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(8) "alava-01" ["created_date"]=> string(19) "2014-04-27T01:57:18" ["id"]=> int(5) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(50) ["province_id"]=> int(33) ["tipo"]=> string(1) "O" ["value"]=> float(500) } [2]=> array(13) { ["bussiness_id"]=> int(1) ["city_id"]=> int(899) ["codigo"]=> string(6) "da-003" ["created_date"]=> string(19) "2014-04-27T01:05:39" ["id"]=> int(4) ["img_url"]=> string(0) "" ["latitud"]=> float(41.385589) ["longitud"]=> float(2.168745) ["nombre"]=> string(0) "" ["porcentaje"]=> float(0) ["province_id"]=> int(33) ["tipo"]=> string(1) "P" ["value"]=> float(2000) } } } ["err"]=> bool(false) ["message"]=> string(2) "ok" } }
To convert I use the next function I found in internet:
public static function objectToArray($d) {
if (is_object($d)) {
// Gets the properties of the given object
// with get_object_vars function
$d = get_object_vars($d);
}
if (is_array($d)) {
/*
* Return array converted to object
* Using __FUNCTION__ (Magic constant)
* for recursive call
*/
return array_map("self::" . __FUNCTION__, $d);
}
else {
// Return array
return $d;
}
}
My question is why do I get all data like float(...), string(...), int(...)?
Can I avoid this and really my array containts only the real data without the format?
I want this kind of information:
["ProductsOffers"]=> array(3) {
[0]=> array(13) {
["bussiness_id"]=> 1
["city_id"]=> 899
["codigo"]=> "davidtest1"
["created_date"]=> "2014-04-30T00:15:05"
["id"]=> 7
["img_url"]=> ""
["latitud"]=> 41.385589
["longitud"]=> 2.168745
["nombre"]=> ""
["porcentaje"]=> 0
["province_id"]=> 33
["tipo"]=> "P"
["value"]=> 123
}
...
}
NO THIS what it is returned for the soap call:
["ProductsOffers"]=> array(3) {
[0]=> array(13) {
["bussiness_id"]=> int(1)
["city_id"]=> int(899)
["codigo"]=> string(10) "davidtest1"
["created_date"]=> string(19) "2014-04-30T00:15:05"
["id"]=> int(7)
["img_url"]=> string(0) ""
["latitud"]=> float(41.385589)
["longitud"]=> float(2.168745)
["nombre"]=> string(0) ""
["porcentaje"]=> float(0)
["province_id"]=> int(33)
["tipo"]=> string(1) "P"
["value"]=> float(123)
}
...
}
You can use var_dump($returnedArray); function and the output should show you the result with type.
I use nusoap to connect to an URL,
But I cannot connect and I didn't get any error in $soapclient->getError() .
I can connect to that URL via SSH commant and telnet, that URL show an XML data on browser and everything seems to be OK but PHP cannot connect!
I think I have problem in php.ini configuration !
can you help me to solve this problem ?
when I trying to echo $soapclient; I get content :
object(nusoap_client)#25 (50) {
["username"]=>
string(0) ""
["password"]=>
string(0) ""
["authtype"]=>
string(0) ""
["certRequest"]=>
array(0) {
}
["requestHeaders"]=>
bool(false)
["responseHeaders"]=>
string(0) ""
["responseHeader"]=>
NULL
["document"]=>
string(0) ""
["endpoint"]=>
string(60) "https://******?wsdl"
["forceEndpoint"]=>
string(0) ""
["proxyhost"]=>
bool(false)
["proxyport"]=>
bool(false)
["proxyusername"]=>
bool(false)
["proxypassword"]=>
bool(false)
["portName"]=>
string(0) ""
["xml_encoding"]=>
string(0) ""
["http_encoding"]=>
bool(false)
["timeout"]=>
int(0)
["response_timeout"]=>
int(30)
["endpointType"]=>
string(4) "wsdl"
["persistentConnection"]=>
bool(false)
["defaultRpcParams"]=>
bool(false)
["request"]=>
string(0) ""
["response"]=>
string(0) ""
["responseData"]=>
string(0) ""
["cookies"]=>
array(0) {
}
["decode_utf8"]=>
bool(true)
["operations"]=>
array(0) {
}
["curl_options"]=>
array(0) {
}
["bindingType"]=>
string(0) ""
["use_curl"]=>
bool(false)
["fault"]=>
NULL
["faultcode"]=>
NULL
["faultstring"]=>
NULL
["faultdetail"]=>
NULL
["title"]=>
string(6) "NuSOAP"
["version"]=>
string(5) "0.9.5"
["revision"]=>
string(18) "$Revision: 1.123 $"
["error_str"]=>
string(0) ""
["debug_str"]=>
string(311) "2013-05-13 10:35:52.670129 nusoap_client: ctor wsdl=wsdl timeout=0 response_timeout=30
endpoint=string(60) "https://******?wsdl"
2013-05-13 10:35:52.670242 nusoap_client: will use lazy evaluation of wsdl from https://******?wsdl
"
["charencoding"]=>
bool(true)
["debugLevel"]=>
int(9)
["XMLSchemaVersion"]=>
string(32) "http://www.w3.org/2001/XMLSchema"
["soap_defencoding"]=>
string(10) "ISO-8859-1"
["namespaces"]=>
array(4) {
["SOAP-ENV"]=>
string(41) "http://schemas.xmlsoap.org/soap/envelope/"
["xsd"]=>
string(32) "http://www.w3.org/2001/XMLSchema"
["xsi"]=>
string(41) "http://www.w3.org/2001/XMLSchema-instance"
["SOAP-ENC"]=>
string(41) "http://schemas.xmlsoap.org/soap/encoding/"
}
["usedNamespaces"]=>
array(0) {
}
["typemap"]=>
array(6) {
["http://www.w3.org/2001/XMLSchema"]=>
array(43) {
["string"]=>
string(6) "string"
["boolean"]=>
string(7) "boolean"
["float"]=>
string(6) "double"
["double"]=>
string(6) "double"
["decimal"]=>
string(6) "double"
["duration"]=>
string(0) ""
["dateTime"]=>
string(6) "string"
["time"]=>
string(6) "string"
["date"]=>
string(6) "string"
["gYearMonth"]=>
string(0) ""
["gYear"]=>
string(0) ""
["gMonthDay"]=>
string(0) ""
["gDay"]=>
string(0) ""
["gMonth"]=>
string(0) ""
["hexBinary"]=>
string(6) "string"
["base64Binary"]=>
string(6) "string"
["anyType"]=>
string(6) "string"
["anySimpleType"]=>
string(6) "string"
["normalizedString"]=>
string(6) "string"
["token"]=>
string(6) "string"
["language"]=>
string(0) ""
["NMTOKEN"]=>
string(0) ""
["NMTOKENS"]=>
string(0) ""
["Name"]=>
string(0) ""
["NCName"]=>
string(0) ""
["ID"]=>
string(0) ""
["IDREF"]=>
string(0) ""
["IDREFS"]=>
string(0) ""
["ENTITY"]=>
string(0) ""
["ENTITIES"]=>
string(0) ""
["integer"]=>
string(7) "integer"
["nonPositiveInteger"]=>
string(7) "integer"
["negativeInteger"]=>
string(7) "integer"
["long"]=>
string(7) "integer"
["int"]=>
string(7) "integer"
["short"]=>
string(7) "integer"
["byte"]=>
string(7) "integer"
["nonNegativeInteger"]=>
string(7) "integer"
["unsignedLong"]=>
string(0) ""
["unsignedInt"]=>
string(0) ""
["unsignedShort"]=>
string(0) ""
["unsignedByte"]=>
string(0) ""
["positiveInteger"]=>
string(0) ""
}
["http://www.w3.org/2000/10/XMLSchema"]=>
array(11) {
["i4"]=>
string(0) ""
["int"]=>
string(7) "integer"
["boolean"]=>
string(7) "boolean"
["string"]=>
string(6) "string"
["double"]=>
string(6) "double"
["float"]=>
string(6) "double"
["dateTime"]=>
string(6) "string"
["timeInstant"]=>
string(6) "string"
["base64Binary"]=>
string(6) "string"
["base64"]=>
string(6) "string"
["ur-type"]=>
string(5) "array"
}
["http://www.w3.org/1999/XMLSchema"]=>
array(11) {
["i4"]=>
string(0) ""
["int"]=>
string(7) "integer"
["boolean"]=>
string(7) "boolean"
["string"]=>
string(6) "string"
["double"]=>
string(6) "double"
["float"]=>
string(6) "double"
["dateTime"]=>
string(6) "string"
["timeInstant"]=>
string(6) "string"
["base64Binary"]=>
string(6) "string"
["base64"]=>
string(6) "string"
["ur-type"]=>
string(5) "array"
}
["http://soapinterop.org/xsd"]=>
array(1) {
["SOAPStruct"]=>
string(6) "struct"
}
["http://schemas.xmlsoap.org/soap/encoding/"]=>
array(3) {
["base64"]=>
string(6) "string"
["array"]=>
string(5) "array"
["Array"]=>
string(5) "array"
}
["http://xml.apache.org/xml-soap"]=>
array(1) {
[0]=>
string(3) "Map"
}
}
["xmlEntities"]=>
array(5) {
["quot"]=>
string(1) """
["amp"]=>
string(1) "&"
["lt"]=>
string(1) "<"
["gt"]=>
string(1) ">"
["apos"]=>
string(1) "'"
}
["wsdlFile"]=>
string(60) "https://******?wsdl"
["wsdl"]=>
NULL
}
this is my code :
require_once('libs/nusoap/nusoap.php');
$soapclient = new nusoap_client('https://*****?wsdl','wsdl');
echo $soapclient->getError() ;
echo $soapclient;