umlsequence-diagramdiagrammingvisual-paradigm

Wrap conditional into a function or not represent it at all in a sequence diagram?


I've this PHP controller class (belongs to Symfony2 bundle):

class ReptoolController extends PageController
{
    // ...

    private function _get($request, $action, $case)
    {
        $app_id = $this->getRequested('app_id');
        if( ( $repappConfig = $this->getDoctrine()->getRepository('PDOneBundle:RepappConfig')->findOneBy(array("app_id"=>$app_id))) )
        {
            $current_timestamp = new \DateTime(date('Y-m-d'));
            if($repappConfig->getExpireDate())
                $expire_date = $repappConfig->getExpireDate()->getTimestamp();
            else
            {
                $temp = $current_timestamp;
                $temp->modify("+7 day");
                $temp->format("Y-m-d");
                $expire_date = $temp->getTimestamp();
            }
            if($expire_date < $current_timestamp->getTimestamp())
            {
                $response = new \stdClass();
                $response->status = FormUtilities::RESPONSE_STATUS_BAD;
                $controller_response = new Response( json_encode($response) );
                $controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
                return $controller_response;
            }
        }

        switch($case)
        {
            // ...
            case FormUtilities::CASE_BRAND_CUSTOM_MESSAGES:
                return $this->getBrandCustomMessages($request, $action, $case);
                break;
            // ...
            default:
                $response = new \stdClass();
                $response->status = FormUtilities::RESPONSE_STATUS_BAD;
                $controller_response = new Response( json_encode($response) );
                $controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
                return $controller_response;
                break;
        }
    }

    // ...

    private function getBrandCustomMessages($request, $action, $case)
    {
        $id = $this->getRequested('app_id');
        $reptool_records = $this->getRequestedSync();

        $response = new \stdClass();
        $response->status = FormUtilities::RESPONSE_STATUS_BAD;

        $repappConfig = new RepappConfig();
        $repappConfig = $this->getDoctrine()->getRepository('PDOneBundle:RepappConfig')->findOneBy(array("app_id"=>$id));
        $project_id = $repappConfig->getProjectId();
        $brand_table = $this->getDoctrine()->getRepository('PDOneBundle:Brand')->findBy(array("project"=>$project_id));

        if($brand_table)
        {
            foreach($brand_table as $bt)
            {
                $brand_id = $bt->getID();

                    $brandCustomMessages = new BrandCustomMessages();
                    if( $brandCustomMessages = $this->getDoctrine()->getRepository('PDOneBundle:BrandCustomMessages')->findBy(array("brand_id"=>$brand_id) ))
                    {
                        $sync = array();
                        foreach ($brandCustomMessages as $brandCustomMessage)
                        {

                            $response->status = FormUtilities::RESPONSE_STATUS_VALID;

                            $brandCustMess = new PDOneResponse(
                                                                                    $brandCustomMessage->getID(),
                                                                                    strtotime($brandCustomMessage->getModifiedAt()->format("Y-m-d H:i:s"))
                                                                                    );


                            $brandCustMess->id = $brandCustomMessage->getID();
                            $brandCustMess->message_text = $brandCustomMessage->getMessageText();
                            $brandCustMess->message_code = $brandCustomMessage->getMessageCode();
                            $brandCustMess->brand_id = (int)$brandCustomMessage->getBrandId();

                            $reptool_records = $brandCustMess->setRecordStatus($reptool_records);

                            // ADD BACKEND RECORD TO SYNC
                            if($brandCustMess->status != FormUtilities::RESPONSE_STATUS_OK ) $sync[] = $brandCustMess;
                        }
                        // COMPOSITE SYNC WITH REPTOOL RECORDS
                        $sync = PDOneResponse::compositeSync($sync, $reptool_records);
                        $response->sync = $sync;

                    }

            }
        }

        $controller_response = new Response( json_encode($response) );
        $controller_response->headers->set('Content-Type', 'application/json; charset=utf-8');
        return $controller_response;
    }

    // ...

I need to build a sequence diagram (SD) for the flow from the actor PDOneApp (which is an iPad application making get|set request to that controller). This is what I have done in the SD Version1, SD Version 2:

Version 1

enter image description here

Version 2

enter image description here

About the diagrams shown above I have the following doubts and taking as example the code shown above also:

Can any give some help for finish this diagram and understand the conditional part for UML SD?


Solution

  • Your 2nd diagram shows the internal call to getBrandCustomMessages correctly.

    If you really want to show if then use fragments (http://www.uml-diagrams.org/sequence-diagrams-combined-fragment.html). You can divide fragments into single partitions (if/else or case; whatever fits).

    The last response should not go to an entity but as return message (from after the internal call) to the actor. That's likely what you intend to show.