Skip to content

Instantly share code, notes, and snippets.

@Tocacar
Created June 13, 2012 13:59
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 Tocacar/2924235 to your computer and use it in GitHub Desktop.
Save Tocacar/2924235 to your computer and use it in GitHub Desktop.
/*
* Is it OK to pass an array of params to the getCages table method?
* Or should I specify each param individually?
* Just worried that would be a very long method signature (if that's the right phrase)
*/
// the controller action, which calls a getCages() table method
public function executeSearch(sfWebRequest $request) {
$this->forward404Unless($query = $request->getParameter('query'));
$this->forward404Unless($capacity_pref = $this->getUser()->getAttribute('cageSizePreference'));
$template = array('projectLicenceId' => NULL, 'labUserId' => NULL, 'currentcageId' => NULL, 'unitId' => NULL, 'gender' => NULL);
$params = $request->getParameterHolder()->getAll();
unset($params['module'], $params['action'], $params['query']);
$params = array_merge($template, $params);
$params['capacity_pref'] = $capacity_pref;
$this->cage = Doctrine_Core::getTable('Cage')->getCages($query, $params);
if ($request->isXmlHttpRequest()) {
if ('*' == $query || !$this->cage) {
return $this->renderText('No results.');
}
$ret['content'] = $this->cage->toArray();
$this->getResponse()->setContentType('application-json');
return $this->renderText(json_encode($ret));
}
}
//the getCages table method
public function getCages($query, $params)
{
$q = $this->createQuery('c')
->leftJoin('c.Strain s')
->where('c.strain_id = ?', $params['strainId'])
->addWhere('c.project_licence_id = ?', $params['projectLicenceId'])
->addWhere('c.lab_user_id = ?', $params['labUserId'] )
->addWhere('c.unit_id = ?', $params['currentUnitId'])
->addWhere('c.id != ?', $param['currentCageId'])
->addWhere('c.gender = ?', $param['gender'])
->addWhere('c.current_count < ?', $param['capacity_pref'])
->addWhere('c.number LIKE ?', $query . '%')
->addWhere('c.cagetype = ?', 'stock')
->limit(10);
return $q->execute();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment