<commit_before><?php

class sfSympalUser extends sfGuardSecurityUser
{
  protected
    $_forwarded = false,
    $_flash     = false;

  public function checkContentSecurity($content)
  {
    $access = true;
    $allPermissions = $content->getAllPermissions();

    if ($this->isAuthenticated() && !$this->hasCredential($allPermissions))
    {
      $access = false;
    }

    if (!$this->isAuthenticated() && !empty($allPermissions))
    {
      $access = false;
    }

    if (!$access && !$this->_forwarded)
    {
      $this->_forwarded = true;
      return sfContext::getInstance()->getController()->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
    }
    return $access;
  }

  public function toggleEditMode()
  {
    $this->setAttribute('sympal_edit', !$this->getAttribute('sympal_edit', false));
    $mode = $this->getAttribute('sympal_edit', false) ? 'on':'off';

    if ($mode == 'off')
    {
      $user = $this->getGuardUser();
      Doctrine::getTable('Content')
        ->createQuery()
        ->update()
        ->set('locked_by', 'NULL')
        ->where('locked_by = ?', $user->id)
        ->execute();
    }
    return $mode;
  }

  public function getOpenContentLock()
  {
    $q = Doctrine_Query::create()
      ->from('Content e')
      ->leftJoin('e.Type t')
      ->andWhere('e.locked_by = ?', $this->getGuardUser()->getId());

    $lock = $q->fetchOne();
    if ($lock)
    {
      Doctrine::initializeModels(array($lock['Type']['name']));
      return $lock;
    } else {
      return false;
    }
  }

  public function addFlash($name, $value, $persist = true)
  {
    $flash = parent::getFlash($name, $value, $persist);
    $flash = $flash ? $flash:array();
    $flash[] = $value;

    parent::setFlash($name, $flash);
  }

  public function setFlash($name, $value, $persist = true)
  {
    $this->addFlash($name, $value, $persist);
  }

  public function getFlash($name, $default = null)
  {<commit_msg>[1.0] sfSympalPlugin: Fixing php warning for string as array<commit_after><?php

class sfSympalUser extends sfGuardSecurityUser
{
  protected
    $_forwarded = false,
    $_flash     = false;

  public function checkContentSecurity($content)
  {
    $access = true;
    $allPermissions = $content->getAllPermissions();

    if ($this->isAuthenticated() && !$this->hasCredential($allPermissions))
    {
      $access = false;
    }

    if (!$this->isAuthenticated() && !empty($allPermissions))
    {
      $access = false;
    }

    if (!$access && !$this->_forwarded)
    {
      $this->_forwarded = true;
      return sfContext::getInstance()->getController()->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
    }
    return $access;
  }

  public function toggleEditMode()
  {
    $this->setAttribute('sympal_edit', !$this->getAttribute('sympal_edit', false));
    $mode = $this->getAttribute('sympal_edit', false) ? 'on':'off';

    if ($mode == 'off')
    {
      $user = $this->getGuardUser();
      Doctrine::getTable('Content')
        ->createQuery()
        ->update()
        ->set('locked_by', 'NULL')
        ->where('locked_by = ?', $user->id)
        ->execute();
    }
    return $mode;
  }

  public function getOpenContentLock()
  {
    $q = Doctrine_Query::create()
      ->from('Content e')
      ->leftJoin('e.Type t')
      ->andWhere('e.locked_by = ?', $this->getGuardUser()->getId());

    $lock = $q->fetchOne();
    if ($lock)
    {
      Doctrine::initializeModels(array($lock['Type']['name']));
      return $lock;
    } else {
      return false;
    }
  }

  public function addFlash($name, $value, $persist = true)
  {
    $flash = (array) parent::getFlash($name, $value, $persist);
    $flash = $flash ? $flash:array();
    $flash[] = $value;

    parent::setFlash($name, $flash);
  }

  public function setFlash($name, $value, $persist = true)
  {
    $this->addFlash($name, $value, $persist);
  }

  public function getFlash($name, $default = null)
  {
{'fraction_non_alphanumeric': 0.1827768014059754, 'fraction_numerical': 0.0005021340697966357, 'mean_word_length': 3.102986611740474, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '498046', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1289, 'n_words': 237}