Add location field to buddy press group in wordpress website - geolocation

Is there a way to add location field to buddy press group in wordpress. And later able to search group based on location.

Below code can be used for adding location field in group edit screen in backend, Put this code in theme functions.php or any plugin:-
add_action('bp_groups_admin_meta_boxes','wdm_groups_custom_group_fields_editable');
function wdm_groups_custom_group_fields_editable(){
add_meta_box( 'wdm_location', 'Location', 'wdm_bp_groups_location', get_current_screen()->id, 'normal', 'core' );
}
function wdm_bp_groups_location($item){
$group_id = $item->id;
$location = groups_get_groupmeta($group_id, 'wdm_location', true);
?>
<select name='wdm_location'>
<option <?php echo ($location == 'india') ? 'selected' : ''; ?>>India</option>
<option <?php echo ($location == 'US') ? 'selected' : ''; ?>>US</option>
</select>
<?php }
add_action('bp_groups_admin_load','wdm_bp_groups_admin_load');
function wdm_bp_groups_admin_load($temp){
if(isset($_POST['wdm_location']) && $_POST['wdm_location']){
groups_update_groupmeta($_REQUEST['gid'], 'wdm_location', $_POST['wdm_location']);
}
}

Related

Opencart custom page foreach not showing

Am creating a custom page using Opencart. Here am using foreach for displaying customer details.
But customer details not showing.
Following codes:
.tpl
<?php foreach($dealerData as $invoice){ ?>
<label> <b>Dealer Name:</b> <?php echo $invoice['name']; ?></label><br>
<label><b>Dealer TIN Number:</b> <?php echo $invoice['tin_number'];?></label><br>
<?php } ?>
Controller
$query13 = $this->db->query("select concat(firstname, ' ', lastname) as name, tin_number from ".DB_PREFIX."customer where customer_id='".$customer_id."'");
$dataDelar = $query13->rows;
foreach ($dataDelar as $dealer) {
$data['dealerData'][] = array(
'name' => $dealer['name'],
'tin_number' => $dealer['tin_number']
);
}
Why are you putting queries in your controller? You have models van database related functions. An foreach on the variable $invoiceData1 should work, you can see in the print_r that there is 1 array in the array. Did you put the print_r in your controller? So yes, look bellow that, maybe you are overriding $invoiceData1.
EDIT
You are not creating an empty array to put your values in:
$query13 = $this->db->query("select concat(firstname, ' ', lastname) as name, tin_number from ".DB_PREFIX."customer where customer_id='".$customer_id."'");
$dataDelar = $query13->rows;
$data['dealerData'] = [];
foreach ($dataDelar as $dealer) {
$data['dealerData'][] = array(
'name' => $dealer['name'],
'tin_number' => $dealer['tin_number']
);
}

Display Update button & save values in database

We are displaying table grid as below image, in last column you can see commission as 10 & 0.
i need to provide an Update button below that and provide an option to edit 10 & 0 , so if we click on "update" button, it should save in database.
we are using below code to display table grid.
php
function getDesignerCollection()
{
$user_home = new USER();
$stmt = $user_home->runQuery("SELECT * FROM tbl_users");
$stmt->execute(array(":uid" => $_SESSION['userSession']));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->execute();
$i=0;
while($data = $stmt->fetch())
{
$responce[$i]=array($data['userID'],
ucfirst($data['name']),
$data['commission1'],
$data['joining_date']);
$i++;
}
echo json_encode($responce);
}
script
var __TEST_DATA__=eval('<?php echo getDesignerCollection();?>');
var grid_demo_id = "myGrid" ;
var dsOption= {
fields :[
{name : 'userID' },
{name : 'name' },
{name : 'commission1'},
{name : 'joining_date'}
],
recordType : 'array',
data : __TEST_DATA__
}
function my_renderId(value ,record,columnObj,grid,colNo,rowNo)
{
var no= record[columnObj.fieldIndex];
return "<input type='checkbox' value='"+record[0]+"' name='userID'/>";
}
var colsOption = [
{id: 'userID' , header: "Customer Id" , width :"90",renderer : my_renderId},
{id: 'name' , header: "Designer Name" , width :"140"},
{id: 'commission1' , header: "commission1" , width :"120"},
{id: 'joining_date' , header: "Customer Since" , width :"120"}
];
now to provide an update button , i am trying below code :
form
<form method="post" name="update" action="updateform.php" />
commission1:
<input type="text" name="commission1" />
<input type="submit" name="Submit" value="update" />
</form>
updateform.php
$sql = "UPDATE tbl_users SET commission1 = '$commission1' WHERE userID= :uid";
$result = $conn->query($sql);
where i need to use form code to display "update" button below values 10 & 0
I am new to php & tried lot before posting here, but did't got any idea related to my code.

