<commit_before><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */
lmb_require('limb/cms/src/controller/lmbObjectController.class.php');
lmb_require('limb/datetime/src/lmbDateTime.class.php');

/**
 * abstract class AdminObjectController.
 *
 * @package cms
 * @version $Id$
 */
abstract class lmbAdminObjectController extends lmbObjectController
{
  protected $_form_name = 'object_form';
  protected $_popup = true;
  protected $_back_url = array();

  protected function _passLocalAttributesToView()
  {
    //passing back_url string into view
    if(is_array($this->_back_url))
      $this->back_url = $this->toolkit->getRoutesUrl($this->_back_url);
    else
      $this->back_url = $this->_back_url;

    parent :: _passLocalAttributesToView();
  }


  function doDisplay()
  {
    $this->items = lmbActiveRecord::find($this->_object_class_name);
    $this->_applySortParams();
  }

  protected function _applySortParams()
  {
    $sort = $this->toolkit->getRequest()->getGetFiltered('sort',FILTER_SANITIZE_SPECIAL_CHARS, false);

    $direction = $this->toolkit->getRequest()->getGet('direction');
    if(!in_array($direction, array('asc','desc')))
      $direction = 'asc';

    if($sort==false) return;
    $this->items->sort(array($sort=>$direction));
  }

  function doCreate()
  {
    $this->item = new $this->_object_class_name();
    $this->_onCreate();

    $this->useForm($this->_form_name);
    $this->setFormDatasource($this->item);

    if($this->request->hasPost())
    {
      $this->_import();
      $this->_validateAndSave(true);
    }
    else
    {
      $this->_initCreateForm();
    }
  }

  function doEdit()
  {
    if(!$this->item = $this->_getObjectByRequestedId())
      return $this->forwardTo404();
    $this->_onUpdate();
    $this->useForm($this->_form_name);
    $this->setFormDatasource($this->item);

    if($this->request->hasPost())
    {
      $this->_import();
      $this->_validateAndSave(false);
    }
    else
    {
      $this->_initEditForm();
    }
  }

  function doDelete()
  {
    if(!$this->request->hasPost())
      $ids = $this->request->get('ids');
    else
      $ids = $this->request->getPost('ids');

    if(!is_array($ids))
      $ids = array($ids);

    $this->items = lmbActiveRecord::findByIds($this->_object_class_name, $ids);

    if(!$this->request->hasPost())
      return;

    $this->_onBeforeDelete();

    foreach ($this->items as $item)
      $item->destroy();

    $this->_onAfterDelete();

    $this->_endDialog();
  }

  function doRevertPublish()
  {
    if($this->request->has('ids'))
      $ids = $this->request->get('ids');
    elseif($this->request->has('id'))
      $ids = array($this->request->get('id'));
    else
      return;

    $info_object = new $this->_object_class_name();

    foreach($ids as $id)
      lmbDBAL :: execute('UPDATE ' . $info_object->getTableName() . ' SET is_published = IF(is_published > 0, 0, 1) WHERE id = ' . lmbToolkit :: instance()->getDefaultDbConnection()->escape($id));

    $this->_endDialog();
  }

  function doPublish()
  {
    if(!$item = $this->_getObjectByRequestedId())
      return $this->forwardTo404();

    $this->_onBeforePublish();
    $item->setIsPublished(true);
    $item->save();
    $this->_onAfterPublish();

    $this->_endDialog();
  }

  function doUnpublish()
  {
    if(!$item = $this->_getObjectByRequestedId())
      return $this->forwardTo404();

    $this->_onBeforeUnpublish();
    $item->setIsPublished(false);
    $item->save();
    $this->_onAfterUnpublish();

    $this->_endDialog();
  }
<commit_msg>[svn r8128] -- fix: exception, when setIsPublished(true);<commit_after><?php
/*
 * Limb PHP Framework
 *
 * @link http://limb-project.com
 * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
 * @license    LGPL http://www.gnu.org/copyleft/lesser.html
 */
lmb_require('limb/cms/src/controller/lmbObjectController.class.php');
lmb_require('limb/datetime/src/lmbDateTime.class.php');

/**
 * abstract class AdminObjectController.
 *
 * @package cms
 * @version $Id$
 */
abstract class lmbAdminObjectController extends lmbObjectController
{
  protected $_form_name = 'object_form';
  protected $_popup = true;
  protected $_back_url = array();

