<?php

class Fiktiv_View_Helper_AuthLink extends Zend_View_Helper_Abstract
{
    public function authLink()
    {
        $auth = Zend_Auth::getInstance();

        $options = array(
            'module'     => 'index',
            'controller' => 'auth'
        );

        $prefix = '';

        if ($auth->hasIdentity()) {
            $identity = $auth->getIdentity();
            $options['action'] = 'logout';
            $display = ' (' . $this->view->translate('u:logout') . ')';

            $prefix = '<a href="'.$this->view->url(array('controller' => 'profile'), 'default', true).'">';

            if (strlen($identity->firstName)) {
                $prefix .= $identity->firstName;
                
                if (strlen($identity->lastName)) {
                    $prefix .= ' ' . mb_substr($identity->lastName,0,1);
                }
            } else {
                $prefix .= $this->view->translate('Unknown');
            }

            $prefix .= '</a> ';
        } else {
            $options['action'] = 'login';
            $display = $this->view->translate('u:login');
        }

        return $prefix
             . '<a href="' . $this->view->url($options, 'auth', true) . '">'
             . $display
             . '</a> ';
    }
}
