<?php
namespace Fortytwo\Wordpress\Plugin\TwoFactorAuthentication\Artefact;


/**
 * Abstract class for artefacts.
 *
 * @license https://opensource.org/licenses/MIT MIT
 */
abstract class ArtefactAbstract
{
    /**
     * Generate an html select.
     *
     * @param object $field Value object.
     *
     * @return string HTML generated by the function.
     */
    protected function select($field)
    {
        $html = '<select id="' . $field->getFieldId() . '" name="fortytwo2fa[' . $field->getFieldId() . ']" >';

        foreach ($field->getOptions() as $value => $label) {
            if ($field->getValue() == $value) {
                $html.= '<option selected="selected" value="' . $value . '">' . $label . '</option>';
            } else {
                $html.= '<option value="' . $value . '">' . $label . '</option>';
            }
        }
        $html.= '</select>';

        return  $html;
    }
}
