Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Funkcja zwracająca tablicę danych, jak zmodyfikować funkcje aby otrzymać kilka tablic
pela222
post 26.03.2021, 13:41:54
Post #1





Grupa: Zarejestrowani
Postów: 85
Pomógł: 0
Dołączył: 17.04.2013

Ostrzeżenie: (0%)
-----


Cześć,
postaram się jak najlepiej opisać co chcę osiągnąć.
Poniżej jak to jest teraz:

  1. //Rekomendacja
  2. private function getRecomendationWOL($documentData) {
  3. $policies = $documentData['policies']['WOL'];
  4.  
  5. $recomend = array();
  6. $count = count($policies);
  7. for($n=0; $n<$count; $n++){
  8. //--- START grupa 1 ---
  9. $recomend[] = array('Podstawowe informacje ('.$policies[$n]['lifeInsured'].') ... '.$policies[$n]['company'].': ');
  10. $recomend[] = array('Podstawowe cd. '.$documentData['primary']['firstName'].' to ?'.$policies[$n]['primary']['lifeCover'].'. '.$policies[$n]['DOC']['lifedis'].'');
  11. $recomend[] = array('Podstawowe cd. '.$policies[$n]['DOC']['lifechanges']);
  12. //--- START grupa 2 ---
  13. $recomend[] = array('Informacje GRUPA 2.');
  14. $recomend[] = array('Informacje GRUPA 2 cd. .');
  15. //--- START grupa 3 ---
  16. $recomend[] = array('Dodatkowo informacje GRUPA 3');
  17. foreach ($policies[$n]['DOC']['companydis'] as $value) {
  18. if(!is_array($value)){
  19. $recomend[] = array($value);
  20. }
  21. }
  22. }
  23. return $recomend;
  24. }


