How can I align different lines in PHP code? - phpstorm

PhpStorm 2021.2:
$is_fullcalendar_nearest_days = $expireDateCheckNearest->isPast();
return [
'id' => 'ad' . $adItem->id,
'title' => $adItem->id . '=>' . $adItem->title,
'adLocationsCount' => $adItem->ad_locations_count,
'status' => $adItem->status,
'status_label' => Ad::getStatusLabel($adItem->status),
'ad_type' => $adItem->ad_type,
'ad_type_label' => Ad::getAdTypeLabel($adItem->ad_type),
'price' => $adItem->price,
'price_formatted' => formatCurrencySum($adItem->price),
'is_fullcalendar_nearest_days' => $is_fullcalendar_nearest_days,
];
How can I align lines above with all => and = at same level?

Related

Laravel 8: Update a record in database using if statement

Below is the function I used to update my record.
public function store_upd_nilai_uji_program(Request $request)
{
$validated = $request->validate([
'nip' => 'required|numeric|digits_between:18,18',
'n1' => 'nullable|numeric',
'n2' => 'nullable|numeric',
'n3' => 'nullable|numeric',
'n4' => 'nullable|numeric',
'n5' => 'nullable|numeric',
'n6' => 'required|numeric',
'tanggal' => 'required',
'waktu' => 'required',
]);
NilaiUjiProgram::where('nim', $request->nim)->update([
'nip' => $request->nip,
'nilai_kemampuan_dasar_program' => floatval($request->n1),
'nilai_kecocokan_algoritma' => floatval($request->n2),
'nilai_penguasaan_program' => floatval($request->n3),
'nilai_penguasaan_ui' => floatval($request->n4),
'nilai_validasi_output' => floatval($request->n5),
'total' => floatval($request->n6),
'tanggal' => $request->tanggal,
'waktu' => $request->waktu,
]);
return redirect('/prodi/daftar_nilai_uji_program')->with('status', 'Nilai berhasil diperbaharui!');
}
Actually, I want to update the attribute 'nilai_kemampuan_dasar_program', 'nilai_kecocokan_algoritma','nilai_penguasaan_program','nilai_penguasaan_ui', and 'nilai_validasi_output' if only the equal value in $request is NOT NULL. If the value is null, I would like to keep my record fill with NULL. To keep in mind that my table doesn't have any primary key. Do you have any idea how to solve my problem?
NilaiUjiProgram::where('nim', $request->nim)->update([
'nip' => $request->nip,
'nilai_kemampuan_dasar_program' => $request->n1 ? floatval($request->n1) : null,
'nilai_kecocokan_algoritma' => $request->n2? floatval($request->n2) :null,
'nilai_penguasaan_program' => $request->n3 ? floatval($request->n3):null,
'nilai_penguasaan_ui' => $request->n4 ? floatval($request->n4) : null,
'nilai_validasi_output' => floatval($request->n5),
'total' => floatval($request->n6),
'tanggal' => $request->tanggal,
'waktu' => $request->waktu,
]);

Yii2 captcha always incorrect

Whan I add 'on' => 'create' in my rule my captcha always incorrect
Off that work good why?
I try to let it to other controller support/captcha but still incorrect
MyView
<?= Captcha::widget([
'id' => 'captcha',
'model' => $model,
'attribute' => 'verifyCode',
'options' => ['class' => 'form-control',
'data-v-rule' => '',
'captchaAction' => 'support/captcha',
'data-v-msg' => $i18n->t('please.input.verify.code'),
'placeholder' => $i18n->t('please.input.verify.code', '', false)]
]); ?>
Myrule
...
[['verifyCode'], 'captcha', 'message' => $i18n->t('error.verifyCode'),'captchaAction' => 'support/captcha' , 'on' => 'create'],
...
I get seesion
$_SESSION = [
'__flash' => [],
'__captcha/site/captcha' => 'nnbioo',
'__captcha/site/captchacount' => 1,
'__captcha/support/captcha' => 'cacijq',
'__captcha/support/captchacount' => 1,
];
Mycontroller
public function actions()
{
return [
'error' => [
'class' => 'yii\web\ErrorAction',
],
'captcha' => [
'class' => CaptchaAction::className(),
],
];
}
$customerServiceModel->load($post) is not working, because attribute verifyCode is not safe in this case. Your rule is specified with 'on' => 'create' - so it means, it's save on scenario create. You didn't assigned this scenario to the model so there's 2 solutions:
Remove 'on' => 'create' from rule
Assign create scenario to model by $customerServiceModel->scenario = 'create'; before using load().

Dynamic value graph creation in yii2 using GoogleChart?

