Search code examples
phpzend-framework

Call a function inside a if condition


Hi guys i am trying to move my if condition code inside another new function and i would like to call that in my another function how can i do that

Here is my if condition :

if (self::GRID_LIST_STATUS_AGENDA === $gridType) {
            // Personal agenda sortation of statuses
            unset($finalFilters['statusId']['distinct']);
            $finalFilters['statusId']['values'] = [
                BAS_Shared_Model_Ticket::STATUS_REPLY_RELATION => 'relation reply',
                BAS_Shared_Model_Ticket::STATUS_REMINDER => 'followup',
                BAS_Shared_Model_Ticket::STATUS_NEW => 'new',
                BAS_Shared_Model_Ticket::STATUS_IN_PROGRESS => 'in progress',
                BAS_Shared_Model_Ticket::STATUS_REOPEN => 'reopened',
            ];
        }

Here is the new function that i want to move

/**
     * Get personal agenda sortation statuses
     */
    public function personalAgendaSortationStatuses()
    {

    }

Can anyone help me how can i do that


Solution

  • You need to change function code like below:-

    public function personalAgendaSortationStatuses($gridType,$finalFilters) //pass parameter
        {
            if (self::GRID_LIST_STATUS_AGENDA === $gridType) {
                // Personal agenda sortation of statuses
                unset($finalFilters['statusId']['distinct']);
                $finalFilters['statusId']['values'] = [
                    BAS_Shared_Model_Ticket::STATUS_REPLY_RELATION => 'relation reply',
                    BAS_Shared_Model_Ticket::STATUS_REMINDER => 'followup',
                    BAS_Shared_Model_Ticket::STATUS_NEW => 'new',
                    BAS_Shared_Model_Ticket::STATUS_IN_PROGRESS => 'in progress',
                    BAS_Shared_Model_Ticket::STATUS_REOPEN => 'reopened',
                ];
                return $finalFilters;
            }
        }
    

    And call it in another function like this:-

    $statuses = $this->personalAgendaSortationStatuses(self::GRID_LIST_STATUS_AGENDA,$finalFilters);//send second parameter too