<?php
/**
 * Session handling class
 *
 */
class myUser extends sfGuardSecurityUser
{

  /**
   * Retrieves current user PK, if any
   *
   * @return int
   */
  public function getId()
  {
    return $this->getAttribute('user_id', null, 'sfGuardSecurityUser');
  }

  /**
   * Retrieves current sfGuardUser associated to current session, if any.
   * Note: it's just here to have typed phpdoc for autocompletion in Eclipse PDT
   *
   * @return sfGuardUser
   */
  public function getGuardUser()
  {
    return parent::getGuardUser();
  }

  /**
   * Returns current session storage instance
   *
   * @return sfSessionStorage
   */
  public function getStorage()
  {
    return $this->storage;
  }

  /**
   * Retrieves related user companies
   *
   * @return array
   */
  public function getRelatedCompanies()
  {
    return $this->getGuardUser()->getCompaniesArray($this->isAdmin() ? 'all' : 'related');
  }

  /**
   * Checks if current connected user is an admin
   *
   * @return boolean
   */
  public function isAdmin()
  {
    return $this->hasCredential('admin') or $this->isSuperAdmin();
  }

}
