コード例 #1
0
 /**
  * Load model from backup
  * @param Page $model
  * @return bool if success
  */
 protected function loadBackup($model)
 {
     $data = Yii::$app->session->get('WEBSITE_PAGE_BACKUP_' . $model->id);
     if ($data && $model->load($data)) {
         $isDirty = count($model->getDirtyAttributes(['slug'])) > 0;
         foreach (I18N::getAvailableLanguages() as $language) {
             $modelI18n = $model->getTranslation($language['locale'], true);
             if ($modelI18n->load($data)) {
                 //Meta data
                 if ($modelI18n->meta_data && isset($modelI18n->meta_data['name']) && isset($modelI18n->meta_data['value'])) {
                     $metaData = array_filter(array_combine($modelI18n->meta_data['name'], $modelI18n->meta_data['value']));
                     if ($metaData) {
                         ksort($metaData);
                         $modelI18n->meta_data = $metaData;
                     } else {
                         $modelI18n->meta_data = null;
                     }
                 } else {
                     $modelI18n->meta_data = null;
                 }
                 $isDirty = $isDirty || count($modelI18n->getDirtyAttributes()) > 0;
             }
         }
         if ($isDirty) {
             if (isset($data['time'])) {
                 return $data['time'];
             } else {
                 return 0;
             }
         }
     }
     return false;
 }
コード例 #2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPage()
 {
     return $this->hasOne(Page::className(), ['id' => 'page_id']);
 }
コード例 #3
0
ファイル: index.php プロジェクト: maddoger/yii2-cms-website
     */
    foreach ($availableLanguages as $language) {
        $model->setLanguage($language['locale']);
        if (!$model->hasTranslation($language['locale'])) {
            continue;
        }
        $res .= '<tr><td>' . Html::a($model->title, $model->getUrl(), ['title' => Yii::t('maddoger/website', 'View on main website')]) . '</td><td class="text-right" width="50">' . $language['name'] . '</td></tr>';
    }
    $res .= '</tbody></table>';
    return $res;
}, 'format' => 'raw'], ['attribute' => 'status', 'value' => function ($model, $key, $index, $column) {
    $res = '
<div class="btn-group status-btn-group">
            <button type="button"
                    class="btn btn-xs btn-' . ($model->status == Page::STATUS_ACTIVE ? 'success' : 'warning') . ' dropdown-toggle"
                    data-toggle="dropdown"><span class="status-desc">' . $model->getStatusDescription() . '</span> <span
                    class="caret"></span>
            </button>
            <ul class="dropdown-menu" role="menu">';
    foreach ($model->getStatusList() as $key => $desc) {
        $res .= Html::tag('li', Html::a($desc, ['status', 'id' => $model->id, 'status' => $key], ['data-class' => $key == Page::STATUS_ACTIVE ? 'success' : 'warning']));
    }
    $res .= '</ul></div>';
    return $res;
}, 'format' => 'raw', 'options' => ['width' => '100'], 'filter' => Page::getStatusList()], ['attribute' => 'updated_at', 'format' => 'datetime', 'options' => ['width' => '150']], ['class' => 'yii\\grid\\ActionColumn', 'options' => ['width' => '100']]]]);
?>
        </div>
    </div>

</div>