Exemplo n.º 1
0
 public function loadProsecutorModel($id)
 {
     $model = Prosecutors::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Exemplo n.º 2
0
 public function actionFill_prosecutor_reference()
 {
     set_time_limit(0);
     $raw_html = file_get_contents('http://genproc.gov.ru/structure/subjects/');
     preg_match_all('`<select([\\s\\S]+)</select>`U', $raw_html, $_matches);
     preg_match_all('`<option value="([\\d]+)"[\\s\\S]*>([\\s\\S]+)</option>`U', $_matches[0][0], $_matches, PREG_SET_ORDER);
     //$_matches = array ( 0 => array ( 0 => '', 1 => '110', 2 => 'Центральный федеральный округ', ), 1 => array ( 0 => '', 1 => '111', 2 => 'Северо-Западный федеральный округ', ), 2 => array ( 0 => '', 1 => '112', 2 => 'Южный федеральный округ', ), 3 => array ( 0 => '', 1 => '241', 2 => 'Северо-Кавказский федеральный округ', ), 4 => array ( 0 => '', 1 => '113', 2 => 'Приволжский федеральный округ', ), 5 => array ( 0 => '', 1 => '114', 2 => 'Уральский федеральный округ', ), 6 => array ( 0 => '', 1 => '115', 2 => 'Сибирский федеральный округ', ), 7 => array ( 0 => '', 1 => '116', 2 => 'Дальневосточный федеральный округ', ), 8 => array ( 0 => '', 1 => '242', 2 => 'Центральный аппарат', ), );
     foreach ($_matches as &$set) {
         $raw_html = file_get_contents('http://genproc.gov.ru/structure/subjects/district-' . $set[1] . '/');
         if (!$raw_html) {
             echo $set[1] . ' - fail<br>';
             continue;
         }
         $raw_html = substr($raw_html, strpos($raw_html, '<dl class="institutions">'));
         $raw_html = explode('<div>', $raw_html);
         foreach ($raw_html as &$office) {
             $office = explode('</a>', $office);
             if ($office[1]) {
                 $office[0] = strip_tags($office[0]);
                 $subjects = explode("\n", $office[0]);
                 //print_r($subjects);
                 if (isset($subjects[2])) {
                     $itemname = $subjects[2];
                     $subjects[1] = preg_replace('/\\(.*\\)/i', '', $subjects[1]);
                     $subjectmodel = RfSubjects::model()->find("name_full LIKE '%" . trim($subjects[1]) . "%'");
                     if ($subjectmodel) {
                         $subject = $subjectmodel->id;
                     } else {
                         $subject = $subject = RfSubjects::model()->SearchID($subjects[1]);
                     }
                 } else {
                     $itemname = $subjects[0];
                     $subject = 0;
                 }
                 $r['name'] = trim(str_replace("\n", ' ', str_replace("\t", ' ', $office[0])));
                 $r['gibdd_name'] = trim(str_replace("\n", '', str_replace("\t", '', $itemname)));
                 $r['preview_text'] = trim(str_replace("\t", ' ', strip_tags($office[1], '<br>')));
                 $r['subject_id'] = $subject;
                 $model = Prosecutors::model()->find('subject_id=' . (int) $subject);
                 if (!$model) {
                     $model = new Prosecutors();
                 }
                 $model->attributes = $r;
                 $model->save();
             }
         }
         echo $set[1] . ' - ok<br>';
     }
 }