/**
  * 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;
 }
 /**
  * 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);
 }