Created
January 20, 2011 17:30
-
-
Save anonymous/788235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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() | |
{ | |
$query = Doctrine::getTable('Employee')->createQuery('e') | |
->leftJoin('e.Departments d') | |
->addWhere('d.id = ?', $this->object->id); | |
$this->widgetSchema['manager_list'] = new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Employee', 'query' => $query, 'default' => $this->object->getManagers()->toKeyValueArray('id', 'id'))); | |
$this->validatorSchema['manager_list'] = new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Employee', 'required' => false)); | |
} | |
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