HighCharts donut chart drilldown - php

I am having trouble creating a HighChart donut chart with two layers in Yii Framework.
This is the code I am using for getting a one layer chart:
<?php
$this->widget('bootstrap.widgets.TbHighCharts', array(
// .. 'options', 'chart', 'legend', ..
'series' => array(
array(
'type' => 'pie',
'name' => 'Series of Browsers',
'data' => array(array('MSIE', 55), array('Firefox',10), array('Chrome',15), array('Safari', 20)),
),
// ..
?>
But on the highchart website I can find only java examples on how to implement the 'drilldown'. Do you have a solution for implementing the same in php in Yii?
Thanks in advance for your help!
-- Edit --
In java I would have to do something like this:
drilldown: {
name: 'MSIE',
categories: ['MSIE 6.0', 'MSIE 7.0', 'MSIE 8.0', 'MSIE 9.0'],
data: [10.85, 7.35, 33.06, 2.81]
}
but what is the equivalent operation when using the widget in Yii?

Found out on my own after all. Hope this answer can help also other people.
<?php
$this->widget('bootstrap.widgets.TbHighCharts', array(
'chart' => array(
'borderColor'=>'#e5e5e5',
'type' => 'pie',
),
// .. 'options', 'legend', ..
'series' => array(
// --------- inner layer of the pie
array(
'size' => '40%',
'data' => array(
array(
'name' => //name
'y' => //value
),
array(
'name' => //name
'y' => //value
),
),
),
// -------- second layer from the inside
array(
'size' => '60%',
'innerSize' => '40%',
'data' => array(
array(
'name' => //name
'y' => //value
),
array(
'name' => //name
'y' => //value
),
),
),
// ----- add as manny layers as you need to
),
// ..
);
?>
Pay attention because layers are not directly linked one to the other. This means that you have to wisely set the values 'y's in order to make so that the bounds matches between the layers.

Related

change id checkboxs in CGridView

there are 2 columns check box in cgridViewtable and two bootstrap widgets TbButton in view page.
I can not get value of my checkbox very good. My value in checkboxs transfer into controller but changed id of checkboxs After a period of timeand , and controller don't knew checkbox,
View:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'profile-information-form',
'enableAjaxValidation' => false,
));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'First validation'),));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'End validation'),));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'profile-information-grid',
'dataProvider' => $model->children(),
'filter' => $model,
'columns' => array(
array(
'header' => '',
'value' => '$this->grid->dataProvider->pagination->offset + $row+1', // row is zero based
),
array(
'name' => 'ProfileInformation.user.scope',
'value' => 'CHtml::encode($data->user->scope->name)',
'filter' => Scope::model()->options,
),
array(
'name' => 'id',
'value' => 'CHtml::encode($data->id)',
),
array(
'name' => 'center',
'value' => 'CHtml::encode($data->center)',
),
array(
'name' => 'sendCount',
'value' => 'CHtml::encode($data->sendCount)',
'filter' => '',
),
// Use CCheckbox column with selectableRows = 2 for Select All
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser2(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser1(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
),
));
// action button
$this->endWidget();
Controller:
if (isset($_POST['profile-information-grid_c10']) & isset($_POST['yt0'])) {
////Do action1
}
if (isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])) {
////Do action2
}
}
my problem is in $_POST['profile-information-grid_c10'] and _POST['profile-information-grid_c12'] , before id were $_POST['profile-information-grid_c8'] and $_POST['profile-information-grid_c10'] , and now is $_POST['profile-information-grid_c12'] and $_POST['profile-information-grid_c14'].
my problem is very involved. I cannot explain very good.
I want to have a fix id.
I donto why change id of check box?
Can I assign ids for checkboxs?
Can I assign ids for checkboxs? Sure, you better explicitly set checkbox column id:
'class' => 'CCheckBoxColumn', 'id'=>'column1', ... see these docs.
This way you firmly set it and you'll have no things like these yt0, yt2...
The same you can do for the buttons. See TButton docs.
Also you need to use double && in logical condition:
isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])

Highchart and yii not drawing a pie

