コード例 #1
0
 /**
  * Returns data provider with filled models. Filter applied if needed.
  *
  * @param array $params an array of parameter values indexed by parameter names
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $this->load($params) && $this->validate();
     /** @var \yii\db\BaseActiveRecord $Model */
     $Model = Instance::ensure(['class' => Changelog::className()]);
     /** @var ChangelogQuery $ChangelogQuery */
     $ChangelogQuery = $Model::find();
     if (!empty($this->action)) {
         $ChangelogQuery->byAction($this->action);
     }
     if (!empty($this->entity_type)) {
         $ChangelogQuery->byEntityType($this->entity_type);
     }
     if (!empty($this->entity_id)) {
         $ChangelogQuery->byEntityId($this->entity_id);
     }
     /** @var ActiveDataProvider $DataProvider */
     $DataProvider = \Yii::createObject(['class' => ActiveDataProvider::className(), 'query' => $ChangelogQuery, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     return $DataProvider;
 }
コード例 #2
0
 /**
  * @inheritdoc
  */
 public static function save()
 {
     /** @var Changelog $Model */
     $Model = Instance::ensure(['class' => Changelog::className()]);
     /** @var Log $Log */
     $Log = Instance::ensure(['class' => Log::className()]);
     $columns = $Log::schema();
     $rows = [];
     $Logs = static::$storage;
     if (!empty($Logs)) {
         foreach ($Logs as $Log) {
             $rows[] = $Log->export();
         }
     }
     if (!empty($rows)) {
         /** @var \yii\db\Connection $DB */
         $DB = \Yii::$app->get('db');
         $DB->createCommand()->batchInsert($Model::tableName(), $columns, $rows)->execute();
     }
 }
コード例 #3
0
ファイル: detail.php プロジェクト: rmrevin/yii2-changelog
 * @author Revin Roman
 * @link https://rmrevin.com
 *
 * @var rmrevin\yii\changelog\debug\panels\ChangelogPanel $panel
 * @var rmrevin\yii\changelog\debug\models\search\ChangelogSearch $searchModel
 * @var yii\data\ActiveDataProvider $dataProvider
 */
use rmrevin\yii\changelog\resources\Changelog;
use yii\bootstrap\Modal;
use yii\di\Instance;
use yii\grid\GridView;
use yii\helpers\Html;
use yii\helpers\VarDumper;
use yii\widgets\Pjax;
/** @var Changelog $Model */
$Model = Instance::ensure(['class' => Changelog::className()]);
echo Html::tag('h1', $panel->getName());
Pjax::begin();
echo GridView::widget(['dataProvider' => $dataProvider, 'id' => 'db-panel-detailed-grid', 'options' => ['class' => 'detail-grid-view table-responsive'], 'filterModel' => $searchModel, 'filterUrl' => $panel->getUrl(), 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'action', 'filter' => $Model::getActions(), 'value' => function ($data) use($Model) {
    return empty($data['action']) ? \Yii::t('app', 'Unknown') : $Model::getActions()[$data['action']];
}, 'options' => ['width' => '10%']], ['format' => 'raw', 'attribute' => 'entity_type', 'filter' => $Model::getAllEntityTypes(), 'value' => function ($data) {
    $result = empty($data['entity_type']) ? \Yii::t('app', 'Unknown type') : $data['entity_type'];
    if (!empty($data['present'])) {
        $result .= '<br>' . Html::tag('small', sprintf(' > %s', $data['present']));
    }
    return $result;
}], ['attribute' => 'entity_id', 'options' => ['width' => '10%']], ['format' => 'raw', 'attribute' => 'changes', 'value' => function ($data) {
    $content = Html::tag('div', VarDumper::dumpAsString(unserialize($data['changes']), 10, true), ['class' => 'content changes hidden', 'data-id' => $data['id']]);
    return empty($data['changes']) ? null : Html::a(\Yii::t('app', 'show'), '#', ['data-role' => 'show-changes', 'data-id' => $data['id']]) . $content;
}, 'options' => ['width' => '7%']], ['format' => 'raw', 'attribute' => 'env', 'value' => function ($data) {
    $content = Html::tag('div', VarDumper::dumpAsString(unserialize($data['env']), 10, true), ['class' => 'content env hidden', 'data-id' => $data['id']]);