i am using the following code for weekly calendar it shows like enter image description here
function tribe_events_get_days_of_week( $format = null ) {
switch ( $format ) {
case 'min' :
$days_of_week = Tribe__Events__Main::instance()->daysOfWeekMin;
break;
case 'short' :
$days_of_week = Tribe__Events__Main::instance()->daysOfWeekShort;
break;
default:
$days_of_week = Tribe__Events__Main::instance()->daysOfWeek;
break;
}
$start_of_week = get_option( 'start_of_week', 0 );
for ( $i = 0; $i < $start_of_week; $i ++ ) {
$day = $days_of_week[ $i ];
unset( $days_of_week[ $i ] );
$days_of_week[ $i ] = $day;
}
return apply_filters( 'tribe_events_get_days_of_week', $days_of_week );
}
but, i want to display in month wise. how can i change my existing code.
Related
I have a query that receive some array parameters without any ideas how rows there is. It must return contents with all filters (AND clause), and one or more categories (OR clause).
I can't get results I'd like because parentheses are not a the good place. I should got this SQL rendering:
WHERE (
f3_.idfilter = '87'
AND f5_.idfilter = '90'
AND f7_.idfilter = '154'
AND f9_.idfilter = '165'
)
AND (
c0_.content_category_idcontent_category = 1
OR c0_.content_category_idcontent_category = 3
)
and got this instead:
WHERE (
(
f3_.idfilter = '87'
AND f5_.idfilter = '90'
AND f7_.idfilter = '154'
AND f9_.idfilter = '165'
AND c0_.content_category_idcontent_category = 1
)
OR c0_.content_category_idcontent_category = 3
)
My code:
public function getContentByFiltersAjax($categs, $filters, $offset, $limit) {
$filtersTab = explode(',', $filters);
$query = $this->createQueryBuilder('c');
for ($i = 1; $i <= count($filtersTab); $i++) {
$query = $query
->leftJoin('c.filterfilter', 'f' . $i)
->andWhere('f' . $i . '.idfilter = :filter_idfilter' . $i)
->setParameter('filter_idfilter' . $i, $filtersTab[$i - 1]);
}
$categsTab = explode(',', $categs);
if(sizeof($categsTab) > 1) {
$expr = $query->expr();
$categsTab = explode(',', $categs);
foreach ($categsTab as $key => $value) {
if($key === 0){
$query->andWhere($expr->eq('c.contentCategorycontentCategory', $value));
} else {
$query->orWhere($expr->eq('c.contentCategorycontentCategory', $value));
}
}
} else {
$query
->andWhere('c.contentCategorycontentCategory = :category')
->setParameter('category', $categs);
}
$query
->andWhere('c.status = :status')
->setParameter('status', 'publie');
$query->orderBy('editor.plan', 'DESC');
$query->addOrderBy('c.creationDate', 'DESC');
$query
->setFirstResult($offset)
->setMaxResults($limit);
$result = $query->distinct()->getQuery()->getResult();
return $result;
}
You put the orWhere's inside 1 andWhere like this:
$query->andWhere(
$query->expr->orX(
$query->expr->eq('c.contentCategorycontentCategory', $value1),
$query->expr->eq('c.contentCategorycontentCategory', $value2)
)
);
Or in your foreach loop:
$orX = $query->expr->orX();
foreach ($categsTab as $value) {
$orX->add($query->expr->eq('c.contentCategorycontentCategory', $value));
}
$query->andWhere($orX);
This question already has answers here:
Replace woocommerce_add_order_item_meta hook in Woocommerce 3.4
(1 answer)
Woocommerce: Which hook to replace deprecated "woocommerce_add_order_item_meta"
(8 answers)
Closed 3 years ago.
Hello I was using woocommerce_add_order_item_meta to add some additional information for order item. After woocommerce update I got error on ordar pay page. I researched that why it happens. I found this article. and I understood why I'm getting error. I changed action hook name but still get errors. What should I do ?
function addBizDays($item_id, $cart_item ,$start, $add){
$start =current_time( 'mysql' );
$add = get_post_meta( $cart_item[ 'product_id' ], 'dp_kargolanma_suresi', true );
$d = new DateTime($start );
$t = $d->getTimestamp();
// loop for X days
for($i=0; $i<$add; $i++){
// add 1 day to timestamp
$addDay = 86400;
// get what day it is next day
$nextDay = date('w', ($t+$addDay));
// if it's Saturday or Sunday get $i-1
if($nextDay == 0 || $nextDay == 6) {
$i--;
}
// modify timestamp, add 1 day
$t = $t+$addDay;
}
$d->setTimestamp($t);
$teslim_tarihi = $d->format( 'd-m-Y' ). "\n";
$desiveyakg = ( $cart_item['quantity'] * $cart_item['data']->get_weight());
$kargosinifi = $cart_item['data']->get_shipping_class();
wc_update_order_item_meta( $item_id, 'En Gec Kargolanma Tarihi', $teslim_tarihi );
wc_update_order_item_meta( $item_id, '_desi_kg', $desiveyakg );
wc_update_order_item_meta( $item_id, '_alici_onay_durumu', 'Onay Bekliyor' );
if($cart_item['quantity'] >= 100)
{
wc_update_order_item_meta( $item_id, '_kargo_sinifi', 'ucretsiz-kargo' );
}
else{
wc_update_order_item_meta( $item_id, '_kargo_sinifi', $kargosinifi );
}
}
add_action( 'woocommerce_checkout_create_order_line_item', 'addBizDays', 10, 5 );
You need to change more than just the hook… The hooked function arguments are wrong in your code and the way to updated data has changed too. Try the following:
add_action( 'woocommerce_checkout_create_order_line_item', 'add_business_days', 10, 4 );
function add_business_days( $order_item, $cart_item_key, $cart_item, $order ){
$now = current_time( 'mysql' );
$add = $cart_item['data']->get_meta( 'dp_kargolanma_suresi' );
$d = new DateTime( $now );
$t = $d->getTimestamp();
$oneDay = 86400;
$nextDay = date('w', ($t + $oneDay));
// loop for X days
for( $i = 0; $i < $add; $i++ ) {
// if it's Saturday or Sunday get $i-1
if($nextDay == 0 || $nextDay == 6) {
$i--;
}
// modify timestamp, add 1 day
$t = $t + $oneDay;
}
$d->setTimestamp($t);
$teslim_tarihi = $d->format( 'd-m-Y' ). "\n";
$desiveyakg = ( $cart_item['quantity'] * $cart_item['data']->get_weight() );
$kargosinifi = $cart_item['data']->get_shipping_class();
$order_item->update_meta_data( 'En Gec Kargolanma Tarihi', $teslim_tarihi );
$order_item->update_meta_data( '_desi_kg', $desiveyakg );
$order_item->update_meta_data( '_alici_onay_durumu', 'Onay Bekliyor' );
if($cart_item['quantity'] >= 100) {
$order_item->update_meta_data( '_kargo_sinifi', 'ucretsiz-kargo' );
} else {
$order_item->update_meta_data( '_kargo_sinifi', $kargosinifi );
}
}
It should work…
My website is not working properly. I get this error:
/var/www/vhosts/xyz.com.tr/httpdocs/wp-includes/wp-db.php on line 1890
Following is the code on those lines. What is the problem in this code that it throws out an error?
// Return number of rows affected
$return_val = $this->rows_affected;
} else {
$num_rows = 0;
if ( $this->use_mysqli && $this->result instanceof mysqli_result ) {
**while ( $row = mysqli_fetch_object( $this->result ) ) {
$this->last_result[$num_rows] = $row;
$num_rows++;**
}
} elseif ( is_resource( $this->result ) ) {
while ( $row = mysql_fetch_object( $this->result ) ) {
$this->last_result[$num_rows] = $row;
$num_rows++;
}
}
// Log number of rows the query returned
// and return number of rows selected
$this->num_rows = $num_rows;
$return_val = $num_rows;
}
return $return_val;
}
/**
I'm trying to get the ago datetime using KnpTimeBundle . As the documentaion says , i need to use the helper class to acess to diff() function :
Take a look to my controller.php :
use Knp\Bundle\TimeBundle\Templating\Helper as Helper;
/**
* #Route("/test",name="test")
* #Method({"GET","POST"})
*/
public function testAction(Request $request){
$date = new \DateTime("now");
$h=new Helper();// here i got a 404 error
$ago=$h->diff($date);
return $this->render('test.html.twig', array());
}
But calling the Helper class by this way didnt work for me , can any one give me the right way to do the trick .
I just Create my own service no need for the bundle :
<?php
namespace AppBundle\Services;
class Helpers {
public function pluralize( $count, $text )
{
return $count . ( ( $count == 1 ) ? ( " $text" ) : ( " ${text}s" ) );
}
function ago( $datetime )
{
$interval = date_create('now')->diff( $datetime );
$suffix = ( $interval->invert ? ' ago' : '' );
if ( $v = $interval->y >= 1 ) return $this->pluralize( $interval->y, 'year' ) . $suffix;
if ( $v = $interval->m >= 1 ) return $this->pluralize( $interval->m, 'month' ) . $suffix;
if ( $v = $interval->d >= 1 ) return $this->pluralize( $interval->d, 'day' ) . $suffix;
if ( $v = $interval->h >= 1 ) return $this->pluralize( $interval->h, 'hour' ) . $suffix;
if ( $v = $interval->i >= 1 ) return $this->pluralize( $interval->i, 'minute' ) . $suffix;
return $this->pluralize( $interval->s, 'second' ) . $suffix;
}
in my services.yml:
services:
app.helpers:
class: AppBundle\Services\Helpers
arguments: [ "#doctrine.orm.entity_manager" , "#service_container" ]
then i just called :
$helpers = $this->get("app.helpers");
$helpers->ago($date);
I have a columnrange graph and want to define the color of a single bar line. If you see the second set in the picture. depending on a certain condition I would liek to change this to different color. $schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to); if endate is not greater than today then change color to red.
How would I do this?
in view
$('#container').highcharts({
'chart':{
'type':'columnrange',
'inverted':true,
},
'exporting':{
'enabled':true
},
'title':{
'text':'Projects incomplete in 2013'
},
'xAxis':{
'categories':<?=$cat?>
},
'yAxis':{
'title':'Date',
'type':'datetime',
'dateTimeLabelFormats':{
'month':'%b'
},
'min':Date.UTC(2013,00,01)
},
'tooltip':{
formatter: function(){
return '<b>' +this.series.name + ':</b> '+ Highcharts.dateFormat('%e %b, %Y', this.point.low) + ' - ' + Highcharts.dateFormat('%e %b, %Y', this.point.high) +'<br/>' ;
}
},
'legend':{
'enabled':false
},
'series':[
{
'name':'Start - End',
'data':<?=$data?>
},
{
'name':'Forecast',
'data':<?=$schedule?>,
'color': 'green'
},
{
'name':'Actual',
'data':<?=$complete?>,
'color': 'yellow'
}
]
});
In my controller I have
public function actionGraph(){
$command = Yii::app()->db->createCommand("
SELECT
view_webprojectreport.PROJECT,
view_webprojectreport.StartDATE,
view_webprojectreport.ProjectEndDate,
view_webprojectreport.PERCENT,
view_webprojectreport.ASAAREA
FROM
view_webprojectreport
WHERE
view_webprojectreport.StartDATE >= '2013' AND
view_webprojectreport.ProjectEndDate IS NOT NULL AND
view_webprojectreport.PERCENT < 100
ORDER BY
view_webprojectreport.PERCENT DESC
")->queryAll();
$series = array();
$cat = array();
$totalLength = array();
$schedule = array();
$complete = array();
foreach ($command as $key => $model) {
$cat[] = $model['PROJECT'];
$date_from = (strtotime($model['StartDATE']) + 1*86400)*1000;
$date_to = (strtotime($model['ProjectEndDate']) + 1*86400)*1000;
$totalLength[] = array($date_from,$date_to);
$today = time();
$startdate = strtotime($model['StartDATE']);
$enddate = strtotime($model['ProjectEndDate']);
$diff_total = $enddate - $startdate;
$diff_today = $today - $startdate;
$percentage_date=round(($diff_today/$diff_total)*100,2);
$duration = ( ((strtotime($model['ProjectEndDate']) + 1*86400)*1000) - ((strtotime($model['StartDATE']) + 1*86400)*1000) );
$burn = ((time() )*1000) - ((strtotime($model['StartDATE']) + 1*86400)*1000);
$pBurned = $burn/$duration;
$time = $time = strtotime( ($date_from + $pBurned) );
//echo date('Y-m-d') . " : " . date('Y-m-d',strtotime($model['ProjectEndDate'])) . "<br>";
// place check for calculating if project end date is in past
$schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to);
$percentage_to_get = round((float)$model['PERCENT'],2);
$percentage_of_days = ((int)$model['PERCENT'] == 0)? 0 : floor($diff_total/100*$percentage_to_get);
//echo date('Y-m-d', $startdate) . " : " . date('Y-m-d', $startdate + $percentage_of_days ) . "<br>";
//echo $startdate . " : " . ($startdate + $percentage_of_days) . "<br>";
$percentComplete = (($startdate + $percentage_of_days)+ 1*86400)*1000;
$complete[] = array($date_from,$percentComplete);
}
$series = array("series"=>array(
array(
'name'=>'Start - End',
'data'=>$totalLength
),
array(
'name'=>'Forecast',
'data'=>$schedule,
'color'=> 'green'
),
array(
'name'=>'Actual',
'data'=>$complete,
'color'=> 'yellow'
)
));
print_r($series);
$this->render('graph',array(
'cat'=>json_encode($cat),
"data"=>json_encode($totalLength),
"schedule"=>json_encode($schedule),
"complete"=>json_encode($complete),
"series"=>json_encode($series)
));
}
output of schedule
[[1357689600000,1372064004000],[1360972800000,1.3686588e+12],[1359158400000,1372064004000],[1.3630464e+12,1365721200000],[1359417600000,1372064004000],[1.3709916e+12,1372064004000],[1.3686588e+12,1372064004000],[1.3681404e+12,1372064004000],[1.3699548e+12,1372064004000],[1366930800000,1372064004000]]
How would I incorporate the color in this?
$schedule[] = array($date_from, ( date('Y-m-d',strtotime($model['ProjectEndDate'])) > date('Y-m-d') )? $today*1000 : $date_to);
I have found http://jsfiddle.net/Q2JMF/2/ and trying to implement but not working. graph displays nothing
My example on jsfiddle http://jsfiddle.net/shorif2000/z4HXX/2/
Your point should be object like :
{
y:10,
color: 'red'
}
So data should looks like:
data:[{
y:10,
color: 'red'
},4,5,6,7,7]
How to prepare correct structure:
http://php.net/manual/en/function.json-encode.php