<?php

namespace MGModule\DNSManager2\models\whmcs\clients;
use MGModule\DNSManager2 as main;

/**
 * Client Model
 * 
 * @Table(name=tblclients,preventUpdate,prefixed=false)
 * @author Michal Czech <michael@modulesgarden.com>
 */
class client extends \MGModule\DNSManager2\mgLibs\models\orm{
    /**
     *
     * @Column(id)
     * @var int
     */
    public $id;
    
    /**
     *
     * @Column()
     * @var string 
     */
    public $firstname;
    
    /**
     *
     * @Column()
     * @var string 
     */
    public $lastname;
    
    /**
     *
     * @Column()
     * @var string 
     */
    public $email;
    
    /**
     *
     * @Column()
     * @var string 
     */
    public $companyname;
    
    /**
     *
     * @Column()
     * @var string 
     */
    public $status;
    
    
    private $_customFields;
    
    
    function fullName(){
        return $this->firstname.' '.$this->lastname.(($this->companyname)?(' ('.$this->companyname.')'):'');
    }
    
    function getProfileUrl(){
        return 'clientssummary.php?userid='.$this->id;
    }
    
    /**
     * Get Custom Fields
     * 
     * @author Michal Czech <michael@modulesgarden.com>
     * @return customFields
     */
    function customFields(){
        if(empty($this->_customFields))
        {
            $this->_customFields = new main\models\whmcs\clients\customFields\repository($this->id);
        }
        
        return $this->_customFields;
    }

    public function getProfileLink()
    {
        return sprintf('<a href="%s">#%s %s</a>', $this->getProfileUrl(), $this->id, $this->fullName());
    }
}
