public function __construct()
 {
     if (Posts::countNewPosts() < Yii::$app->controller->module->getMaxCountPosting()) {
         $this->setProviders();
         $this->init();
         $this->run();
     }
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Posts::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $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(['id' => $this->id, 'type' => $this->type, 'status' => $this->status, 'sid' => $this->sid]);
     $query->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'tags', $this->tags])->andFilterWhere(['like', 'provider', $this->provider])->andFilterWhere(['like', 'created', $this->created])->andFilterWhere(['like', 'published', $this->published])->andFilterWhere(['like', 'url', $this->url]);
     return $dataProvider;
 }
Example #3
0
 public static function countNewPosts()
 {
     return Posts::find()->where(['status' => self::STATUS_NEW])->count();
 }
Example #4
0
    <h1><?php 
echo Html::encode($this->title);
?>
</h1>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <p>
        <?php 
echo Html::a('Create Posts', ['create'], ['class' => 'btn btn-success']);
?>
    </p>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'rowOptions' => function ($model) {
    if ($model->status == $model::STATUS_PUBLISHED) {
        return ['class' => 'success'];
    } elseif ($model->status == $model::STATUS_STOPPED) {
        return ['class' => 'danger'];
    }
}, 'columns' => [['attribute' => 'id', 'options' => ['width' => '30']], ['attribute' => 'type', 'options' => ['width' => '30']], 'text:ntext', ['attribute' => 'status', 'format' => 'html', 'filter' => Html::activeDropDownList($searchModel, 'status', Posts::getStatusAliases(), ['class' => 'form-control']), 'options' => ['width' => '30'], 'value' => function ($model) {
    return $model->getStatus();
}], ['attribute' => 'tags', 'options' => ['width' => '35']], ['attribute' => 'sid', 'options' => ['width' => '35']], ['attribute' => 'provider', 'options' => ['width' => '35']], ['attribute' => 'created', 'format' => ['date', 'php:Y-m-d H:i'], 'options' => ['width' => '200'], 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'created', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']])], ['attribute' => 'published', 'format' => ['date', 'php:Y-m-d H:i'], 'options' => ['width' => '200'], 'filter' => DatePicker::widget(['model' => $searchModel, 'attribute' => 'published', 'clientOptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd']])], ['attribute' => 'url', 'format' => 'raw', 'options' => ['width' => '80'], 'value' => function ($model) {
    return Html::a('Go Link', $model->url, ['title' => $model->url]);
}], ['class' => 'yii\\grid\\ActionColumn']]]);
?>

</div>
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPost()
 {
     return $this->hasOne(Posts::className(), ['id' => 'post_id']);
 }
Example #6
0
$form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]);
?>

    <?php 
echo $form->field($model, 'type')->dropDownList(Posts::getTypesAliases(), ['prompt' => '']);
?>

    <?php 
echo $form->field($model, 'text')->textarea(['rows' => 6]);
?>

    <?php 
if (!$model->isNewRecord) {
    ?>
        <?php 
    echo $form->field($model, 'status')->dropDownList(Posts::getStatusAliases(), ['prompt' => '']);
    ?>
    <?php 
}
?>

    <?php 
echo $form->field($model, 'tags')->textInput(['maxlength' => true]);
?>

    <?php 
echo $form->field($model, 'uploadFiles[]')->widget(FileInput::classname(), ['options' => ['accept' => 'image/*', 'multiple' => true], 'pluginOptions' => ["allowedFileExtensions" => ["jpg", "png", "gif"], 'initialPreview' => $model->getHtmlImagesArray(), 'overwriteInitial' => true]]);
?>

    <div class="form-group">
        <?php 
Example #7
0
 public function rules()
 {
     return ArrayHelper::merge(parent::rules(), [['text', 'required']]);
 }
 public function initPostCollection()
 {
     $model = new Posts();
     $this->_postCollection = $model->getNewPosts($this->_count);
 }
 /**
  * Finds the Posts model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Posts the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Posts::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function __construct($errorMessage, $errorCode, Posts $post)
 {
     $post->setScenario($post::SCENARIO_UPDATE);
     $post->status = Posts::STATUS_STOPPED;
     $post->update();
 }