/** * Update person score in training */ public static function updateScore($ptt_id, $label, $value) { if (!is_numeric($ptt_id)) { return false; } $scoreTable = new Training(array('name' => 'score')); $select = $scoreTable->select()->from('score')->setIntegrityCheck(false); $select->where("person_to_training_id = {$ptt_id} AND score_label = ?", $label); $row = $scoreTable->fetchAll($select)->toArray(); // update if ($row) { $scoreTable->update(array('score_value' => $value), $scoreTable->getAdapter()->quoteInto("person_to_training_id = {$ptt_id} AND score_label = ?", $label)); } else { $scoreTable->insert(array('person_to_training_id' => $ptt_id, 'score_label' => $label, 'score_value' => $value)); } }