A potem wywołuję to tak i w ten sposób tworze formularz html:

  1. public function __construct(DocumentData $documentData = null) {
  2.  
  3. if (!$documentData) {
  4. $documentData = new DocumentData();
  5. }
  6. $documentData = $documentData->getData();
  7.  
  8. //throw new Exception('<pre>'.print_r($documentData['policies'],1). '</pre>');
  9.  
  10. $this->group1 = array (
  11. 'common1' => array (
  12. 'name' => 'Opis',
  13. 'elements'=> array (
  14. 'multiText' => array(
  15. 'type' => 'textMulti',
  16. 'label' => 'Wprowadzenie',
  17. 'optional' => true, // false -> bez checkbox
  18. 'partitions' => $this->getRecomendationWOL($documentData)
  19. ),
  20. ),
  21. ),
  22. );

No i jest ok i to działa.
Teraz wywołując $this->getRecomendationWOL otrzymuję
  1. [common1] => Array
  2. (
  3. [multiText] => Array
  4. (
  5. [0] => Podstawowe informacje (dane osoby) ... (dane firmy):
  6. [1] => Podstawowe cd.
  7. [2] => Podstawowe cd.
  8. [3] => Informacje GRUPA 2.
  9. [4] => Informacje GRUPA 2 cd.
  10. [5] => Dodatkowo informacje GRUPA 3
  11. [6] => Dodatkowo informacje GRUPA 3 cd.
  12.  


A to co chciałbym uzyskać to możliwość wywołania osobno danych dla Grupy 1 / Grupy 2 / Grupy 3

  1. $this->group1 = array (
  2. 'common1 => array (
  3. 'name' => 'Opis1',
  4. 'elements'=> array (
  5. 'multiText' => array(
  6. 'type' => 'textMulti',
  7. 'label' => 'GROUPA 1',
  8. 'optional' => true, // false -> bez checkbox
  9. 'partitions' => $this->getRecomendationWOL1($documentData)
  10. ),
  11. 'multiText1' => array(
  12. 'type' => 'textMulti',
  13. 'label' => 'GRUPA 2',
  14. 'optional' => true, // false -> bez checkbox
  15. 'partitions' => $this->RecomendationWOL2($documentData)
  16. ),
  17. 'multiText2' => array(
  18. 'type' => 'textMulti',
  19. 'label' => 'GRUPA 3',
  20. 'optional' => true, // false -> bez checkbox
  21. 'partitions' => $this->RecomendationWOL3($documentData)
  22. ),
  23. ),
  24. ),
  25. );


Dziękuję za informacje jak to osiągnąć i za wyrozumiałość.

Domyślam się że muszę zmodyfikować:
return $recomend;
na coś w stylu:
public function getValues() {
return array (
'group1' => $this->recomend[1][],
'group2' => $this->recomend[2][],
'group3' => $this->recomend[3][]
);
}

No ale nie potrafię sobie sam z tym poradzić...
Dziękuję jak zawsze za wyrozumiałość.

Temat do zamknięcia

wystarczyło dane w tablicy zapisać jako
  1. $recomend[group1][] = array('Podstawowe informacje ('.$policies[$n]['lifeInsured'].') ... '.$policies[$n]['company'].': ');
  2. ...
  3. $recomend[group2][] = array('Informacje GRUPA 2.');


a potem wywołać funkcje poprzez
  1. $this->getRecomendationWOL($documentData)[group1]
  2. ...
  3. $this->getRecomendationWOL($documentData)[group2]


Ten post edytował pela222 26.03.2021, 13:42:49
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
gino
post 8.04.2021, 13:43:01
Post #2





Grupa: Zarejestrowani
Postów: 324
Pomógł: 52
Dołączył: 18.02.2008

Ostrzeżenie: (0%)
-----


Po mojemu to tak:
Kod
    private $groups = array();

    public function __construct(DocumentData $documentData = null) {

        if (!$documentData) {
            $documentData = new DocumentData();
        }
$this->groups= array (
            'common1' => array (
                'name' => '? Wprowadzenie',
                'elements'=> array (
                    'multiText' => array(
                        'type' => 'textMulti',
                        'label' => 'Wprowadzenie',
                        'optional' => true, // false -> bez checkbox
                        'partitions' => $this->getIntroData($documentData)
                    ),
                ),
            ),
            'textMultiList' => array (
                'name' => '? Potrzeby i cele',
                'elements'=> array (
                    'needs' => array(
                        'type' => 'textMultiList',
                        'label' => 'Poszukujecie/Poszukujesz ubezpieczenia, które',
                        'optional' => true, // false -> bez checkbox
                        'partitions' => $this->getNeedsData($documentData)
                    ),
                ),
            ),
            'common2' => array (
                'name' => '? Sytuacja Osobista',
                'elements'=> array (
                    'multiText' => array(
                        'type' => 'textMulti',
                        'label' => 'Osobista',
                        'optional' => true, // false -> bez checkbox
                        'partitions' => $this->getPersonData($documentData)
                    ),
                ),
            ),
            'common3' => array (
                'name' => '? Sytuacja Finansowa',
                'elements'=> array (
                    'multiText' => array(
                        'type' => 'textMulti',
                        'label' => 'Finansowa',
                        'optional' => true, // false -> bez checkbox
                        'partitions' => $this->getFinancialData($documentData, $additionalData)
                    ),
                ),
            ),
        );
    foreach ($documentData['policies'] as $type => $policieType) {
        foreach ($policieType as $policy) {
            // dla typu TerLifeIns
            if ($type == 'TerLifIns' || $type == 'MorIns') {      
                $termlife = array (    
                    'common4' => array (
                        'name' => '? Rekomendacja Life Term + Mortgage' .$count,
                        'elements'=> array (
                            'multiText' => array(
                                'type' => 'textMultiList',
                                'label' => 'Na podstawie otrzymanych informacji, zalecam Wam / Tobie ubezpieczenie',
                                'optional' => true, // false -> bez checkbox
                                'partitions' => $this->getRecomendationTerLifInsData($documentData)[1]
                            ),
                            'multiText1' => array(
                                'type' => 'textMultiList',
                                'label' => 'Dodatkowo omówiono i zaproponowano następujące cechy i elementy:',
                                'optional' => true, // false -> bez checkbox
                                'partitions' => $this->getRecomendationTerLifInsData($documentData)[2]
                            ),
                            'multiText2' => array(
                                'type' => 'textMultiList',
                                'label' => 'Opis Ubezpieczyciela',
                                'optional' => true, // false -> bez checkbox
                                'partitions' => $this->getRecomendationTerLifInsData($documentData)[3]
                            ),
                        ),
                    ),
                );
                $this->groups = array_merge($this->groups, $termlife);
            }

            // dla Hive
            if ($type == 'PerAcc' || $type =='AccSicAndHos' || $type == 'MedCas') {      
            $hive = array (    
                'common6' => array (
                    'name' => '? Rekomendacja Hive',
                    'elements'=> array (
                        'multiText' => array(
                            'type' => 'textMultiList',
                            'label' => 'Na podstawie otrzymanych informacji, zalecam Wam / Tobie ubezpieczenie',
                            'optional' => true, // false -> bez checkbox
                            'partitions' => $this->getRecomendationHiveData($documentData)[1]
                        ),
                        'multiText2' => array(
                            'type' => 'textMultiList',
                            'label' => 'Opis ubezpieczyciela',
                            'optional' => true, // false -> bez checkbox
                            'partitions' => $this->getRecomendationHiveData($documentData)[3]
                        ),

                    ),
                ),
            );
            $this->groups = array_merge($this->groups, $hive);
            }

            // dla Whole of Life
            if ($type == 'WOL') {      
            $wol = array (    
                'common7' => array (
                    'name' => '? Rekomendacja Whole of Life',
                    'elements'=> array (
                        'multiText' => array(
                            'type' => 'textMultiList',
                            'label' => 'Na podstawie otrzymanych informacji, zalecam Wam / Tobie ubezpieczenie',
                            'optional' => true, // false -> bez checkbox
                            'partitions' => $this->getRecomendationWOL($documentData)[1]
                        ),
                        'multiText1' => array(
                            'type' => 'textMultiList',
                            'label' => 'Dodatkowo omówiono i zaproponowano następujące cechy i elementy:',
                            'optional' => true, // false -> bez checkbox
                            'partitions' => $this->getRecomendationWOL($documentData)[2]
                        ),
                        'multiText2' => array(
                            'type' => 'textMultiList',
                            'label' => 'Opis Ubezpieczyciela',
                            'optional' => true, // false -> bez checkbox
                            'partitions' => $this->getRecomendationWOL($documentData)[3]
                        ),
                    ),
                ),
            );
            $this->groups = array_merge($this->groups, $wol);
            }
//            // dla MCPC
            if ($type == 'MulClaProCov') {      
            $mcpc = array (    
                'common8' => array (
                    'name' => '? Rekomendacja Multi-claim',
                    'elements'=> array (
                        'multiText' => array(
                            'type' => 'textMultiList',
                            'label' => 'Na podstawie otrzymanych informacji, zalecam Wam / Tobie ubezpieczenie',
                            'optional' => true, // false -> bez checkbox
                            'partitions' => $this->getRecomendationMCPC($documentData)[1]
                        ),
                        'multiText1' => array(
                            'type' => 'textMultiList',
                            'label' => 'Dodatkowo omówiono i zaproponowano następujące cechy i elementy',
                            'optional' => true, // false -> bez checkbox
                            'partitions' => $this->getRecomendationMCPC($documentData)[2]
                        ),
                        'multiText2' => array(
                            'type' => 'textMultiList',
                            'label' => 'Opis Ubezpieczyciela',
                            'optional' => true, // false -> bez checkbox
                            'partitions' => $this->getRecomendationMCPC($documentData)[3]
                        ),
                    ),
                ),
            );
            $this->groups = array_merge($this->groups, $mpc);
            }
        }
    }

    }
        public function getGroups() {
        return $this->groups;
    }


edit poprawka literówek :0

Ten post edytował gino 8.04.2021, 13:45:25
Go to the top of the page
+Quote Post

Posty w temacie
- pela222   [PHP]Funkcja zwracająca tablicę danych   26.03.2021, 13:41:54
- - nospor   Nie $recomend[group1][] a $recomend[...   26.03.2021, 15:34:57
- - pela222   Ok to jeszcze jedno pytanie: [PHP] pobierz, plaint...   6.04.2021, 09:56:54
- - nospor   Ja nie kumam o co pytasz. Jakos to skomplikowane d...   6.04.2021, 10:51:45
- - pela222   Ok. Nie jestem autorem tego kodu, a jedynie modyfi...   6.04.2021, 13:11:38
- - nospor   Mi nie chodzilo stricte o zmienne prywatne, tylko ...   6.04.2021, 13:13:57
- - pela222   Ponieważ na podstawie tak stworzonej tablicy ze zm...   6.04.2021, 13:31:07
- - nospor   Dlatego ci mowie zrob z tego tablice z grupami. La...   6.04.2021, 14:26:22
- - pela222   Wiem że teraz to pewnie załamiesz ręce ale mam stw...   6.04.2021, 14:43:14
- - nospor   Hehe, no zalamalem   6.04.2021, 14:56:40
- - pela222   No się pośmialiśmy z mojego dyletanctwa i braku wi...   6.04.2021, 15:31:54
- - nospor   Nie. Caly czas ci mowie: Nie tysiac zmiennych dla ...   6.04.2021, 16:20:26
- - pela222   Jeśli o to chodziło to nie rozumiem co to wnosi......   6.04.2021, 17:12:41
- - nospor   Ano to wnosi, ze jest latwiejsze do pracy Nie roz...   7.04.2021, 09:39:25
- - pela222   RE: [PHP]Funkcja zwracająca tablicę danych   7.04.2021, 11:33:01
- - gino   można tak dodać do tablicy w zależności od warunku...   8.04.2021, 09:38:17
- - pela222   No tak można bo tak to miałem ... co prawda miałem...   8.04.2021, 09:43:14
- - gino   Cytat@nospor Mi nie chodzilo stricte o zmienne pry...   8.04.2021, 09:54:23
- - pela222   Ale wcześniej też tworzyłem jedną tablicę wielowym...   8.04.2021, 10:24:44
- - gino   Jak sam napisałeś CytatKiedyś tak to miałem (plik ...   8.04.2021, 10:46:08
- - pela222   [PHP] pobierz, plaintext // Tutaj zaczyna się sek...   8.04.2021, 12:14:32
- - gino   Po mojemu to tak: Kod private $groups = array...   8.04.2021, 13:43:01
- - pela222   RE: [PHP]Funkcja zwracająca tablicę danych   9.04.2021, 13:52:17
- - nospor   Strasznie ciezko sie czyta ten kod. Pewnie gino og...   9.04.2021, 14:12:48


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 21:20