  protected function _passLocalAttributesToView()
  {
    //passing back_url string into view
    if(is_array($this->_back_url))
      $this->back_url = $this->toolkit->getRoutesUrl($this->_back_url);
    else
      $this->back_url = $this->_back_url;

    parent :: _passLocalAttributesToView();
  }


  function doDisplay()
  {
    $this->items = lmbActiveRecord::find($this->_object_class_name);
    $this->_applySortParams();
  }

  protected function _applySortParams()
  {
    $sort = $this->toolkit->getRequest()->getGetFiltered('sort',FILTER_SANITIZE_SPECIAL_CHARS, false);

    $direction = $this->toolkit->getRequest()->getGet('direction');
    if(!in_array($direction, array('asc','desc')))
      $direction = 'asc';

    if($sort==false) return;
    $this->items->sort(array($sort=>$direction));
  }

  function doCreate()
  {
    $this->item = new $this->_object_class_name();
    $this->_onCreate();

    $this->useForm($this->_form_name);
    $this->setFormDatasource($this->item);

    if($this->request->hasPost())
    {
      $this->_import();
      $this->_validateAndSave(true);
    }
    else
    {
      $this->_initCreateForm();
    }
  }

  function doEdit()
  {
    if(!$this->item = $this->_getObjectByRequestedId())
      return $this->forwardTo404();
    $this->_onUpdate();
    $this->useForm($this->_form_name);
    $this->setFormDatasource($this->item);

    if($this->request->hasPost())
    {
      $this->_import();
      $this->_validateAndSave(false);
    }
    else
    {
      $this->_initEditForm();
    }
  }

  function doDelete()
  {
    if(!$this->request->hasPost())
      $ids = $this->request->get('ids');
    else
      $ids = $this->request->getPost('ids');

    if(!is_array($ids))
      $ids = array($ids);

    $this->items = lmbActiveRecord::findByIds($this->_object_class_name, $ids);

    if(!$this->request->hasPost())
      return;

    $this->_onBeforeDelete();

    foreach ($this->items as $item)
      $item->destroy();

    $this->_onAfterDelete();

    $this->_endDialog();
  }

  function doRevertPublish()
  {
    if($this->request->has('ids'))
      $ids = $this->request->get('ids');
    elseif($this->request->has('id'))
      $ids = array($this->request->get('id'));
    else
      return;

    $info_object = new $this->_object_class_name();

    foreach($ids as $id)
      lmbDBAL :: execute('UPDATE ' . $info_object->getTableName() . ' SET is_published = IF(is_published > 0, 0, 1) WHERE id = ' . lmbToolkit :: instance()->getDefaultDbConnection()->escape($id));

    $this->_endDialog();
  }

  function doPublish()
  {
    if(!$item = $this->_getObjectByRequestedId())
      return $this->forwardTo404();

    $this->_onBeforePublish();
    $item->setIsPublished(1);
    $item->save();
    $this->_onAfterPublish();

    $this->_endDialog();
  }

  function doUnpublish()
  {
    if(!$item = $this->_getObjectByRequestedId())
      return $this->forwardTo404();

    $this->_onBeforeUnpublish();
    $item->setIsPublished(false);
    $item->save();
    $this->_onAfterUnpublish();

    $this->_endDialog();
  }

{'fraction_non_alphanumeric': 0.18603089321692412, 'fraction_numerical': 0.006044325050369375, 'mean_word_length': 3.440071556350626, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 177, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '2493722', 'n_tokens_mistral': 2552, 'n_tokens_neox': 2451, 'n_words': 357}