/lib/form/doctrine/apostrophePlugin/base/BaseaCategoryForm.class.php
PHP | 252 lines | 197 code | 41 blank | 14 comment | 28 complexity | 808b59e767329bfcf3232d700ce8ca1e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, LGPL-3.0, Apache-2.0, ISC, AGPL-3.0
- <?php
- /**
- * aCategory form base class.
- *
- * @method aCategory getObject() Returns the current form's model object
- *
- * @package asandbox
- * @subpackage form
- * @author Your name here
- * @version SVN: $Id: sfDoctrineFormGeneratedTemplate.php 29553 2010-05-20 14:33:00Z Kris.Wallsmith $
- */
- abstract class BaseaCategoryForm extends BaseFormDoctrine
- {
- public function setup()
- {
- $this->setWidgets(array(
- 'id' => new sfWidgetFormInputHidden(),
- 'name' => new sfWidgetFormInputText(),
- 'description' => new sfWidgetFormTextarea(),
- 'created_at' => new sfWidgetFormDateTime(),
- 'updated_at' => new sfWidgetFormDateTime(),
- 'slug' => new sfWidgetFormInputText(),
- 'media_items_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'aMediaItem')),
- 'pages_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'aPage')),
- 'users_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardUser')),
- 'groups_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup')),
- ));
- $this->setValidators(array(
- 'id' => new sfValidatorChoice(array('choices' => array($this->getObject()->get('id')), 'empty_value' => $this->getObject()->get('id'), 'required' => false)),
- 'name' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
- 'description' => new sfValidatorString(array('required' => false)),
- 'created_at' => new sfValidatorDateTime(),
- 'updated_at' => new sfValidatorDateTime(),
- 'slug' => new sfValidatorString(array('max_length' => 255, 'required' => false)),
- 'media_items_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'aMediaItem', 'required' => false)),
- 'pages_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'aPage', 'required' => false)),
- 'users_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardUser', 'required' => false)),
- 'groups_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'sfGuardGroup', 'required' => false)),
- ));
- $this->validatorSchema->setPostValidator(
- new sfValidatorAnd(array(
- new sfValidatorDoctrineUnique(array('model' => 'aCategory', 'column' => array('name'))),
- new sfValidatorDoctrineUnique(array('model' => 'aCategory', 'column' => array('slug'))),
- ))
- );
- $this->widgetSchema->setNameFormat('a_category[%s]');
- $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
- $this->setupInheritance();
- parent::setup();
- }
- public function getModelName()
- {
- return 'aCategory';
- }
- public function updateDefaultsFromObject()
- {
- parent::updateDefaultsFromObject();
- if (isset($this->widgetSchema['media_items_list']))
- {
- $this->setDefault('media_items_list', $this->object->MediaItems->getPrimaryKeys());
- }
- if (isset($this->widgetSchema['pages_list']))
- {
- $this->setDefault('pages_list', $this->object->Pages->getPrimaryKeys());
- }
- if (isset($this->widgetSchema['users_list']))
- {
- $this->setDefault('users_list', $this->object->Users->getPrimaryKeys());
- }
- if (isset($this->widgetSchema['groups_list']))
- {
- $this->setDefault('groups_list', $this->object->Groups->getPrimaryKeys());
- }
- }
- protected function doSave($con = null)
- {
- $this->saveMediaItemsList($con);
- $this->savePagesList($con);
- $this->saveUsersList($con);
- $this->saveGroupsList($con);
- parent::doSave($con);
- }
- public function saveMediaItemsList($con = null)
- {
- if (!$this->isValid())
- {
- throw $this->getErrorSchema();
- }
- if (!isset($this->widgetSchema['media_items_list']))
- {
- // somebody has unset this widget
- return;
- }
- if (null === $con)
- {
- $con = $this->getConnection();
- }
- $existing = $this->object->MediaItems->getPrimaryKeys();
- $values = $this->getValue('media_items_list');
- if (!is_array($values))
- {
- $values = array();
- }
- $unlink = array_diff($existing, $values);
- if (count($unlink))
- {
- $this->object->unlink('MediaItems', array_values($unlink));
- }
- $link = array_diff($values, $existing);
- if (count($link))
- {
- $this->object->link('MediaItems', array_values($link));
- }
- }
- public function savePagesList($con = null)
- {
- if (!$this->isValid())
- {
- throw $this->getErrorSchema();
- }
- if (!isset($this->widgetSchema['pages_list']))
- {
- // somebody has unset this widget
- return;
- }
- if (null === $con)
- {
- $con = $this->getConnection();
- }
- $existing = $this->object->Pages->getPrimaryKeys();
- $values = $this->getValue('pages_list');
- if (!is_array($values))
- {
- $values = array();
- }
- $unlink = array_diff($existing, $values);
- if (count($unlink))
- {
- $this->object->unlink('Pages', array_values($unlink));
- }
- $link = array_diff($values, $existing);
- if (count($link))
- {
- $this->object->link('Pages', array_values($link));
- }
- }
- public function saveUsersList($con = null)
- {
- if (!$this->isValid())
- {
- throw $this->getErrorSchema();
- }
- if (!isset($this->widgetSchema['users_list']))
- {
- // somebody has unset this widget
- return;
- }
- if (null === $con)
- {
- $con = $this->getConnection();
- }
- $existing = $this->object->Users->getPrimaryKeys();
- $values = $this->getValue('users_list');
- if (!is_array($values))
- {
- $values = array();
- }
- $unlink = array_diff($existing, $values);
- if (count($unlink))
- {
- $this->object->unlink('Users', array_values($unlink));
- }
- $link = array_diff($values, $existing);
- if (count($link))
- {
- $this->object->link('Users', array_values($link));
- }
- }
- public function saveGroupsList($con = null)
- {
- if (!$this->isValid())
- {
- throw $this->getErrorSchema();
- }
- if (!isset($this->widgetSchema['groups_list']))
- {
- // somebody has unset this widget
- return;
- }
- if (null === $con)
- {
- $con = $this->getConnection();
- }
- $existing = $this->object->Groups->getPrimaryKeys();
- $values = $this->getValue('groups_list');
- if (!is_array($values))
- {
- $values = array();
- }
- $unlink = array_diff($existing, $values);
- if (count($unlink))
- {
- $this->object->unlink('Groups', array_values($unlink));
- }
- $link = array_diff($values, $existing);
- if (count($link))
- {
- $this->object->link('Groups', array_values($link));
- }
- }
- }