I've been researching how to add markers to a drupal 7 gmap for more hours than I feel comfortable admitting. The reason I have to do it through a module and not views is because of client specifications that I won't go into here. The code below is what I have so far, everything I've found seems to point in this direction and it looks right to me. But when I go to the page, no markers show on the map. Can anyone help me out here?
This uses the gmaps module for drupal 7 btw.
function rrs_custom_menu() {
$items = array();
$items['search-by-towns'] = array(
'title' => 'Search by Towns',
'page callback' => 'search_by_towns',
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
return $items;
}
function search_by_towns() {
$query = "SELECT node.title AS node_title, location.lid AS location_lid, location.latitude AS gmap_lat, location.longitude AS gmap_lon, location.name as loc_name, location.street, location.city, location.province, location.postal_code, gmap_taxonomy_node.marker AS gmap_node_marker, taxonomy_term_data.tid AS tid, taxonomy_term_data.vid AS vid, gmap_taxonomy_term.marker AS marker
FROM
{node} node
LEFT JOIN {location_instance} location_instance ON node.vid = location_instance.vid
LEFT JOIN {location} location ON location_instance.lid = location.lid
LEFT JOIN {gmap_taxonomy_node} gmap_taxonomy_node ON node.vid = gmap_taxonomy_node.vid
INNER JOIN {taxonomy_index} taxonomy_index ON node.nid = taxonomy_index.nid
INNER JOIN {taxonomy_term_data} taxonomy_term_data ON taxonomy_index.tid = taxonomy_term_data.tid
LEFT JOIN {gmap_taxonomy_term} gmap_taxonomy_term ON taxonomy_term_data.tid = gmap_taxonomy_term.tid
WHERE (( (node.status = '1') AND (node.type IN ('listing', 'town')) AND (taxonomy_term_data.vid = '3') ))
ORDER BY tid desc";
$javascript = drupal_add_js();
$result = db_query($query);
$marker = array();
foreach ($result as $res) {
$text = '<div class="location vcard"> <div class="adr"> <span class="fn">'.$res->loc_name.'</span> <div class="street-address"> '.$res->street.' </div> <span class="locality">'.$res->city.'</span>, <span class="region">'.$res->province.'</span> <span class="postal-code">'.$res->postal_code.'</span> </div> <div class="map-link"> <div class="location map-link">See map: Google Maps</div> </div> </div>';
$marker[] = array(
'latitude' => $res->gmap_lat,
'longitude' => $res->gmap_lon,
'markername' => $res->marker,
'offset' => 0,
'text' => $text,
'opts' => array(
'title' => '',
'highlight' => 0,
'highlightcolor' => '#FF0000'
)
);
}
$map_array = array(
'id' => "auto1map", // id attribute for the map
'width' => "685px", // map width in pixels or %
'height' => "480px", // map height in pixels
'latitude' => '36.10237644873644', // map center latitude
'longitude' => '-80.8758544921875', // map center longitude
'zoom' => 8, // zoom level
'maptype' => "Map", // baselayer type
'controltype' => "Small" // size of map controls
);
$map_array['markers'] = $marker;
$output = theme('gmap', array(
'element' => array(
'#type' => 'gmap',
'#gmap_settings' => $map_array,
'#input' => FALSE,
'#theme' => 'gmap',
'#children' => '',
)
)
);
return $output;
}
Related
i'm already can insert data into database using below query. But i want to shortening code for my a few column name because my it just like a continues number. i already explode mark by m1=A, m2=B, m3=C, m4=A and continue..
Below is my controller:
$mark = 'ABCADDBBAACBCDDABBCA';
$totalquestion = '10';
for($i=0; $i<$totalquestion; $i++):
$no = $i+1;
$m = substr($mark, 0, $no);
endfor;
$data[] = array(
'TotalQuestion' => $totalquestion,
'Mark' => $mark,
'm1' => $m[0],
'm2' => $m[1],
'm3' => $m[2],
'm4' => $m[3],
'm5' => $m[4],
'm6' => $m[5],
'm7' => $m[6],
'm8' => $m[7],
'm9' => $m[8],
'm10' => $m[9],
'm11' => $m[10],
'm12' => $m[11],
'm13' => $m[12],
'm14' => $m[13],
'm15' => $m[14],
'm16' => $m[15],
'm17' => $m[16],
'm18' => $m[17],
'm19' => $m[18],
'm20' => $m[19]
);
$this->excel_import_model->insert($data);
This is my result:
My question is how to re-code for my data[] array so i dont need to type manually m1, m2, m3 till m20. Sorry for my bad english
$mark = 'ABCADDBBAACBCDDABBCA';
$totalquestion = '20';
$data = array();
$data = array(
'TotalQuestion' => $totalquestion,
'Mark' => $mark,
);
//Split String into array
$list = str_split($mark);
$mlist = array();
//Loop through splited string
for($i=0; $i<$totalquestion; $i++):
$mlist['m'.$i] = $list[$i];
endfor;
//Merge here or you an even use push array in for loop itslef
$data = array_merge($data,$mlist);
I have a column in a table where all the details of the bill are getting stored. My brother used PHP web project to do that. Now I am trying to deserialize in VB.NET
Here is the PHP code (Controller)
public function add_to_list() {
$this->load->model('product_model', 'Product');
$pdts = $this->Product->get_data(true);
$available = $this->in_cart($this->input->post('id'));
$cart_qty = $available ? $available : 0;
if (!is_numeric($this->input->post('qty')) || !$this->input->post('id')) {
$res['success'] = false;
$res['msg'] = "Please enter the valid input";
} else {
$discount_percentage = $this->input->post('discount_percentage') ? $this->input->post('discount_percentage') : 0;
$discount_rate = $pdts->selling_price * ($discount_percentage / 100);
$final = $pdts->selling_price - $discount_rate;
$igst = $pdts->igst;
$igst_amt = calculate_price_by_precentage($this, $final, $pdts->igst);
$gross = $pdts->selling_price;
$total = $final + $igst_amt;
// $total = $gross + $igst_amt;
$available_qty = 5;
$data = array(
'id' => $pdts->id,
'qty' => $this->input->post('qty'),
'price' => $pdts->final_price,
'name' => $pdts->product,
'options' => array(
'product_id' => $pdts->id,
'product_hsn' => $pdts->hsn,
'product_name' => $pdts->product,
'product_unit' => $pdts->unit,
'product_rate' => $pdts->selling_price,
'product_mrp' => $pdts->mrp,
'product_gst' => $pdts->igst,
'product_cgst' => $pdts->cgst,
'product_gst_amount' => $igst_amt * $this->input->post('qty'),
'product_net_rate' => $pdts->cost_price,
'product_qty' => $this->input->post('qty'),
'product_free' => 0,
'product_discount_percentage' => $discount_percentage,
'product_discount_rate' => $discount_rate,
'product_total' => $total * $this->input->post('qty'),
'available_qty' => $available_qty,
'category' => $pdts->category,
'rate' => $pdts->selling_price,
'gross' => $gross,
'igst' => $igst,
'cgst' => $igst / 2,
'sgst' => $igst / 2,
'igst_amount' => $igst_amt,
'cgst_amount' => $igst_amt / 2,
'sgst_amount' => $igst_amt / 2,
'total' => $total //final_price($this, $pdts->selling_price, calculate_price_by_precentage($this, $pdts->selling_price, $pdts->discount), calculate_price_by_precentage($this, $pdts->selling_price, $pdts->sgst))
)
);
$this->cart->insert($data);
$this->pageViewData['final_discount'] = $this->input->post('discount') == '' ? '0' : $this->input->post('discount');
$this->pageViewData['final_discount_percentage'] = $this->input->post('discount_percentage') == '' ? '0' : $this->input->post('discount_percentage');
$this->pageViewData['ajax'] = true;
$res['success'] = true;
$res['msg'] = $this->load->view('order/cart_item', $this->pageViewData, true);
}
echo json_encode($res);
}
And this is how the cell Value looks.
> a:1:{s:32:"b3712e169500f4754be4a6a681220a96";a:7:{s:2:"id";s:2:"69";s:3:"qty";d:1;s:5:"price";d:26.25;s:4:"name";s:28:"Seeded
> Dates 200gm Wet
> Dates";s:7:"options";a:26:{s:10:"product_id";s:2:"69";s:11:"product_hsn";s:8:"08041020";s:12:"product_name";s:28:"Seeded
> Dates 200gm Wet
> Dates";s:12:"product_unit";s:2:"GM";s:12:"product_rate";s:5:"26.25";s:11:"product_mrp";s:2:"35";s:11:"product_gst";s:2:"12";s:12:"product_cgst";s:1:"6";s:18:"product_gst_amount";d:3.149999999999999911182158029987476766109466552734375;s:16:"product_net_rate";s:5:"24.70";s:11:"product_qty";s:1:"1";s:12:"product_free";i:0;s:27:"product_discount_percentage";i:0;s:21:"product_discount_rate";d:0;s:13:"product_total";d:29.39999999999999857891452847979962825775146484375;s:13:"available_qty";i:5;s:8:"category";s:9:"AD
> Seeded";s:4:"rate";s:5:"26.25";s:5:"gross";s:5:"26.25";s:4:"igst";s:2:"12";s:4:"cgst";i:6;s:4:"sgst";i:6;s:11:"igst_amount";d:3.149999999999999911182158029987476766109466552734375;s:11:"cgst_amount";d:1.5749999999999999555910790149937383830547332763671875;s:11:"sgst_amount";d:1.5749999999999999555910790149937383830547332763671875;s:5:"total";d:29.39999999999999857891452847979962825775146484375;}s:5:"rowid";s:32:"b3712e169500f4754be4a6a681220a96";s:8:"subtotal";d:26.25;}}
That looks a lot to me. As a beginner, I need a big help from you guys to get this done.
how can i get the first row of result? Below is my code which is giving me an error like this Undefined index: module
if ( substr( $action, 0, 4 ) === "stl_" )
{
$query = "SELECT * FROM a_actions LEFT JOIN a_modules ON ( a_modules.id=a_actions.module_id )
WHERE a_actions.id=(SELECT dependency FROM a_actions WHERE action='{$action}') AND a_modules.module_status = 1 ";
$action = \Yii::$app->db->createCommand( $query )
->queryAll();
//print_r($action);die();
$module = $action[ 'module' ];
$action = $action[ 'action' ];
}
$action has value
Array ( [0] => Array ( [id] => 7 [module_id] => 7 [action] => index [label] => Members [dependency] => [created_by] => [created_at] => [updated_by] => [updated_at] => [is_deleted] => 0 [module] => members [module_name] => [module_status] => 1 ) )
in Yii1 i would have used
$action = \Yii::$app->db->createCommand( $query )
->queryRow();
You can use queryOne()
\Yii::$app->db->createCommand( $query )
->queryOne();
QueryOne()
I'm trying to add aWP_Query with
post_where filter and WP_META_QUERY to a wordpress main query:
function example_range_m2( $where ) {
$min_price = doubleval($_GET['min-price']);
$max_price = doubleval($_GET['max-price']);
$query_args = array( 'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'PREFIX_min_property_price_m2',
'value' => array($min_price, $max_price),
'type' => 'NUMERIC',
'compare' => 'BETWEEN'
),
array(
'key' => 'PREFIX_max_property_price_m2',
'value' => array($max_price, $min_price),
'type' => 'NUMERIC',
'compare' => 'BETWEEN'
),
) );
$query_args2 = array('meta_query' => array(
'relation' => 'AND',
array(
'key' => 'PREFIX_min_property_price_m2',
'value' => $min_price,
'compare' => '<=',
'type' => 'NUMERIC'
),
array(
'key' => 'PREFIX_max_property_price_m2',
'value' => $max_price,
'compare' => '>=',
'type' => 'NUMERIC'
),
));
$meta_query = new WP_Meta_Query();
$meta_query->parse_query_vars( $query_args );
$mq_sql = $meta_query->get_sql(
'post',
$wpdb->posts,
'ID',
null
);
$tmp_one = str_replace('mt1', 'example_postmeta', $mq_sql['where']) . ' ';
echo $tmp_one;
$meta_query = new WP_Meta_Query();
$meta_query->parse_query_vars( $query_args2 );
$mq_sql = $meta_query->get_sql(
'post',
$wpdb->posts,
'ID',
null
);
$tmp_two = str_replace('mt1', 'example_postmeta', $mq_sql['where']) . ' ';
$where .= $tmp_one . ' OR ' . $tmp_two;
return $where;
}
The first query_args have to determine whether one of the custom_meta_field value are between the given range.
The secound query_args have to determine whether values in the database make a range that contains given range.
I need to make wordpress to query database:
SELECT post_meta WHERE
(meta_value1 BETWEEN min MAX max) OR (meta_value2 BETWEEN min AND max)
OR (meta_value1 <= min AND meta_value2 >= max)
var_dump of main wordpress query gives me following request:
SELECT SQL_CALC_FOUND_ROWS example_posts.id
FROM example_posts
INNER JOIN example_postmeta
ON ( example_posts.id = example_postmeta.post_id )
WHERE
1 = 1
AND example_posts.post_type = 'property'
AND (
example_posts.post_status = 'publish'
OR
example_posts.post_status = 'private'
)
AND ( example_postmeta.meta_key = 'PREFIX_min_property_price_m2' )
AND (
(
example_postmeta.meta_key = 'PREFIX_min_property_price_m2'
AND
Cast(example_postmeta.meta_value AS signed) BETWEEN '1000' AND '9000'
)
OR
(
example_postmeta.meta_key = 'PREFIX_max_property_price_m2'
AND
Cast(example_postmeta.meta_value AS signed) BETWEEN '9000' AND '1000'
)
)
OR
And (
(
example_postmeta.meta_key = 'PREFIX_min_property_price_m2'
AND
Cast(example_postmeta.meta_value AS signed) <= '1000'
)
AND
(
example_postmeta.meta_key = 'PREFIX_max_property_price_m2'
AND Cast(example_postmeta.meta_value AS signed) >= '9000'
)
)
GROUP BY example_posts.id
ORDER BY example_postmeta.meta_value + 0 ASC
LIMIT 0, 4
I need this to work with main WP_Query in order to maintain WP and template logic.
I have one post that should work with request and it just doesn't.
I'm a SQL Noob if that is not obvious ;)
Ok. After a strong brainstorming session with myself and a piece of paper and pen I understood that I can rephrase my query / 'problem' with totally different conditions.
I was trying write a query that will return all the objects with a range of values that meet a range. I decided that I will work on maximum and minimum values in a different way, so I came up with meta query that could be used in standard WP_QUERY:
/* Logic for Min and Max Price Parameters */
if( isset($_GET['min-price']) && ($_GET['min-price'] != 'any') && isset($_GET['max-price']) && ($_GET['max-price'] != 'any') ){
$min_price = doubleval($_GET['min-price']);
$max_price = doubleval($_GET['max-price']);
if( $min_price >= 0 && $max_price > $min_price ){
$meta_query[] = array(
'key' => 'EXAMPLE_max_property_price_m2',
'value' => $min_price,
'type' => 'NUMERIC',
'compare' => '>='
);
$meta_query[] = array(
'key' => 'EXAMPLE_min_property_price_m2',
'value' => $max_price,
'type' => 'NUMERIC',
'compare' => '<='
);
}
}elseif( isset($_GET['min-price']) && ($_GET['min-price'] != 'any') ){
$min_price = doubleval($_GET['min-price']);
if( $min_price > 0 ){
$meta_query[] = array(
'key' => 'EXAMPLE_max_property_price_m2',
'value' => $min_price,
'type' => 'NUMERIC',
'compare' => '>='
);
}
}elseif( isset($_GET['max-price']) && ($_GET['max-price'] != 'any') ){
$max_price = doubleval($_GET['max-price']);
if( $max_price > 0 ){
$meta_query[] = array(
'key' => 'EXAMPLE_min_property_price_m2',
'value' => $max_price,
'type' => 'NUMERIC',
'compare' => '<='
);
}
}
This allowed me to cover all the objects I while comparing ranges.
I have this relation CompanyhasMany Branch
And using $this->Company->find('all') output this:
(int) 1 => array(
'Company' => array(
'id' => '4',
'nome' => 'Somov',
'diretores' => 'Marcelo, Carl'
),
'Branch' => array(
(int) 0 => array(
'id' => '3',
'nome' => 'Serra',
'rua' => 'Rua teste 2 exttttt',
'numero' => '22',
'estado' => 'ES',
'cidade' => 'Etc',
'cep' => '',
'responsavel' => '',
'company_id' => '4',
'cnpj' => ''
)
)
),
(int) 2 => array(
'Company' => array(
'id' => '5',
'nome' => 'Soimpex',
'diretores' => ''
),
'Branch' => array()
)
)
I want to transform this in a json like this to use with Highchart:
[{
name: NAME OF COMPANY (nome),
data: NUMBER OF BRANCHS
}, {
name: NAME OF COMPANY (nome),
data: NUMBER OF BRANCHS
}]
How I do this convertion? Thanks
This will return a json object with only one result.
If we use previous example, can be done like this:
$arr = $this->Company->find('all'); // fetch the array
$arr1 = array();
foreach ($arr as $value) {
$tmp = array();
$tmp['name'] = $value['Company']['nome'];
$tmp['data'] = count($value['Branch']);
$arr1[] = $tmp;
}
return json_encode($arr1);
<?php
$sql=mysql_query("select * from Posts limit 20");
$response = array();
$posts = array();
while($row=mysql_fetch_array($sql))
{
$title=$row['title'];
$url=$row['url'];
$posts[] = array('title'=> $title, 'url'=> $url);
}
$response['posts'] = $posts;
$fp = fopen('results.json', 'w');
fwrite($fp, json_encode($response));
fclose($fp);
?>
This will generate a file called results.json file where your php file is stored on your online server, taking url and title variables from your MySQL db, you can change the variable names to what you want to fetch.
The whole idea is about like this
$arr=$this->Company->find('all'); // fetch the array
$arr1=array();
foreach ($arr as $value) {
$arr1['name']=$value['Company']['nome'];
//some more manual transform to desire format
}
return json_encode($arr1);