/** * Returns false if the city is known to be in another district or province * Returns false if the district is not in the province * Returns an id if the city is unknown or is in the correct parent location */ public static function verifyCityHierarchy($cityName, $province_id, $district_id = false) { $rowset = self::suggestionQuery($cityName); $count = 0; // foreach ($rowset as $row) { // no longer validating a city's district and province, since it was preventing duplicate city names. // // if ( ($row->city_name == $cityName) and ($province_id == $row->parent_province_id) and ((!$district_id) or ($district_id == $row->parent_district_id)) ) { // return $row->id; // } // $count++; // } if ($count == 0) { //for unknowns check that the district is in the province if ($district_id) { $district = new OptionList(array('name' => 'location_district')); $select = $district->select()->from('location_district', array('id'))->setIntegrityCheck(false); $select->join(array('p' => 'location_province'), 'location_district.parent_province_id = p.id', 'p.province_name'); $select->where('location_district.id = ? ', $district_id); $select->where('p.id = ? ', $province_id); $select->where('location_district.is_deleted = 0'); if (!$district->fetchRow($select)) { return false; } } return 'unknown'; //it's a new city } return false; }
public static function insertIfNotFound($table, $col, $text) { $topicTable = new OptionList(array('name' => $table)); $select = $topicTable->select()->from($table, 'id')->where("{$col} = ?", $text); $row = $topicTable->fetchRow($select); if ($row) { return $row->id; } return $topicTable->insert(array($col => $text)); }
public function assignTrainingAction() { $id = $this->getSanParam('id'); $this->view->assign('id', $id); require_once 'models/table/Training.php'; require_once 'models/table/OptionList.php'; $training = new Training(); $rows = $training->find($id); $row = $rows->current(); $this->view->assign('training', $row); $this->view->assign('training_name', $training->getCourseName($id)); $evaluations = OptionList::suggestionList('evaluation', array('id', 'title')); $this->view->assign('evaluations', $evaluations); //find currently selected $evalTable = new OptionList(array('name' => 'evaluation_to_training')); $select = $evalTable->select()->from('evaluation_to_training', array('evaluation_id'))->where('training_id = ' . $id); $row = $evalTable->fetchRow($select); if ($row) { $this->view->assign('evaluation_id', $row->evaluation_id); } $request = $this->getRequest(); if ($request->isPost()) { $status = ValidationContainer::instance(); $evaluation_id = $this->getSanParam('evaluation_id'); $status->setStatusMessage(t('The evaluation has been assigned.')); $eval_id = $this->getSanParam('evaluation_id'); require_once 'models/table/MultiOptionList.php'; MultiOptionList::updateOptions('evaluation_to_training', 'evaluation', 'training_id', $id, 'evaluation_id', array($eval_id => $eval_id)); $status->setRedirect('/training/edit/id/' . $id); $this->sendData($status); } }