This code actually doesn't draw nothing but the title
It's uses Highcharts like an yii extension
<?php $this->Widget('ext.highcharts.HighchartsWidget', array(
'options'=>array(
'title' => array('text' => 'Grafico a torta'),
'chart' => array('renderTo' =>'charts'),
'credits' => array('enabled' => false),
'series' => array (
'type' => 'pie',
'name' => 'name of serie',
'data' => array (
array('Firefox', 44.2),
array('IE7', 26.6),
array('IE6', 20),
array('Chrome', 3.1),
array('Other', 5.4)
),
),
)
));
?>
It create this javascript
jQuery(window).on('load',function() {
var chart = new Highcharts.Chart(
{'chart':{'renderTo':'charts'},
'exporting':{'enabled':true},
'title':{'text':'Grafico a torta'},
'credits':{'enabled':false},
'series':{
'type':'pie',
'name':'name of serie',
'data':[
['Firefox',44.2000000000000028],
['IE7',26.6000000000000014],
['IE6',20],
['Chrome',3.1000000000000001],
['Other',5.4000000000000004]
]}});
});
I'm not able to understand whats wrong.... no js error was throwed, not console debug info, nothing ....
What I'm missing ?
Check your serie:
series:**[**{
type:'pie',
name:'name of serie',
data:[
['Firefox',44.2000000000000028],
['IE7',26.6000000000000014],
['IE6',20],
['Chrome',3.1000000000000001],
['Other',5.4000000000000004]
]}**]**
});
You are missing [] in series. Check this: http://jsfiddle.net/tqVF8/9/
use array once more for series
section =>
'series' => array (
array (
'type' => 'pie',
'name' => 'Browser share',
'data' => array (
array('Firefox', 44.2),
array('IE7', 26.6),
array('IE6', 20),
array('Chrome', 3.1),
array('Other', 5.4)
),
),
),
it works with me.
in this data is array of count of number of event.
<?php
$this->Widget('application.extensions.highcharts.HighchartsWidget',
array('options'=>array( 'title'=>array('text'=>'User Distribution'),
'tooltip'=>array('formatter'=> 'js:function() {
return "<b>"+this.point.name+"</b>: "+Math.round(this.percentage)+"%"
}'),
'credits' => array('enabled' => true),
'exporting' => array('enabled' => true),
'plotOptions'=>array('pie'=> array('allowPointSelect'=>true,'cursor'=>'pointer',
'dataLabels'=>array('enabled'=>true),
'showInLegend'=>true)
),
'series' => array(array('type'=>'pie', 'name'=>'User Distrubution',
'data' => $data,)
)
)
)
);
?>

jqgrid update two tables from one grid

I have two tables in one grid displayed (via LEFT JOIN) and I wonder is there a way to implement an inline edit functionality for both table from the same grid?
I.e:
when the main grid table updated:
onSuccess { table_name, {column1=value1,column2=value2,..}}
not necessarily above scenario - I'm seeking here for ideas and logic to it...
I know there is setAfterCrudAction function in jqGridPHP suit, but from the whole suit I only need this functionality... so I'm seeking to try to implement it myself with some help from you
any ideas appreciated, thanks
Example shows how to update fields when join is used (check 'PHP Grid' tab, btw jqgrid-php is free):
<?php
class jqOperBasic extends jqGrid
{
protected function init()
{
$this->table = 'tbl_order_item';
$this->query = "
SELECT {fields}
FROM tbl_order_item i
JOIN tbl_books b ON (i.book_id=b.id)
WHERE {where}
";
#Set columns
$this->cols = array(
'item_id' => array('label' => 'ID',
'db' => 'i.id',
'width' => 10,
'align' => 'center',
'formatter' => 'integer',
),
'order_id' => array('label' => 'Order id',
'db' => 'i.order_id',
'width' => 15,
'align' => 'center',
'formatter' => 'integer',
),
'name' => array('label' => 'Book name',
'db' => 'b.name',
'width' => 30,
'editable' => true,
'editrules' => array('required' => true),
),
'price' => array('label' => 'Price',
'db' => 'i.price',
'width' => 15,
'align' => 'center',
'formatter' => 'integer',
'editable' => true,
'editrules' => array('required' => true,
'integer' => true,
'minValue' => 1,
'maxValue' => 3000
),
),
);
#Set nav
$this->nav = array('edit' => true, 'edittext' => 'Edit');
}
#Save columns to different tables
protected function opEdit($id, $upd)
{
#Server-side validation
if(strlen($upd['name']) < 5)
{
#Just throw the exception anywhere inside the oper functions to stop execution and display error
throw new jqGrid_Exception('The book name is too short!');
}
#Get editing row
$result = $this->DB->query('SELECT * FROM tbl_order_item WHERE id=' . intval($id));
$row = $this->DB->fetch($result);
#Save book name to books table
$this->DB->update('tbl_books', array('name' => $upd['name']), array('id' => $row['book_id']));
unset($upd['name']);
#Save other vars to items table
$this->DB->update('tbl_order_item', $upd, array('id' => $id));
}
}

Associating an item to multiple other items (of a different class) using Prestashop's backoffice

