public function sp_capture_blocks() { global $DB; $t = time(); $studyplan_id = $this->current->id; $blocks = $_POST['studyplanblocks']; foreach ($blocks as $block) { $b = sp_utility_arrayToStdClass($block); $b->studyplan = $studyplan_id; if ($b->markfordeletion == '1') { #marked for deletion -- delete if there is an associated id if ($b->id != '') { $DB->delete_records('studyplan_blocks', array('id' => $b->id)); $DB->delete_records('studyplan_overrides', array('block' => $b->id)); } } elseif ($b->id != '') { #update if there is an id $b->timemodified = $t; $DB->update_record('studyplan_blocks', $b); } else { #create if there is no id $b->timecreated = $t; $DB->insert_record('studyplan_blocks', $b); } } }
function sp_toggle_block_assigned($blockid, $studyplanid, $user_id) { global $DB; $out = array(); $conditions['block'] = $blockid; $conditions['studyplan'] = $studyplanid; $conditions['user'] = $user_id; $results = $DB->get_record('studyplan_overrides', $conditions); if ($results !== false) { #delete it $DB->delete_records('studyplan_overrides', $conditions); } else { #create it $conditions['timecreated'] = time(); $DB->insert_record('studyplan_overrides', sp_utility_arrayToStdClass($conditions)); } }