Skip to content

Instantly share code, notes, and snippets.

@Tocacar
Created June 26, 2012 13:26
Show Gist options
  • Select an option

  • Save Tocacar/2995768 to your computer and use it in GitHub Desktop.

Select an option

Save Tocacar/2995768 to your computer and use it in GitHub Desktop.
Moving mouse
/**
* Completes process of moving of mouse to selected cage
*
* @param sfWebRequest $request
* @return json-encoded template
*/
public function executeDoMove(sfWebRequest $request)
{
$this->checkRequest($request);
$this->form = new MouseCageDateInForm();
$newCageId = $request->getParameter('cageid');
if ($this->processForm($request, $this->form)) {
$oldcage = $this->mouse->getActiveMouseCageRecord();
if ($oldcage->count() !== 0) {
$oldcage[0]->setDateout($this->form->getValue('datein'));
$oldcage[0]->save();
}
//set foreign keys in join table
$this->savedObj->setMouseId($this->mouse->getId());
$this->savedObj->setCageId($newCageId);
$this->savedObj->save();
//set new cage id in mouse
$this->mouse->setCurrentCageId($newCageId);
$this->mouse->save();
$this->mouseCages = $this->mouse->getCageHistory();
$ret['status'] = 'success';
$ret['content'][] = $this->getPartial('cageHistory', array('mouseCages' => $this->mouseCages, 'mouse' => $this->mouse));
} else {
$ret['status'] = 'failure';
$ret['error_message'] = 'The form did not validate';
$ret['content'][] = $this->getPartial('mousecage/dateInForm', array('form' => $this->form, 'mouseid' => $request->getParameter('mouseid'), 'cageid' => $newCageId));
}
$this->getResponse()->setContentType('application-json');
$this->renderText(json_encode($ret));
return sfView::NONE;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment