Example #1
0
 function jsonListProjectsAction()
 {
     $sEcho = $_REQUEST['sEcho'];
     $columns = array('ProjectId', 'ProjectName', 'ProjectOwner', 'ProjectDesc', 'ProjectDataStatus');
     // create a dummy array for now
     header("Content-Type: application/json");
     // mock data
     //$d = array(array(1,2,3,4),array('a','b','c','d'),array('x','y','z','zz'));
     //$s = sizeof($d);
     // real data
     $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($row->id, $row->name, "<a class='tip' name='#'>" . $u[$row->created_by]['first_name'] . "<span>" . $u[$row->created_by]['email'] . "</span></a>", $row->description, $row->has_data ? "<a href='#?pid=" . $row->id . "'>View</a>" : self::_getUploadMarkup($row->id));
         error_log(print_r($d, true));
     }
     $s = count($d);
     //error_log(print_r($rows,true));
     $data = array('aaData' => $d, 'iTotalRecords' => $s, 'iTotalDisplayRecords' => $s, 'sEcho' => $sEcho, 'sColumns' => $columns);
     $response = json_encode($data);
     echo $response;
     return;
 }
Example #2
0
 function setupView()
 {
     $view = $this->getView();
     $view->assign('controller', Pfw_Request::getParam('controller'));
     if (self::is_logged_in()) {
         # gettng user with profile photo
         Pfw_Loader::loadModel('User');
         $user = User::Q()->where(array('this.id = %s', Pfw_Session::get('login_id')))->exec();
         $logged_in_user = $user[0];
         $view->assign('logged_in_user', $logged_in_user);
         $view->assign('is_logged_in', true);
     }
 }
Example #3
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'));
 }
Example #4
0
 public function testLogin()
 {
     $u = new User();
     $first_name = 'phpunit_' . uniqid();
     $u->first_name = $first_name;
     $u->last_name = "smith";
     $u->email = $first_name . '@example.com';
     $u->password = '******';
     $u->password_confirm = 'toast';
     $u_id = $u->save();
     # check username password validation
     $u2 = User::Q()->getByAuth($u->email, $u->password)->limit(1)->exec();
     //objp($u2);
     $this->assertEquals($u2->email, $u->email);
     $updated_count = User::Q()->deleteAll(array('first_name = %s', $first_name));
     $this->assertEquals($updated_count, 1);
 }
Example #5
0
 public function testDeleteAll()
 {
     $u = new User();
     $u->first_name = "sean";
     $u->last_name = "smith";
     $u->save();
     $u = new User();
     $u->first_name = "sean";
     $u->last_name = "jones";
     $u->save();
     $u = new User();
     $u->first_name = "jim";
     $u->last_name = "jones";
     $u->save();
     $updated_count = User::Q()->deleteAll(array('first_name = %s', 'sean'));
     $users = User::Q()->exec();
     $this->assertEquals(2, $updated_count);
     $this->assertEquals(1, count($users));
     $this->assertEquals($users[0]->first_name, 'jim');
 }
Example #6
0
 public function getByAuth($email, $password)
 {
     $user = null;
     $password = User::encryptPassword(trim($password));
     if (strpos($email, '@') !== false) {
         $user_sql = User::Q()->getByEmail($email)->where(array('password = %s', $password));
         //$user =  User::Q()->where(array('this.email = %s', $email));
     }
     return $user_sql;
 }