$prices_min = $this->prices()->limit(1)->orderBy('days')->first();
if($days < $prices_min) {
return $prices_min;
}
$exact_match = $this->prices()->where('days','=',$days)->first();
if($exact_match) {
return $exact_match;
}
$smaller = $this->prices()->where('days','<',$days)->first();
if($smaller) {
return $smaller;
}
throw new NotFoundException('Not Found');
$prices_min = $this->prices()->limit(1)->orderBy('days')->first();
if($days < $prices_min) {
$price = $prices_min;
}
$exact_match = $this->prices()->where('days','=',$days)->orWhere('days','<',$days)->orderByDesc('days')->first();
if($exact_match) {
$price = $exact_match;
}
public static function getProviderByTotalParams()
{
$mainTable = self::tableName();
$sql = '
SELECT m_departments.id, m_departments.name,
COUNT(m_news.id) + COUNT(m_posts.id) + COUNT(m_forums.id) + COUNT(m_questions.id) AS total_count
FROM m_departments
LEFT JOIN m_news ON m_departments.id = m_news.department_id
LEFT JOIN m_posts ON m_departments.id = m_posts.department_id
GROUP BY m_departments.id
ORDER BY total_count DESC
LIMIT 5
';
$dataProvider = new SqlDataProvider([
'sql' => $sql,
'totalCount' => 5,
'pagination' => [
'pageSize' => 5,
],
]);;
return $dataProvider;
}
<?php yii\widgets\Pjax::begin(['id' => 'new_note']) ?>
<?php $form = ActiveForm::begin(
[
'fieldConfig' => [
'template' => '{label}{error}{input}',
'inputOptions'=>[
'class'=>'form-control h-form__input h-input-response'
],
'options' => [
'tag' => 'div',
],
],
'options' => [
'data-pjax' => true,
]
]); ?>
<?= $form->field($model, 'description')->textarea([
'rows' => 6,
'style' => 'margin-bottom:0;'
])->label(false) ?>
<div class="c-voices__footer">
<?= Html::submitButton( Yii::t('app', 'send'), [
'class' => 'btn btn-success pull-right'
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php Pjax::end(); ?>
</div>