<?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_FieldMultiCheckbox extends Fields_View_Helper_FieldAbstract
{
  public function fieldMultiCheckbox($subject, $field, $value)
  {
    // Build values
    $vals = array();
    foreach( $value as $singleValue ) {
      if( is_string($singleValue) ) {
        $vals[] = $singleValue;
      } else if( is_object($singleValue) ) {
        $vals[] = $singleValue->value;
      }
    }

    $options = $field->getOptions();
    $first = true;
    $content = '';
    foreach( $options as $option ) {
      if( !engine_in_array($option->option_id, $vals) ) continue;
      if( !$first ) $content .= ', ';
      $first = false;

      $label = $this->view->translate($option->label);
      $content .= $this->encloseInLink($subject, $field, $option->option_id, $label);
    }

    return $content;
  }
}
