Skip to content

Instantly share code, notes, and snippets.

@bval
Forked from anonymous/gist:788235
Created January 20, 2011 17:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bval/788241 to your computer and use it in GitHub Desktop.
Save bval/788241 to your computer and use it in GitHub Desktop.
<?php
/**
* Department form.
*
* @package skeleton
* @subpackage form
* @author Your name here
* @version SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
*/
class DepartmentForm extends BaseDepartmentForm
{
public function configure()
{
$employees = $this->object()->getEmployees()->toKeyValueArray('id' => 'name');
$this->widgetSchema['manager_list'] = new sfWidgetFormDoctrineChoice(array(
'multiple' => true,
'model' => 'Employee',
'choices' => $employees,
);
$this->validatorSchema['manager_list'] = new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Employee', 'required' => false));
$this->setDefault('manager_list', $department->getManagers()->toKeyValueArray('id' => 'name'));
}
public function doSave($con = null)
{
$this->saveManager($con);
parent::doSave($con);
}
public function saveManager($con = null)
{
$refs = Doctrine::getTable('EmployeeDepartment')->createQuery('ed')
->addWhere('ed.employee_id in ?', array($this->object->Employee->toKeyValueArray('id', 'id')))
->execute();
foreach ($refs as $ed)
{
if (in_array($ed->employee_id, $this->getValue('manager_list')))
{
$ed->is_manager = true;
$ed->save();
} else
{
$ed->is_manager = false;
$ed->save();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment