kartik-v / yii2-tabs-x

Extended bootstrap tabbed navigation widget for Yii 2.0 with various alignment and styling options.
Other
30 stars 17 forks source link

show filtered array in different tabs #68

Closed erenali closed 4 years ago

erenali commented 4 years ago

Hi, I'm trying to use tabsx for the different tabs and every tabs will show different filtred array. When I used basic view or basic data it show but I try the filter array with foreach , I take undefined variables error. First I'm taking the data in web service, then according to selected tab array filtered shown.

sitecontroller.php

public function actionUnisweb2($fkid)
    {    
        $options = array(
            'login' => 'xxxx', 'password' => 'yyyy',
            'cache_wsdl' => 0,
            'trace' => 1,
            'stream_context' => stream_context_create(array(
                  'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                  )
            )));
        $client = new \SoapClient("xxxxxxxx?wsdl", $options);       
        $akademisyenler = $client->GetAcademiciansByUnitId($fkid); 
        foreach ($akademisyenler as $kisi) {
                $list[$kisi->TcNo] = $client->GetPublications($kisi->TcNo); 
        }
        $listtek = call_user_func_array('array_merge', $list);
        $list2['deger']=$listtek;
        $this->layout = 'xxx';
        return ($this->render('unisweb',['fkid'=>$fkid,'list'=>$list2]));
    }

views/site/unisweb.php

<?php
use kartik\tabs\TabsX;
use yii\helpers\Url;
?>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js" crossorigin="anonymous"></script>
<?php 
 $m="Makale";
 $b="Bildiri";
 $k="Kitap";
$items = 
[
['label'=>'<i class="fas fa-chevron-right"></i> Tüm',
            'encode'=>false,
            'content' => (Yii::$app->controller->renderPartial('_view', ['model' => json_encode($list)])),
      ],
      [
            'label'=>'<i class="fas fa-user"></i> Makale',
            'items'=>[
                  [
                       'label'=>'<i class="fas fa-chevron-right"></i>'.date('Y'),
                       'options' => ['id' => 'makaleY'],
                       'encode'=>false,
                       'content'=>'',
                       'linkOptions'=>['data-url'=>Url::to(['/site/fetch?fkid='.$fkid.'&tab='.$m.'&yil='.strval(date('Y'))])]
                  ],
                  [
                       'label'=>'<i class="fas fa-chevron-right"></i>'.strval(date('Y')-1),
                       'encode'=>false,
                       'options' => ['id' => 'makaleZ'],
                       'content' => (Yii::$app->controller->renderPartial('contact_form2', ['model' => json_encode($list), 'yil'=>strval(date('Y')-1)])),
                  ],
            ],
      ],
];
echo TabsX::widget([
      'id' => 'tab-term-plan', 
      'items' => $items, 
      'position' => TabsX::POS_ABOVE, 
      'encodeLabels' => false]);
?>

I tried to linkoptions or content attributes but not take a response . My first tab work ,it show all data array.

Screenshot_2

When I clicked the "id=makaleY" tab linkoptions call fetch action and it runs but return error.

Screenshot_3 Screenshot_4

when I echo $secili_tur variables before foreach it shown, but this variables is not define in foreach. In this code, I want to filtered the this year's data in all array so I use foreach and array_filter.

sitecontroller.php

public function actionFetch($fkid,$tab,$yil)
    {    
        $options = array(
            'login' => 'xxxx', 'password' => 'yyyyy',
            'cache_wsdl' => 0,
            'trace' => 1,
            'stream_context' => stream_context_create(array(
                  'ssl' => array(
                        'verify_peer' => false,
                        'verify_peer_name' => false,
                        'allow_self_signed' => true
                  )
            )));

        $client = new \SoapClient("xxxxxx?wsdl", $options);

        $akademisyenler = $client->GetAcademiciansByUnitId($fkid); 

        foreach ($akademisyenler as $kisi) {
                $list[$kisi->TcNo] = $client->GetPublications($kisi->TcNo); //tüm akademisyenlerin listesi
        }
        $listtek = call_user_func_array('array_merge', $list);
        $list2['deger']=$listtek;

        $secili_yil=$yil;
        $secili_tur=$tab;

            if ($secili_tur == 'Makale') {
                $sorgu='($value->TurKod === "MAKALE_DIGER" or $value->TurKod === "MAKALE_TAM")';
            }elseif ($secili_tur == 'Bildiri' ) {       
                $sorgu='($value->TurKod === "BILDIRI")';
            }elseif ($secili_tur == 'Kitap') {      
                $sorgu='($value->TurKod === "KITAP_BOLUM" or $value->TurKod === "KITAP_ARASTIRMA")';
            }else{
                $sorgu='(1==1)';
            }
        foreach ($list2 as $key => $value) {
            $sonuc = array_filter($value, function($value){
                if (isset($value->BasimTarih) and isset($value->TurKod)) {                  
                  $a=$value->BasimTarih;
                  $yayinyili=substr($a, (strlen($a)-4),4);
                  if ($yayinyili === $secili_yil ) return true;
                }
                return false;
            });
        }
        //return $this->renderPartial('_view', ['sonuc'=>json_encode($sonuc)]);
        //return Yii::$app->controller->renderPartial('_view', ['sonuc'=>json_encode($sonuc)]);
        return Json::encode($sonuc);
    }

Thanks for helps.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.