コード例 #1
0
 public function actionEdit($id)
 {
     $category = CategoryModel::getById($id);
     $totalCategories = CategoryModel::getTotal();
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $sortOrder = FL::clearInt($_POST['sortOrder']);
         $status = FL::clearInt($_POST['status']);
         if (!FL::isValue($name)) {
             $errors[] = 'Название не может быть пустым';
         }
         if (empty($errors)) {
             $category->name = $name;
             $category->sort_order = $sortOrder;
             $category->status = $status;
             $result = $category->save();
             if (!$result) {
                 $errors[] = 'Редактирование не удалось';
             } else {
                 FL::redirectTo('/admin/category');
             }
         }
     }
     $view = new View();
     $view->category = $category;
     $view->totalCategories = $totalCategories;
     $view->display('admin_category/edit.php');
     return true;
 }
コード例 #2
0
 public function actionIndex()
 {
     $product_count_main_page = FL::fileGetContents('product_count_main_page.txt');
     $product_count_catalog_page = FL::fileGetContents('product_count_catalog_page.txt');
     $product_count_category_page = FL::fileGetContents('product_count_category_page.txt');
     if (isset($_POST['submit'])) {
         if (isset($_POST['productCountMainPage'])) {
             $productCountMainPage = FL::clearInt($_POST['productCountMainPage']);
             AdminModel::filePutContents(ROOT . '/config/product_count_main_page.txt', $productCountMainPage);
         }
         if (isset($_POST['productCountCatalogPage'])) {
             $productCountCatalogPage = FL::clearInt($_POST['productCountCatalogPage']);
             AdminModel::filePutContents(ROOT . '/config/product_count_catalog_page.txt', $productCountCatalogPage);
         }
         if (isset($_POST['productCountCategoryPage'])) {
             $productCountCategoryPage = FL::clearInt($_POST['productCountCategoryPage']);
             AdminModel::filePutContents(ROOT . '/config/product_count_category_page.txt', $productCountCategoryPage);
         }
         FL::redirectTo('/admin/view');
     }
     $view = new View();
     $view->product_count_main_page = $product_count_main_page;
     $view->product_count_catalog_page = $product_count_catalog_page;
     $view->product_count_category_page = $product_count_category_page;
     $view->display('admin_view/index.php');
     return true;
 }
コード例 #3
0
ファイル: SiteController.php プロジェクト: php-user/shop.loc
 public function actionAbout()
 {
     $categories = CategoryModel::getAllUsingColumns();
     $view = new View();
     $view->categories = $categories;
     $view->display('site/about.php');
     return true;
 }
コード例 #4
0
ファイル: BlogController.php プロジェクト: php-user/shop.loc
 public function actionView($id)
 {
     $categories = CategoryModel::getAllUsingColumns();
     $blog = BlogModel::getById($id);
     $view = new View();
     $view->categories = $categories;
     $view->blog = $blog;
     $view->display('blog/view.php');
     return true;
 }
コード例 #5
0
 public function actionView($id)
 {
     $categories = CategoryModel::getAllUsingColumns();
     $product = ProductModel::getById($id);
     $view = new View();
     $view->categories = $categories;
     $view->product = $product;
     $view->display('product/view.php');
     return true;
 }
コード例 #6
0
 public function actionLogin()
 {
     /** @noinspection PhpIncludeInspection */
     $form = new FormBuilder(include $this->container->kernel->getAppDir() . '/views/default/loginform.php', new LoginFormModel($this->container), 'POST');
     if ($post = $this->container->request->post('LoginFormModel')) {
         $form->setModelData($post);
         /** @noinspection PhpUndefinedMethodInspection */
         if ($form->validateModel() && $form->getModel()->logined()) {
             $this->redirect('/profile');
         }
     }
     $v = new View($this->container);
     $v->addParameter('form', $form);
     return $v;
 }
コード例 #7
0
 public function actionCreate()
 {
     $blog = new Blog($this->container);
     /** @var array $blogData */
     if ($blogData = $this->container->request->post('Blog')) {
         $blog->name = $blogData['name'];
         $blog->content = $blogData['content'];
         if ($blog->save()) {
             $this->redirect('/blog/post/' . $blog->id);
         }
     }
     $v = new View($this->container);
     $v->addParameter('model', $blog);
     return $v;
 }
