Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

watch preselection #91

Merged
merged 21 commits into from
Jan 7, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: php
php:
- '5.6'
- '7.0'

notifications:
slack: toolwatchapp:AfvHCPE9Em1MY3j04gdlqbYe
Expand Down
9 changes: 8 additions & 1 deletion app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@
},
"TW_EVENT_URL": {
"required": true
},
"NEW_RELIC_APP_NAME": {
"required": true
},
"NEW_RELIC_CONFIG_FILE": {
"required": true
}
},
"addons": [
"cleardb"
"cleardb",
"newrelic"
]
}
16 changes: 8 additions & 8 deletions application/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 0;
$config['log_threshold'] = 2;

/*
|--------------------------------------------------------------------------
Expand Down Expand Up @@ -360,13 +360,13 @@
| except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.
|
*/
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_save_path'] = 'ci_sessions';
$config['sess_expiration'] = 1440;
$config['sess_match_ip'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
$config['sess_driver'] = 'database';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 1440;
$config['sess_save_path'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;

/*
|--------------------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions application/controllers/Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ function login() {
}

echo json_encode($result);
}else{
echo "POST FAIL";
}

}

/**
Expand Down
27 changes: 21 additions & 6 deletions application/controllers/Measures.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,10 @@ private function constructMeasurePage(){
$this->_headerData['headerClass'] = 'blue';
$this->load->view('header', $this->_headerData);

$this->_bodyData['watches'] = $this->watch->getWatches(
$this->session->userdata('userId'));
$this->_bodyData['allMeasure'] = $this->measure->getMeasuresByUser(
$this->session->userdata('userId'), $this->_bodyData['watches']);
$this->session->userdata('userId'));

$this->load->view('measure/all', $this->_bodyData);
$this->load->view('measure/dashboard', $this->_bodyData);

$this->load->view('footer');
}
Expand Down Expand Up @@ -94,7 +92,7 @@ public function add_watch(){
*/
public function delete_watch(){

if($this->expectsPost(array('deleteWatch'))){
if($this->expectsPost(array('watchId'))){

if ($this->watch->deleteWatch($this->watchId)) {
$this->_bodyData['success'] = 'Watch successfully deleted!';
Expand Down Expand Up @@ -148,18 +146,35 @@ public function new_watch() {
*/
public function new_measure() {

$this->_bodyData['watches'] = $this->watch->getWatches(
$this->session->userdata('userId'));

$this->event->add(MEASURE_LOAD);

$this->_headerData['headerClass'] = 'blue';
$this->load->view('header', $this->_headerData);

$this->_bodyData['watches'] = $this->watch->getWatches($this->session->userdata('userId'));
$this->load->view('measure/new-measure', $this->_bodyData);
$this->load->view('measure/audio.php');

$this->load->view('footer');
}

/**
* Serves the new measure form (1/2) for a watch
* with existing measures.
*/
public function new_measure_for_watch(){

if($this->expectsPost(array('watchId'))){

$this->_bodyData['selected_watch'] = $this->watchId;

$this->new_measure();

}
}

/**
* Serves the new accuracy form (2/2)
*/
Expand Down
54 changes: 53 additions & 1 deletion application/core/MY_Controller.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
<?php if (!defined('BASEPATH')) {exit('No direct script access allowed');
}

/**
* Specialisation of CI_Controller that provided some additional services
* - headerdata
* - login gestion
* - post data check
* - logging
*/
class MY_Controller extends CI_Controller {
protected $_headerData = array();
protected $_bodyData = array();
protected $_footerData = array();
protected $_needLoggedIn = false;

/**
* Default constructor
*/
public function __construct() {
parent::__construct();

Expand All @@ -21,16 +31,58 @@ public function __construct() {
}
}

/**
* Convenient method to check that variables have been posted.
* In addition, all the variables contained in $postNames are copied in
* this. So you can access it by $this->myPostVariable.
*
* @param Array $postNames name of the variables expected to be posted
* @return Boolean returns true if all the variables were present
*/
protected function expectsPost($postNames){

foreach ($postNames as $postName) {
if(!$this->input->post($postName)){

//If the variable is NULL (not posted), we log and exit
if($this->input->post($postName) === NULL){
log_message('error', "Was expecting " . print_r($postNames, true) .
" got " . print_r($_POST, true));
return false;
}

//Add the variable in $this
$this->{$postName} = $this->input->post($postName);
}

return true;
}

/**
* Intercepts all method call on controller in order to provide logging
* capabilities.
*
* @param String $method the method name
* @param Array $params An array of get parameters (segments following the
* method segment)
* @return mixed Result of the method call
*/
public function _remap($method, $params = array()){

//Entry logging
$begin = new DateTime();
log_message('info', 'Entering ' . get_class($this).':'
.$method .'->'.print_r($param, true));

//method execution
$result = call_user_func_array(array($this, $method), $params);

//Exit logging
$end = new DateTime();
$diff = $begin->diff($end);
log_message('info', 'Exiting ' . get_class($this).':'
.$method .' after '.$diff->format( '%H:%I:%S' ).'->'
.print_r($result, true)
);
}

}
84 changes: 84 additions & 0 deletions application/core/MY_Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

// this class is adapted from system/libraries/Log.php
/**
* CodeIgniter
*
* An open source application development framework for PHP 5.1.6 or newer
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc.
* @copyright Copyright (c) 2014 - 2015, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://codeigniter.com/user_guide/license.html
* @link http://codeigniter.com
* @since Version 1.0
* @filesource
*/

// ------------------------------------------------------------------------

/**
* Logging Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Logging
* @author EllisLab Dev Team
* @link http://codeigniter.com/user_guide/general/errors.html
*/
class MY_Log {

protected $_threshold = 1;
protected $_date_fmt = 'Y-m-d H:i:s';
protected $_levels = array('ERROR' => '1', 'DEBUG' => '2', 'INFO' => '3', 'ALL' => '4');

/**
* Constructor
*/
public function __construct()
{
$config =& get_config();

if (is_numeric($config['log_threshold']))
{
$this->_threshold = $config['log_threshold'];
}

if ($config['log_date_format'] != '')
{
$this->_date_fmt = $config['log_date_format'];
}
}

// --------------------------------------------------------------------

/**
* Write Log to php://stderr
*
* Generally this function will be called using the global log_message() function
*
* @param string the error level
* @param string the error message
* @param bool whether the error is a native PHP error
* @return bool
*/
public function write_log($level = 'error', $msg, $php_error = FALSE)
{
$level = strtoupper($level);

if ( ! isset($this->_levels[$level]) OR ($this->_levels[$level] > $this->_threshold))
{
return FALSE;
}

file_put_contents('php://stderr', $level.' '.(($level == 'INFO') ? ' -' : '-').' '.date($this->_date_fmt). ' --> '.$msg."\n");

return TRUE;
}

}
// END Log Class

/* End of file MY_Log.php */
/* Location: ./application/libraries/MY_Log.php */
6 changes: 0 additions & 6 deletions application/core/MY_Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,6 @@ public function find_all_by($field = null, $value = null, $type = 'and') {
*/
public function find_by($field = '', $value = '', $type = 'and') {
if (empty($field) || (!is_array($field) && empty($value))) {
$this->error = lang('ff_model_find_error');
$this->logit('['.get_class($this).': '.__METHOD__ .'] '.lang('ff_model_find_error'));

return false;
}
Expand Down Expand Up @@ -980,8 +978,6 @@ public function delete_where($where = null) {
*/
public function is_unique($field = '', $value = '') {
if (empty($field) || empty($value)) {
$this->error = lang('ff_model_unique_error');
$this->logit('['.get_class($this).': '.__METHOD__ .'] '.lang('ff_model_unique_error'));

return false;
}
Expand Down Expand Up @@ -1024,8 +1020,6 @@ public function count_all() {
*/
public function count_by($field = '', $value = null) {
if (empty($field)) {
$this->error = lang('ff_model_count_error');
$this->logit('['.get_class($this).': '.__METHOD__ .'] '.lang('ff_model_count_error'));

return false;
}
Expand Down
7 changes: 1 addition & 6 deletions application/libraries/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ public function updateObserver($subject, $event, $data) {
public function add($event) {

if (ENVIRONMENT === 'production') {
if (isset($_SERVER["HTTP_CF_CONNECTING_IP"])) {
$_SERVER['REMOTE_ADDR'] = $_SERVER["HTTP_CF_CONNECTING_IP"];
}

$country = "undefined";

Expand All @@ -33,8 +30,6 @@ public function add($event) {

$data_string = json_encode($data);

event_url();

$ch = curl_init(event_url());

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
Expand All @@ -48,4 +43,4 @@ public function add($event) {
$result = curl_exec($ch);
}
}
}
}
Loading