Exemple #1
0
 function indexAction()
 {
     $view = $this->getView();
     $view->assign('home', true);
     $view->assign('site_title', 'CalPalyn: Quaternary Paleoecology Lab');
     // call project model
     $rows = Project::Q()->exec();
     //Not the most efficient but since there are handful of users
     $users = User::Q()->exec();
     foreach ($users as $user) {
         $u[$user->id] = array('email' => $user->email, 'first_name' => $user->first_name);
     }
     error_log(print_r($rows, true));
     foreach ($rows as $row) {
         $d[] = array('id' => $row->id, 'name' => $row->name, 'user_info' => "<a class='tip' name='#'>" . $u[$row->created_by]['first_name'] . "<span>" . $u[$row->created_by]['email'] . "</span></a>", 'desc' => $row->description);
         $p[$row->id] = array('name' => $row->name, 'description' => $row->description);
         error_log(print_r($d, true));
     }
     $view->assign('projects', $d);
     $view->assign('projects_info', $p);
     // Get list of taxons
     Pfw_Loader::loadModel('Taxon');
     $txs = Taxon::Q()->exec();
     //objp($txs);
     foreach ($txs as $t) {
         $taxons[$t->type] = $t->name;
     }
     //objp($taxons);
     error_log("Taxons are " . print_r($taxons, true));
     $view->assign('taxons', $taxons);
     if (isset($_REQUEST['pid']) and !empty($_REQUEST['pid'])) {
         Pfw_Loader::loadModel('ProjectData');
         $key_data = ProjectData::Q()->getKeyValuesForProject($_REQUEST['pid']);
         $chart_data = $key_data['chart_data'];
         foreach ($chart_data as $cdk => $cdv) {
             $depth_values = array_keys($cdv);
             $taxon_values = array_values($cdv);
             $chart_values[$cdk] = array('depth_min' => min($depth_values), 'depth_max' => max($depth_values), 'taxon_min' => min($taxon_values), 'taxon_max' => max($taxon_values), 'depths' => self::_extendedEncode($depth_values, max($depth_values)), 'taxon_values' => self::_extendedEncode($taxon_values, max($taxon_values)));
         }
         #objp($chart_values);
         $view->assign('chart_data', $chart_values);
         $view->assign('field_names', $key_data['field_names']);
         $view->assign('project_data', $key_data['data']);
         $view->assign('project_id', $_REQUEST['pid']);
         $view->assign('depths', $key_data['depths']);
         $view->assign('debug', print_r($view->get_template_vars(), true));
     }
     $view->display(array('layout' => 'layouts/main.tpl', 'body' => 'home/index.tpl'));
 }
Exemple #2
0
 public function saveProjectData($data, $options)
 {
     // Create taxon map one time
     Pfw_Loader::loadModel('Taxon');
     $field_names = $options['field_names'];
     $pid = $options['pid'];
     $num_cols = count($field_names);
     $taxons = Taxon::Q()->exec();
     $taxon = array();
     // strtolower
     $fields = array_filter($field_names, "strtolower");
     $depth_index = array_search('depth', $fields);
     error_log("fields columns are " . print_r($fields, true));
     foreach ($taxons as $t) {
         $taxon[$t->name] = $t->type;
     }
     error_log("taxons are " . print_r($taxon, true));
     // foreach row in data array process individual columns
     foreach ($data as $d) {
         $sql = null;
         $depth = $d[$depth_index];
         for ($i = 0; $i < $num_cols; $i++) {
             if ($i == $depth_index) {
                 continue;
             }
             //error_log(print_r($d,true));
             $tname = strtolower($fields[$i]);
             $null_val = "'NULL'";
             $taxon_type = empty($taxon[$tname]) ? $null_val : $taxon[$tname];
             $taxon_value = empty($d[$i]) ? $null_val : $d[$i];
             error_log("TAXON VALUE IS {$taxon_value}");
             $sql = "INSERT  INTO project_data (project_id,depth,taxon_type, taxon_value) VALUES({$pid},{$depth},{$taxon_type},{$taxon_value});";
             error_log($sql);
             Pfw_Db::factory()->query($sql);
         }
         // now fire the insert sql
     }
 }