Skip to content
This repository has been archived by the owner on Jan 18, 2019. It is now read-only.

Commit

Permalink
refactoring panchayats #26
Browse files Browse the repository at this point in the history
  • Loading branch information
Vikas Yadav committed Oct 11, 2017
1 parent cd49714 commit 0319ad0
Show file tree
Hide file tree
Showing 6 changed files with 485 additions and 3 deletions.
66 changes: 65 additions & 1 deletion protected/commands/VillageUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,70 @@
class VillageUpdateCommand extends CConsoleCommand
{
var $state;

public function actionRefactor()
{
//*******************
// identify districts
// create in lb_distrcts
// update in villages2011
$places = Village::model ()->findAll (
[
'select' => 'distinct id_district',
'condition' => 'id_lb_district is null'
] );
foreach ( $places as $district )
{
$this->refactorDistrict ( $district->id_district );
}

//*******************
// find blocks
// create in lb_block
// update in villages2011
$places = Village::model ()->findAll (
[
'select' => 'distinct id_district',
] );
foreach ( $places as $district )
{
$this->refactorBlock ( $district->id_district );
// find blocks
// create in lb_block
// update in villages2011
// find villages
// create in fb_village
// update village2011
// find wards
// create in fb_wards
// update in villages2011
}

}

public function refactorDistrict($id_place2)
{
$place = Place::model ()->findByPk ( $id_place2 );
if (! $place)
{
echo "$id_place2 Not found in place_names\n";
}
$dis = new District ();
$dis->name = $place->name;
$dis->id_state = $place->id_state;
if (! $dis->save ())
{
print_r ( $dis->errors );
die ();
}
$upctr = Village::model ()->updateAll ( [
'id_lb_district' => $dis->id_district
], 'id_district = :dis', [
':dis' => $id_place2
] );
echo "{$dis->state->name} \t {$dis->name} Saved. village records updated:$upctr\n";
}

public function actionIndex($id_state)
{
$this->state = State::model ()->findByPk ( $id_state );
Expand All @@ -32,7 +96,7 @@ public function step1($id_state)
echo $dirtyfile . ' already found, continue using it? (y/n)';
$yn = strtolower ( trim ( fgets ( STDIN ) ) );
if ('y' != $yn)
unlink($dirtyfile);
unlink ( $dirtyfile );
}

if (! file_exists ( $dirtyfile ))
Expand Down
101 changes: 101 additions & 0 deletions protected/models/Block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

/**
* This is the model class for table "lb_block".
*
* The followings are the available columns in table 'lb_block':
* @property integer $id_block
* @property integer $id_district
* @property string $name
* @property string $updated
*/
class Block extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'lb_block';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id_district, name, updated', 'required'),
array('id_district', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>70),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id_block, id_district, name, updated', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id_block' => 'Id Block',
'id_district' => 'Id District',
'name' => 'Name',
'updated' => 'Updated',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id_block',$this->id_block);
$criteria->compare('id_district',$this->id_district);
$criteria->compare('name',$this->name,true);
$criteria->compare('updated',$this->updated,true);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return Block the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
114 changes: 114 additions & 0 deletions protected/models/District.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

/**
* This is the model class for table "lb_district".
*
* The followings are the available columns in table 'lb_district':
* @property integer $id_district
* @property string $name
* @property string $updated
* @property integer $id_state
*/
class District extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'lb_district';
}

public function behaviors()
{
return [
'CTimestampBehavior' => array (
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => null,
'updateAttribute' => 'updated',
)
];
}


/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name, id_state', 'required'),
array('id_state', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id_district, name, updated, id_state', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'state' => array(self::BELONGS_TO, 'State', 'id_state'),
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id_district' => 'Id District',
'name' => 'Name',
'updated' => 'Updated',
'id_state' => 'Id State',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id_district',$this->id_district);
$criteria->compare('name',$this->name,true);
$criteria->compare('updated',$this->updated,true);
$criteria->compare('id_state',$this->id_state);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return District the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
101 changes: 101 additions & 0 deletions protected/models/LBVillage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php

/**
* This is the model class for table "lb_village".
*
* The followings are the available columns in table 'lb_village':
* @property integer $id_village
* @property integer $id_block
* @property string $name
* @property string $updated
*/
class LBVillage extends CActiveRecord
{
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'lb_village';
}

/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('id_block, name, updated', 'required'),
array('id_block', 'numerical', 'integerOnly'=>true),
array('name', 'length', 'max'=>255),
// The following rule is used by search().
// @todo Please remove those attributes that should not be searched.
array('id_village, id_block, name, updated', 'safe', 'on'=>'search'),
);
}

/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
);
}

/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'id_village' => 'Id Village',
'id_block' => 'Id Block',
'name' => 'Name',
'updated' => 'Updated',
);
}

/**
* Retrieves a list of models based on the current search/filter conditions.
*
* Typical usecase:
* - Initialize the model fields with values from filter form.
* - Execute this method to get CActiveDataProvider instance which will filter
* models according to data in model fields.
* - Pass data provider to CGridView, CListView or any similar widget.
*
* @return CActiveDataProvider the data provider that can return the models
* based on the search/filter conditions.
*/
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.

$criteria=new CDbCriteria;

$criteria->compare('id_village',$this->id_village);
$criteria->compare('id_block',$this->id_block);
$criteria->compare('name',$this->name,true);
$criteria->compare('updated',$this->updated,true);

return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}

/**
* Returns the static model of the specified AR class.
* Please note that you should have this exact method in all your CActiveRecord descendants!
* @param string $className active record class name.
* @return LBVillage the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
}
Loading

0 comments on commit 0319ad0

Please sign in to comment.