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); } }
protected function execStandardMapping($association, $desc, &$o, &$objects) { $count = $desc['count']; $class = $desc['class']; // the class of the thing we're associated with $fk = $desc['foreign_key']; $table = $desc['table']; $pks = array(); foreach ($objects as &$object) { if (Pfw_Model::ASSOC_MANY == $count) { $object->{$association} = array(); $my_key = $desc['my_key']; $pks[$object->{$my_key}] = $object; } elseif (Pfw_Model::ASSOC_ONE == $count) { $object->{$association} = null; $my_key = $desc['my_key']; $pks[$object->{$my_key}] = $object; } elseif (Pfw_Model::ASSOC_BELONGSTO == $count) { $object->{$association} = null; $pks[$object->{$fk}] = $object; } } Pfw_Loader::loadModel($class); $inst = new $class(); // empty instance of thing we're associated with $qo = $inst->Q($o->_getDb()); if (isset($desc['conditions'])) { $join_cond = str_replace($association, 'this', $desc['conditions']); $qo->where($join_cond); } if (Pfw_Model::ASSOC_MANY == $count or Pfw_Model::ASSOC_ONE == $count) { $associated_objs = $qo->whereIn("this.{$fk}", array_keys($pks))->exec(); } elseif (Pfw_Model::ASSOC_BELONGSTO == $count) { $owner_key = $desc['owner_key']; $associated_objs = $qo->whereIn("this.{$owner_key}", array_keys($pks))->exec(); $fk = $owner_key; } foreach ($associated_objs as $associated_obj) { $object = $pks[$associated_obj->{$fk}]; if (empty($object)) { continue; } if (Pfw_Model::ASSOC_MANY == $count) { array_push($object->{$association}, $associated_obj); } elseif (Pfw_Model::ASSOC_ONE == $count or Pfw_Model::ASSOC_BELONGSTO == $count) { $object->{$association} = $associated_obj; } } unset($pks); }
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')); }
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 } }
<?php ini_set('post_max_size', "11M"); ini_set('upload_max_filesize', "11M"); Pfw_Loader::loadClass('Prj_Controller_Standard'); Pfw_Loader::loadClass('Prj_Components_FileUploaderComponent'); Pfw_Loader::loadModel('Project'); class ProjectController extends Prj_Controller_Standard { public function __construct() { parent::__construct(); // do any view initialization in here error_log(">>>IN PROJECT CONTROLLER[" . __CLASS__ . "]"); $view = $this->getView(); $view->addCssLink('custom-theme/jquery-ui-1.8.10.custom.css'); $view->addJsLink('jquery-1.4.4.min.js'); $view->addJsLink('jquery.dataTables.min.js'); #$view->addJsLink('jquery.simplemodal-1.3.4.min.js'); //$view->addCssLink('jquery.fileupload-ui.css'); //$view->addJsLink('jquery.fileupload.js'); //$view->addJsLink('jquery.fileupload-ui.js'); $view->addJsLink('jquery.jqUploader.js'); $view->addJsLink('jquery.flash.js'); $view->addJsLink('custom-theme/jquery-ui-1.8.10.custom.min.js'); #$view->addJsLink('custom-theme/jquery-ui-form.custom.min.js'); } function indexAction() { $view = $this->getView(); $view->assign('site_title', 'CalPalyn: Quaternary Paleoecology Lab Project Listing Page');
<?php Pfw_Loader::loadClass('Pfw_UnitTest_PHPUnit_TestCase'); Pfw_Loader::loadModel('User'); class User_Test extends Pfw_UnitTest_PHPUnit_TestCase { protected function setup() { // runs before every test } protected function tearDown() { // runs after every test } 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); }
<?php Pfw_Loader::loadClass('Pfw_UnitTest_PHPUnit_TestCase'); Pfw_Loader::loadModel('ProjectData'); class ProjectData_Test extends Pfw_UnitTest_PHPUnit_TestCase { protected function setup() { // runs before every test } protected function tearDown() { // runs after every test } public function xtestGetKeyData() { $data = ProjectData::Q()->getKeyValuesForProject(1); print_r($data); $this->assertNotNull($data); } public function testDepths() { $project_data = new ProjectData(); $depths = $project_data->getDepths(1); $this->assertNotNull($depths); print_r($depths); } }
protected function doJoins() { $withs = array_keys($this->with); if (empty($withs)) { return; } foreach ($withs as $with) { $with_params = $this->description['has'][$with]; // get the model description for the association model $with_model_class = $with_params['class']; Pfw_Loader::loadModel($with_model_class); $model_inst = new $with_model_class(); $with_model_desc = $model_inst->_getDescription(); $this->withDesc[$with] = $with_model_desc; $with_model_fields = array_to_hash(array_keys($with_model_desc['schema'])); // remove anything that should be blocked if (isset($with_model_desc['block_fetch_fields'])) { $block_fetch_fields = array_keys($with_model_desc['block_fetch_fields']); foreach ($with_model_fields as $alias => $field) { if (in_array($field, $block_fetch_fields)) { unset($with_model_fields[$alias]); } } } if (isset($with_model_desc['fetch_fields'])) { $with_model_fields = array_merge($with_model_fields, $with_model_desc['fetch_fields']); } // all of the fields in the association model $with_select_fields = array(); foreach ($with_model_fields as $field => $value) { if (is_a($value, 'Pfw_Db_Expr')) { $value->setAlias($with); } $with_select_fields["{$with}.{$field}"] = $value; } // just an alias $join_extra_cond = ""; if (isset($with_params['conditions'])) { $join_extra_cond .= " AND {$with_params['conditions']}"; } $ct = $with_params['count']; if ($ct == Pfw_Model::ASSOC_BELONGSTO) { $cond = "this.{$with_params['foreign_key']} = {$with}.{$with_params['owner_key']}"; $this->select->joinLeft(array($with => $with_params['table']), array("{$cond}{$join_extra_cond}"), $with_select_fields); } elseif ($ct == Pfw_Model::ASSOC_ONE or $ct == Pfw_Model::ASSOC_MANY) { $my_key = $this->description['has'][$with]['my_key']; if (isset($with_params['thru'])) { $this->hasThru = true; $this->thruDesc[$with_params['thru']] = array('owned_by' => $with, 'class' => $with_params['thru_class']); // setup the select fields for the thru table $thru_fields = array_to_hash($with_params['thru_fields']); $thru_select_fields = array(); foreach ($thru_fields as $field) { $thru_select_fields["{$with_params['thru']}.{$field}"] = $field; } // us->join table $thru_extra_cond = ""; if (isset($with_params['thru_conditions'])) { $thru_extra_cond = "AND {$with_params['conditions']}"; } $cond = "this.{$with_params['my_key']} = {$with_params['thru']}.{$with_params['my_join_key']}"; $this->select->joinLeft(array($with_params['thru'] => $with_params['thru_table']), array("{$cond}{$thru_extra_cond}"), $thru_select_fields); // join table->association $cond = "{$with_params['thru']}.{$with_params['as_join_key']} = {$with}.{$with_params['as_key']}"; $this->select->joinLeft(array($with => $with_params['table']), array("{$cond}{$join_extra_cond}"), $with_select_fields); } else { // us->association $cond = "this.{$with_params['my_key']} = {$with}.{$with_params['foreign_key']}"; $this->select->joinLeft(array($with => $with_params['table']), array("{$cond}{$join_extra_cond}"), $with_select_fields); } } } }