<?php namespace TPS\Birzha\Controllers;

use Backend\Classes\Controller;
use BackendMenu;
use TPS\Birzha\Models\Comment as CommentModel;
use Sms\Sms\Models\SmsSender;
use Flash;

class Comment extends Controller
{
    public $implement = [        'Backend\Behaviors\ListController',        'Backend\Behaviors\FormController'    ];
    
    public $listConfig = 'config_list.yaml';
    public $formConfig = 'config_form.yaml';

    public function __construct()
    {
        parent::__construct();
        BackendMenu::setContext('TPS.Birzha', 'birzha-menu', 'side-menu-item3');
    }
    
    
    
    public function onSendSmsApprove($id){
        $comment = CommentModel::where("id", $id)->with(["product.vendor"])->first();
        
        $smsSender = new SmsSender();
        $smsSender->phone = (string)'+993'.$comment->product->vendor->username;
        $smsSender->message = strval((string) $comment->product->name.' teswir ýazyldy.');
        $smsSender->save();
        
        if($smsSender){
           
            Flash::info("Ustunlikli Habar edildi");
             //return $smsSender;
        }else{
            
            Flash::error("Ylanyshlyk yuze çykdy");
             //return $smsSender;
        }
    }
}
