I have a plugin filter installed from https://github.com/lecterror/cakephp-filter-plugin.
How can i rename the values in the dropdown bar?
Right now I can choose between:
[ ]
[0]
[1]
What I need is:
[ ]
[Agent]
[Investor]
.
public $filters = array(
'index' => array(
'Model' => array(
'Model.Tablename' => array('label' => 'Find'),
'Model.Tablename' => array(
'label' => 'Position type',
'type' => 'select',
'selectOptions' => array (
0 => 'Agent',
1 => 'Investor'
)
)
)
)
);
At the selector type I want to rename 0 to Agent and 1 to Investor.
Find it myself:
//plugincode-----> filter_form_fields
foreach ($viewFilterParams as $field) {
// Edited on 28-03-2013
// check if option type is select.
if ($field['options']['type'] == "select") {
// check for all option values ( 0,1,2,3,4 ect ) and rename it with optionNewValue
foreach ($field['options']['options'] as $optionvalue) {
$optionNewValue = $field['options']['OptionKey'][$optionvalue];
// Rename the optionvalue
$field['options']['options'][$optionvalue] = $optionNewValue;
}
}
// filtercomponent.ctp add (plugin code )
// Optionkey gives the values filter_form_fields
// use inside the controller Optionkey => array() to rename values
$options['OptionKey'] = $settings['OptionKey'];
and now you can put in the controller
'index' => array(
'Model' => array(
'Model.Tablename' => array('label' => 'Find'),
'Model.Tablename' => array(
'label' => 'Position type',
'type' => 'select',
'OptionKey' => array (
0 => 'agent',
1 => 'investor'
)
)
)
);
:D:D:D:D:D
Related
When i try to add new documents to an index type , i loose existing documents which are overwritten by the new added ones . The problem can be related to the id of each added document ??
Here is the code :
$elasticaClient = new \Elastica\Client(array(
'host' => $this->container->getParameter('elastic_host'),
'port' => $this->container->getParameter('elastic_port')
));
$elasticaIndex = $elasticaClient->getIndex('app');
$elasticaIndex->create(
array(
'number_of_shards' => 4,
'number_of_replicas' => 1,
'analysis' => array(
'analyzer' => array(
'indexAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => array('lowercase', 'mySnowball')
),
'searchAnalyzer' => array(
'type' => 'custom',
'tokenizer' => 'standard',
'filter' => array('standard', 'lowercase', 'mySnowball')
)
),
'filter' => array(
'mySnowball' => array(
'type' => 'snowball',
'language' => 'German'
)
)
)
),
true
);
$elasticaType = $elasticaIndex->getType('type');
$mapping = new \Elastica\Type\Mapping();
$mapping->setType($elasticaType);
$mapping->setParam('index_analyzer', 'indexAnalyzer');
$mapping->setParam('search_analyzer', 'searchAnalyzer');
$mapping->setProperties(array(
'id' => array('type' => 'string'),
'title' => array('type' => 'string'),
'duration' => array('type' => 'string'),
'start' => array('type' => 'string'),
'end' => array('type' => 'string'),
));
// Send mapping to type
$mapping->send();
$documents = array();
foreach($medias as $media) {
$id = uniqid() ;
$documents[] = new \Elastica\Document(
$id,
array(
'id' => $id,
'title' => $media['title'],
'duration' => $media['duration'],
'start' => $media['start'],
'end' => $media['end'],
)
);
}
$elasticaType->addDocuments($documents);
$elasticaType->getIndex()->refresh();
Please i need your help . Thank you
PHP does not recommend using uniqid for this use case. Since you are wanting a random, safe id, let Elasticsearch do it for you. The Elastica Document construct method notes that the id field is optional. So don't pass it and let Elasticsearch issue the id.
Several things
$elasticaIndex->create (....) you only have to enter it once. Index is unique after creating the index that you can comment or generate a different index and other things. I leave an example that works.
class PersistencyElastic
{
private $conection;
public function __construct()
{
$this->conection = new \Elastica\Client(['host' => '127.0.0.1', 'port' => 9200]);
}
public function save($ msg)
{
// $ msg is an array with whatever you want inside
$index = $this->conection->getIndex('googlephotos');
// This is the index I created, it's called googlephotos
// $index->create(array (), true);
$type = $index->getType('googlephotos');
$type->addDocument(new Document (uniqid ('id _', false), $msg, $type, $index));
$index->refresh();
}
}
I have next variables:
$type_model = ProductTypeModel::model()->findByPk($id);
$prod = $type_model->product;
Now in $prod:
array
(
0 => ProductModel#1
(
[CActiveRecord:_new] => false
[CActiveRecord:_attributes] => array
(
'product_id' => '6'
'product_type_id' => '5'
)
...
)
1 => ProductModel#2
(
'product_id' => '8'
'product_type_id' => '5'
)
...
How i can display my products in CGridView?
Thx.
I Suppose you are using CarrayDataProvider. So in your controller
$dataProvider = new CArrayDataProvider($prod);
Here $product could be any array you want to display in CgridView. Now
In you view write this.
$gridColumns = array(
array(
'header' => 'First Name',
'value' => 'ProductTypeModel::model()->findByPk($data->product_id)->key',
'htmlOptions' => array('style' => 'text-align:center;')
),
$this->widget('zii.widgets.grid.CGridView',array('dataProvider' => $dataProvider,));
As in CarrayDataprovider array is obtained so we cant use relations in it. Thats why u have to write 'ProductTypeModel::model()->findByPk($data->product_id)->key'
Here you can display anything attribute of ProductTypeModel so u can replace above mentioned key with your desired attribute
Try this ...
it automatic convert to array data provider.
$dataProvider=new CArrayDataProvider($type_model->product);
Thanks all. By means of answers "naveen goyal" and "jailed abroad" i did like this:
$dataProvider=new CArrayDataProvider($type_model->product);
$dataProvider->keyField = 'product_id';
$this->widget('bootstrap.widgets.TbGridView', array(
'dataProvider' => $dataProvider,
'columns' => array(
array(
'header' => 'Title',
'value' => 'CHtml::encode($data["product_title"])',
),
)));
Nice work for me.
I have been looking how to do this and am a bit stumped.
My array is as follows:
$returndata->setup_array = array(
'General' => array(
'Main Details' => 'setup/maindets',
'Directories' => 'directories',
'Extension Allocation' => 'xtnallo',
'List Holidays' => 'setup/holidays',
'List Group VM' => 'groupvm',
'Conference Rooms' => 'confroom'
),
'Offices' => array(
'List Offices' => 'iptoffices'
),
'Users' => array(
'List Users' => 'iptusers'
),
'Phones' => array(
'List Phones' => 'iptphones'
),
);
However I have 1 item that on a certain condition(triggered by the users session) that needs to be added to the listin the general array. The section being 'View Details => setup/viewdetails'. I have tried array push (probably incorrectly) but this adds the item as another array at the end under the main array.
I want/need it to work like this:
$returndata->setup_array = array(
'General' => array(
$viewdets
'Main Details' => 'setup/maindets',
'Directories' => 'directories',
'Extension Allocation' => 'xtnallo',
'List Holidays' => 'setup/holidays',
'List Group VM' => 'groupvm',
'Conference Rooms' => 'confroom'
),
'Offices' => array(
'List Offices' => 'iptoffices'
),
'Users' => array(
'List Users' => 'iptusers'
),
'Phones' => array(
'List Phones' => 'iptphones'
),
);
$viewdets = "'View Details' => 'setup/viewdetails'";
and still be interpreted as a functioning array for use as a menu.
$returndata->setup_array['General']['View Details'] = 'setup/viewdetails'
Cheers Rick!
You can use ArrayObject to have the array as a reference:
$a = new ArrayObject();
$b = array(
"a" => $a
);
$a[] = "foo";
print_r($b);
What did you try calling array_push() on? Have you tried
array_push($returndata->setup_array['General'], $viewdets);
You would need to add the variable to the specific depth of the array you wanted it to be present. check out array_push here, there's also a short language syntax that avoids the function call:
$returndata->setup_array['General'][] = $viewdets;
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,)
)
)
)
);
?>
I have the following fields in a magento adminhtml form.
On submit im expecting to grab the post, and simply dump its contents, which im doing in my saveAction.
public function saveAction()
{
if ($this->getRequest()->getPost())
{
try{
$postData = $this->getRequest()->getPost();
echo '<pre>';
print_r($postData);
exit;
the output looks as follows.
Array
(
[form_key] => I6jK6swe1EMl0wER
[carrier_code] => test
[postcode] => tescode
[sku] => 123445
)
Seeing my form is defined as:
$form = new Varien_Data_Form();
$this->setForm($form);
$fieldset = $form->addFieldset('instance_form', array('legend'=>Mage::helper('instance')->__('Instance Filters')));
$fieldset->addField('carrier_code', 'text', array(
'label' => Mage::helper('instance')->__('Carrier service'),
'name' => 'carrier_code',
'after_element_html' => '<small>Leave blank for all Carriers.</small>',
));
$fieldset->addField('postcode', 'text', array(
'label' => Mage::helper('instance')->__('Postcode'),
'name' => 'postcode',
'after_element_html' => '<small>Leave blank for all Postcodes.</small>',
));
$fieldset->addField('sku', 'text', array(
'label' => Mage::helper('instance')->__('Sku'),
'name' => 'sku',
'after_element_html' => '<small>Leave blank for all Skus.</small>',
));
$fieldset->addField('start_date', 'date', array(
'label' => Mage::helper('instance')->__('Start Date'),
'after_element_html' => '<small>Comments</small>',
'tabindex' => 1,
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
));
$fieldset->addField('aura', 'file', array(
'label' => Mage::helper('instance')->__('Upload'),
'value' => 'Uplaod',
'disabled' => false,
'readonly' => true,
'after_element_html' => '<small>Comments</small>',
'tabindex' => 1
));
I was expecting to see output like this instead :
Array
(
[form_key] => I6jK6swe1EMl0wER
[carrier_code] => test
[postcode] => tescode
[sku] => 123445
[start_date] => someValue
[aura] => anotherValue
)
am i missing something? why would say the date field, not be added to the post, like all the other text input fields?
Cheers
You're missing the name key in your addField('start_date', ..) call.
Each field of a Varien_Data_Form you want to be submittable needs a name key/value pair.
The value you assign to your field's name key is used as value for the name attribute of the corresponding <input> element when rendering the <form>.