Creating a bar chart using ObHighchartsBundle - symfony

I want to create using ObHighchartsBundle a bar chart(image below) but I couldnt do that the chart is rendered empty !! the problem is in the type of the chart bar
is that even possible using the ObHighchartsBundle
My code:
chartingController .php :
public function productionEst($date,$liste1,$liste2,$liste3)
{
$ob = new Highchart();
$dates = $date;
$production = array(
$liste1,
$liste2,
$liste3
);
$ob->chart->type('bar');
$ob->chart->renderTo('container'); // The #id of the div where to render the chart
$ob->plotOptions->bar(
array(
'dataLabels' => array(
'enabled' => true
)
)
);
$ob->title->text('Production);
$ob->xAxis->categories($dates );
$ob->xAxis->title(array('text' => "Horizontal axis title"));
$ob->yAxis->title(array('text' => "Vertical axis title"));
$ob->legend->legend(
array(
'layout' => 'vertical',
'align'=> 'right',
'verticalAlign' =>'top',
'floating'=> true,
'borderWidth' =>1,
'shadow' =>true
)
);
$ob->series($production);
return $ob;
}
index.twig :
<div id="container" style="min-width: 200px; height: 600px; margin: 0 auto"></div>
<script type="text/javascript">
{{ chart(container) }}
</script>

Related

Get the top most menu item of a page menu using the page id - wordpress

I want to be able to fetch the label of the topmost menu item of a child menu with the child menu page id.
For ex: - I have the page id of test page. So, I want to fetch the text L1 which is the topmost parent menu of test menu
Note: test page is not the current page - I have only its page id present.
I used the below code to solve my problem.
function get_l1_menu_label( $page_id, $menu = 'primary-menu' ) {
//get menu
$all_menus = new WP_Query( [
'post_type' => [ 'nav_menu_item' ],
'meta_key' => '_menu_item_object_id',
'meta_value' => $page_id, // page id here
'tax_query' => [
[
'taxonomy' => 'nav_menu',
'field' => 'slug',
'terms' => $menu, //menu slug here
]
],
'fields' => 'ids'
] );
$current_page_menu_id = $all_menus->posts[0];
if ( !$current_page_menu_id ) {
//looks like the page is not menu
return '';
}
$parent_menu_id = (int) get_parent_menu_label_recursion($current_page_menu_id);
//get the custom nav title set in menu admin
$title = get_the_title( $parent_menu_id );
if ( $title !== '' ) {
return $title;
} else {
//the page orginal title is the label
$parent_menu_page_id = get_post_meta( $parent_menu_id, '_menu_item_object_id', true );
return get_the_title( $parent_menu_page_id );
}
}
//recursive function to fetch a top most parent id in nav menu
function get_parent_menu_label_recursion($menu_id) {
$parent_menu_id = (int) get_post_meta( $menu_id, '_menu_item_menu_item_parent', true );
if ( $parent_menu_id !== 0 ) {
//the parent exist - send the parent menu
return get_parent_menu_label_recursion($parent_menu_id);
} else {
//the menu sent to this function is the top most menu
return $menu_id;
}
}
Hope this helps someone.

Is it possible to upload a custom image or use the default image provided by a Drupal Theme, such as for the Logo Image?

I've made a custom theme for Drupal 8. Now I want to provide a banner image for the front page. I wouldn't like to create a custom content type Banner, then create a Banner-node and promote it to the front page, because the promoted node-teasers are arranged inside a grid-view in my theme (together with other node-teasers of other content types, such as Article) and when I do it I do not get what I expect. So it is totally not what I would like to do.
So first I decided to provide a custom banner_image field inside my_custom_theme.theme file (by implementing the appropriate hooks):
function my_custom_theme_preprocess_page(&$variables)
{
$variables['banner_image'] = theme_get_setting(‘banner_image’);
}
function my_custom_theme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state)
{
$form['my_custom_theme_settings']['website'] = array(
'#type' => 'details',
'#title' => t('Website Settings'),
);
$form['my_custom_theme_settings']['website']['banner_image'] = array(
'#type' => 'managed_file',
'#upload_location' => 'public://media/branding/',
'#upload_validators' => array(
'file_validate_extensions' => array('gif png jpg jpeg'),
),
'#default_value' => theme_get_setting('banner_image'),
);
}
And I've got following result (Admin Panel):
It means: uploading a banner image works. However, I think I have done everything to get the image on my front page, without any success (the banner image doesn't show up).
Therefore I overrode the page--front.html.twig file:
<...>
{{ banner_image }}
<...>
No image, no Url, nothing (The image has been correctly uploaded to the appropriate location, the theme has been uninstalled, the cache has been cleared, and the theme has been reinstalled again).
What am I doing wrong? If it's impossible to do it that way, is there a way just to copy the same functionality of logo_image and use it for my banner_image?
1) By defining the banner_image settings in the install\my_theme_settings.yml file:
features:
logo: true
banner: true
2) By initializing a checked checkbox, such as for logo_image:
3) By showing the upload-fields, such as for logo_image, when the checkbox is unchecked:
I could solve it this way:
1) my_custom_theme.theme file:
function my_custom_theme_preprocess_page(&$variables)
{
$variables['banner_image_url'] = theme_get_setting('banner_image_url');
$variables['banner_image'] = my_custom_theme_get_banner_image_content();
}
function my_custom_theme_get_banner_image_content()
{
$bannerImage = theme_get_setting('banner_image_path', 'my_custom_theme');
$path = '';
if (!empty($bannerImage)) {
$file = file_load($bannerImage[0]);
if (!empty($file)) {
$uri = $file->getFileUri();
$path = file_create_url($uri);
}
}
if (empty($path)) {
$path = base_path() . drupal_get_path('theme', 'my_custom_theme') . '/' . theme_get_setting('banner_image_path', 'my_custom_theme');
}
$content = '<img alt="Banner Image" src="' . $path . '"/>';
return $content;
}
function my_custom_theme_form_system_theme_settings_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state)
{
$form['my_custom_theme_settings']['website'] = array(
'#type' => 'details',
'#title' => t('Website Settings'),
);
$form['my_custom_theme_settings']['website']['banner_image_url'] = array(
'#type' => 'textfield',
'#title' => t('Banner Image Url'),
'#default_value' => theme_get_setting('banner_image_url'),
);
$form['my_custom_theme_settings']['website']['banner_image_path'] = array(
'#type' => 'managed_file',
'#title' => t('Banner Image'),
'#default_value' => theme_get_setting('banner_image_path'),
'#upload_location' => 'public://media/branding',
);
}
2) config\install\my_custom_theme.settings.yml:
banner_image_url: '#'
banner_image_path: 'banner-image.jpg'
3) Inside the page.html.twig template:
{% if is_front and banner_image %}
<a href="{{ banner_image_url }}" class="banner-image">
{{ banner_image | raw }}
</a>
{% endif %}
you can make config form in custom module -src -Form -BannerConfigForm.php
$form['banner_image']= [
'#type' => 'managed_file',
'#required' => TRUE,
'#title' => $this->t('banner image'),
'#default_value' => $config->get('banner_image'),
'#upload_validators' => array(
'file_validate_extensions' => array('png gif jpg jpeg'),
),
'#upload_location' => 'public://'
];
and make menu link - module_name.links.menu.yml for add this as link in drupal admin setting
and in dolab.theme you can call it like that
function my_custom_theme_preprocess_page(&$variables)
{
$variables['banner_image_url'] = $file::load($config->get('banner_image')[0])->url();
}
and now you have this var banner_image_url you can use it in
<img src="{{banner_image_url}}" >
i wish that help you