コード例 #8
0
ファイル: DB.php プロジェクト: php-user/shop.loc
 public function __construct()
 {
     $paramsPath = ROOT . '/config/db_params.php';
     $params = (include $paramsPath);
     $dsn = "mysql:host={$params['host']};dbname={$params['dbname']}";
     try {
         $this->db = new PDO($dsn, $params['user'], $params['password']);
         $this->db->exec("SET NAMES 'utf-8'");
     } catch (PDOException $e) {
         $logger = Logger::getInstance();
         $logger->setLog($e->getFile(), $e->getLine(), $e->getMessage());
         $view = new View();
         $view->error = "Нет соединения с БД";
         $view->display('error.php');
         die;
     }
 }
コード例 #9
0
 public function actionEdit($id)
 {
     $order = ProductOrderModel::getById($id);
     if (isset($_POST['submit'])) {
         $status = (int) $_POST['status'];
         if ($status) {
             $order->status = $status;
             $result = $order->save();
             if ($result) {
                 FL::redirectTo('/admin/order');
             }
         }
     }
     $view = new View();
     $view->order = $order;
     $view->display('admin_order/edit.php');
     return true;
 }
コード例 #10
0
 public function actionIndex()
 {
     $user = User::findByPk($this->container->user->getID(), $this->container);
     if (!$user) {
         $this->redirect('/logout');
     }
     /** @var array $setup */
     if ($setup = $this->container->request->post('Setup')) {
         if (!empty($setup['pass'])) {
             $user->pass = md5($setup['pass']);
         }
         if (!empty($setup['fio'])) {
             $user->fio = $setup['fio'];
         }
         $user->save();
     }
     $v = new View($this->container);
     $v->addParameter('user', $user);
     return $v;
 }
コード例 #11
0
 /**
  * @param type - тип фотки: photo, club
  * @param photoId
  */
 public static function actionView()
 {
     $post = Yii::$app->request->post();
     $photo_id = $post['photo_id'];
     $type = $post['type'];
     if ($type == 'photo') {
         View::viewPhoto($photo_id);
     } elseif ($type == 'club') {
         View::viewPhotoClub($photo_id);
     }
 }
コード例 #12
0
 public function actionEdit($id)
 {
     $id = (int) $id;
     $name = '';
     $password = '';
     $errors = [];
     $user = UserModel::getUser('user');
     if (!$user) {
         FL::redirectTo('/');
     }
     $categories = CategoryModel::getAllUsingColumns();
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $password = FL::clearStr($_POST['password']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isPassword($password)) {
             $errors[] = 'Пароль должен быть больше 5 символов';
         }
         if (empty($errors)) {
             $user = UserModel::getById($id);
             $user->name = $name;
             $user->password = $password;
             Session::deleteSession('user');
             Cookie::deleteCookie('user');
             $result = $user->save(false, true);
             if ($result) {
                 FL::redirectTo('/cabinet');
             }
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->id = $id;
     $view->errors = $errors;
     $view->password = $password;
     $view->user = $user;
     $view->display('cabinet/edit.php');
     return true;
 }
コード例 #13
0
 public function actionCreate()
 {
     $errors = [];
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $email = FL::clearStr($_POST['email']);
         $password = FL::clearStr($_POST['password']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isEmail($email)) {
             $errors[] = 'Некорректный email';
         }
         if (UserModel::getByColumn('email', $email)) {
             $errors[] = 'Такой email уже существует';
         }
         if (!FL::isPassword($password)) {
             $errors[] = 'Пароль должен быть больше 5 символов';
         }
         if (empty($errors)) {
             $user = new UserModel();
             $user->name = $name;
             $user->email = $email;
             $user->password = $password;
             $user->role = 'admin';
             $result = $user->save(false, true);
             if ($result) {
                 FL::redirectTo('/admin/user');
             }
         }
     }
     $view = new View();
     $view->errors = $errors;
     $view->display('admin_user/create.php');
     return true;
 }
コード例 #14
0
 public function actionCategory($categoryId, $page = 1)
 {
     $limit = FL::fileGetContents('product_count_category_page.txt');
     if (!$limit) {
         $limit = 9;
     }
     $page = (int) $page;
     $categories = CategoryModel::getAllUsingColumns();
     $products = ProductModel::getByCategoryId($categoryId, $limit, $page);
     if (!$products) {
         $products = [];
     }
     $total = ProductModel::getTotal('category_id', $categoryId);
     $pagination = FL::buildPagination($total, $page, $limit, 'page-');
     $view = new View();
     $view->categories = $categories;
     $view->products = $products;
     $view->categoryId = $categoryId;
     if (isset($pagination)) {
         $view->pagination = $pagination;
     }
     $view->display('catalog/category.php');
     return true;
 }
