<?php echo $form->labelEx($model, 'region_id'); ?> <?php $data = Region::model()->GetRegionsICanEdit(); echo CHtml::activeDropDownList($model, 'region_id', CHtml::listData($data, 'id', 'name'), array('empty' => Yii::t('app', 'choose'))); echo $form->error($model, 'region_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'municipality_id'); ?> <?php $data = Municipality::model()->GetMunicipalityICanEdit(); echo CHtml::activeDropDownList($model, 'municipality_id', CHtml::listData($data, 'id', 'name'), array('empty' => Yii::t('app', 'choose'))); echo $form->error($model, 'municipality_id'); ?> </div> <div class="row"> <?php echo $form->labelEx($model, 'tax_number'); ?> <?php echo $form->textField($model, 'tax_number', array('size' => 12, 'maxlength' => 12)); echo $form->error($model, 'tax_number'); ?> </div>
public static function SyncZavodiWhereKategorijaActive() { $schoolCategories = SchoolCategory::model()->findAll('active=:active', array(':active' => 1)); $kategorije = array(); $kategorija_map = array(); foreach ($schoolCategories as $schoolCategory) { $kategorije[] = $schoolCategory->name; $kategorija_map[$schoolCategory->name] = $schoolCategory->id; } echo "Current categories for sync:<br />"; pre_print($kategorije); $list = self::GetRegZavod(); if (!isset($list['return'])) { return array(); } $list = $list['return']; echo "Current schools to sync:<br />"; $country = Country::model()->find('country=:country', array(':country' => 'Slovenija')); if ($country == null) { echo "Add country Slovenija!<br />\n"; die; } $country_id = $country->id; // cache all občine $municipalities = Municipality::model()->findAll('country_id=:country_id', array(':country_id' => $country_id)); $municipality_map = array(); foreach ($municipalities as $municipality) { $municipality_map[$municipality->name] = $municipality->id; } // cache all regije $regions = Region::model()->findAll('country_id=:country_id', array(':country_id' => $country_id)); $region_map = array(); foreach ($regions as $region) { $region_map[$region->name] = $region->id; } $counter = 0; $updated = 0; $inserted = 0; for ($i = 0; $i < count($list); ++$i) { if (in_array($list[$i]['KATEGORIJA'], $kategorije)) { $counter++; $el = $list[$i]; $school = School::model()->find('name=:name and country_id=:country_id', array(':name' => trim($el['ZAVOD_NAZIV']), ':country_id' => $country_id)); if ($school == null) { $school = new School(); $school->name = trim($el['ZAVOD_NAZIV']); $school->country_id = $country_id; $inserted++; } $school->school_category_id = $kategorija_map[trim($el['KATEGORIJA'])]; // občina if (!isset($municipality_map[trim($el['OBCINANAZIV'])])) { $municipality = new Municipality(); $municipality->name = trim($el['OBCINANAZIV']); $municipality->country_id = $country_id; $municipality->save(); $municipality_map[trim($el['OBCINANAZIV'])] = $municipality->id; } $school->municipality_id = $municipality_map[trim($el['OBCINANAZIV'])]; // regija if (!isset($region_map[trim($el['REGIJANAZIV'])])) { $region = new Region(); $region->name = trim($el['REGIJANAZIV']); $region->country_id = $country_id; $region->save(); $region_map[trim($el['REGIJANAZIV'])] = $region->id; } $school->region_id = $region_map[trim($el['REGIJANAZIV'])]; $school->post = trim($el['POSTANAZIV']); $school->postal_code = trim($el['POSTASIFRA']); $school->identifier = trim($el['ZAVPRS']); $school->headmaster = trim($el['ZAVRAVN']); if (isset($el['ZAVDAVST'])) { $school->tax_number = trim($el['ZAVDAVST']); } if ($school->save()) { $updated++; } } } echo 'Found schools to sync: ', $counter, "<br />\n"; echo 'New schools imported: ', $inserted, "<br />\n"; echo 'Updated schools: ', $updated - $inserted, "<br />\n"; }
public function import($content) { $header_cols = array('name' => 0, 'school_category_id' => 1, 'level_of_education' => 2, 'post' => 3, 'postal_code' => 4, 'municipality_id' => 5, 'region_id' => 6, 'country_id' => 7); header('Content-Type: text/html; charset=utf-8'); $lines = explode("\n", $content); for ($i = 1; $i < count($lines); ++$i) { if (trim($lines[$i]) == '') { continue; } $cols = explode(";", $lines[$i]); // država $country_id = 0; $country = Country::model()->find('country=:country', array(':country' => trim($cols[$header_cols['country_id']]))); if ($country == null) { echo Yii::t('app', 'Country does not exist! Country: ') . trim($cols[$header_cols['country_id']]); die; } $country_id = $country->id; // regija $region = Region::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['region_id']]), ':country_id' => $country_id)); if ($region == null) { $region = new Region(); $region->country_id = $country_id; $region->name = trim($cols[$header_cols['region_id']]); $region->save(); } $region_id = $region->id; // občina $municipality = Municipality::model()->find('name=:name and country_id=:country_id', array(':name' => trim($cols[$header_cols['municipality_id']]), ':country_id' => $country_id)); if ($municipality == null) { $municipality = new Municipality(); $municipality->country_id = $country_id; $municipality->name = trim($cols[$header_cols['municipality_id']]); $municipality->save(); } $municipality_id = $municipality->id; $school_name = trim($cols[$header_cols['name']]); if ($school_name[0] == '"') { $school_name = mb_substr($school_name, 1, mb_strlen($school_name, 'UTF-8') - 2, 'UTF-8'); } $school_name = str_replace('""', '"', $school_name); $school = School::model()->find('name=:name and country_id=:country_id', array(':name' => $school_name, ':country_id' => $country_id)); if ($school == null) { $school = new School(); $school->name = $school_name; $school->country_id = $country_id; $school->municipality_id = $municipality_id; $school->region_id = $region_id; $school->post = trim($cols[$header_cols['post']]); $school->postal_code = trim($cols[$header_cols['postal_code']]); $school->school_category_id = (int) trim($cols[$header_cols['school_category_id']]); $school->level_of_education = (int) trim($cols[$header_cols['level_of_education']]); $school->save(); echo 'Imported: ', $school_name, "<br />\n"; if (count($school->errors) > 0) { print_r($school->errors); die; } } else { echo 'Already imported: ', $school_name, "<br />\n"; } } }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Municipality::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.')); } return $model; }