I have this code in my view
<div class="col-xs-6">
<?php echo $form->field($model, 'deskripsi_produk')->widget(Redactor::className(),['clientOptions'=>['autoresize'=>'true', 'limiter' => 20, 'plugins' => ['limiter'], 'buttons'=> ['html', 'formatting', 'bold', 'italic','underline','lists','horizontalrule'],]]);?>
</div>
it can limit 20 char but How I can limit text area to max string defined on model instead of limit with specific number?
Here is my model
class TbProduk extends \yii\db\ActiveRecord
{
/**
* #inheritdoc
*/
public $image;
public static function tableName()
{
return 'tb_produk';
}
public function rules()
{
return [
...
[['deskripsi_produk'], 'string', 'max' => 2000],
[['deskripsi_produk'], 'checkDesc'],
...
];
}
}
Trying to get the value via rules is a terrible idea. Instead you should create a constant in TbProduk that will hold the length:
class TbProduk extends \yii\db\ActiveRecord
{
const DESKRIPSI_PRODUK_LENGTH = 2000;
...
public function rules()
{
return [
...
[['deskripsi_produk'], 'string', 'max' => static::DESKRIPSI_PRODUK_LENGTH],
...
];
}
}
And in your view:
<div class="col-xs-6">
<?php echo $form->field($model, 'deskripsi_produk')->widget(Redactor::className(),['clientOptions'=>['autoresize'=>'true', 'limiter' => TbProduk::DESKRIPSI_PRODUK_LENGTH, 'plugins' => ['limiter'], 'buttons'=> ['html', 'formatting', 'bold', 'italic','underline','lists','horizontalrule'],]]);?>
</div>
Related
I am making some customizations to OroCRM, in this case I need to do a massive action on several records, but when selecting the desired option a modal should appear to choose one of the possible owners of the system.
For that I included the following changes in the system:
I included the mass-actions option in the datagrids:
change_owner:
type: lead_change_owner_mass_edit
handler: pb_lead.mass_action.change_owner.handler
acl_resource: oro_sales_lead_update
route: pb_lead_datagrid_mass_action_change_owner
label: pb.lead.mass_actions.change_owner.label
icon: user
data_identifier: lead.id
frontend_options:
title: "#translator->trans(pb.lead.mass_actions.change_owner.label)"
dialogOptions:
width: 500
modal: true
allowMaximize: false
allowMinimize: false
I defined an associated action as shown:
class ChangeOwnerAction extends WindowMassAction
{
/** #var array */
protected $requiredOptions = ['handler', 'route', 'data_identifier'];
/**
* {#inheritDoc}
*/
public function setOptions(ActionConfiguration $options)
{
if (empty($options['frontend_type'])) {
$options['frontend_type'] = 'edit-mass';
}
return parent::setOptions($options);
}
/**
* {#inheritdoc}
*/
protected function getAllowedRequestTypes()
{
return [Request::METHOD_POST];
}
}
This action is defined as a service:
services:
#Change owner windows action
pb_lead.mass_action.type.changeownermass:
class: PB\Bundle\LeadBundle\Datagrid\Extension\MassAction\Actions\Widget\ChangeOwnerAction
shared: false
tags:
- { name: oro_datagrid.extension.mass_action.type, type: lead_change_owner_mass_edit }
Additionally, the controller that has a method with the route defined in the datagrid is included:
/**
* #Route("/change-owner-mass-edit-lead", name="pb_lead_datagrid_mass_action_change_owner")
* #AclAncestor("oro_sales_lead_update")
* #Template("#PBLead/Lead/widget/mass_change_owner_update.html.twig")
* #param Request $request
* #return array
*/
public function massChangeOwnerAction(Request $request)
{
dump($request);
$responseData = [
'inset' => $request->get('inset', null),
'values' => $request->get('values', null),
];
...
return $responseData;
}
This controller was defined as a service in controllers.yml:
PB\Bundle\LeadBundle\Controller\Frontend\LeadChangeOwnerController:
calls:
- [setContainer, ['#Psr\Container\ContainerInterface']]
tags:
- { name: container.service_subscriber }
On the other hand, 2 classes were defined: an abstract and a handler that extends from it to manage the mass actions. Both handlers are defined as services:
#Abstract Lead mass action handler
pb_lead.abstract_lead_mass_action_handler:
class: PB\Bundle\LeadBundle\Datagrid\Extension\MassAction\AbstractLeadMassActionHandler
abstract: true
arguments:
- '#oro_entity.doctrine_helper'
- '#oro_security.acl_helper'
#Lead change owner mass action HANDLER
pb_lead.mass_action.change_owner.handler:
parent: pb_lead.abstract_lead_mass_action_handler
public: true
class: PB\Bundle\LeadBundle\Datagrid\Extension\MassActionxzczxcz\LeadChangeOwnerMassActionHandler
calls:
- ['setTranslator', ['#translator']]
- ['setFormFactory', ['#form.factory']]
There is a custom form and a view that are called from the controller.
Form:
class LeadChangeOwnerMassType extends AbstractType
{
const NAME = 'pb_lead_change_owner_mass_type';
/**
* {#inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add(
'owner',
UserAclSelectType::class,
[
'required' => true,
'label' => 'pb.lead.mass_actions.change_owner.label',
'constraints' => [
new NotNull()
]
]
);
}
/**
* {#inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Lead::class,
]);
}
View:
{% extends '#OroAction/Operation/form.html.twig' %}
{% set formAction = path('pb_lead_datagrid_mass_action_change_owner', {gridName: 'sales-lead-grid', actionName: 'change_owner', inset: inset, values: values }) %}
{% block form %}
<form id="{{ form.vars.id }}"
name="{{ form.vars.name }}"
action="{{ formAction }}"
method="{{ form.vars.method }}"
class="form-dialog"
>
<fieldset class="form-horizontal">
{{ form_row(form) }}
</fieldset>
<div class="hidden">
{{ form_rest(form) }}
</div>
<div class="widget-actions">
<button class="btn" type="reset">{{ 'Cancel'|trans }}</button>
<button class="btn btn-success" type="submit">{{ 'Apply'|trans }}</button>
</div>
</form>
{{ oro_form_js_validation(form) }}
{% endblock %}
The question is: Why is the modal not showing?
Thank you very much for the help
the error is that the route must start with "oro_", only that a small detail does not allow to show modal.
change_owner:
type: lead_change_owner_mass_edit
handler: pb_lead.mass_action.change_owner.handler
acl_resource: oro_sales_lead_update
route: oro_lead_mass_action_change_owner
label: pb.lead.mass_actions.change_owner.label
icon: user
data_identifier: lead.id
frontend_options:
title: "#translator->trans(pb.lead.mass_actions.change_owner.label)"
dialogOptions:
width: 500
modal: true
allowMaximize: false
allowMinimize: false
I have a function that displays the 'tarificationtaches' list i would like to add an avg to get the average 'techniciens' moyenne_avis from tables avis_intervention where "intervention.technicien_id" = "tarificationtaches.techncien_id" , in this is my schema .
taches_table
public function up()
{
Schema::create('taches', function (Blueprint $table) {
$table->increments('id');
$table->string('libelle_tache');
$table->float('Tarif', 8,2)->nullable();
$table->integer('metier_id')->unsigned();
$table->foreign('metier_id')->references('id')->on('metiers');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});
}
tarificationtaches_tables
Schema::create('tarificationtaches', function (Blueprint $table) {
$table->increments('id');
$table->float('tarif', 8,2);
$table->integer('tache_id')->unsigned();
$table->foreign('tache_id')->references('id')->on('taches');
$table->integer('technicien_id')->unsigned();
$table->foreign('technicien_id')->references('id')->on('techniciens');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});
techniciens_tables
Schema::create('techniciens', function (Blueprint $table) {
$table->increments('id');
$table->boolean('actif')->default(1);
$table->float('moyenne_avis')->nullable();
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users');
$table->datetime('deleted_at')->nullable();
$table->timestamps();
});
avis_interventions_tables
Schema::create('avis_interventions', function (Blueprint $table) {
$table->increments('id');
$table->string('qualité');
$table->integer('nbr_heure');
$table->string('service');
$table->float('note', 1,1);
$table->integer('client_id')->unsigned();
$table->foreign('client_id')->references('id')->on('clients');
$table->integer('intervention_id')->unsigned();
$table->foreign('intervention_id')->references('id')->on('interventions');
$table->timestamps();
});
interventions_tables
Schema::create('interventions', function (Blueprint $table) {
$table->increments('id');
$table->date('date_intervention')->nullable();
$table->string('description');
$table->dateTime('duree_prevu');
$table->boolean('statut');
$table->integer('technicien_id')->unsigned();
$table->foreign('technicien_id')->references('id')->on('techniciens');
$table->integer('tarification_id')->unsigned();
$table->foreign('tarification_id')->references('id')->on('tarificationtaches');
$table->integer('client_id')->unsigned();
$table->foreign('client_id')->references('id')->on('Clients');
$table->timestamps();
});
this is my function
public function getTar(){
$tarifications = tarificationtache::with('technicien')->get();
return $tarifications->map(function ($tarification) {
return [
'nom' => $tarification->technicien->user->nom,
'moyenne_avis' => $tarification->technicien->moyenne_avis,
'tache' => $tarification->tache->libelle_tache,
'tarif' => $tarification->tarif,
];
});
}
it shown like this
[{"nom":"tech 1","moyenne_avis":null,"tache":"tache 2","tarif":29.55},
{"nom":"tech
2","moyenne_avis":null,"tache":"tache 3","tarif":55.12},{"nom":"tech
1","moyenne_avis":null,"tache":"tache 3","tarif":253},{"nom":"tech
2","moyenne_avis":null,"tache":"tache 3","tarif":28.22}]
EDIT:
Below are the model files followed by model relationships eloquent query which I have used to generate the output:
technicien model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\User;
class technicien extends Model
{
protected $table = "techniciens";
public function user()
{
return $this->belongsTo('App\User', 'user_id', 'id');
}
}
tarificationtache model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\technicien;
use App\tache;
use App\interventions;
class tarificationtache extends Model
{
protected $table = "tarificationtaches";
public function technicien()
{
return $this->belongsTo('App\technicien', 'technicien_id', 'id');
}
public function tache()
{
return $this->belongsTo('App\tache', 'tache_id', 'id');
}
public function interventions()
{
return $this->hasMany('App\interventions', 'technicien_id', 'id');
}
}
tache model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class tache extends Model
{
protected $table = "taches";
}
interventions model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\avis_interventions;
class interventions extends Model
{
protected $table = "interventions";
public function avis_interventions()
{
return $this->hasMany('App\avis_interventions', 'intervention_id', 'id');
}
}
avis_interventions model:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class avis_interventions extends Model
{
protected $table = "avis_interventions";
}
Model relationship query:
$tarifications = tarificationtache::with('technicien')->get();
$results = $tarifications->map(function ($tarification) {
return [
'nom' => $tarification->technicien->user->name,
'moyenne_avis' => $tarification->technicien->moyenne_avis,
'tache' => $tarification->tache->libelle_tache,
'tarif' => $tarification->tarif,
'avg_avis_interventions' => $tarification -> interventions -> count()
];
});
print_r($results -> toJson());
exit;
That returns below output to me:
[{
"nom": "Ravi-carpenter",
"moyenne_avis": 2,
"tache": "Task #1",
"tarif": 5.22,
"avg_avis_interventions": 2
}, {
"nom": "Ravi-carpenter",
"moyenne_avis": 3.5,
"tache": "Task #2",
"tarif": 6.52,
"avg_avis_interventions": 3
}]
public function getTar(){
$tarifications = tarificationtache::with('technicien')->get();
return $tarifications->map(function ($tarification) {
return [
'nom' => $tarification->technicien->user->nom,
'tache' => $tarification->tache_id,
'tarif' => $tarification->tarif,
'avg_avis_interventions' => $tarification->technicien-
>avisinterventions->avg('note')
];
});
print_r($results -> toJson());
exit;
}
I extended "dektrium/yii2-user" controller's class as below, now I want to have $authItems in render view file of parent class, how should I pass this variable?
namespace app\controllers;
use app\models\AuthItem;
use dektrium\user\controllers\RegistrationController as BaseRegistrationController;
class RegistrationController extends BaseRegistrationController
{
public function actionRegister()
{
$authItems = AuthItem::find()->all();
return parent::actionRegister();
}
}
its is main class method
public function actionRegister()
{
if (!$this->module->enableRegistration) {
throw new NotFoundHttpException();
}
/** #var RegistrationForm $model */
$model = \Yii::createObject(RegistrationForm::className());
$event = $this->getFormEvent($model);
$this->trigger(self::EVENT_BEFORE_REGISTER, $event);
$this->performAjaxValidation($model);
if ($model->load(\Yii::$app->request->post()) && $model->register()) {
$this->trigger(self::EVENT_AFTER_REGISTER, $event);
return $this->render('/message', [
'title' => \Yii::t('user', 'Your account has been created'),
'module' => $this->module,
]);
}
return $this->render('register', [
'model' => $model,
'module' => $this->module,
]);
}
A solution could be
don't invoke the parent::actionRegister();
and add the code directly in your actionRegister
and last add the autItems to the render function array parameters
class RegistrationController extends BaseRegistrationController
{
public function actionRegister()
{
$authItems = AuthItem::find()->all();
// return parent::actionRegister();
if (!$this->module->enableRegistration) {
throw new NotFoundHttpException();
}
/** #var RegistrationForm $model */
$model = \Yii::createObject(RegistrationForm::className());
$event = $this->getFormEvent($model);
$this->trigger(self::EVENT_BEFORE_REGISTER, $event);
$this->performAjaxValidation($model);
if ($model->load(\Yii::$app->request->post()) && $model->register()) {
$this->trigger(self::EVENT_AFTER_REGISTER, $event);
return $this->render('/message', [
'title' => \Yii::t('user', 'Your account has been created'),
'module' => $this->module,
]);
}
return $this->render('register', [
'model' => $model,
'module' => $this->module,
'authItems' => $authItems;
]);
}
}
I would do something like this:
Add a member variable to your extended class, such as:
namespace app\controllers;
use app\models\AuthItem;
use dektrium\user\controllers\RegistrationController as BaseRegistrationController;
class RegistrationController extends BaseRegistrationController
{
public $authitems;
public function actionRegister()
{
$this->authitems = AuthItem::find()->all();
return parent::actionRegister();
}
}
Then in your parent class, do a test to see if that variable is set, such as:
public function actionRegister()
{
//.........
return $this->render('register', [
'model' => $model,
'module' => $this->module,
'authitems' => (isset($this->authitems)) ? $this->authitems : null;
]);
}
I'm using 2amigos datepicker in my application and it's working good throughout. Today I tried to apply AdminLTE theme to the application. I've added all the css, js in the asset file and uploaded them in the respective folders. No error in the browser console so far.
The first thing I notice is that the datepicker is not working. When I click on the calendar icon on the datepicker, the datepicker doesn't open.
Asset file
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* Main frontend application asset bundle.
*/
class DashboardAsset extends AssetBundle
{
public $basePath = '#webroot';
public $baseUrl = '#web';
public $css = [
'css/site.css',
'css/bootstrap.min.css',
'css/font-awesome.min.css',
'https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css',
'css/AdminLTE.min.css',
'css/skins/_all-skins.min.css',
'plugins/iCheck/flat/blue.css',
'plugins/morris/morris.css',
'plugins/jvectormap/jquery-jvectormap-1.2.2.css',
'plugins/datepicker/datepicker3.css',
'plugins/daterangepicker/daterangepicker.css',
'plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css',
];
public $js = [
'js/bootstrap/bootstrap.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js',
'plugins/morris/morris.min.js',
'plugins/sparkline/jquery.sparkline.min.js',
'plugins/jvectormap/jquery-jvectormap-1.2.2.min.js',
'plugins/jvectormap/jquery-jvectormap-world-mill-en.js',
'plugins/knob/jquery.knob.js',
'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js',
'plugins/daterangepicker/daterangepicker.js',
'plugins/datepicker/bootstrap-datepicker.js',
'plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js',
'plugins/slimScroll/jquery.slimscroll.min.js',
'plugins/fastclick/fastclick.js',
'js/app.min.js',
'js/dashboard.js',
'js/demo.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
I'm using the datepicker like below -
use dosamigos\datepicker\DatePicker;
<?= $form->field($model1, 'startdate')->widget(
DatePicker::className(), [
'options' => ['placeholder' => 'Start Date ...', 'id' => 'startdate1'],
'inline' => false,
style="background-color: #fff; width:250px">{input}</div>',
'clientOptions' => [
'autoclose' => true,
'todayHighlight' => true,
'format' => 'yyyy-mm-dd'
]
]);?>
I have created custom model for my report.Here i have declared two variables fy_yr and fy_qtr.In my report form ,i have two combo boxes and I have to generate my report according to values from my combo boxes.But my problem is the selected values from combos are not set in my custom model.What is the problem?
My report view code:
<?php $form = ActiveForm::begin(['id' => 'member-report',
'action' => ['member-report'],
'method' => 'post',
]); ?>
<table border="1" class="table-bordered">
<tr>
<td style="margin-right:20px;">
<?= $form->field($model, 'fy_yr')->dropDownList(
ArrayHelper::map(FiscalYear::getAllFiscalYr(),'fy_id','fiscal_yr'),
['prompt'=>'Select Fiscal Year.']
)
?>
</td>
<td>
<?= $form->field($model, 'fy_qtr')->dropDownList(
ArrayHelper::map(CodeValue::getFiscalYrQuater(),'cv_id','cv_lbl'),
['prompt'=>'Select Quarter.']
)
?>
</td>
<td><input type="submit" value="Search" class="btn btn-primary btn-block btn-flat"/></td>
<td><input type="submit" value="Print" class="btn btn-primary btn-block btn-flatb"/></td>
</tr>
</table>
<?php ActiveForm::end(); ?>
My model is:
class SfclReport extends Model
{
public $fy_yr;
public $fy_qtr;
public function rules()
{
return [
[['fy_id', 'fy_qtr'], 'required'],
];
}
}
and my controller is
public function actionMemberReport()
{
$model = new SfclReport;
if ($model->load(Yii::$app->request->post())) {
}
return $this->render('member_report',['model'=>$model]);
}
add fy_yr and Specify your variable datatype
class SfclReport extends Model
{
public $fy_yr;
public $fy_qtr;
public function rules()
{
return [
[['fy_id', 'fy_qtr'], 'required'],
[['fy_id',], 'integer'],
[['fy_yr','fy_qtr'], 'string'],
];
}
}