Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

merge two CActiveDataProvider and show result in a CGridview in yii

I have 2 model :

 $model = new ProfileInformation('internetConection');
 $modeliner = new ProfileInformation('inerConection');

I show those in 2 CGridView in yii how can show in a CGridView

Model:

 public function internetConection() {
        // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria = new CDbcriteria();
    $criteria->with = array('user');
    $criteria->condition = 'serviceId=:serviceId';
    $criteria->params = array(':serviceId' => '1');
    $criteria->group = 't.user_Id';
    $criteria->select = array('count(distinct psh_profile_information_services.profileInformationId) AS internetConectionCount');
    $criteria->join = 'left join psh_profile_information_services on t.id=psh_profile_information_services.profileInformationId';
    $criteria->order = 't.id';
    $criteria->compare('user_Id', $this->user_Id);
    $criteria->compare('isService', $this->isService, true);


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

public function inerConection() {
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria = new CDbcriteria();
    $criteria->with = array('user');
    $criteria->addInCondition('serviceId', array(2, 3, 4, 5));
    $criteria->group = 't.user_Id';
    $criteria->select = array('count(distinct psh_profile_information_services.profileInformationId) AS inerConectionCount');
    $criteria->join = 'left join psh_profile_information_services on t.id=psh_profile_information_services.profileInformationId';
    $criteria->order = 't.id';
    $criteria->compare('user_Id', $this->user_Id);
    $criteria->compare('isService', $this->isService, true);


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

I am using 2 CgridView now , but if i can show in a table it is very good. eache result search have a new field : inerConectionCount and internetConectionCount.

table for internetConectionCount table for internetConectionCount
table for inernetConectionCount table for inernetConectionCount

I want it: I want it:

 $this->widget('zii.widgets.grid.CGridView', array(
        'id' => 'profile-information-grid1',
        'dataProvider' => $dataprovider
            'columns' => array(
            array(
                'header' => '',
                'value' => '$this->grid->dataProvider->pagination->offset + $row+1', //  row is zero based
            ),

             array(
                'name' => 'ProfileInformation.user.organization',
                'value' => 'CHtml::encode($data->user->organization)',

            ),

            array(
                'name' => 'ProfileInformation.user.scope',
                'value' => 'CHtml::encode($data->user->scope->name)',
                'filter' => Scope::model()->options,
            ),
            array(
                'name' => 'id',
                'value' => 'CHtml::encode($data->id)',
            ),

          'inerConectionCount',



        ),
    ));
like image 980
maryam Avatar asked Dec 11 '25 10:12

maryam


1 Answers

You can combine data from two providers, but you have to disable pagination or it will limit to 10 record in each providers

$model = new ProfileInformation('internetConection');
$modeliner = new ProfileInformation('inerConection');

$data = CMap::mergeArray( // combine two data
    $model->search()->getData(),
    $modeliner ->search()->getData()
);

$provider = new CArrayDataProvider( $data ); // use CArrayDataProvider instead of CActiveDataProvider
like image 86
Developerium Avatar answered Dec 13 '25 23:12

Developerium



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!