Wordpress Shorcode after update not working - how to debug?

I have a "custom plugin" for scraping a website content and putting on my webiste via shortcode. After update on newset version of wordpress (and switching to HTTPS) the shortcode is not working.
I tried to switch on other theme, but not helped.
<?php
function file_get_contents_utf8($fn) {
$content = file_get_contents($fn);
$ary[] = "ISO-8859-2";
$ary[] = "UTF-8";
$ary[] = "ASCII";
return w1250_to_utf8($content);
/*return mb_convert_encoding($content, 'UTF-8',
mb_detect_encoding($content,$ary, true));*/
}
function w1250_to_utf8($text) {
// map based on:
// http://konfiguracja.c0.pl/iso02vscp1250en.html
// http://konfiguracja.c0.pl/webpl/index_en.html#examp
// http://www.htmlentities.com/html/entities/
$map = array(
chr(0x8A) => chr(0xA9),
chr(0x8C) => chr(0xA6),
chr(0x8D) => chr(0xAB),
chr(0x8E) => chr(0xAE),
chr(0x8F) => chr(0xAC),
chr(0x9C) => chr(0xB6),
chr(0x9D) => chr(0xBB),
chr(0xA1) => chr(0xB7),
chr(0xA5) => chr(0xA1),
chr(0xBC) => chr(0xA5),
chr(0x9F) => chr(0xBC),
chr(0xB9) => chr(0xB1),
chr(0x9A) => chr(0xB9),
chr(0xBE) => chr(0xB5),
chr(0x9E) => chr(0xBE),
chr(0x80) => '€',
chr(0x82) => '‚',
chr(0x84) => '„',
chr(0x85) => '…',
chr(0x86) => '†',
chr(0x87) => '‡',
chr(0x89) => '‰',
chr(0x8B) => '‹',
chr(0x91) => '‘',
chr(0x92) => '’',
chr(0x93) => '“',
chr(0x94) => '”',
chr(0x95) => '•',
chr(0x96) => '–',
chr(0x97) => '—',
chr(0x99) => '™',
chr(0x9B) => '’',
chr(0xA6) => '¦',
chr(0xA9) => '©',
chr(0xAB) => '«',
chr(0xAE) => '®',
chr(0xB1) => '±',
chr(0xB5) => 'µ',
chr(0xB6) => '¶',
chr(0xB7) => '·',
chr(0xBB) => '»',
);
if(strpos(get_permalink(),"eurojackpot") !== false)
return $text;
else
return html_entity_decode(mb_convert_encoding(strtr($text, $map), 'UTF-8', 'ISO-8859-2'), ENT_QUOTES, 'UTF-8');
}
function download_tipos( $atts ) {
$atts = shortcode_atts( array(
'url' => '',
), $atts, 'download_tipos' );
$content = file_get_contents_utf8($atts["url"]);
if($atts["url"] == "http://eurojackpot.tipos.sk/sk/eurojackpot/vysledky"){
preg_match('/(<div class="row".*?)<div id="footer"/s',$content,$vys);
}
else{
preg_match('/(<div class="bgResultsPnlTop".*?)<div class="bgResultsPnlBottom"/s',$content,$vys);
}
$ret = str_replace('<div id="M5_pnlOptional1"',$reklama.'<div id="M5_pnlOptional1"',$vys[1]).$reklama2;
$ret = str_replace('<div id="_7b7b0a087277_pnlOptional1"',$reklama.'<div id="_7b7b0a087277_pnlOptional1"',$ret);
$ret = str_replace('<p class="kenoPlusNo"',$reklama.'<p class="kenoPlusNo"',$ret);
$ret = str_replace('<div class="content col-md-6 right-col"',$reklama.'<div class="content col-md-6 right-col"',$ret);
$ret = preg_replace('#<a.*?>.*?</a>#i', '', $ret);
$ret = preg_replace('#<img.*?>#i', '', $ret);
return $ret;
}
add_shortcode( 'download_tipos', 'download_tipos' );
add_action('wp_head','hook_css');
function hook_css() {?>
<style>
.orderedNumbers span,.unorderedNumbers span,.result-number li{
border-radius: 50px;
background-color: #eee;
width: 50px;
display: inline-block;
text-align: center;
font-size: 20px;
}
</style>
<?php
}
?>
In the output page ther is this shortode:
<p>[download_tipos url="http://www.tipos.sk/Default.aspx?CatID=711"]
</p>
My expect was the table with numbers, but I dont get any output and on the output URL i dont find in the source code (download_tipos tag). Is there a way how to debug this problem?