Having just arrived at Prestashop 1.5, I am making a very simple module: a video of the week, associated with multiple products that need to appear right next to it.
I decided to start from the Backoffice. Right now, I can view, add, edit and remove all the Video entries but I'm a bit lost on how to map the N-N association between a video and its related products... The lack of documentation isn't helping either.
Any ideas how to pull this off?
Here's a bit of my code, the Video class is defined by:
class Video extends ObjectModel {
public $id_video;
public $title;
public $url;
public $active;
public static $definition = array(
'table' => 'video',
'primary' => 'id_video',
'multilang' => false,
'fields' => array(
'id_video' => array(
'type' => ObjectModel :: TYPE_INT
),
'title' => array(
'type' => ObjectModel :: TYPE_STRING,
'required' => true
),
'url' => array(
'type' => ObjectModel :: TYPE_STRING,
'required' => true
),
'active' => array(
'type' => ObjectModel :: TYPE_BOOL,
'required' => true
)
),
);
(...)
and the AdminVideo class is here:
class AdminVideoController extends ModuleAdminController {
public function __construct()
{
$this->table = 'video';
$this->className = 'Video';
$this->lang = false;
$this->fields_list['id_video'] = array(
'title' => $this->l('ID'),
'align' => 'center',
);
$this->fields_list['title'] = array(
'title' => $this->l('Title'),
'width' => 'auto'
);
$this->fields_list['url'] = array(
'title' => $this->l('URL'),
'width' => 'auto'
);
$this->fields_list['active'] = array(
'title' => $this->l('Active'),
'width' => '70',
'align' => 'center',
'active' => 'status',
'type' => 'bool',
'orderby' => false
);
parent::__construct();
}
public function postProcess()
{
parent::postProcess();
}
public function renderList()
{
$this->addRowAction('edit');
$this->addRowAction('delete');
$this->addRowAction('details');
return parent::renderList();
}
public function renderForm()
{
if (!($obj = $this->loadObject(true)))
return;
$this->fields_form = array(
'legend' => array(
'title' => $this->l('This weeks video'),
'image' => '../img/admin/world.gif'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Nome'),
'name' => 'title',
'size' => 33,
'required' => true,
'desc' => $this->l('Title')
),
array(
'type' => 'text',
'label' => $this->l('URL'),
'name' => 'url',
'size' => 33,
'required' => true,
'desc' => $this->l('Video URL')
),
array(
'type' => 'radio',
'label' => $this->l('Active:'),
'name' => 'active',
'required' => false,
'class' => 't',
'is_bool' => true,
'values' => array(
array(
'id' => 'active_on',
'value' => 1,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => 0,
'label' => $this->l('Disabled')
)
),
'desc' => $this->l('Only one video can be active at any given time')
),
)
);
if (Shop::isFeatureActive())
{
$this->fields_form['input'][] = array(
'type' => 'shop',
'label' => $this->l('Shop association:'),
'name' => 'checkBoxShopAsso',
);
}
$this->fields_form['submit'] = array(
'title' => $this->l(' Save '),
'class' => 'button'
);
if (!($obj = $this->loadObject(true)))
return;
return parent::renderForm();
}
}
One other thing: would it be possible to add a preview of the video inside the backoffice? I tried to echo YouTube's embed code, but it gets inserted even before the header. Is there a clean way of doing this or do I have to use some jQuery trickery? I was basically doing an echo of YT's embed code just before the end of postProcess().
Thanks in advance!
The simplest way to associate the videos to the products is by adding a "products" text field in your "video" table to store a comma separated list of the ids of the associated products (eg.: 1,10,27). Even if it's a bit rudimentary, it should work.
Alternatively, you could use a table like this:
create table video_product (
id_association int not null auto_increment,
id_video int,
id_product int,
primary key (id_association)
);
The problem with this solution is that the PrestaShop ObjectModel core does not provide any method to automatically update or delete the related tables (at least as far as I know), so you have to insert the code to manage the "video_product" table in your "Video" class.
If you want an example of how to do this, you should look at the classes/Product.php script, which manages the product table and all its related tables (categories, tags, features, attachments, etc.).
To have an idea of how the Prestashop database is structured, have a look at the docs/dbmodel.mwb file, which contains the schema of the database; this file can be viewed by using the MySQL Workbench application.

How to add new fields to user profile in Drupal 7 programmatically

I want to develop a module that add fields to user profile in drupal 7, like phone number and CV ...
and I don't know how to do that (using Database or using fields API)
pls help me.
Any clear tutorials will be appreciated.
Try to follow the following code
$myField_name = "NEW_FIELD_NAME";
if(!field_info_field($myField_name)) // check if the field already exists.
{
$field = array(
'field_name' => $myField_name,
'type' => 'text',
);
field_create_field($field);
$field_instance = array(
'field_name' => $myField_name,
'entity_type' => 'user', // change this to 'node' to add attach the field to a node
'bundle' => 'user', // if chosen 'node', type here the machine name of the content type. e.g. 'page'
'label' => t('Field Label'),
'description' => t(''),
'widget' => array(
'type' => 'text_textfield',
'weight' => 10,
),
'formatter' => array(
'label' => t('field formatter label'),
'format' => 'text_default'
),
'settings' => array(
)
);
field_create_instance($field_instance);
Hope this works... Muhammad.

Categories