Doubt about example

Hello friends

I’m studying the chapter 6 and I have a doubt

I put this code in Issue class:




public function getStatusText()

        {

            $statusOptions=$this->statusOptions;

            return isset($statusOptions[$this->status_id]) ? $statusOptions[$this->status_id] : "unknow status ({$this->status_id})";

        }


        public function getTypeText()

        {

            $typeOptions=$this->typeOptions;

            return isset($typeOptions[$this->type_id]) ? $typeOptions[$this->type_id] : "unknow type ({$this->type_id})";

        }



and this in _view of Issue:




<b><?php echo CHtml::encode($data->getAttributeLabel('type_id')); ?>:</b>

	<?php echo CHtml::encode($data->getTypeText()); ?>

	<br />


	<b><?php echo CHtml::encode($data->getAttributeLabel('status_id')); ?>:</b>

	<?php echo CHtml::encode($data->getStatusText()); ?>

	<br />



This code change the display, after this code was diplay number, when I put this code display the text.

Please. Can anyone explain the code? I don’t understand

Both of these methods do basically the same thing (one for returning the text associated with the integer status value and one for returning the text associated with the integer type value). So, taking the one for status:


public function getStatusText()

{

		$statusOptions=$this->statusOptions;

		return isset($statusOptions[$this->status_id]) ? $statusOptions[$this->status_id] : "unknown status ({$this->status_id})";

}

$statusOptions will be an array that looks like:


array(0=>'Not Yet Started', 1=>'Started', 2=>'Finished')

And this method just returns the text that is associated with the key whose value happens to be the same as the status_id property of the instance.

So, if the issue instance happens to have its status_id property = 1, this method will return the value associated with


$statusOptions[1]

which is the value ‘Started’.

Hope this helps.

thanks for help. I get it