コード例 #15
0
ファイル: form.php プロジェクト: ThijsBosch/batboxes
						jQuery.each(result, function(index, value) {
							tmpString = '<div>' +
								'<label><input type="checkbox" name="Visits[checked_boxes][]" value="' + value.id + '"> ' + value.code + '</label>' +
							'</div>';
							htmlList.push(tmpString);
						});
						$('.boxList').html(htmlList.join(""))
						$('.field-visits-checked-boxes').show();
						HoldOn.close();
					});
				}
		
				function clearBoxList() {
					$('.field-visits-checked-boxes').hide();
					$('.boxList').html();
				}
			</script>
		<?php 
    View::endJs();
    ?>
	<?php 
} else {
    ?>
		<p><?php 
    echo Yii::t('app', "U heeft nog geen beschikbare projecten of projecten zonder kast.<br>Klik <a href='" . Url::toRoute('boxes/form') . "'>hier</a> om een nieuwe kast aan te maken of <a href='" . Url::toRoute('projects/form') . "'>hier</a> om een project aan te maken.");
    ?>
</p>
	<?php 
}
?>
</div>
コード例 #16
0
 public function actionIndex()
 {
     $v = new View($this->container);
     $v->addParameter('model', new User($this->container));
     return $v;
 }
コード例 #17
0
ファイル: CartController.php プロジェクト: php-user/shop.loc
 public function actionOrder()
 {
     $userName = '';
     $errors = [];
     $categories = CategoryModel::getAllUsingColumns();
     $productsKeysArray = Session::getSession('products');
     if ($productsKeysArray) {
         $keysArray = array_keys($productsKeysArray);
         $keysString = implode(',', $keysArray);
         if ($keysString) {
             $products = ProductModel::getAll($keysString);
             $amountPrice = CartModel::amountProductsPriceInCart($productsKeysArray, $products);
         }
     }
     $user = UserModel::getUser('user');
     if ($user) {
         $userName = $user->name;
         $userId = $user->id;
     } else {
         $userId = 0;
     }
     if (isset($_POST['submit'])) {
         $name = FL::clearStr($_POST['name']);
         $phone = FL::clearStr($_POST['phone']);
         $comment = FL::clearStr($_POST['comment']);
         if (!FL::isValue($name)) {
             $errors[] = 'Имя не может быть пустым';
         }
         if (!FL::isValue($phone)) {
             $errors[] = 'Телефон не может быть пустым';
         }
         if (!FL::isPhone($phone)) {
             $errors[] = 'Невалидный телефон';
         }
         if (!FL::isValue($comment)) {
             $errors[] = 'Комментарий не может быть пустым';
         }
         if (empty($errors)) {
             $productsKeysArray = Session::getSession('products');
             if ($productsKeysArray) {
                 $products = json_encode($productsKeysArray);
             }
             $cart = new CartModel();
             $cart->user_name = $name;
             $cart->user_phone = $phone;
             $cart->user_comment = $comment;
             $cart->user_id = $userId;
             $cart->products = $products;
             $orderId = $cart->save();
             if ($orderId) {
                 Session::deleteSession('products');
                 Session::createSession('message', 'Заказ оформлен!');
                 FL::redirectTo('/cart');
             }
         }
     } else {
         $countProducts = CartModel::countProductsInCart();
         if ($countProducts <= 0) {
             FL::redirectTo('/');
         }
     }
     $view = new View();
     $view->categories = $categories;
     $view->amountPrice = $amountPrice;
     $view->userName = $userName;
     $view->errors = $errors;
     $view->display('cart/order.php');
     return true;
 }
コード例 #18
0
ファイル: UserController.php プロジェクト: php-user/shop.loc
 public function actionLogin()
 {
     $email = '';
     $password = '';
     $remember = '';
     $errors = [];
     if (isset($_POST['submit'])) {
         $email = FL::clearStr($_POST['email']);
         $password = FL::clearStr($_POST['password']);
         if (isset($_POST['remember'])) {
             $remember = $_POST['remember'];
         }
         if (!FL::isEmail($email)) {
             $errors[] = 'Некорректный email';
         }
         if (!FL::isValue($password)) {
             $errors[] = 'Пароль не может быть пустым';
         }
         if (empty($errors)) {
             $user = UserModel::checkRegister($email, $password, $remember);
             if ($user) {
                 Session::createSession('user', $user, true);
                 FL::redirectTo('/cabinet');
             } else {
                 $errors[] = 'Неправильные данные для входа на сайт';
             }
         }
     }
     $categories = CategoryModel::getAllUsingColumns();
     $view = new View();
     $view->categories = $categories;
     $view->email = $email;
     $view->password = $password;
     $view->errors = $errors;
     $view->display('user/login.php');
     return true;
 }
