Exemplo n.º 1
0
 public static function getContents($where = null, $orderBy = null, $limit = 10, $options = [])
 {
     $query = Content::find();
     if (!empty($where)) {
         $query->andWhere($where);
     }
     if (isset($options['is_pic'])) {
         $query->andWhere(['!=', 'thumb', '']);
     }
     if (isset($options['content_type'])) {
         $type = null;
         if (is_string($options['content_type'])) {
             $type = $options['content_type'];
         } else {
             $moduleId = LuLu::$app->controller->module->id;
             if ($moduleId !== 'app-frontend') {
                 $type = $moduleId;
             }
         }
         if (!empty($type)) {
             $query->andWhere(['=', 'content_type', $type]);
         }
     }
     if (empty($orderBy)) {
         $orderBy = 'created_at desc';
     }
     $query->orderBy($orderBy);
     if ($limit > 0) {
         $query->limit($limit);
     }
     return $query->all();
 }
Exemplo n.º 2
0
	public function actionDetail($id)
	{
	    Content::updateAllCounters(['view_count'=>1],['id'=>$id]);
	     
	    $locals = $this->getDetail($id);
	
	    return $this->render('detail_default', $locals);
	}
Exemplo n.º 3
0
 public function actionIndex()
 {
     $query = Content::leftJoinWith('takonomy');
     $locals = LuLu::getPagedRows($query, ['orderBy' => 'created_at desc', 'pageSize' => 6]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 5]]);
     $locals['dataProvider'] = $dataProvider;
     return $this->render('index', $locals);
 }
Exemplo n.º 4
0
 protected function findModel($id)
 {
     if (($model = Content::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 5
0
 public function actionDetail($id)
 {
     Content::updateAllCounters(['view_count' => 1], ['id' => $id]);
     $locals = $this->getDetail($id);
     $locals['taxonomyModel'] = $this->taxonomyService->getTaxonomyById($locals['model']['taxonomy_id']);
     $vars = $this->getDetailVars($locals['taxonomyModel'], $locals['model']);
     $this->layout = $vars['layout'];
     return $this->render($vars['view'], $locals);
 }
Exemplo n.º 6
0
 public function getDetail($id)
 {
     $model = Content::getBody(ContentPost::className(), [
         'a.id' => $id
     ])->one();
    
     return [
         'model' => $model
     ];
 }
Exemplo n.º 7
0
 public function actionIndex()
 {
     $query = Content::leftJoinWith('takonomy');
     $locals = LuLu::getPagedRows($query, [
         'orderBy' => 'created_at desc', 
         'pageSize' => 6
     ]);
     
     return $this->render('index', $locals);
 }
Exemplo n.º 8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Content::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere([]);
     $query->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'last_user_name', $this->last_user_name])->andFilterWhere(['like', 'password', $this->password])->andFilterWhere(['like', 'content_type', $this->content_type])->andFilterWhere(['like', 'seo_title', $this->seo_title])->andFilterWhere(['like', 'seo_keywords', $this->seo_keywords])->andFilterWhere(['like', 'seo_description', $this->seo_description])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'summary', $this->summary])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'url_alias', $this->url_alias]);
     return $dataProvider;
 }
Exemplo n.º 9
0
 private static function buildContentQuery($where = null, $options = [])
 {
     $query = Content::findPublished($where);
     if (isset($options['taxonomy'])) {
         $ids = [];
         if (is_array($options['taxonomy'])) {
             foreach ($options['taxonomy'] as $t) {
                 if (intval($t) > 0) {
                     $ids[] = intval($t);
                 }
             }
         } else {
             if (intval($options['taxonomy']) > 0) {
                 $ids = intval($options['taxonomy']);
             }
         }
         if (!empty($ids)) {
             $query->andWhere(['taxonomy_id' => $ids]);
         }
     }
     foreach (['recommend', 'headline', 'sticky'] as $att) {
         if (isset($options[$att]) && is_integer($options[$att])) {
             $query->andWhere([$att => $options[$att]]);
         }
     }
     if (isset($options['flag'])) {
         $flagValue = Common::getFlagValue($options['flag']);
         if ($flagValue > 0) {
             $query->andWhere('flag&' . $flagValue . '>0');
         }
     }
     if (isset($options['is_pic'])) {
         $query->andWhere(['!=', 'thumb', '']);
     }
     if (isset($options['content_type'])) {
         if (is_string($options['content_type'])) {
             $type = $options['content_type'];
         } else {
             $module = LuLu::$app->controller->module;
             if (!$module instanceof Application) {
                 $type = $module->id;
             }
         }
         if (!empty($type)) {
             $query->andWhere(['content_type' => $options['content_type']]);
         }
     }
     return $query;
 }
Exemplo n.º 10
0
 public function actionIndex()
 {
     $taxonomy = LuLu::getGetValue('taxonomy');
     $query = Content::find();
     $query->where(['content_type' => $this->content_type]);
     $query->andFilterWhere(['taxonomy_id' => $taxonomy]);
     if ($taxonomy === null) {
         $taxonomyModel = Taxonomy::findOne(['id' => $taxonomy]);
     } else {
         $taxonomyModel = ['id' => null, 'name' => '所有'];
     }
     $locals = LuLu::getPagedRows($query, ['orderBy' => 'created_at desc', 'pageSize' => 10]);
     $locals['taxonomyModel'] = $taxonomyModel;
     return $this->render('index', $locals);
 }
