Example #1
0
 /**
  * Render static pages
  */
 public function actionStatic()
 {
     $sitemap = '<?xml version="1.0" encoding="UTF-8"?>' . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
     echo "Static pages for deputies...\n";
     $this->layout = 'deputy';
     $dir = \yii::getAlias('@frontend/депутати');
     $deputies = Deputy::find()->orderBy('name')->all();
     foreach ($deputies as $deputy) {
         // Save deputy page
         $this->view->params['deputy'] = $deputy;
         $pageHtml = $this->render('deputy', ['deputy' => $deputy]);
         $fileName = str_replace(' ', '-', "{$deputy->name} {$deputy->id}");
         $file = fopen("wfio://{$dir}/{$fileName}.html", 'w');
         fwrite($file, $pageHtml);
         fclose($file);
         // Append to sitemap
         $sitemap .= "<url><loc>http://vvkp.in.ua/депутати/{$fileName}.html</loc></url>";
     }
     echo "Sitemap...\n";
     $sitemap .= '</urlset>';
     file_put_contents(\yii::getAlias('@frontend') . '/sitemap.xml', $sitemap);
 }
Example #2
0
 /**
  * Import deputies' votes
  */
 public function actionVotes($url = '')
 {
     foreach (Law::find()->all() as $law) {
         // Skip
         if (!$law->urlVoting) {
             continue;
         }
         if ($url && $url !== $law->urlVoting) {
             continue;
         }
         // Get votes
         echo "{$law->id}\n";
         $content = file_get_contents($law->urlVoting);
         $content = iconv('windows-1251', 'utf-8', $content);
         $html = $this->parser->str_get_html($content);
         // Parse date
         $lawInfo = $html->find('.head_gol', 0)->plaintext;
         preg_match('/\\d\\d\\.\\d\\d\\.\\d\\d\\d\\d \\d\\d:\\d\\d/', $lawInfo, $matches);
         $law->dateVoting = date('Y-m-d H:i:s', strtotime($matches[0]));
         $law->save();
         // Parse votes
         $votes = $html->find('.golos');
         $deputyNo = 0;
         foreach (Deputy::find()->orderBy('name')->all() as $deputy) {
             // Delete voting
             DeputyLaw::deleteAll(['deputyId' => $deputy->id, 'lawId' => $law->id]);
             // Check if law voting date is in authority date range
             if ($law->dateVoting) {
                 if ($deputy->dateAuthorityStart > $law->dateVoting || $deputy->dateAuthorityStop && $deputy->dateAuthorityStop < $law->dateVoting) {
                     continue;
                 }
             }
             // Get vote
             $voteStr = strip_tags($votes[$deputyNo]->plaintext);
             if ($law->urlVoting === 'http://w1.c1.rada.gov.ua/pls/radan_gs09/ns_golos?g_id=3049' && in_array($deputy->name, array('Кулініч Олег Іванович', 'Мельничук Сергій Петрович', 'Рудик Сергій Ярославович'))) {
                 $vote = DeputyLaw::VOTE_YES;
             } else {
                 switch ($voteStr) {
                     case 'За':
                     case 'За*':
                         $vote = DeputyLaw::VOTE_YES;
                         break;
                     default:
                         $registration = Registration::find()->where(['deputyId' => $deputy->id, 'date' => date('Y-m-d', strtotime($law->dateVoting))])->andWhere(['<=', 'time', date('H:i:s', strtotime($law->dateVoting))])->orderBy('time DESC')->one();
                         if ($registration->isPresent) {
                             $vote = DeputyLaw::VOTE_NO;
                         } else {
                             $vote = DeputyLaw::VOTE_ABSENT;
                         }
                         break;
                 }
             }
             // Save law vote
             $deputyLaw = new DeputyLaw();
             $deputyLaw->setAttributes(['deputyId' => $deputy->id, 'lawId' => $law->id, 'vote' => $vote], false);
             $deputyLaw->save();
             // Next deputy index
             $deputyNo++;
         }
     }
 }