how to set a secondary axis for this series?
$series = new PHPExcel_Chart_DataSeries(
PHPExcel_Chart_DataSeries::TYPE_LINECHART, // plotType
PHPExcel_Chart_DataSeries::GROUPING_CLUSTERED, // plotGrouping
$chartOrder, // plotOrder
$chartLables, // plotLabel
$chartCategories, // plotCategory
$chartValues // plotValues
);
$series->setPlotDirection(PHPExcel_Chart_DataSeries::DIRECTION_COL);
$plotarea = new PHPExcel_Chart_PlotArea(null, array($series));
$legend = new PHPExcel_Chart_Legend(PHPExcel_Chart_Legend::POSITION_BOTTOM, null, false);
$chart = new PHPExcel_Chart(
"chart_$topRow_$leftColumn", // name
null, // title
$legend, // legend
$plotarea, // plotArea
true, // plotVisibleOnly
0, // displayBlanksAs
null, // xAxisLabel
null // yAxisLabel
);
$chart->setTopLeftPosition('A1');
$chart->setBottomRightPosition(K12');
$objWorksheet->addChart($chart);
You can't, secondary Y-axes are not yet supported.... remember that charting is still considered experimental, and chart functionality is still being built
Related
I'm storing page code in database so that the admin will be able to rearrange sections and edit content.
I'm organizing all the code in the controller before sending a response that has all the code for the page.
I've seen this question: How to render Twig template from database in symfony2 and it is not the same as the one I'm asking
I'd like to be able to have a code in the database like "{% include 'tmp/header.html.twig' %} and have the twig run that.
So far twig gives an error that 'Template "tmp/header.html.twig" is not defined in __string_template__59b79c6909e3d467bcae264ee8ebdf3697db94a9096b7457d0c43bac9c0d8fb1 at line 345.'
Here is a test page:
/**
* #Route("/test/for/conservatoire/of/music", name="test")
*/
public function test(PageRepository $pageRepo, SectionRepository $sectionRepo): Response
{
// this page
$page = $pageRepo->findOneByName('about');
// html is now empty
$html = "<html><body><h1>Hello pal</h1></body></html>";
// THIS IS THE PROBLEMATIC PART
$html .= '{% include("tmp/header.html.twig") %}';
$variables = ['this' => 'that'];
$loader = new \Twig\Loader\ArrayLoader([
'test.html.twig' => '{{ include(template_from_string(html)) }}',
]);
$twig = new \Twig\Environment($loader);
$profile = new \Twig\Profiler\Profile();
$context = new Routing\RequestContext();
$router = $this->get('router');
$routes = $router->getRouteCollection();
$generator = new Routing\Generator\UrlGenerator($routes, $context);
$versionStrategy = new StaticVersionStrategy('v1');
$defaultPackage = new Package($versionStrategy);
$namedPackages = [
'img' => new UrlPackage('http://img.example.com/', $versionStrategy),
'doc' => new PathPackage('/somewhere/deep/for/documents', $versionStrategy),
];
$packages = new Packages($defaultPackage, $namedPackages);
// this enables template_from_string function
$twig->addExtension(new \Twig\Extension\StringLoaderExtension());
// this enables debug
$twig->addExtension(new \Twig\Extension\DebugExtension());
// this enables {{asset('somefile')}}
$twig->addExtension(new AssetExtension($packages));
// this enables {{path('someroute')}}
$twig->addExtension(new RoutingExtension($generator));
// I NEED ONE THAT ENABLES {% include('tmp/header.html.twig') %}
// so far I'm getting this error:
// Template "tmp/header.html.twig" is not defined in __string_template__59b79c6909e3d467bcae264ee8ebdf3697db94a9096b7457d0c43bac9c0d8fb1 at line 345.
$response = new Response();
$response->setContent($twig->render('test.html.twig', ['html' => $html]));
$response->setStatusCode(Response::HTTP_OK);
// sets a HTTP response header
$response->headers->set('Content-Type', 'text/html');
// return response
return $response;
}
It doesn't work even when the include is added separately like so:
$loader = new \Twig\Loader\ArrayLoader([
'test.html.twig' => '{% include("tmp/header.html.twig") %}{{ include(template_from_string(html)) }}',
]);
Error: Template "tmp/header.html.twig" is not defined in test.html.twig at line 1.
I finally found out the way to do it.
I only needed to add the page to be included to the ArrayLoader like so:
use Symfony\Component\Routing;
use Symfony\Component\Asset\VersionStrategy\StaticVersionStrategy;
use Symfony\Component\Asset\Package;
use Symfony\Component\Asset\UrlPackage;
use Symfony\Component\Asset\PathPackage;
use Symfony\Component\Asset\Packages;
use Symfony\Bridge\Twig\Extension\AssetExtension;
use Symfony\Bridge\Twig\Extension\RoutingExtension;
/**
* #Route("/test/for/conservatoire/of/music", name="test")
*/
public function test(PageRepository $pageRepo, SectionRepository $sectionRepo): Response
{
// this page
$page = $pageRepo->findOneByName('about');
// html is now empty
$html = "<html><body><h1>Hello from test</h1></body></html>";
// THIS WAS THE PROBLEMATIC PART
$html .= '{{ include("header.html.twig") }}';
$variables = ['this' => 'that'];
// HERE IS THE SOLUTION -> ADD THE NEW TEMPLATE TO THE ARRAY LOADER
$loader = new \Twig\Loader\ArrayLoader([
'test.html.twig' => '{{ include(template_from_string(html)) }}',
'header.html.twig' => "<html><body><h1>Hello from {{name}}</h1></body></html>",
]);
$twig = new \Twig\Environment($loader);
$profile = new \Twig\Profiler\Profile();
$context = new Routing\RequestContext();
$router = $this->get('router');
$routes = $router->getRouteCollection();
$generator = new Routing\Generator\UrlGenerator($routes, $context);
$versionStrategy = new StaticVersionStrategy('v1');
$defaultPackage = new Package($versionStrategy);
$namedPackages = [
'img' => new UrlPackage('http://img.example.com/', $versionStrategy),
'doc' => new PathPackage('/somewhere/deep/for/documents', $versionStrategy),
];
$packages = new Packages($defaultPackage, $namedPackages);
// this enables template_from_string function
$twig->addExtension(new \Twig\Extension\StringLoaderExtension());
// this enables debug
$twig->addExtension(new \Twig\Extension\DebugExtension());
// this enables {{asset('somefile')}}
$twig->addExtension(new AssetExtension($packages));
// this enables {{path('someroute')}}
$twig->addExtension(new RoutingExtension($generator));
$response = new Response();
$response->setContent($twig->render('test.html.twig', ['html' => $html, 'name' => 'header']));
$response->setStatusCode(Response::HTTP_OK);
// sets a HTTP response header
$response->headers->set('Content-Type', 'text/html');
// return response
return $response;
}
Only related reference for the same I found with accepted by few people is the below mentioned code but there is no session stored in options table with the following key '_wc_session_'.$user_id
function add_products_programmatically($user_id) {
// Get the current session data and saved cart
$wc_session_data = get_option('_wc_session_'.$user_id);
// Get the persistent cart
$full_user_meta = get_user_meta($user_id,'_woocommerce_persistent_cart', true);
// Create a new WC_Cart instance and add products programmatically
$cart = get_new_cart_with_products();
// If there is a current session cart, overwrite it with the new cart
if($wc_session_data) {
$wc_session_data['cart'] = serialize($cart->cart_contents);
update_option('_wc_session_'.$user_id, $wc_session_data);
}
// Overwrite the persistent cart with the new cart data
$full_user_meta['cart'] = $cart->cart_contents;
update_user_meta($user_id, '_woocommerce_persistent_cart', $full_user_meta);
}
After a lot of research to the way woo-commerce uses persistent cart I have created a working solution.
function woocomm_add_to_cart($param) {
global $wpdb;
$user_id = $param['user_id'];
$objProduct = new WC_Session_Handler();
$wc_session_data = $objProduct->get_session($user_id);
// Get the persistent cart may be _woocommerce_persistent_cart can be in your case check in user_meta table
$full_user_meta = get_user_meta($user_id,'_woocommerce_persistent_cart_1',true);
// create new Cart Object
$cartObj = new WC_Cart();
// Add old cart data to newly created cart object
if($full_user_meta['cart']) {
foreach($full_user_meta['cart'] as $sinle_user_meta) {
$cartObj->add_to_cart( $sinle_user_meta['product_id'], $sinle_user_meta['quantity'] );
}
}
// Add product and quantities coming in request to the new cart object
if($param['products']){
foreach($param['products'] as $prod) {
$cartObj->add_to_cart( $prod['product_id'], $prod['quantity'] );
}
}
$updatedCart = [];
foreach($cartObj->cart_contents as $key => $val) {
unset($val['data']);
$updatedCart[$key] = $val;
}
// If there is a current session cart, overwrite it with the new cart
if($wc_session_data) {
$wc_session_data['cart'] = serialize($updatedCart);
$serializedObj = maybe_serialize($wc_session_data);
$table_name = 'wp_woocommerce_sessions';
// Update the wp_session table with updated cart data
$sql ="UPDATE $table_name SET 'session_value'= '".$serializedObj."', WHERE 'session_key' = '".$user_id."'";
// Execute the query
$rez = $wpdb->query($sql);
}
// Overwrite the persistent cart with the new cart data
$full_user_meta['cart'] = $updatedCart;
update_user_meta($user_id, '_woocommerce_persistent_cart_1', $full_user_meta);
$response = [
'status' => true,
'message' => 'Products successfully added to cart'
];
return rest_ensure_response($response);
}
Here is the Request json data for the Rest API:
{"user_id": 15, "products" : [{"product_id":"81","quantity":"0.5"},{"product_id":"1817","quantity":"0.5"}]}
I have done some changes in previous code as this code is not working with me independently.
I have created Rest API for my Vue.js application.
Create route and make function and paste this code use as add to
cart
This can also update the session of user on web side when you add
from mobile end
if (checkloggedinuser()) {
include_once WC_ABSPATH . 'includes/wc-cart-functions.php';
include_once WC_ABSPATH . 'includes/wc-notice-functions.php';
include_once WC_ABSPATH . 'includes/wc-template-hooks.php';
global $wpdb;
$user_id = get_current_user_id();
WC()->session = new WC_Session_Handler();
WC()->session->init();
$wc_session_data = WC()->session->get_session($user_id);
// Get the persistent cart may be _woocommerce_persistent_cart can be in your case check in user_meta table
$full_user_meta = get_user_meta($user_id,'_woocommerce_persistent_cart_1',true);
WC()->customer = new WC_Customer( get_current_user_id(), true );
// create new Cart Object
WC()->cart = new WC_Cart();
// return $full_user_meta;
// Add old cart data to newly created cart object
if($full_user_meta['cart']) {
foreach($full_user_meta['cart'] as $sinle_user_meta) {
WC()->cart->add_to_cart( $sinle_user_meta['product_id'], $sinle_user_meta['quantity'] );
}
}
WC()->cart->add_to_cart( $request['product_id'], $request['quantity'] );
$updatedCart = [];
foreach(WC()->cart->cart_contents as $key => $val) {
unset($val['data']);
$updatedCart[$key] = $val;
$updatedCart[$key]['file'] = "hello file herer";
}
// If there is a current session cart, overwrite it with the new cart
if($wc_session_data) {
$wc_session_data['cart'] = serialize($updatedCart);
$serializedObj = maybe_serialize($wc_session_data);
$table_name = 'wp_woocommerce_sessions';
// Update the wp_session table with updated cart data
$sql ="UPDATE $table_name SET 'session_value'= '".$serializedObj."', WHERE 'session_key' = '".$user_id."'";
// Execute the query
$rez = $wpdb->query($sql);
}
// Overwrite the persistent cart with the new cart data
$full_user_meta['cart'] = $updatedCart;
update_user_meta($user_id, '_woocommerce_persistent_cart_1', $full_user_meta);
return array(
'success' => false,
'responsecode' => 403,
"message" => "Products successfully added to cart",
"data" => [],
);
}else{
return array(
'success' => false,
'responsecode' => 403,
"message" => "Please Logged In to get Data",
"data" => [],
);
}
this is the simplest solution:
if ( defined( 'WC_ABSPATH' ) ) {
// WC 3.6+ - Cart and other frontend functions are not included for REST requests.
include_once WC_ABSPATH . 'includes/wc-cart-functions.php';
include_once WC_ABSPATH . 'includes/wc-notice-functions.php';
include_once WC_ABSPATH . 'includes/wc-template-hooks.php';
}
if ( null === WC()->session ) {
$session_class = apply_filters( 'woocommerce_session_handler', 'WC_Session_Handler' );
WC()->session = new $session_class();
WC()->session->init();
}
if ( null === WC()->customer ) {
WC()->customer = new WC_Customer( get_current_user_id(), true );
}
if ( null === WC()->cart ) {
WC()->cart = new WC_Cart();
// We need to force a refresh of the cart contents from session here (cart contents are normally refreshed on wp_loaded, which has already happened by this point).
WC()->cart->get_cart();
}
WC()->cart->add_to_cart($prod['product_id'], $prod['quantity']);
reference from the link:
https://barn2.com/managing-cart-rest-api-woocommerce-3-6/
Hi friends i'am using maddhatter fullcalendar in my project laravel 5.6,when i fetch my data in calendar its work by data contains format y-m-d but when i change my format to datetime my camlendar does not display anything this my code:
$events = Agenda::where('code_commercial', $code)->get();
$event_list = [];
foreach ($events as $event) {
$event_list[] = Calendar::event(
$event->description,
true,
date_format(date_create($event->date_debut), "Y-m-d H:i:s"),
date_format(date_create($event->date_fin), "Y-m-d H:i:s")
// new \DateTime($event->date_debut),
// new \DateTime($event->date_fin),
// Carbon::createFromFormat('Y-m-d H:i:s', $event->date_debut)->toDateTimeString(),
// Carbon::createFromFormat('Y-m-d H:i:s', $event->date_fin)->toDateTimeString()
);
}
and this is my configuration for fullcalendar :
$calendar_details = Calendar::addEvents($event_list, [ //set custom color
fo this event
'color' => '#800',
])->setOptions([ //set fullcalendar options
'firstDay' => 1,
'selectable' => true,
'defaultView' => 'agendaWeek',
'allDay' => false,
'slotLabelFormat' => 'HH:mm:ss',
'editable' => true,
'eventLimit' => true,
// 'minTime' => '07:00:00',
// 'maxTime' => '22:00:00',
// 'slotDuration' => '01:30:00',
])
please any help thanks for you
I'm doing an entity reference to fetch a node from under a specific content. I'm looking to how I can render the entity reference function I've just created to my region.html.twig template. Below is a snippet of the code I'm currently working on
// Page region level pre-processing
function iom_preprocess_region(&$variables) {
if ($node = \Drupal::routeMatch()->getParameter('node')) {
$variables['content_type'] = $node->bundle();
}
$elements = $variables['elements'];
if (array_key_exists('#entity', $elements)) {
$region = $elements['#region'];
$entity = $elements['#entity'];
$bundle = _overrideBundle($entity->bundle());
preprocess($region, 'region', $entity, $variables);
preprocess($region."_{$bundle}", 'region', $entity, $variables);
}
}
function _preprocess_country_regional_offices_node($entity, &$variables) {
$entityStorage = \Drupal::service('entity_type.manager')->getStorage('node');
$regionalOffices = \Drupal::service('entity.query')
->get('node')
->condition('status', 1, '=')
->condition('type', 'regional_office')
->condition('field_primary_offices', '1')
->sort('created', 'DESC')
->execute();
$regionalOfficeEntities = $entityStorage->loadMultiple($regionalOffices);
$variables['regional_office'] = $regionalOfficeEntities;
}
I'd probably do this using an exposed block, but if you need to do it in code for a specific reason then..
$output = render(
\Drupal::entityTypeManager()
->getViewBuilder('node')
->view($node, 'teaser')
);
How can I take a result as an array from PagerFanta in Symfony2.1.1 ?
$adapter = new \Pagerfanta\Adapter\DoctrineORMAdapter($query);
$pager = new \Pagerfanta\Pagerfanta($adapter);
$pager->setMaxPerPage(45);
$data = $pager->getCurrentPageResults();
Results of print_r($data);
ArrayIterator Object
(
[storage:ArrayIterator:private] => Array
(
[0] => Trucking\MainBundle\Entity\Sparcs Object
(
[id:Trucking\MainBundle\Entity\Sparcs:private] => 77940
[container:Trucking\MainBundle\Entity\Sparcs:private] => MEDUUUU
...
...
...
I want to get results as getQuery->getArrayResult();
I will Do the query
$array = $query->getResult(Query::HYDRATE_ARRAY);
Use the ArrayAdapter
$adapter = new ArrayAdapter($array);
$pagerfanta = new Pagerfanta($adapter);
You must to set hydratation mode to Query from the adapter:
$adapter = new DoctrineORMAdapter($queryBuilder);
$adapter->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY);
$pager = new Pagerfanta($adapter);