codeigniter jquery sortable save to database

I am trying to save the order of a list of images to the database when using jquery sortable.
I feel i am very close, but cant get my head around the final details.
I am working with CI 2.1.3 and jquery-ui 1.10.3.
I have a dynamicaly generated list with an image:
<ul id="order">
<li id="item-1"><img src="abc.jpg" /></li>
<li id="item-2"><img src="def.jpg" /></li>
<li id="item-3"><img src="ghi.jpg" /></li>
</ul>
And the following Jquery:
<script>
$(document).ready(function() {
$( "#order" ).sortable({
opacity: 0.6,
cursor: 'move',
update: function(event, ui){
var order = $(this).sortable("serialize");
console.log(order);
$.ajax({
url: "http://localhost/gridrobin/home/save_order",
type: 'POST',
data: order,
success: function (data) {
$("#test").html(data);
}
});
}
});
});
</script>
This works fine and i can reorder my list. Now i want to save the new order to the database. I send the ajax post to the controller and it comes through. I checked with a var_dump.
//var_dump($_POST);
$items = $this->input->post('item');
$total_items = count($this->input->post('item'));
echo '<h3>Debugging</h3>';
echo "<p>Total items sent: $total_items</p>";
$this->rd_model->update_order($total_items, $items);
Then I send this data to my model:
for($item = 0; $item < $total_items; $item++ )
{
$data = array(
'id' => $items[$item],
'order' => $order = $item
);
$this->db->where('id', $data['id']);
$this->db->update('portfolio_items', $data);
echo '<br />'.$this->db->last_query();
}
And echo out the last db-query for debugging.
Now when i switch item 1 and item 2, i get a 500 internal error. When i switch them back, i receive the echo of the last query executed, which seems fine.
UPDATE `portfolio_items` SET `order` = 1 WHERE `id` = '1'
UPDATE `portfolio_items` SET `order` = 2 WHERE `id` = '2'
UPDATE `portfolio_items` SET `order` = 3 WHERE `id` = '3'
I dont quite understand why the database updates when th list is switched back to its orignial state, but not otherwise.
UPDATE
For people with the same problem, sakibmoon answer helped me a lot, but the main problem was a duplicate entry error, because apparently i had set the order table as a unique index...
The problem is within your data array in the model. Change that with this -
$data = array(
'id' => $items[$item],
'order' => $item+1
);
Also change the update line -
$this->db->update('portfolio_items', $data['order']);
UPDATE:
Couple of changes. Change the update to this-
$this->db->update('portfolio_items', array('order' => $data['order']));
The code is working now if I set $config['csrf_protection'] = FALSE in config.php. But you should set it to TRUE. I don't know how to make that work. All I know is that you have to send csrf_token with your ajax call. You should create a separate question for that. This question title means something entirely different.

How can I dynamically add an attribute to each option tag generated by sfWidgetFormPropelChoice?

