I have a project in this i am stuck because i want to search by industry, educational level, Areas of Experience but it does not act in the way i want to do. I have a dropdown list named industry after selecting industry the educational level, Areas of Experience comes in a checkbox. After selecting the box i want to search and display the result. My Search controller is
public function searchProfessionals (Request $request)
{
$industry = $request->input('industry');
$educationLevels = $request->input('educationLevels');
$areasOfExperiences = $request->input('areasOfExperiences');
$startPrice = $request->input('start_price');
$endPrice = $request->input('end_price');
$meetingType = $request->input('meeting_type');
if ($meetingType == 1) {
$type = [1, 1];
} elseif ($meetingType == 2) {
$type = [2, 2];
} elseif ($meetingType === 3) {
$type = [1, 2];
} else {
$type = [1, 2];
}
$userMeetings = array();
$userRoles = array();
$users = array();
$showUsers = array();
$userHourRates = array();
$userIndus = UserIndustry::where('industry_id', $industry)->get();
$userDegrees = UserDegree::where('degree_id', $educationLevels)->get();
$userAreaOfExperiences = UserAreaOfExperience::where('area_of_experience_id', $areasOfExperiences)->get();
if (!empty($userIndus)) {
foreach ($userIndus as $userInd) {
if (!empty($userDegrees)) {
foreach ($userDegrees as $userDegree) {
if (!empty($userAreaOfExperiences)) {
foreach ($userAreaOfExperiences as $userAreaOfExperience) {
$userHourRates[] = UserTime::where('user_id', $userAreaOfExperience->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
}
$userHourRates[] = UserTime::where('user_id', $userDegree->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
}
$userHourRates[] = UserTime::where('user_id', $userInd->user_id)->whereBetween('hour_rate', [$startPrice, $endPrice])->first();
}
My blade template is
#extends ('frontends.layouts.app')
#section ('main')
<div id="content-block" class="margin-top-140">
<div class="container-fluid block custom-container">
<h3 class="block-title">Browse Professionals</h3>
<div class="block-subtitle"><span>Connect</span> <span>Learn</span> <span>Inspire</span> <span>Thrive</span> </div>
<div class="row">
{{--<form action="" method="post">--}}
<div class="col-md-2 left-feild">
<div class="margin-bottom-30">
<h3>Search Filters</h3>
</div>
#if(Auth::check() && Auth::user()->user_role->role_id == 1000000)
<div class="be-vidget">
<h3 class="letf-menu-article"> Looking To </h3>
<div class="creative_filds_block">
<div class="radio">
<label><input type="radio" name="lookingTo" onclick="lookingTo(2)"> Seek Advice</label>
</div>
<div class="radio">
<label><input type="radio" name="lookingTo" onclick="lookingTo(3)"> Share Advice</label>
</div>
</div>
</div>
<script>
function lookingTo(e) {
$.ajax({
type: 'POST',
url: '{{ URL::to('looking/to') }}/' + e,
success: function (result) {
$('#browse_professionals').html(result);
}
});
}
</script>
#endif
<div class="be-vidget">
<h3 class="letf-menu-article">Professionals</h3>
<div class="-creative_filds_block">
<div class="fp-panel-wrap">
<a class="toggle-btn active" onclick="open_industry()" href="#" data-target="#ul_industry" id="a_industry">Industry</a>
<ul id="ul_industry" class="fp-panel open" style="overflow:scroll; height:200px;">
#if(!empty($industries))
#foreach($industries as $industry)
<li value="{{ $industry->id }}">{{ (!empty($industry['name'])) ? $industry['name'] : '' }} </li>
#endforeach
#endif
</ul>
<script>
function industry_search(e) {
$.ajax({
type: 'POST',
url: '{{ URL::to('professionals/industry') }}/' + e,
success: function (result) {
$('#education_experience').html(result);
$('#a_industry').attr('class', 'toggle-btn');
$('#ul_industry').css('display', 'none');
$('#education_experience').css('display', 'block');
$('#eduLevel').css('display', 'block');
$('#areaExperience').css('display', 'block');
}
});
}
function open_industry() {
$('#education_experience').css('display', 'block');
$('#education_experience').css('display', 'block');
$('#eduLevel').css('display', 'none');
$('#areaExperience').css('display', 'none');
}
</script>
<div id="education_experience" style="">
<a id="a_education" class="toggle-btn" href="#" data-target="#eduLevel">Education Level</a>
<ul id="eduLevel" class="no-link fp-panel" style="overflow:scroll; height:200px;">
#if(!empty($degrees))
#foreach($degrees as $degree)
<li value="{{ $degree->id }}">{{ (!empty($degree['name'])) ? $degree['name'] : '' }}</a> </li>
#endforeach
#endif
</ul>
<a id="a_experience" class="toggle-btn" href="#" data-target="#areaExperience">Areas of Experience</a>
<ul id="areaExperience" class="no-link fp-panel" style="overflow:scroll; height:200px;">
</ul>
</div>
</div>
</div>
</div>
<div class="be-vidget">
<h3 class="letf-menu-article">Meeting Preferences</h3>
<label>Price</label>
<br> <br>
<input type="hidden" id="price_ranger" class="range-slider" value="23"/>
<label style="margin-top: 30px;">Type</label>
<div class="form-group">
<select class="form-input" id="meeting_type">
<option value="3">All</option>
<option value="1">Phone Meeting</option>
<option value="2">Web Meeting</option>
</select>
</div>
</div>
<button id="search_professionals" type="button" class="btn color-2 size-2 btn-block hover-1">Apply Filter</button>
#if(Session::has('remove_filter'))
<button type="button" class="btn btn-danger size-2 btn-block hover-1">Remove Filter</button>
#endif
<script>
var industry = '';
$('#ul_industry li').click(function() {
industry = $(this).attr('value');
// console.log(industry);
});
$("#search_professionals").click(function () {
var degrees = new Array();
$('input[name="degrees_checkbox"]:checked').each(function() {
degrees.push(this.value);
});
var experiences = new Array();
$('input[name="experiences_checkbox"]:checked').each(function() {
experiences.push(this.value);
});
var price_ranger = $("#price_ranger").val();
var price_ranger_array = price_ranger.split(",");
var start_price = price_ranger_array[0];
var end_price = price_ranger_array[1];
var meeting_type = $("#meeting_type").val();
$.ajax({
'type' : 'post',
'url' : '{{ URL::to('search/professionals') }}',
'data' : {
'industry' : industry,
'educationLevels' : degrees,
'areasOfExperiences' : experiences,
'start_price' : start_price,
'end_price' : end_price,
'meeting_type' : meeting_type
},
'success' : function (result) {
console.log(result);
$('#browse_professionals').html(result);
}
});
});
</script>
</div>
{{--</form>--}}
<div class="col-md-10">
<div id="browse_professionals" class="row _post-container_">
#if (!empty($valid_providers))
#foreach ($valid_providers as $provider)
<div class="category-1 custom-column-5">
<div class="be-post">
<figure class="ratio-4-3 be-img-block-alt">
<div class="ratio-inner" style="background-image: url('{{ !empty($provider->user_detail->avatar) ? URL::to($provider->user_detail->avatar) : '' }}')">
<img src="{{ !empty($provider->user_detail->avatar) ? URL::to($provider->user_detail->avatar) : '' }}" alt="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}">
</div>
</figure>
<div class="be-post-title">{{ (!empty($provider->user_share->share)) ? str_limit($provider->user_share->share, 90) : '' }}</div>
<div class="author-post">
<span>{{ !empty($provider->user_detail->first_name) ? $provider->user_detail->first_name : '' }} {{ !empty($provider->user_detail->last_name) ? $provider->user_detail->last_name : '' }}</span>
</div>
<span>{{ (!empty($provider->user_detail->credentials)) ? str_limit($provider->user_detail->credentials, 25) : '' }}</span>
<div data-value="4" class="static-rating"></div>
<div class="info-block clearfix">
<a class="btn color-1 size-2 hover-1 pull-right" href="{{ !empty($provider->username) ? URL::to($provider->username) : '' }}">Contact</a>
<h3 class="rate"> ${{ (!empty($provider->user_time->hour_rate)) ? $provider->user_time->hour_rate : '' }} /hr</h3>
</div>
</div>
</div>
#endforeach
#endif
</div>
</div>
</div>
</div>
</div>
#endsection
please help me. I am stuck this very badly. Sorry for my bad English
The answer will be
public function searchProfessionals(Request $request)
{
$industry = $request->input('industry');
$educationLevels = $request->input('educationLevels');
$areasOfExperiences = $request->input('areasOfExperiences');
$startPrice = $request->input('start_price');
$endPrice = $request->input('end_price');
$meetingType = $request->input('meeting_type');
$userDetails = array();
$userMeetings = array();
$userRoles = array();
$users = array();
$showUsers = array();
$userHourRates = array();
$userDegrees = array();
$userIndustryArray = array();
$userExperience = array();
$userAr = array();
$data['usersDegress'] = '';
$data['usersExperience'] = '';
$intersect_array = array();
$data['userDetails'] = UserDetail::all();
$data['userTime'] = UserTime::whereBetween('hour_rate',[$startPrice,$endPrice])->get();
$userPriceArray = array();
foreach ($data['userTime'] as $price) {
foreach ($data['userDetails'] as $userDetail) {
if ($price->user_id == $userDetail->user_id) {
$userPriceArray[] = $userDetail;
}
}
}
$newArray = array();
$data['userMeeting'] = UserMeeting::where('meeting_id', $meetingType)->get();
foreach ($userPriceArray as $price) {
foreach ($data['userMeeting'] as $meet) {
if ($price->user_id == $meet->user_id) {
$newArray[] = $price;
}
}
}
if(!empty($industry)) {
$data['userIndustry'] = UserIndustry::where('industry_id',$industry)->get();
foreach ($data['userIndustry'] as $userIn){
foreach ($newArray as $new){
if($new->user_id == $userIn->user_id){
$userIndustryArray[] = $new ;
}
}
}
if(count($educationLevels) >0){
$data['usersDegress'] = UserDegree::whereIn('degree_id',$educationLevels)->get();
foreach ($data['usersDegress'] as $education ){
foreach ($userIndustryArray as $n){
if($n->user_id == $education->user_id){
$userDegrees[] = $n ;
}
}
}
}
if(count($areasOfExperiences) >0){
$data['usersExperience'] = UserAreaOfExperience::whereIn('area_of_experience_id',$areasOfExperiences)->get();
foreach ($data['usersExperience'] as $experience ){
foreach ($userIndustryArray as $ex){
if($ex->user_id == $experience->user_id){
$userExperience[] = $ex ;
}
}
}
}
}else{
$userIndustryArray = $newArray ;
}
if(count($educationLevels)> 0 && count($areasOfExperiences) >0) {
$intersect_array = array_intersect ($userDegrees,$userExperience);
$userIndustryArray =$intersect_array;
}else if(count($educationLevels) == 0 && count($areasOfExperiences) >0) {
$intersect_array = $userExperience;
$userIndustryArray =$intersect_array;
}
else if(count($educationLevels)> 0 && count($areasOfExperiences) == 0) {
$intersect_array = $userDegrees;
$userIndustryArray =$intersect_array;
}else if(count($educationLevels) == 0 && count($areasOfExperiences) == 0) {
$userIndustryArray =$userIndustryArray;
}
$string = '' ;
foreach ($userIndustryArray as $item){
$userRatingShow = Review::where('provider_id',$item->user_id)->avg('rating');
if(empty($userRatingShow)){
$userRatingShow = 0;
}
$avatar = '';
$name = '';
$user = User::find($item->user_id) ;
if(!empty($user)){
$name = $user->username ;
}
if(!empty($item->avatar )){
$avatar = url($item->avatar);
}else{
}
$userTime= UserTime::where('user_id',$item->user_id)->orderby('id','desc')->first();
if(!empty($userTime)){
$userTimeShow = $userTime->hour_rate ;
}
$bio = '';
$user_share = UserShare::where('user_id',$item->user_id)->orderby('id','desc')->first();
if(!empty($user_share)) {
$bio =str_limit($user_share->share,85);
}
$string .= '<div class="category-1 custom-column-5">
<div class="be-post">
<figure class="ratio-4-3 be-img-block-alt">
<div class="ratio-inner" style="background-image: url(' . $avatar . ')">
<img src="' . $avatar . '" alt="omg">
</div>
</figure>
<div class="be-post-title">' . $bio . '</div>
<div class="author-post">
<span>
<a href="' . url($name) . '">' .
$item->first_name . ' ' . $item->last_name . '
</a>
</span>
</div>
<span>' . $item->credentials . '</span>
</div>
<div data-value="' . $userRatingShow . '" class="static-rating"></div>
<div class="info-block clearfix">
<a class="btn color-1 size-2 hover-1 pull-right" href="' . url($name) . '">Contact</a>
<h3 class="rate">$' . $userTimeShow . '/hr</h3>
</div>
</div>
</div>
';
}
if(!empty($string)) {
return response($string);
}else{
echo '<div class="text-center margin-top-140"><h2>Sorry, no members meet your criteria.</h2></div>';
echo '<div class="text-center margin-top-50"><h2>Please revise your search.</h2></div>';
}
}
Related
I am trying to display messages in the error section from sender and receiver, both returning view mes_res from MessageController, but it is displaying an error message.
#controller method:
public function respone_msg($myid){
$dd = DB::table('messeges')->where(['is_read'=>0,'sender_id' =>$myid , 'receiver_id' => Session::get('id')])->get();
$myCount = count($dd);
var_dump($myCount);
$sendmsesgesreal = DB::table('messeges')->where(['sender_id' => Session::get('id') , 'receiver_id' => $myid])->orWhere(['receiver_id' => Session::get('id') ])->get();
//return view('users.mes_res')->with(['msg_data' => $sendmsesgesreal, 'user_id' => $myid, 'conv_id' => $sendmsesgesreal[0]->conversation_id]);
return view('users.mes_res')->with(['msg_data' => $sendmsesgesreal, 'user_id' => $myid, 'conv_id' => $sendmsesgesreal[0]->conversation_id])->header('Cache-Control', 'no-cache, no-store, must-revalidate');
}
view mes_reg:
<div class="messages-headline">
<i class="icon-feather-trash-2"></i> Delete Conversation
</div>
<!-- Message Content Inner -->
<div class="message-content-inner">
<?php
foreach ($msg_data as $msg) {
//
if($msg->sender_id==Session::get('id') && $msg->receiver_id==$user_id) //conv_id
{
$getuserdat1 = DB::table('profile_users')->where('user_id',$msg->sender_id)->get();
// print_r($msg);
if (count($getuserdat1)>0)
{
$fullname=$getuserdat1[0]->fname.' '.$getuserdat1[0]->lname;
if ($getuserdat1[0]->profile_images)
{
$img11 = url('')."/public/uploads/".$getuserdat1[0]->profile_images;
}
else
{
$img11 = url('')."/public/users/images/user-avatar-placeholder.png";
}
}
else
{
$img11 = url('')."/public/users/images/user-avatar-placeholder.png";
}
echo '<input type="hidden" name="receiver_id" id="receiver_id" value="'.$msg->sender_id.'">';
//print_r($img11);
?>
<div class="message-time-sign">
<span>{{ \Carbon\Carbon::parse($msg->CreatedBydate)->diffForhumans() }}</span>
</div>
<div class="message-bubble me">
<div class="message-bubble-inner">
<div class="message-avatar"><img src="{{$img11}}" alt="" /></div>
<div class="message-text"><p>{{$msg->messeges}}</p></div>
</div>
<div class="clearfix"></div>
</div>
<?php }
elseif($msg->sender_id==$user_id)
//else
{
//print_r($msg);
// $receiverdata = DB::table('messeges')
// ->where('sender_id',$msg->sender_id)->get();
// print_r($receiverdata);
//print_r($msg);
$getuserdat11 = DB::table('profile_users')->where('user_id',$msg->sender_id)->get();
if(count($getuserdat11)>0)
{
if ($getuserdat11[0]->profile_images)
{
$img111 = url('')."/public/uploads/".$getuserdat11[0]->profile_images;
}
else
{
$img111 = url('')."/public/users/images/user-avatar-placeholder.png";
}
}
else
{
$img111 = url('')."/public/users/images/user-avatar-placeholder.png";
}
echo '<input type="hidden" name="receiver_id" id="receiver_id" value="'.$msg->sender_id.'">';
//print_r($img111);
?>
<div class="message-time-sign">
<span>{{ \Carbon\Carbon::parse($msg->CreatedBydate)->diffForhumans() }}</span>
</div>
<div class="message-bubble">
<div class="message-bubble-inner">
<div class="message-avatar"><img src="{{$img111}}" alt="" /></div>
<div class="message-text"><p>{{$msg->messeges}}</p></div>
</div>
<div class="clearfix"></div>
</div>
<?php }
?>
</div>
I have a problem with ajax search in my codeigniter project.
The search no show data, and after click SEARCH button page freez 1-2 sec. I think the problem is anywhere in getting the information from the database but, also the model is correct.
There is the code:
Model:
var $table = 'users';
function search($options = array(), $status = true, $limit = null, $offset = 0) {
$this->db->select('users.username,types.t_title,media.photo');
$str = '';
if ($options['username'] != '') {
$str .= ' AND users.username =' . $this->db->escape($options['username']);
}
if (!$status) {
$str .= ' AND users.active = 1';
}
$this->db->where('users.username', 'LIKE', '%' . $options['username'] . '%' . $str);
$this->db->group_by('users.id');
$this->db->limit($limit, $offset);
$search = $this->db->get($this->table);
return $search->result();
}
Controller:
public function search($offset = 0) {
$options = $this->Users->array_from_post(array('username'));
if ($this->form_validation->run('search')) {
$count = $this->Property->search($options, $status = FALSE);
$perpage = 10;
if (count($count) > $perpage) {
$config['base_url'] = site_url('welcome/search');
$config['total_rows'] = count($count);
$config['per_page'] = $perpage;
$config['uri_segment'] = 4;
$q = $this->pagination->initialize($config);
$offset = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
} else {
$this->data['pagination'] = '';
$offset = 0;
}
$status = 1;
$this->data['search'] = $this->Users->search($options, $status = FALSE, $perpage, $offset);
$this->load_search('search');
}
}
And View with ajax:
<script type="text/javascript">
$(document).ready(function() {
$("form[name='search']").submit(function(e) {
var formData = new FormData($(this)[0]);
$.ajax({
url: "<?php echo site_url('welcome/welcome/search'); ?>",
type: "POST",
dataType: "text",
data: formData,
async: false,
success: function (msg) {
$(".search_area").html(msg);
},
cache: false,
contentType: false,
processData: false
});
e.preventDefault();
});
});
</script>
<form class="form-horizontal" method="post" name="search">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-6">
<div class="form-group">
<div class="col-md-12">
<input type="text" class="input-text" id="username" name="username" placeholder="Username">
</div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6 col-xs-6">
<div class="form-group">
<input type="submit" class="search-button" name="search" value="Search">
</div>
</div>
</div>
</form>
<div class="search_area">
</div>
All is connected and load the template, but the only message with No Record Found
And here is search view:
<div class="main-title">
<h1>Search Results</h1>
<div class="border">
<div class="border-inner"></div>
</div>
</div>
<?php if ($search) : ?>
<?php foreach ($search as $sr): ?>
<p>Tralalala <?php echo $sr['title']; ?></p>
<?php endforeach; ?>
<?php else:?>
<div class="notification-box">
<h3><?php echo $this->lang->line('no_record'); ?></h3>
</div>
<?php endif; ?>
I am using opencart version 2.0.1.1 and I have modified common cart.tpl according to my requirement I meant alignment so after I changed if I add any product to cart means it will show success message and even product is adding to cart but when I click on cart button it is showing "ul" but inside ul, li is there that is not displaying and If I load page means it will show products in the cart otherwise not showing.
Please any one help me on this.
Below is cart.tpl,
<a id="cart_close_1">X</a>
<div id="cart" class="btn-group btn-block">
<button type="button" data-toggle="dropdown" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-inverse btn-block btn-lg dropdown-toggle animate"><i class="crtIcon animAll"></i><!-- <span id="cart-total"><?php echo $text_items; ?></span> --></button>
<ul class="dropdown-menu pull-right <?php echo $class_cart; ?> " id="remove_cart">
<?php if ($products || $vouchers) { ?>
<li><div class="cart-container cf">
<?php $count=0;
foreach ($products as $product) { $count++;
?>
<div class="qckimg-vd">
<div class="quck-img">
<?php if ($product['thumb']) { ?>
<!-- <img src="image/10-cm-blue-sparklers.jpg" alt="10-cm-blue-sparklers"> -->
<img src="<?php echo $product['thumb']; ?>" alt="<?php echo $product['name']; ?>" title="<?php echo $product['name']; ?>" class="img-thumbnail" />
<?php }?>
</div><!-- quck-img -->
<div class="proqty">
<div class="nobTn">
<button type="button" class="btn-number" data-type="minus" data-field="input-quantity_<?php echo $product['product_id']; ?>" data-price="<?php echo $product['product_id']; ?>">
<input type="hidden" class="min_order_amount" data-value="<?php echo "3400";?>"/>
<span>-</span>
</button>
</div>
<input type="text" name="quantity" min="1" max="100" value="1" size="2" id="input-quantity_<?php echo $product['product_id']; ?>" class="pro_class" data-id="<?php echo $product['product_id']; ?>" maxlength="3" onkeypress="return IsNumeric(event);" ondrop="return false;" onpaste="return false;">
<div class="nobTn">
<button type="button" class="btn-number" data-type="plus" data-field="input-quantity_<?php echo $product['product_id']; ?>" data-price="<?php echo $product['product_id']; ?>">
<span>+</span>
</button>
</div>
<span id="error" style="color: Red; display: none">Input digits (0 - 9)</span>
<input type="hidden" name="product_id" id="p_id" value="<?php echo $product['product_id']; ?>">
</div>
</div><!-- qckimg-vd -->
<div class="shoping-cart-desc">
<h2><?php echo $product['name']; ?></h2>
<h3><?php echo $product['attribute_value']; ?></h3>
<h4><!-- <span class="qty_total <?php echo "count_".$count;?>" data-count="<?php echo $count;?>"><?php echo $product['quantity']; ?> X </span> --><span class="orgprice count_total" id="or_price_<?php echo $product['product_id']; ?>" data-actprice="<?php echo str_replace( ',', '', $product['price'] ); ?>"><?php echo $product['price']; ?></span></h4>
<!-- Remove -->
Remove
</div><!-- shoping-cart-desc -->
<?php }?>
</div><!-- cart-container -->
<div class="sub-tot">
<?php $count=0;foreach($products as $product){$count++;?>
<?php } ?>
<?php foreach ($totals as $total) {?>
<?php }?>
<div class="cf">
<h4 class="lft">Subtotal (<?php echo $count;?> item(s))</h4>
<h4 class="rght total_price" data-type="minus plus" data-total="<?php echo str_replace( ',', '', $total['text'] ); ?>"><?php echo $total['text']; ?></h4>
<!-- <h4 class="lft">Shipping</h4>
<h4 class="rght">NA</h4> -->
</div>
<div class="total cf">
<h4 class="lft">Total</h4>
<h4 class="rght total_price"><?php echo $total['text']; ?></h4>
</div>
</div><!-- sub-tot -->
<div class="shp-btns">
<a class="chckout" href="<?php echo $checkout; ?>">Checkout</a>
</div><!-- shp-btns -->
<div class="min-ordr">
<h3>Minimum order amount should be
Rs.3400 to checkout.</h3>
</div><!-- min-ordr -->
</li>
<?php }else{?>
<li style="height:auto;">
<p class="text-center tCeTxt"><?php echo $text_empty; ?></p>
</li>
<?php }?>
</ul>
</div>
js cart function,
'add': function(product_id, quantity) {
$.ajax({
url: 'index.php?route=checkout/cart/add',
type: 'post',
data: 'product_id=' + product_id + '&quantity=' + (typeof(quantity) != 'undefined' ? quantity : 1),
dataType: 'json',
beforeSend: function() {
$('#cart > button').button('loading');
},
success: function(json) {
var error_msg = false;
$('.alert, .text-danger').remove();
$('#cart > button').button('reset');
//For Showing Product Stock Error
if (json['error_warning']) {
error_msg = true;
$('#cart_id').parent().before('<div class="alert alert-danger"><i class="fa fa-check-circle"></i> ' + json['error_warning'] + '<button type="button" class="close" data-dismiss="modal">×</button></div>');
$('#cart-total').html(json['total']);
}
if (json['redirect'] && error_msg == false) {
location = json['redirect'];
}
if (json['success']) {
$('#cart_id').parent().before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + '<button type="button" class="close" data-dismiss="modal">×</button></div>');
$('#cart-total').html(json['total']);
/*$('html, body').animate({ scrollTop: 0 }, 'slow');*/
$('#cart > ul').load('index.php?route=common/cart/info ul li');
}
}
});
},
Controller,
<?php
class ControllerCommonCart extends Controller {
public function index() {
$this->load->language('common/cart');
// Totals
$this->load->model('extension/extension');
$total_data = array();
$total = 0;
$taxes = $this->cart->getTaxes();
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$sort_order = array();
$results = $this->model_extension_extension->getExtensions('total');
foreach ($results as $key => $value) {
$sort_order[$key] = $this->config->get($value['code'] . '_sort_order');
}
array_multisort($sort_order, SORT_ASC, $results);
foreach ($results as $result) {
if ($this->config->get($result['code'] . '_status')) {
$this->load->model('total/' . $result['code']);
$this->{'model_total_' . $result['code']}->getTotal($total_data, $total, $taxes);
}
}
$sort_order = array();
foreach ($total_data as $key => $value) {
$sort_order[$key] = $value['sort_order'];
}
array_multisort($sort_order, SORT_ASC, $total_data);
}
$data['text_empty'] = $this->language->get('text_empty');
$data['text_cart'] = $this->language->get('text_cart');
$data['text_checkout'] = $this->language->get('text_checkout');
$data['text_recurring'] = $this->language->get('text_recurring');
$data['text_shipping'] = $this->language->get('text_shipping');
$data['text_minimum_ord_amount'] = $this->language->get('text_minimum_ord_amount');
$data['text_items'] = sprintf($this->language->get('text_items'), $this->cart->countProducts() + (isset($this->session->data['vouchers']) ? count($this->session->data['vouchers']) : 0), $this->currency->format($total));
$data['text_loading'] = $this->language->get('text_loading');
$data['button_remove'] = $this->language->get('button_remove');
$this->load->model('tool/image');
$this->load->model('tool/upload');
$data['products'] = array();
foreach ($this->cart->getProducts() as $product) {
if ($product['image']) {
$image = $this->model_tool_image->resize($product['image'], $this->config->get('config_image_cart_width'), $this->config->get('config_image_cart_height'));
} else {
$image = '';
}
$option_data = array();
foreach ($product['option'] as $option) {
if ($option['type'] != 'file') {
$value = $option['value'];
} else {
$upload_info = $this->model_tool_upload->getUploadByCode($option['value']);
if ($upload_info) {
$value = $upload_info['name'];
} else {
$value = '';
}
}
$option_data[] = array(
'name' => $option['name'],
'value' => (utf8_strlen($value) > 20 ? utf8_substr($value, 0, 20) . '..' : $value),
'type' => $option['type']
);
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
// Display prices
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$total = $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity']);
} else {
$total = false;
}
//For Getting Pieces/Items per box
$product_attribute = $this->model_catalog_product->getSpecificProductAttribute($product['product_id']);
$attribute_value = '';
if($product_attribute) {
$attribute_value = $product_attribute['text'];
}
$data['products'][] = array(
'key' => $product['key'],
'product_id'=> $product['product_id'],
'thumb' => $image,
'name' => $product['name'],
'model' => $product['model'],
'option' => $option_data,
'recurring' => ($product['recurring'] ? $product['recurring']['name'] : ''),
'quantity' => $product['quantity'],
'price' => $price,
'attribute_value'=> $attribute_value,
'total' => $total,
'href' => $this->url->link('product/product', 'product_id=' . $product['product_id'])
);
}
// Gift Voucher
$data['vouchers'] = array();
if (!empty($this->session->data['vouchers'])) {
foreach ($this->session->data['vouchers'] as $key => $voucher) {
$data['vouchers'][] = array(
'key' => $key,
'description' => $voucher['description'],
'amount' => $this->currency->format($voucher['amount'])
);
}
}
$data['totals'] = array();
foreach ($total_data as $result) {
$data['totals'][] = array(
'title' => $result['title'],
'text' => $this->currency->format($result['value']),
);
}
$data['cart'] = $this->url->link('checkout/cart');
$data['checkout'] = $this->url->link('checkout/checkout', '', 'SSL');
if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/cart.tpl')) {
return $this->load->view($this->config->get('config_template') . '/template/common/cart.tpl', $data);
} else {
return $this->load->view('default/template/common/cart.tpl', $data);
}
}
public function info() {
$this->response->setOutput($this->index());
}
}
I have integrated the PHP SDK from Github: https://github.com/evernote/evernote-cloud-sdk-php
I have managed to connect a Premium account using Developer Token. It works a treat.
However, when I try to access more accounts, I get an error. Here is my code
<pre>
require_once '../libs/evernote/src/autoload.php';
require_once('../libs/mysql.class.php');
require_once('../libs/debug.php');
require_once('../libs/functions.php');
session_start();
//Siren is the search term
$gMysql = new MySQL_Class(array("host"=>"localhost","user"=>"horscote","password"=>"feO#6i77","dbname"=>"horscote"));
$gMysql->connect();
$siren = $_POST['id'];
//if logged user - saved as viewed
$sqlViewed = 'SELECT evernoteSync FROM company WHERE SIREN='.$siren;
$isSync = $gMysql->queryValue($sqlViewed);
$gMysql->close();
if($isSync==1)
{
$gMysql->connect();
//get all admin evernotes
$evernotes = $gMysql->queryList('SELECT * FROM evernote_users e inner join users u on u.id=e.userid WHERE evernote=1 ORDER BY e.ID');
$maintable = '';
foreach($evernotes as $evernote)
{
//var_dump($evernote);
$token = $evernote['token'];
$sandbox = false;
$china = false;
$client = new \Evernote\Client($token, $sandbox, null, null, $china);
$search = new \Evernote\Model\Search($siren);
$notebook = new \Evernote\Model\Notebook();
//$notebook->guid = $evernote['notebook_guid'];
//$scope = \Evernote\Client::SEARCH_SCOPE_ALL;
//$order = \Evernote\Client::SORT_ORDER_REVERSE | \Evernote\Client::SORT_ORDER_RECENTLY_CREATED;
//var_dump($notebook);
$maxResult = 5;
$results = $client->findNotesWithSearch($search, $notebook, $scope, $order, $maxResult);
//var_dump($results);
$table = '<div class="panel-group" id="accordionEvernote" role="tablist" aria-multiselectable="true" style="margin-top:10px">';
$i=0;
foreach ($results as $result) {
$noteGuid = $result->guid;
$note = $client->getNote($noteGuid);
$in = '';
if($i==0)
{
$in = ' in';
$plusMinus = '<i class="more-less fa fa-chevron-right"></i>';
}
else
{
$plusMinus = '<i class="more-less fa fa-chevron-right"></i>';
}
$advancedClient = new \Evernote\AdvancedClient($token, $sandbox);
$noteStore = $advancedClient->getNoteStore();
$userStore = $advancedClient->getUserStore();
$userInfo = $userStore->getPublicUserInfo($evernote['username']);
$completeNote = $noteStore->getNote($token,$noteGuid,TRUE,TRUE,TRUE,TRUE);
$resources = $completeNote->resources;
$sResources = '';
foreach($resources as $res)
{
$resource = $noteStore->getResource($token, $res->guid, true, true, true, true);
$fileContent = $res->data->body;
$fileType = $res->mime;
$fileName = $res->attributes->filename;
$resGuid = $res->guid; // example GUID
$resUrl = $userInfo->webApiUrlPrefix . 'res/' . $resGuid;
$attribute = $noteStore->getResourceAttributes($token, $res->guid);
$fileName = $attribute->fileName;
$sResources .= '
<div class="col-xs-10 col-sm-4 col-md-2">
<div class="thumbnail" style="text-align:center">
<i class="fa fa-file-text" aria-hidden="true" style="font-size:40px;color:#F05F40"></i>
<div class="caption">
<a tatget="_blank" href="'.$resUrl.'" style="font-size:10px">'.$fileName.'</a>
</div>
</div>
</div>';
}
$tags = $noteStore->getNoteTagNames($token,$noteGuid);
$created = date('d/m/Y',$completeNote->created/1000);
$updated = date('d/m/Y',$completeNote->updated/1000);
$hashTags = '';
foreach($tags as $tag)
{
$hashTags .='<span class="label label-primary" style="margin-right:5px"> <i class="fa fa-tag" aria-hidden="true"></i> '.$tag.'</span>';
}
$table .='<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading'.$note->guid.'">
<h4 class="panel-title" style="font-size:12px">
<a role="button" data-toggle="collapse" data-parent="#accordionEvernote" href="#collapse'.$note->guid.'" aria-expanded="true" aria-controls="collapse'.$note->guid.'">
'.$plusMinus.'
'.$note->title.' - Crée le '.$created.' par '.$evernote['firstName'].' - Modifié le '.$updated.'</i>
</a>
</h4>
</div>
<div id="collapse'.$note->guid.'" class="panel-collapse collapse" role="tabpanel" aria-labelledby="heading'.$note->guid.'">
<div class="panel-body">
<div id="ntD'.$note->guid.'">
<div style="margin-bottom:10px">'.$hashTags.'</div>
<div style="margin-bottom:10px" id="resources" class="row">'.$sResources.'</div>
'.$note->content.'
</div>
</div>
</div>
</div>';
$i++;
}
$maintable .=$table;
}
$gMysql->close();
if(isset($noteGuid) && !empty($noteGuid))
{
echo '<div style="text-align:justify">'.$maintable.'</div>';
}
else
{
$table = 'Aucune note trouvée pour cette société.';
echo $table;
}
}
else
{
$table = '<div style="text-align:center"><button class="btn btn-success btn-lg" onclick="sync('.$siren.')"> Syncroniser</button></div>';
echo $table;
}
</pre>
Any idea if all the accounts need to be premium? The premium account works but the others don't.
I currently pull through data from a soap feed using this PHP, is there anyway for me to have the results ordered from high to low using the data from $weekrent?
Any help would be great! Here is my PHP code:
<?php
$wsdl = "http://portal.letmc.com/PropertySearchService.asmx?WSDL";
$client = new SoapClient($wsdl, array ("trace"=>1, "exceptions"=>0));
$strClientID = "{0050-e58a-cd32-3771}";
$strBranchID = "{0004-e58a-cd32-399e}";
$strAreaID = $_GET['area'];
$nMaxResults = $_GET['perpage'];
$nRentMinimum = $_GET['minrent'];
$nRentMaximum = $_GET['maxrent'];
$nMaximumTenants = $_GET['numtennants'];
$parameters = array( "strClientID"=>$strClientID,
"strBranchID"=>$strBranchID,
"strAreaID"=>$strAreaID,
"nMaxResults"=>$nMaxResults,
"nRentMinimum"=>$nRentMinimum,
"nRentMaximum"=>$nRentMaximum,
"nMaximumTenants"=>$nMaximumTenants
);
$values = $client->SearchProperties($parameters);
if(!is_array($values->SearchPropertiesResult->PropertyInfo))
{
$values->SearchPropertiesResult->PropertyInfo = array($values->SearchPropertiesResult->PropertyInfo);
}
if($values != '')
{
foreach ($values->SearchPropertiesResult->PropertyInfo as $message)
{
$uglyid = $message->ID;
$id = $message->FriendlyID;
$mainphoto = $message->MainPhoto->PhotoUrl;
$furnished = $message->Furnished;
$addressline1 = $message->Address1;
$rooms = $message->MaxTenants;
$rent = $message->Rent;
$description = $message->Description;
$isletagreed = $message->IsLetAgreed;
$facilities = $message->Facilities->FacilityInfo;
$photos = $message->Photos->PhotoInfo;
$roomsinfo = $message->Rooms->RoomInfo;
$facilitiesstring = serialize($facilities);
$extractnumbers = ereg_replace("[^0-9]", "", $rent);
$monthrent = ($extractnumbers) / $rooms;
$monthrentrounded = number_format(($monthrent/100),2);
$weekrent = ($monthrentrounded) * 12 / 52;
$weekrentrounded = floor($weekrent * 100) / 100;
$roomsinfojson = json_encode($roomsinfo);
$facilitiesjson = json_encode($facilities);
$roomsinfodouble = (substr_count(strip_tags($roomsinfojson),"Double"));
$roomsinfosingle = (substr_count(strip_tags($roomsinfojson),"Single"));
$roomsinfobathroom = (substr_count(strip_tags($roomsinfojson),"Bathroom"));
$roomsinfoshower = (substr_count(strip_tags($roomsinfojson),"Shower"));
$facilitiesparking = (substr_count(strip_tags($facilitiesjson),"Parking"));
$facilitiesgarden = (substr_count(strip_tags($facilitiesjson),"Garden"));
$totalbathrooms = $roomsinfobathroom + $roomsinfoshower;
$totalimages = count($photos);
echo '
<div class="col-property-box col-property-box-1-3">
<div class="owl-property-box">';
$i=0; foreach ($photos as $data) { if($i==4) break; echo '<div class="property-grid-box-picture" style="background: url('. $data->PhotoUrl .') center center;"></div>'; $i++; };
echo '</div>
<div class="property-grid-box">
'. $addressline1 .'
<p class="property-grid-box-text">'. limit_words($description,19) .'...</p>
<div class="property-grid-box-price">
<div class="section group">
<div class="col col-property-box-1-2 property-grid-box-price-border-right">
<div class="property-grid-box-price-top">£'. $weekrentrounded.'pp</div> <div class="property-grid-box-price-under">Weekly</div>
</div>
<div class="col col-property-box-1-2">
<div class="property-grid-box-price-top">£'. $monthrentrounded .'pp</div> <div class="property-grid-box-price-under">Monthly</div>
</div>
</div>
</div>
<div class="property-grid-box-icon-box">
<div class="section group">
<div class="col col-1-3-border no-left-border">
<span class="property-grid-box-number-icon"><center><i class="fa fa-bed"></i></center><div class="property-grid-box-number-text">'. $rooms .'</div></span>
</div>
<div class="col col-1-3-border">
<span class="property-grid-box-number-icon"><center><i class="flaticon-shower5"></i></center><div class="property-grid-box-number-text">'. $totalbathrooms .'</div></span>
</div>
<div class="col col-1-3-border">
<span class="property-grid-box-number-icon"><center><i class="flaticon-beds12"></i></center><div class="property-grid-box-number-text">'. $totalimages .'</div></span>
</div>
</div>
</div>
</div>
</div>
';
}
}
function limit_words($string, $word_limit)
{
$words = explode(" ",$string);
return implode(" ",array_splice($words,0,$word_limit));
}
?>
you can use usort function .. so you get the sorted result
Read more on php
You can put your messages data to temporary array along with calculated weekrent and then sort desc by weekrent value with usort
if($values != '')
{
$arrayForSort = array();
foreach ($values->SearchPropertiesResult->PropertyInfo as $message) {
$rent = $message->Rent;
$rooms = $message->MaxTenants;
$extractnumbers = ereg_replace("[^0-9]", "", $rent);
$monthrent = ($extractnumbers) / $rooms;
$monthrentrounded = number_format(($monthrent/100),2);
$weekrent = ($monthrentrounded) * 12 / 52;
$arrayForSort[] = array('weekrent' => $weekrent, 'message' => $message);
}
usort($arrayForSort, function($a, $b) {
if ($a['weekrent'] == $b['weekrent']) {
return 0;
}
return ($a['weekrent'] > $b['weekrent']) ? -1 : 1;
});
foreach ($arrayForSort as $item)
{
$message = $item['message'];
// Your code here to proper process the message ...