コード例 #19
0
ファイル: index.php プロジェクト: php-user/shop.loc
<?php

use App\Components\Router;
use App\Components\View;
use App\Components\Logger;
use App\Components\FunctionLibrary as FL;
// Front Controller
// 1. Общие настройки
ini_set('display_errors', 1);
error_reporting(E_ALL);
session_start();
// 2. Подключение системных файлов
define('ROOT', dirname(__FILE__));
require_once ROOT . '/components/autoload.php';
// 3. Вызов Router
try {
    $router = new Router();
    $router->run();
    FL::deleteLink();
} catch (Exception $e) {
    $logger = Logger::getInstance();
    $logger->setLog($e->getFile(), $e->getLine(), $e->getMessage());
    $view = new View();
    $view->error = $e->getMessage();
    $view->display('error.php');
}
コード例 #20
0
 public function actionDelete($id)
 {
     $product = ProductModel::getById($id);
     if (isset($_POST['delNo'])) {
         FL::redirectTo('/admin/product');
     }
     if (isset($_POST['delYes'])) {
         $result = ProductModel::delete($id);
         if ($result) {
             FL::redirectTo('/admin/product');
         }
     }
     $view = new View();
     $view->product = $product;
     $view->display('admin_product/delete.php');
     return true;
 }
コード例 #21
0
 public function actionPhoto($photo_id)
 {
     $photo = ClubPhoto::getAllPhotoInfo($photo_id);
     $club_id = $photo['club_id'];
     $this->getClubInfo($club_id, $club, $role, $potentialMembers, $isOpen);
     if (!$club['club_id']) {
         throw new \yii\web\HttpException(404);
     }
     if (!$isOpen) {
         return $this->redirect("/club{$club_id}");
     }
     View::viewPhotoClub($photo_id);
     $model = new CommentsClub();
     $from = "comments_club";
     $comments = Comments::getCommentsNew($photo_id, $from);
     $request = Yii::$app->request;
     if (!$club['is_closed_comments'] && $request->isAjax && $model->load($request->post()) && $model->validate()) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $model->date_time = date('Y-m-d H:i:s');
         $model->id_user = Yii::$app->user->getId();
         $model->text = htmlspecialchars($model->text);
         //визначення чи це простий комент чи це ре-комент
         $text = explode(":", $model->text);
         //перевіряємо чи введено коректне ім'я користувача якому дана відповідь
         $true_name = 0;
         foreach ($comments as $key) {
             if ($key['name'] == $text[0]) {
                 $true_name = 1;
             }
         }
         if (!$true_name) {
             $model->answer_id = 0;
         }
         if ($model->save()) {
             ClubPhoto::updateComments($photo_id, 1);
             $latest_id = $model->id;
             $user = User::find()->select('avatar, name')->where(["id" => $model->id_user])->one();
             echo json_encode(['text' => $model->text, 'id_user' => $model->id_user, 'name' => $user[name], 'avatar' => $user[avatar], 'id_comment' => $latest_id]);
             die;
         } else {
             echo 0;
         }
     }
     return $this->render('photo_page', ['club' => $club, 'photo' => $photo, 'comments' => $comments, 'model' => $model]);
 }
コード例 #22
0
ファイル: detail.php プロジェクト: ThijsBosch/batboxes
	<?php 
} else {
    ?>
		var marker = new google.maps.Marker({
			position: {'lat': <?php 
    echo $box->cord_lat;
    ?>
, 'lng': <?php 
    echo $box->cord_lng;
    ?>
},
			map: map,
			icon: '/images/googlemap-pointer.png'
		});
		map.setZoom(14);
		map.setCenter(marker.position);
	<?php 
}
?>

	function calcBounds(center,size){
	    var n=google.maps.geometry.spherical.computeOffset(center,size.height/2,0).lat(),
	        s=google.maps.geometry.spherical.computeOffset(center,size.height/2,180).lat(),
	        e=google.maps.geometry.spherical.computeOffset(center,size.width/2,90).lng(),
	        w=google.maps.geometry.spherical.computeOffset(center,size.width/2,270).lng();
	        return new google.maps.LatLngBounds(new google.maps.LatLng(s,w), new google.maps.LatLng(n,e));
	 }