In my symfony 1.4 application, I'm generating a select drop down as part of a form.
I later want to apply some jQuery (ddSlick) to that select to re-style it. In order to do so, I need to add an attribute to each option tag.
So for example, I'd like my select to generate:
<select id="demo-htmlselect">
<option value="0" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png"
data-description="Description with Facebook">Facebook</option>
<option value="1" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png"
data-description="Description with Twitter">Twitter</option>
<option value="2" selected="selected" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/linkedin-icon-32.png"
data-description="Description with LinkedIn">LinkedIn</option>
<option value="3" data-imagesrc="http://dl.dropbox.com/u/40036711/Images/foursquare-icon-32.png"
data-description="Description with Foursquare">Foursquare</option>
Any suggestions on how to achieve this? Perhaps with an alternate or extended widget?
If you want to customize the select render, you should extend the default widget and made your own render.
So, create this file for exemple: /lib/widget/myWidgetFormSelect.class.php with:
class myWidgetFormSelect extends sfWidgetFormSelect
{
protected function getOptionsForSelect($value, $choices)
{
$mainAttributes = $this->attributes;
$this->attributes = array();
if (!is_array($value))
{
$value = array($value);
}
$value_set = array();
foreach ($value as $v)
{
$value_set[strval($v)] = true;
}
$options = array();
foreach ($choices as $key => $option)
{
$attributes = array(
'value' => self::escapeOnce($key),
'data-imagesrc' => self::escapeOnce($option['imagesrc']),
'data-description' => self::escapeOnce($option['description'])
);
if (isset($value_set[strval($key)]))
{
$attributes['selected'] = 'selected';
}
$options[] = $this->renderContentTag('option', self::escapeOnce($option['title']), $attributes);
}
$this->attributes = $mainAttributes;
return $options;
}
}
Then, you should trick the way you gave the $choices to the widget. Here, the widget wait for an array like that:
$choices = array(
0 => array(
'title' => 'Facebook',
'imagesrc' => 'http://dl.dropbox.com/u/40036711/Images/facebook-icon-32.png',
'description' => 'Description with Facebook',
),
1 => array(
'title' => 'Twitter',
'imagesrc' => 'http://dl.dropbox.com/u/40036711/Images/twitter-icon-32.png',
'description' => 'Description with Twitter',
),
);

Breadcrumb navigation with Doctrine NestedSet

I have a model that implements NestedSet behaviour:
Page:
actAs:
NestedSet:
hasManyRoots: true
rootColumnName: root_id
columns:
slug: string(255)
name: string(255)
Example fixtures:
Page:
NestedSet: true
Page_1:
slug: slug1
name: name1
Page_2:
slug: slug2
name: name2
children:
Page_3:
slug: page3
name: name3
I am looking for the easiest way to implement breadcrumb navigation (trail). For example, for Page_3 navigation will look like this:
name2 > <a href="page2/page3>name3</a>
Since I hate having any kind of logic in templates (and partials), here's my slightly improved version.
//module/templates/_breadcrumbElement.php
<?php foreach ($node as $child): ?>
<li>
<?php echo $child->getName() ?>
<?php if (count($child->get('__children')) > 0): ?>
<ul>
<?php include_partial('node', array('node' => $child->get('__children'), 'parent' => $child)) ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
So, all the logic for building a url is now in Page::getPath() method.
class Page extends BasePage
{
/**
* Full path to node from root
*
*/
protected $path = false;
public function __toString()
{
return $this->getSlug();
}
public function getPath($parent = null)
{
if (!$this->path)
{
$this->path = join('/', null !== $parent ? array($parent->getPath(), $this) : array($this));
}
return $this->path;
}
}
What I don't like it having to pass $parent to Page::getPath(). It just doesn't make any semantical sense.
Almost the same as in the other question, but you have to add a 'parentUrl' variable :
//module/templates/_breadcrumbElement.php
foreach ($node->get('__children') as $child) :
if ($child->isAncestorOf($pageNode)):
$currentNodeUrl = $parentUrl . $child->getSlug() . '/';
echo link_to($child->getName(), $currentNodeUrl) . ' > ' ;
include_partial('module/breadcrumbElement', array('node' => $child, 'pageNode' => $pageNode, 'parentUrl' => $currentNodeUrl));
endif;
endforeach;
Feed it the root of your tree as $node (hydrate it hierarchically), the node of the current page as $pageNode, and '' as $currentNodeUrl and add ' > ' and the link to the current page.
Why does this solution use recursion and not getAncestors()? Because your urls seem to imply recursion.
Another answer, more simple (and perhaps more efficient), with getAncestors() and recursion:
//module/templates/_breadcrumbElement.php
if ($node = array_pop($nodes)) // stop condition
{
$currentNodeUrl = $parentUrl . $node->getSlug() . '/';
echo link_to($node->getName(), $currentNodeUrl) . ' > ' ;
include_partial('module/breadcrumbElement', array(
'nodes' => $nodes, 'parentUrl' => $currentNodeUrl));
}
Call this with an array of ancestor nodes or find a way to pop a Doctrine_Collection if you want to use it with getAncestors() directly.
Again, all your problem comes from the fact that your urls are recursively computed, it would be simpler and faster to display if you had a colum path with the current url (but then you would have to compute, update it), etc... consider doing this if you have more reads than writes (if your tree does not change often).

Resources