/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('Tank', array('local' => 'tact_tank_id', 'foreign' => 'tank_id', 'onDelete' => 'CASCADE')); $this->hasOne('ActivityMaster', array('local' => 'tact_actm_id', 'foreign' => 'actm_id', 'onDelete' => 'CASCADE')); $this->hasOne('Project', array('local' => 'tact_prj_id', 'foreign' => 'prj_id', 'onDelete' => 'CASCADE')); }
/** * Create * * @param array $data * @return unknown */ protected function air_create($data) { if (!isset($data['prj_uuid'])) { throw new Rframe_Exception(Rframe::BAD_DATA, "prj_uuid required"); } $prj = AIR2_Record::find('Project', $data['prj_uuid']); if (!$prj) { $u = $data['prj_uuid']; throw new Rframe_Exception(Rframe::BAD_DATA, "Invalid prj_uuid '{$u}'"); } $pinq = new ProjectInquiry(); $pinq->pinq_inq_id = $this->parent_rec->inq_id; $pinq->Project = $prj; $pinq->mapValue('prj_uuid', $pinq->Project->prj_uuid); // adding a Project to a Query requires write authz on the Query, not the Project. if (!$pinq->user_may_write($this->user)) { throw new Rframe_Exception(Rframe::BAD_DATA, "Invalid Query authz"); } // log activity $activity = new InquiryActivity(); $activity->ia_inq_id = $this->parent_rec->inq_id; $activity->ia_actm_id = 49; $activity->ia_dtim = air2_date(); $activity->ia_desc = sprintf('project %s added by {USER}', $prj->prj_name); $this->parent_rec->InquiryActivity[] = $activity; return $pinq; }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('Project', array('local' => 'porg_prj_id', 'foreign' => 'prj_id', 'onDelete' => 'CASCADE')); $this->hasOne('Organization', array('local' => 'porg_org_id', 'foreign' => 'org_id', 'onDelete' => 'CASCADE')); $this->hasOne('User as ContactUser', array('local' => 'porg_contact_user_id', 'foreign' => 'user_id', 'onDelete' => 'CASCADE')); }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('User', array('local' => 'bin_user_id', 'foreign' => 'user_id', 'onDelete' => 'CASCADE')); $this->hasMany('BinSource', array('local' => 'bin_id', 'foreign' => 'bsrc_bin_id')); $this->hasMany('BinSrcResponseSet', array('local' => 'bin_id', 'foreign' => 'bsrs_bin_id')); }
/** * Setup relationships */ public function setUp() { parent::setUp(); $this->hasMany('TestRelatedRecord', array('local' => 'test_id', 'foreign' => 'tr_test_id')); // Tagging $this->hasMany('TagTestRecord as Tags', array('local' => 'test_id', 'foreign' => 'tag_xid')); }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('TankSource', array('local' => 'trs_tsrc_id', 'foreign' => 'tsrc_id', 'onDelete' => 'CASCADE')); $this->hasOne('Inquiry', array('local' => 'srs_inq_id', 'foreign' => 'inq_id')); $this->hasMany('TankResponse', array('local' => 'trs_id', 'foreign' => 'tr_trs_id')); }
/** * Override save() to workaround Doctrine bug in cascading save(). * * @return parent::save() */ public function save() { if (!$this->iorg_org_id) { throw new Exception("iorg_org_id not set"); } return parent::save(); }
/** * Create * * @param array $data * @return unknown */ protected function air_create($data) { if (!isset($data['org_uuid'])) { throw new Rframe_Exception(Rframe::BAD_DATA, "org_uuid required"); } $org = AIR2_Record::find('Organization', $data['org_uuid']); if (!$org) { $u = $data['org_uuid']; throw new Rframe_Exception(Rframe::BAD_DATA, "Invalid org_uuid '{$u}'"); } if (!$this->parent_rec->user_may_write($this->user)) { throw new Rframe_Exception(Rframe::BAD_DATA, "You do not appear to have access to modify this Inquiry (Invalid Inquiry authz)"); } $iorg = new InqOrg(); $iorg->iorg_inq_id = $this->parent_rec->inq_id; $iorg->Organization = $org; $iorg->mapValue('org_uuid', $iorg->Organization->org_uuid); // log activity $activity = new InquiryActivity(); $activity->ia_inq_id = $this->parent_rec->inq_id; $activity->ia_actm_id = 49; $activity->ia_dtim = air2_date(); $activity->ia_desc = sprintf('org %s added by {USER}', $org->org_name); $this->parent_rec->InquiryActivity[] = $activity; return $iorg; }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('TankResponseSet', array('local' => 'tr_trs_id', 'foreign' => 'trs_id', 'onDelete' => 'CASCADE')); $this->hasOne('Question', array('local' => 'sr_ques_id', 'foreign' => 'ques_id')); $this->hasOne('TankSource', array('local' => 'tr_tsrc_id', 'foreign' => 'tsrc_id', 'onDelete' => 'CASCADE')); }
/** * Create * * @param array $data * @return Doctrine_Record $rec */ protected function air_create($data) { $p = new Project(); // org_uuid required if (!isset($data['org_uuid'])) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Project Organization uuid required!'); } $org = AIR2_Record::find('Organization', $data['org_uuid']); if (!$org) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid Organization specified!'); } $p->ProjectOrg[0]->porg_contact_user_id = $this->user->user_id; $p->ProjectOrg[0]->Organization = $org; // immediately add inquiry to project if (isset($data['inq_uuid'])) { $inq = AIR2_Record::find('Inquiry', $data['inq_uuid']); if (!$inq) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid Inquiry specified!'); } if (!$inq->user_may_write($this->user)) { throw new Rframe_Exception(Rframe::BAD_AUTHZ, 'Invalid Inquiry authz!'); } $p->ProjectInquiry[0]->Inquiry = $inq; } return $p; }
/** * Set the table columns */ public function setTableDefinition() { $this->setTableName('state'); $this->hasColumn('state_id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); $this->hasColumn('state_name', 'string', 128, array('notnull' => true)); $this->hasColumn('state_code', 'string', 2, array('fixed' => true, 'notnull' => true)); parent::setTableDefinition(); }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('SrcResponseSet', array('local' => 'sr_srs_id', 'foreign' => 'srs_id', 'onDelete' => 'CASCADE')); $this->hasOne('Question', array('local' => 'sr_ques_id', 'foreign' => 'ques_id', 'onDelete' => 'CASCADE')); $this->hasOne('Source', array('local' => 'sr_src_id', 'foreign' => 'src_id', 'onDelete' => 'CASCADE')); $this->hasMany('SrAnnotation', array('local' => 'sr_id', 'foreign' => 'sran_sr_id')); }
/** * Set the table columns */ public function setTableDefinition() { $this->setTableName('stale_record'); $this->hasColumn('str_xid', 'integer', 4, array('primary' => true)); $this->hasColumn('str_type', 'string', 1, array('primary' => true)); $this->hasColumn('str_upd_dtim', 'timestamp', null, array('notnull' => true)); parent::setTableDefinition(); }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('Bin', array('local' => 'bsrs_bin_id', 'foreign' => 'bin_id', 'onDelete' => 'CASCADE')); $this->hasOne('SrcResponseSet', array('local' => 'bsrs_srs_id', 'foreign' => 'srs_id', 'onDelete' => 'CASCADE')); $this->hasOne('Inquiry', array('local' => 'bsrs_inq_id', 'foreign' => 'inq_id', 'onDelete' => 'CASCADE')); $this->hasOne('Source', array('local' => 'bsrs_src_id', 'foreign' => 'src_id', 'onDelete' => 'CASCADE')); }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('TankSource', array('local' => 'tf_tsrc_id', 'foreign' => 'tsrc_id', 'onDelete' => 'CASCADE')); $this->hasOne('Fact', array('local' => 'tf_fact_id', 'foreign' => 'fact_id')); $this->hasOne('FactValue as AnalystFV', array('local' => 'sf_fv_id', 'foreign' => 'fv_id')); $this->hasOne('FactValue as SourceFV', array('local' => 'sf_src_fv_id', 'foreign' => 'fv_id')); }
/** * Converts dotted quad to long integer for tb_ip. * * @param unknown $event * @return parent preValidate */ public function preValidate($event) { if (!is_numeric($this->tb_ip)) { $this->tb_ip = ip2long($this->tb_ip); } if (!$this->tb_dtim) { $this->tb_dtim = air2_date(); } return parent::preValidate($event); }
/** * Set the table columns */ public function setTableDefinition() { $this->setTableName('geo_lookup'); $this->hasColumn('zip_code', 'string', 16, array('primary' => true)); $this->hasColumn('state', 'string', 128, array('notnull' => true)); $this->hasColumn('city', 'string', 255, array('notnull' => true)); $this->hasColumn('county', 'string', 128, array()); $this->hasColumn('latitude', 'float', null, array()); $this->hasColumn('longitude', 'float', null, array()); $this->hasColumn('population', 'integer', 4, array()); parent::setTableDefinition(); }
/** * Set the table columns */ public function setTableDefinition() { $this->setTableName('api_key'); $this->hasColumn('ak_id', 'integer', 4, array('primary' => true, 'autoincrement' => true)); $this->hasColumn('ak_key', 'string', 32, array('notnull' => true, 'unique' => true)); $this->hasColumn('ak_email', 'string', 255, array('notnull' => true)); $this->hasColumn('ak_contact', 'string', 255, array('notnull' => true)); $this->hasColumn('ak_approved', 'integer', 1, array('default' => 0)); $this->hasColumn('ak_cre_dtim', 'timestamp', null, array('notnull' => true)); $this->hasColumn('ak_upd_dtim', 'timestamp', null, array()); parent::setTableDefinition(); }
/** * Load data for html printing * * @param type $uuid * @param type $base_rs */ protected function show_print_html($uuid, $base_rs) { $bin = AIR2_Record::find('Bin', $uuid); $base_rs['sources'] = array(); // authorized sources $authz_sources = array(); $q = Doctrine_Query::create()->from('BinSource bs'); $q->leftJoin('bs.Source s'); $q->where('bs.bsrc_bin_id = ?', $bin->bin_id); $q->select('bs.bsrc_src_id, s.src_uuid'); BinSource::query_may_read($q, $this->user, 'bs'); $bsrcs = $q->fetchArray(); foreach ($bsrcs as $bsrc) { $authz_sources[$bsrc['Source']['src_uuid']] = true; } // only keep fetching if there is stuff to get $authz_responses = array(); if (count($authz_sources) > 0) { $q = Doctrine_Query::create()->from('BinSrcResponseSet bs'); $q->leftJoin('bs.SrcResponseSet s'); $q->where('bs.bsrs_bin_id = ?', $bin->bin_id); $q->select('bs.bsrs_srs_id, s.srs_uuid'); BinSrcResponseSet::query_may_read($q, $this->user, 'bs'); $bsrss = $q->fetchArray(); foreach ($bsrss as $bsrs) { $authz_responses[$bsrs['SrcResponseSet']['srs_uuid']] = true; } // let perl do the heavy lifting $binsources = CallPerl::exec('AIR2::Bin->flatten', $bin->bin_id); foreach ($binsources as $src) { $src_uuid = $src['src_uuid']; if (isset($authz_sources[$src_uuid])) { // apply authz to responses if (is_array($src['response_sets'])) { foreach ($src['response_sets'] as $idx => $srs) { $srs_uuid = $srs['srs_uuid']; if (!isset($authz_responses[$srs_uuid])) { unset($src['response_sets'][$idx]); } } $src['response_sets'] = array_values($src['response_sets']); } // add as value $authz_sources[$src_uuid] = $src; } } } // reorganize for the print view $raw = array('bin' => $base_rs['radix'], 'sources' => array_values($authz_sources)); $this->airoutput->view = 'print/bin'; $this->response($raw); }
/** * RESTful Create * * @param array $data * @return BinSource $rec */ protected function air_create($data) { $this->require_data($data, array('src_uuid')); $src = AIR2_Record::find('Source', $data['src_uuid']); if (!$src) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid Source specified!'); } $b = new BinSource(); $b->Bin = $this->parent_rec; $b->Source = $src; $b->mapValue('src_uuid', $src->src_uuid); return $b; }
/** * Create * * @param array $data * @return Doctrine_Record $rec */ protected function air_create($data) { $o = new Organization(); // org parent (optional) if (isset($data['org_parent_uuid'])) { $parent = AIR2_Record::find('Organization', $data['org_parent_uuid']); if (!$parent) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid parent Org specified!'); } $o->parent = $parent; } return $o; }
protected function air_create($data) { if (!isset($data['org_uuid'])) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Must specify org_uuid'); } $org = AIR2_Record::find('Organization', $data['org_uuid']); if (!$org) { throw new Rframe_Exception(Rframe::BAD_DATA, 'Invalid org_uuid'); } $so = new SrcOrg(); $so->Source = $this->parent_rec; $so->Organization = $org; return $so; }
/** * Load inline HTML * * @param type $uuid * @param type $base_rs */ protected function show_html($uuid, $base_rs) { $inq = AIR2_Record::find('Inquiry', $uuid); // redmine #7794 adminstrative queries disallowed for non-system users if (!$this->user->is_system()) { if ($inq && $inq->inq_type == Inquiry::$TYPE_MANUAL_ENTRY) { $this->airoutput->write_error(403, 'Query for internal use only', 'This query is for internal use only'); return; } } $search_query = array('q' => "inq_uuid={$uuid}"); $inline = array('UUID' => $base_rs['uuid'], 'URL' => air2_uri_for($base_rs['path']), 'BASE' => $base_rs, 'QUESDATA' => $this->api->query("inquiry/{$uuid}/question", array('limit' => 0, 'sort' => 'ques_dis_seq asc')), 'QUESTPLS' => AIR2_QueryBuilder::get_defs(), 'QUESURL' => air2_uri_for("inquiry/{$uuid}/question"), 'ORGDATA' => $this->api->query("inquiry/{$uuid}/organization", array('sort' => 'org_display_name asc')), 'PROJDATA' => $this->api->query("inquiry/{$uuid}/project", array('sort' => 'prj_display_name asc')), 'OUTDATA' => $this->api->query("inquiry/{$uuid}/outcome", array('limit' => 10)), 'ANNOTDATA' => $this->api->query("inquiry/{$uuid}/annotation", array('limit' => 3, 'sort' => 'inqan_cre_dtim desc')), 'TAGDATA' => $this->api->query("inquiry/{$uuid}/tag", array('limit' => 0)), 'STATSDATA' => $this->_stats_data($inq), 'SUBMDATA' => $this->api->query("inquiry/{$uuid}/submission", array('limit' => 5)), 'SUBMSRCH' => air2_uri_for("reader/query/{$uuid}"), 'ACTIVDATA' => $this->api->query("inquiry/{$uuid}/activity", array('limit' => 5)), 'AUTHORDATA' => $this->api->query("inquiry/{$uuid}/author", array('limit' => 5)), 'WATCHERDATA' => $this->api->query("inquiry/{$uuid}/watcher", array('limit' => 5))); // show page $title = $base_rs['radix']['inq_ext_title'] . ' - ' . AIR2_SYSTEM_DISP_NAME; $data = $this->airhtml->get_inline($title, 'Inquiry', $inline); $this->response($data); }
/** * Load inline HTML * * @param type $uuid * @param type $base_rs */ protected function show_html($uuid, $base_rs) { // Record visit by the current user against the current source. See UserVisit model. $source = AIR2_Record::find('Source', $uuid); $source->visit(array('ip' => $this->input->ip_address(), 'user' => $this->user)); /** * Prep and display page. */ $search_query = array('q' => "src_uuid={$uuid}"); $inline = array('UUID' => $base_rs['uuid'], 'URL' => air2_uri_for($base_rs['path']), 'BASE' => $base_rs, 'SUBMSRCH' => air2_uri_for('search/responses', $search_query), 'ORGDATA' => $this->api->query("source/{$uuid}/organization", array('limit' => 5, 'sort' => 'so_home_flag desc,so_status asc,org_display_name asc')), 'SUBMDATA' => $this->api->query("source/{$uuid}/submission", array('limit' => 8, 'sort' => 'srs_date desc,srs_cre_dtim desc')), 'FACTDATA' => $this->api->query("source/{$uuid}/fact", array('limit' => 7, 'sort' => 'fact_id asc')), 'ACTVDATA' => $this->api->query("source/{$uuid}/activity", array('limit' => 5, 'sort' => 'sact_dtim desc')), 'INTDATA' => $this->api->query("source/{$uuid}/interest", array('limit' => 5)), 'EXPDATA' => $this->api->query("source/{$uuid}/experience", array('limit' => 5)), 'ANNOTDATA' => $this->api->query("source/{$uuid}/annotation", array('limit' => 4, 'sort' => 'srcan_upd_dtim desc')), 'TAGDATA' => $this->api->query("source/{$uuid}/tag", array('limit' => 0)), 'OUTDATA' => $this->api->query("source/{$uuid}/outcome", array('limit' => 4)), 'PREFDATA' => $this->api->query("source/{$uuid}/preference", array('limit' => 4)), 'STATSDATA' => $this->_stats_data($uuid), 'FLDDATA' => $this->api->query("fact", array('limit' => 0)), 'PREFSDATA' => $this->api->query("preference", array('pt_identifier' => 'preferred_language', 'limit' => 0))); // show page $uname = $base_rs['radix']['src_username']; $first = $base_rs['radix']['src_first_name']; $last = $base_rs['radix']['src_last_name']; $name = $first && $last ? "{$first} {$last}" : $uname; $title = "{$name} - " . AIR2_SYSTEM_DISP_NAME; $data = $this->airhtml->get_inline($title, 'Source', $inline); $this->response($data); }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('TankSource', array('local' => 'tp_tsrc_id', 'foreign' => 'tsrc_id', 'onDelete' => 'CASCADE')); }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('User', array('local' => 'tank_user_id', 'foreign' => 'user_id', 'onDelete' => 'CASCADE')); $this->hasMany('TankSource', array('local' => 'tank_id', 'foreign' => 'tsrc_tank_id')); $this->hasMany('TankActivity', array('local' => 'tank_id', 'foreign' => 'tact_tank_id')); $this->hasMany('TankOrg', array('local' => 'tank_id', 'foreign' => 'to_tank_id')); }
/** * Override save() to set src_status after all children are saved. * Apparently the postSave() hook happens *before* children are saved, * which means the set_src_status() algorithm has immature data. * * @param Doctrine_Connection $conn * @return unknown */ public function save(Doctrine_Connection $conn = null) { $ret = parent::save($conn); $this->set_and_save_src_status(); return $ret; }
/** * Gets (or creates, if DNE) the manual-input inquiry associated with this * particular project. This is used to manually enter source responses for * things like emails and phone calls. * * @return Inquiry */ public function get_manual_entry_inquiry() { $me_uuid = air2_str_to_uuid('me-' . $this->prj_name); $inq = AIR2_Record::find('Inquiry', $me_uuid); if (!$inq) { $inq = Inquiry::make_manual_entry(); $inq->inq_uuid = $me_uuid; $inq->add_projects(array($this)); $orgs = array(); foreach ($this->ProjectOrg as $porg) { $orgs[] = $porg->Organization; } $inq->add_orgs($orgs); $inq->save(); } return $inq; }
/** * Set table relations * * @return unknown */ public function setUp() { parent::setUp(); $this->hasOne('Inquiry', array('local' => 'inqan_inq_id', 'foreign' => 'inq_id', 'onDelete' => 'CASCADE')); }
/** * Set table relations */ public function setUp() { parent::setUp(); $this->hasOne('PreferenceType', array('local' => 'ptv_pt_id', 'foreign' => 'pt_id')); $this->hasMany('SrcPreference', array('local' => 'ptv_id', 'foreign' => 'sp_ptv_id')); }