/** * Apply authz rules for who may manage a SrcResponse. * * @param AIR2_Query $q * @param User $u * @param string $alias (optional) */ public static function query_may_manage(AIR2_Query $q, User $u, $alias = null) { if ($u->is_system()) { return; } $a = $alias ? "{$alias}." : ""; // manageable src_response_sets $tmp = AIR2_Query::create(); SrcResponseSet::query_may_manage($tmp, $u); $tmp = array_pop($tmp->getDqlPart('where')); $srs_ids = "select srs_id from src_response_set where {$tmp}"; // add to query $q->addWhere("{$a}sr_srs_id in ({$srs_ids})"); }
/** * Move tank_response_set records into src_response_set. * * @param array $data TankResponseSet data * @param integer $src_id * @param TankSource $tsrc */ protected function move_tank_response_set($data, $src_id, $tsrc) { // get array data from the tank_response_set $data['SrcResponse'] = $data['TankResponse']; // create a new response set $new_resp = new SrcResponseSet(); $new_resp->fromArray($data, true); //deep // add the source id's $new_resp->srs_src_id = $src_id; foreach ($new_resp->SrcResponse as $r) { $r->sr_src_id = $src_id; } try { $new_resp->save(); } catch (Exception $e) { $msg = $e->getMessage(); $tsrc->add_error("FATAL ERROR creating Source Responses - {$msg}"); } // cleanup $new_resp->free(true); }
/** * SrcResponseSet creates activities when inserting a SrcResponseSet. * Here, we give callers a chance to not do this, so data isn't left around. * * @return void * @author Sean Gilbertson **/ public function postInsert($ev) { if ($this->create_activity) { parent::postInsert($ev); } }
/** * Create a manual-entry submission * * @param SrcResponseSet $rec * @param Project $prj * @param string $dsc * @param string $txt * @return Doctrine_Record $rec */ private function _create_manual_submission($prj, $typ, $dsc, $txt) { $src_id = $this->parent_rec->src_id; $rec = new SrcResponseSet(); $rec->srs_src_id = $src_id; // just-in-time inquiry (does NOT require the usual WRITE authz) $inq = $prj->get_manual_entry_inquiry(); // debug help //$remote_user = air2_get_remote_user(); //Carper::carp(sprintf("create manual submission for inquiry %s by user %s", $inq->inq_uuid, $remote_user->user_username)); $rec->srs_inq_id = $inq->inq_id; $rec->srs_type = SrcResponseSet::$TYPE_MANUAL_ENTRY; // entry type (the answer to the first question) $def = Inquiry::$MANUAL_TYPES[$typ]; $rec->SrcResponse[0]->sr_src_id = $src_id; $rec->SrcResponse[0]->sr_ques_id = $inq->Question[0]->ques_id; $rec->SrcResponse[0]->sr_orig_value = $def['label']; // entry description and text (the next 2 questions) $rec->SrcResponse[1]->sr_src_id = $src_id; $rec->SrcResponse[1]->sr_ques_id = $inq->Question[1]->ques_id; $rec->SrcResponse[1]->sr_orig_value = $dsc; $rec->SrcResponse[2]->sr_src_id = $src_id; $rec->SrcResponse[2]->sr_ques_id = $inq->Question[2]->ques_id; $rec->SrcResponse[2]->sr_orig_value = $txt; // setup to log a src_activity post-insert SrcResponseSet::$LOG_MANUAL_ENTRY = true; return $rec; }