Can their be actioncontroller and no view for button in yii

I have a the register button which I have created in cgridview I need to know whether can we have action in controller buuton and no view for that particular action for that button in yii
view user
<?php echo CHtml::link('Advanced Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$model,
)); ?>
</div><!-- search-form -->
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'product-grid',
'dataProvider'=>$model->countregister($_GET['id']),
'enablePagination' => true,
'filter'=>$model,
'columns'=>array(
'name',
'email',
array(
'class'=>'CButtonColumn',
'template'=>'{Register}{update}{view}',
'buttons'=>array(
'Register'=>array(
'label'=>'Register',
.'url'=>Yii::app()->createUrl('register/create',array( 'email'=>$data->email) )
)
),
),
),
)); ?>
controller user
public function actionCreate($email)
{
$model=$this->loadModel($email);
if($_SESSION['userid'])
{
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
));
}
//$this->redirect(array('display','id'=>$model->productid));
$this->redirect(array('user/login'));
}
i don get error but then the below line not the url iam looking
/localhost/test/index.php/register/create/product/create
it should be
/localhost/test/index.php/product/create/id/1
i think there's something wrong in line 1
Please let me know how do i resolve this
change this
$this->redirect('product/create',array( //line 1
'model'=>$model,'id'=>$model->productid,
to
$this->redirect(Yii::app()->createUrl('product/create',array( //line 1
'id'=>$model->productid))
You can parametrise your individual CButtonColumn instances:
array(
'class' => 'CButtonColumn',
'template' => '{Register}{view}{update}',
'buttons' => array(
'Register' => array(
'label' => 'Register',
'url'=>Yii::app()->createUrl('register/create', array('email' => $data->email)),
'visible'=>'$data->entries == 0',
),
'view' => array(
'visible'=>'$data->entries > 0',
)
)
),
But to answer you question after you updated your response (I was already typing it out)
You can use the raw type:
'type'=>'raw',
and the url becomes something like :
'url'=>'Yii::app()->createUrl("register/create",array( "email"=>$data->email) )'
thx to #let-me-see
source: http://www.yiiframework.com/wiki/106/using-cbuttoncolumn-to-customize-buttons-in-cgridview/#hh2
this works
$this->redirect(array('product/create','id'=>$model->productid));

Wordpress theme custom background feature doesn't edit the background correctly

I'm building a custom Wordpress theme and I'm trying to add the ability to use a custom background through the admin panel. I used the example given here in the WP codex.
I'm using WordPress 3.5.2
I am getting the background option and it all appears to work fine until I actual view the page. I have noticed that it adds an internal style which refers to a body with class name "custom-background" but the body's actual class is "customize-support".
When I adjust these using Chrome's debug it applies the correct styling so is it a bug in a Wordpress function somewhere?
I've tried to find where it would give the body that class but can't find anything.
functions.php from theme
<?php
/*
* Adds the custom header option to the theme
*/
function addthemeoptions(){
//Default values of the header image
$header_defaults = array(
'default-image' => '%s/images/header.png',
'random-default' => false,
'flex-height' => false,
'flex-width' => false,
'default-text-color' => '',
'header-text' => false,
'uploads' => true,
'wp-head-callback' => '',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
//Adds the support to use custom header images
add_theme_support( 'custom-header', $header_defaults );
$background_defaults = array(
'default-color' => '#000000',
'default-image' => '',
'wp-head-callback' => '_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => ''
);
add_theme_support( 'custom-background', $background_defaults );
}
//Execute our custom theme functionality
add_action( 'after_setup_theme', 'addthemeoptions' );
?>
generated style in head
<style type="text/css" id="custom-background-css">
body.custom-background { background-color: #0a0a0a; }
</style>
body tag from debug
<body class=" customize-support" style>
Thanks in advance
Edit:
I've found a temporary fix to just add the correct class value into my header.php where body tag is opened but I feel there should be a more complete solution as I'm hard-correcting something that should be generated correctly by a function in WordPress?
Your body tag inside header.php should look:
<body <?php body_class(''); ?>>
i had the same problem and i found in the codex custom background in the last line : ** To override this default behavior, you would have to provide a replacement for the _custom_background_cb() function. **
so i tried to over ride it by coding my own function my_custom_background_cb like this:
$args_background = array(
'default-image' => '',
'default-preset' => 'default', // 'default', 'fill', 'fit', 'repeat', 'custom'
'default-position-x' => 'center', // 'left', 'center', 'right'
'default-position-y' => 'center', // 'top', 'center', 'bottom'
'default-size' => 'auto', // 'auto', 'contain', 'cover'
'default-repeat' => 'repeat', // 'repeat-x', 'repeat-y', 'repeat', 'no-repeat'
'default-attachment' => 'fixed', // 'scroll', 'fixed'
'default-color' => '#fff',
'wp-head-callback' => 'my_custom_background_cb',
'admin-head-callback' => '',
'admin-preview-callback' => '',
);
add_theme_support( 'custom-background', $args_background);
function my_custom_background_cb() {
echo '<style>';
//your custom css
echo '</style>';
}
i'm now working on how to remove the backround color control from the default colors section.
Edit: okay, in customizer.php just remove the default color section and add yours like this:
// removing the default color sections from customizer
$wp_customize->remove_section('colors');
// colors Options Section
$wp_customize->add_section('sec_colors', array(
'title' => esc_attr__('Colors Options', 'yourtheme'),
'description' => sprintf(__('Colors Options for theme', 'yourtheme')),
'priority' => 60,
));
then add your custom colors settings and controls.
it works with me, hope to you too.
Happy Coding
Edit 2:
sorry for the second edit :D , but i found that we need to replace the default wp-head-callback function with our custom function custom_custom_background_cb 'as i found a bug', i also deleted all codes related to color as we created our color options like this:
function custom_custom_background_cb() {
// $background is the saved custom image, or the default image.
$background = set_url_scheme( get_background_image() );
if ( ! $background )
return;
$style ='';
if ( $background ) {
$image = " background-image: url('$background');";
$repeat = get_theme_mod( 'background_repeat', get_theme_support( 'custom-background', 'default-repeat' ) );
if ( ! in_array( $repeat, array( 'no-repeat', 'repeat-x', 'repeat-y', 'repeat' ) ) )
$repeat = 'repeat';
$repeat = " background-repeat: $repeat;";
$position = get_theme_mod( 'background_position_x', get_theme_support( 'custom-background', 'default-position-x' ) );
if ( ! in_array( $position, array( 'center', 'right', 'left' ) ) )
$position = 'left';
$position = " background-position: top $position;";
$attachment = get_theme_mod( 'background_attachment', get_theme_support( 'custom-background', 'default-attachment' ) );
if ( ! in_array( $attachment, array( 'fixed', 'scroll' ) ) )
$attachment = 'scroll';
$attachment = " background-attachment: $attachment;";
$style .= $image . $repeat . $position . $attachment;
}
?>
<style type="text/css" id="custom-background-css">
body.custom-background { <?php echo trim( $style ); ?> }
</style>
<?php
}
Happy Coding Again
I had this problem, had just a <script type="text/javascript> opened, missing </script

Resources