<?php
namespace App\Model\Table;

use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * Cmsusers Model
 *
 * @property \Cake\ORM\Association\BelongsTo $Companies
 */
class SupportsTable extends Table
{

    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config)
    {
        parent::initialize($config);

        $this->table('supports');
        $this->primaryKey('id');





    }
    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('cms_user_id')
            ->notEmpty('cms_user_id');

        $validator
            ->integer('priority')
            ->notEmpty('priority');

        $validator
            ->integer('parent_id')
            ->notEmpty('parent_id');

        $validator
            ->notEmpty('title');
            
        $validator
            ->notEmpty('video_url');

        $validator
            ->notEmpty('description');

        $validator
            ->integer('status')
            ->notEmpty('status');

        $validator
            ->date('reply_date')
            ->notEmpty('reply_date');

        $validator
            ->email('email')
            ->notEmpty('email');


        return $validator;
    }

    
    public function updateSupportTicketStatusById($id,$status){
        $result = false;
        if($id > 0){
            $ticket = $this->get($id);
            $ticket->status = $status;
            if($this->save($ticket)){
                $result = true;
            }
        }
        
        return $result;
    }

    public function updateSupportTicketDesc($id,$description){
        $result = false;
        if($id > 0){
            $condition['id'] = $id;
            $fields['description'] = $description;
            if($this->updateAll($fields,$condition)){
                $result = true;
            }
        }

        return $result;
    }

    public function deleteSupportTicket($id){
        $result = false;
        if($id > 0){
            $condition['id'] = $id;
            if($this->deleteAll($condition)){
                $result = true;
            }
        }

        return $result;
    }
    
}
