Skip to content

Instantly share code, notes, and snippets.

@bval bval/gist:788241 forked from anonymous/gist:788235
Created Jan 20, 2011

Embed
What would you like to do?
<?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
You can’t perform that action at this time.