Here I wanna draw line chart graph by dynamic value.but in my case for every value of array created different different graph...Please help me I am first time do this task.Thanks in Advances
<?php
$modelEmployee=Employee::find()->select(['id','sales','expenses'])->all();
$arr = array('id'=>array(),
'sales'=>array(),
'expenses'=>array());
for($i = 0, $modEm = $modelEmployee; $i < sizeof($modelEmployee); $i++){
$arr['id'] = $modEm[$i]['id'];
$arr['sales'] = $modEm[$i]['sales'];
$arr['expenses'] = $modEm[$i]['expenses'];
print_r($arr);
echo GoogleChart::widget(array('visualization' => 'LineChart',
'data' => array(
array('Year', 'Sales', 'Expenses'),
array($arr['id'],$arr['sales'],$arr['expenses']),
),
'options' => array(
'title' => 'My Company Performance2',
'titleTextStyle' => array('color' => '#FF0000'),
'vAxis' => array(
'title' => 'Scott vAxis',
'gridlines' => array(
'color' => 'transparent' //set grid line transparent
)),
'hAxis' => array('title' => 'Scott hAixs'),
'curveType' => 'function', //smooth curve or not
'legend' => array('position' => 'bottom'),
)));
?>
first of all the multiple graphs are because you are doing echo inside for loop so it will take only one value and create graph from that.
you have to create an array of values and pass it to the graph widget as following
$graph_data = [];
$graph_data[] = array('Year', 'Sales', 'Expenses');
for($i = 0, $modEm = $modelEmployee; $i < sizeof($modelEmployee); $i++){
$arr['id'] = $modEm[$i]['id'];
$arr['sales'] = $modEm[$i]['sales'];
$arr['expenses'] = $modEm[$i]['expenses'];
$graph_data[] = array($arr['id'],$arr['sales'],$arr['expenses']); //add the values you require as set in the order of Year, Sales , Expenses
} //loop ends here
echo GoogleChart::widget(array('visualization' => 'LineChart',
'data' => $graph_data,
'options' => array(
'title' => 'My Company Performance2',
'titleTextStyle' => array('color' => '#FF0000'),
'vAxis' => array(
'title' => 'Scott vAxis',
'gridlines' => array(
'color' => 'transparent' //set grid line transparent
)),
'hAxis' => array('title' => 'Scott hAixs'),
'curveType' => 'function', //smooth curve or not
'legend' => array('position' => 'bottom'),
)));
Try this
action
$model=Employee::find()->select(['id','sales','expenses'])->all();
$data[]=["id","sales","expenses"];
foreach ($model as $item) {
$data[]=[(string) $item['id'],(int) $item['sales'],(int) $item['expenses']];
}
return $this->render('test',['data'=>$data]);
view
echo GoogleChart::widget(array('visualization' => 'LineChart',
'data' => $data,
'options' => array(
'title' => 'My Company Performance2',
'titleTextStyle' => array('color' => '#FF0000'),
'vAxis' => array(
'title' => 'Scott vAxis',
'gridlines' => array(
'color' => 'transparent' //set grid line transparent
)),
'hAxis' => array('title' => 'Scott hAixs'),
'curveType' => 'function', //smooth curve or not
'legend' => array('position' => 'bottom'),
)));

Open in a new window in yii2 [For a button dropdown]

how can one open a link in a new tab. in my case i wanna do it in the following code
if( Yii::$app->session->get('department_id') == 5 )
{
$items[] = ['label' => 'Offer Letter',
'url' => Yii::$app->urlManager->createUrl(['dashboard/print_offer_letter', 'id' => $data->id]),
];
i tried like this but didn't work
$items[] = ['label' => 'Offer Letter', ['title'=>'go','target'=>'_blank'],
'url' => Yii::$app->urlManager->createUrl(['dashboard/print_offer_letter', 'id' => $data->id]),
];
any help would be appreciated.
I think you can use something like below:
$items[] = [
'label' => 'items',
'url' => Yii::$app->urlManager->createUrl(['dashboard/print_offer_letter', 'id' => $data->id]),
'linkOptions' => ['target'=>'_blank']
];

Drupal Html array. How to reference a changing radio selection within a fieldset

I cannot make this Drupal html array fire the visible property on change of radio option. I have moved everything inside of the fieldset, not sure if this makes any difference.
Does anyone know why it isn't firing?
function services_formation_founders($form, &$form_state) {
$form = array();
$form['#tree'] = TRUE;
$form['description'] = array(
'#type' => 'item',
'#title' => t('Founders form'),
);
$form['founder']['add_officer'] = array(
'#type' => 'fieldset',
'#title' => t('Add Founder'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#states' => array(
'visible' => array(TRUE,
),
),
);
$form['founder']['add_officer']['founder_type'] = array(
'#type' => 'radios',
'#options' => array(
'individual' => t('Individual'),
'corporate' => t('Corporation'),
),
'#default_value'=>'individual',
'#title' => t('What type of Founder?')
);
if (empty($form_state['num_names'])) {
$form_state['num_names'] = 1;
}
$form['founder']['add_officer']['individual'] = array(
'#type' => 'textfield',
'#title' => t('Individual'),
'#states' => array(
'visible' => array(
':input[name="founder_type"' => array('value' => "individual"),
),
),
);
$form['founder']['add_officer']['corporation'] = array(
'#type' => 'textfield',
'#title' => t('Corporation'),
'#states' => array(
'visible' => array(
':input[name="founder_type"' => array('value' => "corporate"),
),
),
);
return $form;
}
Place $ sign at line no 2
$form = array();