</script>
<?php 
View::endJS();
コード例 #23
0
 public function actionPost($slug)
 {
     $model = new CommentsBlog();
     //витягнення статті
     $post = Blog::getPostByUrl($slug);
     //якщо немає 404
     if (!$post['article_id']) {
         throw new \yii\web\HttpException(404);
     }
     //якщо стаття закрита адміністратором, то редірект на всі статті
     if (!$post['article_id'] || time() < $post['time_closed']) {
         return $this->redirect('/blog/all');
     }
     View::viewArticle($post['article_id'], $post['views']);
     //перевірка чи користувач лайкнув
     if (!Yii::$app->user->isGuest) {
         $post['islike'] = Blog::isLikeArticle($post['article_id'], Yii::$app->user->getId());
     } else {
         $post['islike'] = false;
     }
     $i_blocked = User::checkIfIInBlaclList($post['id_author']);
     $user_id = $post['user_id'];
     $marks = Marks::getArticleMarks(20);
     $categories = Category::getAllCategory();
     //інші статті автора
     $other_articles = Blog::getOtherArticle($user_id, 0, 2, $post['article_id']);
     foreach ($other_articles as &$article) {
         $article['text'] = substr($article['text'], 0, 350) . '...';
     }
     ////        КОМЕНТАРІ         ////
     //витягуємо всі коменті до статті
     $from = "comments_blog";
     //отримання всіх коментарів до фотографії
     $comments = Comments::getCommentsNew($post['article_id'], $from);
     $request = Yii::$app->request;
     if ($request->isAjax && $model->load($request->post()) && $model->validate()) {
         if (!Yii::$app->user->isGuest) {
             $author_id = Blog::getIdAuthorArticle($model['id_article']);
             if (!User::checkIfIInBlaclList($author_id)) {
                 Yii::$app->response->format = Response::FORMAT_JSON;
                 $model->date_time = date('Y-m-d H:i:s');
                 $model->id_user = Yii::$app->user->getId();
                 $model->text = htmlspecialchars($model->text);
                 //визначення чи це простий комент чи це ре-комент
                 $text = explode(":", $model->text);
                 //перевіряємо чи введено коректне ім'я користувача якому дана відповідь
                 $true_name = 0;
                 foreach ($comment as $key) {
                     if ($key['name'] == $text[0]) {
                         $true_name = 1;
                     }
                 }
                 if (!$true_name) {
                     $model->answer_id = 0;
                 }
                 if ($model->save()) {
                     Blog::updateComments($post['article_id'], 1);
                     $latest_id = $model->id;
                     $user = User::find()->select('avatar, name')->where(["id" => $model->id_user])->one();
                     echo json_encode(['text' => $model->text, 'id_user' => $model->id_user, 'name' => $user['name'], 'avatar' => $user['avatar'], 'sex' => $user['sex'], 'id_comment' => $latest_id]);
                     die;
                 } else {
                     echo 0;
                 }
             } else {
                 return json_encode('error');
             }
         }
         ////        КОМЕНТАРІ         ////
     } else {
         return $this->render('post', ['post' => $post, 'other_articles' => $other_articles, 'marks' => $marks, 'categories' => $categories, 'user_id' => $user_id, 'model' => $model, 'comments' => $comments, 'i_blocked' => $i_blocked]);
     }
 }
コード例 #24
0
ファイル: AdminController.php プロジェクト: php-user/shop.loc
 public function actionIndex()
 {
     $view = new View();
     $view->display('admin/index.php');
     return true;
 }
コード例 #25
0
ファイル: form.php プロジェクト: ThijsBosch/batboxes
?>
			<?php 
echo $form->field($model, 'blur')->dropDownList(Projects::getBlurOptions());
?>
		    <?php 
echo $form->field($model, 'embargo')->widget(DatePicker::className(), ['type' => 1, 'options' => ['placeholder' => Yii::t('app', 'Selecteer datum')], 'pluginOptions' => ['format' => 'dd-mm-yyyy', 'todayHighlight' => true, 'autoclose' => true, 'weekStart' => 1]]);
?>
		    <?php 
echo $form->field($model, 'remarks')->widget(\yii\redactor\widgets\Redactor::className(), ['clientOptions' => ['buttons' => ['formatting', 'bold', 'italic', 'unorderedlist', 'orderedlist', 'outdent', 'indent', 'link', 'alignment', 'horizontalrule']]]);
?>
    	</div>
        <div class="form-group">
            <?php 