Exemplo n.º 11
0
					<input type='button' class='form-control' style="display: inline-block;width:60px;" value='浏览...' /> 
					<input type="file" name="Content[thumb]" class="file" onchange="document.getElementById('content-thumb').value=getFilePath(this);" /> 
				</div>
				
	
				<div class="help-block"></div>
			</div>
		</div>

		<div class="col-md-3 form-horizontal" >
	
			<?php 
echo $form->field($model, 'status')->dropDownList(Content::getStatusItems());
?>
			<?php 
echo $form->field($model, 'visibility')->dropDownList(Content::getVisibilityItems());
?>
			
			<?php 
echo $form->field($model, 'password')->passwordInput(['maxlength' => 64]);
?>
		
		    <?php 
echo $form->field($model, 'allow_comment')->checkbox([], false);
?>
		    
		    <?php 
echo $form->field($model, 'is_sticky')->checkbox([], false);
?>
		   
	
Exemplo n.º 12
0
<?php

use yii\web\View;
use yii\helpers\Html;
use yii\helpers\Url;
use source\libs\Resource;
use source\models\Content;
/* @var $this yii\web\View */
$themeUrl = Resource::getThemeUrl();
if (!isset($orderBy)) {
    $orderBy = 'created_at desc';
}
if (!isset($limit)) {
    $limit = 5;
}
$contents = Content::findAll(null, $orderBy, $limit);
?>

<?php 
foreach ($contents as $content) {
    ?>
<li><a href="<?php 
    echo Url::to(['/post/detail', 'id' => $content['id']]);
    ?>
" title="<?php 
    echo $content['title'];
    ?>
"><span class="thumbnail"><img src="<?php 
    echo $content['thumb'];
    ?>
?h=64&w=100&q=90&zc=1&ct=1" alt="这狗也能享受和人一样的待遇" /></span><span class="text"><?php 
Exemplo n.º 13
0
 public static function getBody($class, $condition = [], $columns = [])
 {
     $bodyModel = new $class();
     $table = $bodyModel::tableName();
     if (empty($columns)) {
         $columns = $bodyModel->getTableSchema()->columns;
     }
     $selects = ['a.*'];
     foreach ((array) $columns as $column) {
         $columnName = '';
         if (is_string($column)) {
             $columnName = $column;
         } else {
             $columnName = $column->name;
         }
         $selects[] = "body.{$columnName} as body_{$columnName}";
     }
     $query = new Query();
     $query->select($selects)->from(['a' => Content::tableName()])->innerJoin(['body' => $table], '{{a}}.[[id]]={{body}}.[[content_id]]');
     if (!empty($condition)) {
         $query->andWhere($condition);
     }
     return $query;
 }
Exemplo n.º 14
0
 public function getHead()
 {
     return $this->hasOne(Content::className(), ['id' => 'content_id']);
 }
Exemplo n.º 15
0
 public function actionIndex($id)
 {
     Content::updateAllCounters(['views' => 1], ['id' => $id]);
     $model = Content::findOne(['id' => $id]);
     return $this->render('index', ['model' => $model]);
 }
Exemplo n.º 16
0
 public function getDetail($id)
 {
     $model = Content::getBody($this->bodyClass, ['a.id' => $id])->one();
     return ['model' => $model];
 }
Exemplo n.º 17
0
use source\LuLu;
use source\models\Content;
/* @var $this yii\web\View */
/* @var $searchModel app\models\search\ContentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$type = 'post';
$this->title = '';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="content-index">

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('新建' . Content::getTypes($type), ['create', 'type' => $type], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'id', 'headerOptions' => ['style' => 'width:80px;']], 'title', ['attribute' => 'updated_at', 'format' => 'datetime', 'headerOptions' => ['style' => 'width:200px;']], ['attribute' => 'user_id', 'headerOptions' => ['style' => 'width:80px;']], ['attribute' => 'comments', 'headerOptions' => ['style' => 'width:80px;']], ['attribute' => 'views', 'headerOptions' => ['style' => 'width:80px;']], ['attribute' => 'status', 'headerOptions' => ['style' => 'width:80px;']], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Exemplo n.º 18
0
use source\LuLu;
/* @var $this yii\web\View */
if (!isset($orderBy)) {
    $orderBy = 'created_at desc';
}
if (!isset($limit)) {
    $limit = 5;
}
if (!isset($item)) {
    $item = 'item_pic';
}
$where = [];
if (!isset($isPic)) {
    $isPic = true;
}
$moduleId = LuLu::$app->controller->module->id;
if ($moduleId !== 'app-frontend') {
    $where = ['content_type' => $moduleId];
}
$query = Content::findQuery($where, $orderBy);
if ($isPic) {
    $query->andWhere(['!=', 'thumb', '']);
}
$query->limit($limit);
$contents = $query->all();
?>

<?php 
foreach ($contents as $content) {
    echo $this->render(Resource::getThemePath('/views/_inc/' . $item), ['content' => $content]);
}