Esempio n. 1
0
 /**
  * Рисует графики с прошлым и будущим
  *
  * @param int $id идентификатор курса
  *
  * @return string
  */
 public function actionStock_item3($id)
 {
     $item = \app\models\Stock::find($id);
     $start = (new \DateTime())->sub(new \DateInterval('P31D'));
     $end = (new \DateTime())->sub(new \DateInterval('P1D'));
     $isPaid = Yii::$app->user->identity->isPaid($id);
     $defaultParams = ['start' => $start, 'end' => $end, 'formatX' => 'd.m'];
     $params = ArrayHelper::merge($defaultParams, ['rows' => [\app\models\StockKurs::query(['stock_id' => $id])->andWhere(['between', 'date', $start->format('Y-m-d'), $end->format('Y-m-d')])->all()]]);
     $lineArrayKurs = \app\service\GraphExporter::convert($params);
     $params = ArrayHelper::merge($defaultParams, ['rows' => [\app\models\StockPrognosisRed::query(['stock_id' => $id])->andWhere(['between', 'date', $start->format('Y-m-d'), $end->format('Y-m-d')])->select(['date', 'delta as kurs'])->all()]]);
     $lineArrayRed = \app\service\GraphExporter::convert($params);
     $params = ArrayHelper::merge($defaultParams, ['rows' => [\app\models\StockPrognosisBlue::query(['stock_id' => $id])->andWhere(['between', 'date', $start->format('Y-m-d'), $end->format('Y-m-d')])->select(['date', 'delta as kurs'])->all()]]);
     $lineArrayBlue = \app\service\GraphExporter::convert($params);
     $lineArrayPast = \app\service\GraphUnion::convert(['x' => $lineArrayRed['x'], 'y' => [$lineArrayKurs['y'][0], $lineArrayRed['y'][0], $lineArrayBlue['y'][0]]]);
     if ($isPaid) {
         $start = new \DateTime();
         $end = (new \DateTime())->add(new \DateInterval('P30D'));
         $defaultParams = ['start' => $start, 'end' => $end];
         $params = ArrayHelper::merge($defaultParams, ['rows' => [\app\models\StockPrognosisRed::query(['stock_id' => $id])->andWhere(['between', 'date', $start->format('Y-m-d'), $end->format('Y-m-d')])->select(['date', 'delta as kurs'])->all()]]);
         $lineArrayRed = \app\service\GraphExporter::convert($params);
         $params = ArrayHelper::merge($defaultParams, ['rows' => [\app\models\StockPrognosisBlue::query(['stock_id' => $id])->andWhere(['between', 'date', $start->format('Y-m-d'), $end->format('Y-m-d')])->select(['date', 'delta as kurs'])->all()]]);
         $lineArrayBlue = \app\service\GraphExporter::convert($params);
         $lineArrayFuture = \app\service\GraphUnion::convert(['x' => $lineArrayRed['x'], 'y' => [$lineArrayRed['y'][0], $lineArrayBlue['y'][0]]]);
     } else {
         $lineArrayFuture = null;
     }
     return $this->render(['item' => $item, 'lineArrayPast' => $lineArrayPast, 'lineArrayFuture' => $lineArrayFuture, 'isPaid' => $isPaid]);
 }
Esempio n. 2
0
<?php

use yii\helpers\Url;
use yii\helpers\Html;
/* @var $this \yii\web\View */
/* @var $item  \app\models\Stock */
$this->title = $item->getField('name');
?>

<h1 class="page-header"><?php 
echo $this->title;
?>
</h1>



<?php 
echo \cs\Widget\ChartJs\Line::widget(['width' => 800, 'lineArray' => \app\service\GraphExporter::convert(['rows' => [\app\models\StockKurs::query(['stock_id' => $item->getId()])->all(), \app\models\StockPrognosis::query(['stock_id' => $item->getId()])->all()]])]);