echo Html::submitButton(Yii::t('app', 'Opslaan'), ['class' => 'btn btn-primary pull-right']);
?>
        </div>
    <?php 
ActiveForm::end();
?>
</div>

<?php 
echo View::beginJs();
?>
<script>
	/* CSS fix */
	$('.select2-search__field').attr('style', 'width: 100%;');
</script>
<?php 
echo View::endJs();
コード例 #26
0
 public function actionEdit($id)
 {
     $errors = [];
     $blog = BlogModel::getById($id);
     if (isset($_POST['submit'])) {
         $title = FL::clearStr($_POST['title']);
         $description = FL::clearStr($_POST['description']);
         $content = FL::clearStr($_POST['content']);
         if (!FL::isValue($title)) {
             $errors[] = 'Название не может быть пустым';
         }
         if (!FL::isValue($description)) {
             $errors[] = 'Описание не может быть пустым';
         }
         if (!FL::isValue($content)) {
             $errors[] = 'Контент не может быть пустым';
         }
         if (empty($errors)) {
             $blog->title = $title;
             $blog->description = $description;
             $blog->content = $content;
             $res = $blog->save();
             if ($res) {
                 if ($_FILES['image']['name'] && $_FILES['image']['type'] == 'image/jpeg') {
                     $fileName = 'blog' . $id . '.jpg';
                     $tmpName = $_FILES['image']['tmp_name'];
                     if (is_uploaded_file($tmpName)) {
                         $imagePath = '/images/blog/' . $fileName;
                         $destination = ROOT . '/template/images/blog/' . $fileName;
                         $result = move_uploaded_file($tmpName, $destination);
                         if ($result) {
                             $blog->image = $imagePath;
                             $blog->save();
                         }
                     }
                 }
             }
             FL::redirectTo('/admin/blog');
         }
     }
     $view = new View();
     $view->blog = $blog;
     $view->errors = $errors;
     $view->display('admin_blog/edit.php');
     return true;
 }
コード例 #27
0
 public function actionPhoto_page($id)
 {
     if (Photo::isClosedPhoto($id) == 1) {
         if (!Photo::checkPhotoAccess($id)) {
             $this->redirect('/id' . Yii::$app->user->getId());
         }
     }
     $model = new CommentsPhoto();
     $photo = Photo::getAllPhotoInfo($id);
     $i_blocked = User::checkIfIInBlaclList($photo['user_id']);
     if (!$photo['photo_id']) {
         throw new \yii\web\HttpException(404);
     }
     if ($photo['time_closed'] > time() && $photo['user_id'] != Yii::$app->user->getId()) {
         return $this->render('close_photo.php', ['time' => $photo['time_closed']]);
     }
     if ($photo['time_closed'] > time()) {
         $photo['photo_closed'] = "Дане фото було заблоковане";
     }
     //отримання всіх коментарів до фотографії
     $from = "comments_photo";
     $comments = Comments::getCommentsNew($photo['photo_id'], $from);
     $request = Yii::$app->request;
     if ($request->isAjax && $model->load($request->post()) && $model->validate()) {
         if (!User::checkIfIInBlaclList($photo['user_id'])) {
             Yii::$app->response->format = Response::FORMAT_JSON;
             $model->date_time = date('Y-m-d H:i:s');
             $model->id_user = Yii::$app->user->getId();
             $model->text = htmlspecialchars($model->text);
             //визначення чи це простий комент чи це ре-комент
             $text = explode(":", $model->text);
             //перевіряємо чи введено коректне ім'я користувача якому дана відповідь
             $true_name = 0;
             foreach ($comments as $key) {
                 if ($key['name'] == $text[0]) {
                     $true_name = 1;
                 }
             }
             if (!$true_name) {
                 $model->answer_id = 0;
             }
             if ($model->save()) {
                 Photo::updateComments($photo['photo_id'], 1);
                 $latest_id = $model->id;
                 $user = User::find()->select('avatar, name')->where(["id" => $model->id_user])->one();
                 echo json_encode(['text' => $model->text, 'id_user' => $model->id_user, 'name' => $user['name'], 'avatar' => $user['avatar'], 'id_comment' => $latest_id]);
                 die;
             } else {
                 echo 0;
             }
         } else {
             return json_encode('error');
         }
     }
     View::viewPhoto($photo['photo_id'], $photo['photo_views']);
     return $this->render('photo_page', ['photo' => $photo, 'comments' => $comments, 'model' => $model, 'estimation' => self::$estimation, 'i_blocked' => $i_blocked]);
 }