<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class Fields_View_Helper_FieldOptions extends Fields_View_Helper_FieldAbstract
{
  public function fieldOptions($subject, $field, $value)
  {
    $info = Engine_Api::_()->fields()->getFieldInfo($field->type, 'multiOptions');

    // Single
    if( is_object($value) ) {
      if( isset($info[$value->value]) ) {
        $label =  $this->view->translate($info[$value->value]);
        
        //Income Profile Field
        if($field->type == 'income') {
          $values = explode(' - ', $info[$value->value]);
          $label = Engine_Api::_()->payment()->getCurrencyPrice(str_replace(',', '', $values[0])) . ' - ' . Engine_Api::_()->payment()->getCurrencyPrice(str_replace(',', '', $values[1]));
        }
        return $this->encloseInLink($subject, $field, $value->value, $label);
      }
    }

    // Multi
    else if( is_array($value) ) {
      $first = true;
      $content = '';
      foreach( $value as $sVal ) {
        if( !isset($info[$sVal->value]) ) continue;
        if( !$first ) $content .= ', ';
        $first = false;

        $label = $this->view->translate($info[$sVal->value]);
        $content .= $this->encloseInLink($subject, $field, $sVal->value, $label);
      }
      return $content;
    }

    return '';
  }
}
