Beispiel #1
0
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #2
0
 /**
  * Возвращает модель поста.
  * @param int $id
  * @throws NotFoundHttpException в случае, когда пост не найден или не опубликован
  * @return Post
  */
 public function getPost($id)
 {
     if (($model = Post::findOne($id)) !== null && $model->isPublished()) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested post does not exist.');
     }
 }
Beispiel #3
0
 /**
  * Deletes an existing Comment model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $mode = $this->findModel($id);
     $post = Post::findOne($mode->post_id);
     $post->updateCounters(['comment_count' => -1]);
     $mode->delete();
     Comment::deleteAll('parent_id = ' . $id);
     return $this->redirect(['index']);
 }
Beispiel #4
0
 public function run()
 {
     $menu = Menu::find()->where(['position' => 'top'])->one();
     $p = explode(",", $menu->content);
     $pages = Page::find()->where(['id' => $p])->all();
     if (strpos(\Yii::$app->request->url, "view-post")) {
         $post = Post::findOne(\Yii::$app->request->get('id'));
         $current_page = $post->page;
     } else {
         $slug = \Yii::$app->request->get('slug');
         $current_page = Page::find()->where(['slug' => $slug])->one();
     }
     return $this->render('nav', ['pages' => $pages, 'current_page' => $current_page]);
 }
 public function actionEdit($id)
 {
     $postModel = Post::findOne(['id' => $id]);
     if ($postModel->load(Yii::$app->request->post()) && $postModel->save()) {
         $postModel->unlinkAll('categories', true);
         $selectedCategories = Category::find()->where(['id' => $postModel->categoryIds])->all();
         foreach ($selectedCategories as $category) {
             $postModel->link('categories', $category);
         }
         return $this->render('new', ['message' => 'Updated success', 'model' => new Post(), 'categoryList' => ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'title')]);
     }
     $postModel->categoryIds = ArrayHelper::getColumn($postModel->categories, 'id');
     return $this->render('edit', ['model' => $postModel, 'categoryList' => ArrayHelper::map(Category::find()->asArray()->all(), 'id', 'title')]);
 }
Beispiel #6
0
 public function run()
 {
     $menu = Menu::find()->where(['position' => 'top'])->one();
     $p = explode(',', $menu->content);
     $model = Page::find()->orderBy('display_order asc')->all();
     $pages = $this->tree($model, 0, $p);
     if (strpos(\Yii::$app->request->url, "view-post")) {
         $post = Post::findOne(\Yii::$app->request->get('id'));
         $current_page = $post->page;
     } else {
         $slug = \Yii::$app->request->get('slug');
         $current_page = Page::find()->where(['slug' => $slug])->one();
     }
     return $this->render('cateWidget', ['pages' => $pages, 'current_page' => $current_page]);
 }
Beispiel #7
0
 public function run()
 {
     if (strpos(\Yii::$app->request->url, "view-post")) {
         $post = Post::findOne(\Yii::$app->request->get('id'));
         $current_page = $post->page;
     } else {
         if (strpos(\Yii::$app->request->url, "view-album")) {
             $photo = Photo::findOne(\Yii::$app->request->get('id'));
             $current_page = $photo->page;
         } else {
             $slug = \Yii::$app->request->get('slug');
             $current_page = Page::find()->where(['slug' => $slug])->one();
         }
     }
     $parent = $current_page->parent_id == 0 ? null : Page::findOne($current_page->parent_id);
     return $this->render('breadCrumb', ['parent' => $parent, 'current_page' => $current_page]);
 }
Beispiel #8
0
 public function saveImages()
 {
     $this->CaMDir($this->id);
     $oPost = new Post();
     $aPost = $oPost->findOne($this->id);
     $sNiceName = $aPost['nice_link'];
     $sPath = $this->sPath . $this->id;
     //$files = $this->readDir($sPath);
     //echo '<pre>' .print_r($_FILES, TRUE). '</pre>'; die();
     $files = $_FILES['attachment_' . $this->id . ''];
     $sMaxFiles = count($files['name']);
     $aNumberFiles = $this->readDir($sPath . '/' . $this->sThumb);
     $sNumberFiles = $aNumberFiles['max'];
     for ($a = 0; $a < $sMaxFiles; $a++) {
         $iFileNumber = $sNumberFiles + $a + 1;
         $sFileName = $sNiceName . '-' . $iFileNumber;
         $ext = substr($files['name'][$a], strrpos($files['name'][$a], '.') + 1);
         move_uploaded_file($files['tmp_name'][$a], $sPath . '/' . $sFileName . '.' . $ext);
         $this->resizeImage($sPath, $sFileName, $ext);
     }
     return TRUE;
 }
Beispiel #9
0
?>
<!-- CONTACT ITEM -->
<div class="panel panel-default">
    <div class="panel-body profile">
        <div class="profile-image">
            <img src="/templates/atlant/assets/images/users/user3.jpg"
                 alt="Nadia Ali"/>
        </div>
        <div class="profile-data">
            <div class="profile-data-name"><?php 
echo $model->getFullName();
?>
</div>
            <div
                class="profile-data-title"><?php 
echo $model->post_id ? Post::findOne($model->post_id)->title : '';
?>
</div>
        </div>
        <div class="profile-controls">
            <a href="#" class="profile-control-left"><span
                    class="fa fa-info"></span></a>
            <a href="#" class="profile-control-right"><span
                    class="fa fa-phone"></span></a>
        </div>
    </div>
    <div class="panel-body">
        <div class="contact-info">
            <p>
                <small><?php 
echo Yii::t('app', 'Phone work (stationary)');
Beispiel #10
0
 /**
  * Finds the post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Monitor the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelpost($id)
 {
     if (($modelpost = Post::findOne($id)) !== null) {
         return $modelpost;
     } else {
         throw new NotFoundHttpException('Пост не найден.');
     }
 }
Beispiel #11
0
 public function getPostTileByPostId($id)
 {
     $raw = Post::findOne($id);
     return $raw['title'];
 }
Beispiel #12
0
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Post::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Strona nie istnieje.');
     }
 }
 public static function savePost(\common\components\Post $post)
 {
     $c = Post::findOne($post->getId());
     $c->post_text = $post->getContent();
     $c->post_editdate = date('Y-m-d H:i:s');
     return $c->save();
     //tu pobierz wszystko z posta i zapisz (łacznie z komentarzami itd.
 }
 public function actionGrab()
 {
     //        Yii::$app->response->format = Response::FORMAT_JSON;
     $success = true;
     $source = Source::find()->joinWith('logs')->where(['enable' => true])->orderBy(['updated' => SORT_ASC])->one();
     if ($source) {
         $grabber = new Grabber($source);
         $newPosts = $grabber->execute();
         if (!empty($newPosts)) {
             foreach ($newPosts as $post) {
                 $hashPost = md5($post);
                 // есть ли в базе Post или Moderation
                 $doubling = Post::findOne(['hash' => $hashPost]) || Moderation::findOne(['hash' => $hashPost]);
                 if ($doubling) {
                     continue;
                 }
                 // добавляем новый пост на модерацию
                 $model = new Moderation();
                 $model->text = $post;
                 $model->hash = $hashPost;
                 $model->ip = "127.0.0.1";
                 //Yii::$app->request->getUserIP();
                 $model->user_agent = "Auto Grabber";
                 //Yii::$app->request->getUserAgent();
                 $success = $model->save() && $success;
             }
         }
         $source->updateLog();
     }
     return $success;
 }
Beispiel #15
0
<?php

use app\components\helpers\Phone;
use app\models\Post;
use app\modules\department\models\Department;
use app\modules\user\models\User;
use yii\helpers\Html;
use yii\widgets\DetailView;
echo DetailView::widget(['model' => $model, 'attributes' => [['attribute' => 'post_id', 'value' => $model->post_id ? Post::findOne($model->post_id)->title : ''], ['attribute' => 'department_id', 'format' => 'raw', 'value' => $model->department_id ? Html::a(Department::findOne($model->department_id)->title, ['/department/view', 'id' => $model->department_id]) : ''], ['attribute' => 'user_id', 'format' => 'raw', 'value' => $model->user_id ? Html::a(User::findOne($model->user_id)->getName(), ['/user/view', 'id' => $model->user_id]) : ''], ['attribute' => 'phone_stationary', 'format' => 'raw', 'value' => Html::a(Phone::getFormatView($model->phone_work), 'tel:' . $model->phone_work)], ['attribute' => 'phone_work', 'format' => 'raw', 'value' => Html::a(Phone::getFormatView($model->phone_work), 'tel:' . $model->phone_work)], 'email_work:email', 'cabinet', 'worked_at:date', ['attribute' => 'experience', 'format' => 'raw', 'value' => $model->getExperience()], 'rate', ['attribute' => 'status', 'format' => 'raw', 'value' => 1]]]);
 /**
  * Finds the Post model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $alias
  * @return Post the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModelByAlias($alias)
 {
     if (($model = $post = Post::findOne(['alias' => $alias])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #17
0
 public function setDown($id)
 {
     $post = Post::findOne($id);
     $post->rating_plus += 1;
     $post->update();
 }