Example #1
0
 function __construct($arr = null, $arr_pre = "t_")
 {
     parent::__construct($arr, $arr_pre);
     $this->date = strtotime($this->date);
     $this->time = TrainingLog::getSecondsFromFormat($this->time);
     //$this->route = new Route($arr);
 }
Example #2
0
 public function training()
 {
     if (!isset($_GET["username"])) {
         exit;
     }
     $user = User::fromUsername($_GET["username"]);
     $t_items = TrainingLog::getItemsForUser($user->uid);
     $feed = new Rss_Feed("Training entries for {$user->username}", "http://{$_SERVER["SERVER_NAME"]}", "Includes the training data for a given user.");
     $feed->pubDate = date(DATE_RSS);
     $feed->defineImageForFeed(new Rss_Image("running logo", "http://byroni.us", "http://runndaily.com/img/logo.png"));
     foreach ($t_items as $item) {
         $rss_item = new Rss_Item();
         $rss_item->guid = "http://{$_SERVER["SERVER_NAME"]}/training/view/{$item->tid}";
         $rss_item->link = "http://{$_SERVER["SERVER_NAME"]}/training/view/{$item->tid}";
         $rss_item->description = "{$item->date} : {$item->distance} miles";
         $rss_item->pubDate = date(DATE_RSS, $item->date);
         $rss_item->title = "{$user->username} logged an entry on " . date("F j, Y, g:i a", $item->date);
         $feed->addItemToFeed($rss_item);
     }
     //die(var_dump($feed));
     RoutingEngine::getSmarty()->assign("RssFeed", $feed);
     $rss_out = RoutingEngine::getSmarty()->fetch("generic/rss.tpl");
     header("Content-Type: application/rss+xml");
     echo $rss_out;
 }
Example #3
0
 public function view()
 {
     RoutingEngine::setPage("runnDAILY View Route", "PV__300");
     RoutingEngine::getInstance()->registerParams("rid");
     if (!isset($_GET["rid"])) {
         Page::redirect("/routes");
     }
     $rid = $_GET["rid"];
     //$route = Route::fromRouteIdentifier($rid);
     $route = Route::sql()->select("routes.*, u_username, u_uid")->leftjoin("users", "u_uid", "r_uid", true)->where_eq("r_id", $rid)->execute(true, false);
     //get training types for create new training modal
     /*$stmt = Database::getDB()->prepare("
     			SELECT t_type_id, t_type_name
     			FROM training_types
     		");
     		$stmt->execute();
     		$stmt->store_result();
     		$types = array();
     		while($row = $stmt->fetch_assoc()){
     			$types[] = array("id"=>$row["t_type_id"], "name"=>$row["t_type_name"]);
     		}
     		$stmt->close();*/
     $types_sql = new SQL("training_types");
     $types = $types_sql->select("t_type_id, t_type_name")->execute(false, true);
     //$training_items = TrainingLog::getItemsForUserForRoute(User::$current_user->uid, $rid);
     $training_items = TrainingLog::sql()->select("r_name, t_rid, t_tid, t_time, t_distance, t_pace, t_date, t_comment")->leftjoin("routes", "r_id", "t_rid")->where_eq("t_uid", User::$current_user->uid)->where_eq("t_rid", $rid)->orderby("t_date")->execute(false, true);
     RoutingEngine::getSmarty()->assign("t_types", $types);
     RoutingEngine::getSmarty()->assign("route_view", $route);
     RoutingEngine::getSmarty()->assign("training_items", $training_items);
 }
Example #4
0
 public function view($id)
 {
     if (!isset($id)) {
         Page::redirect("/goals");
     }
     RoutingEngine::setPage("runnDAILY View Goal", "PV__300");
     $goal = Goal::getGoalById($id);
     $training_items = TrainingLog::getItemsForUserForGoalView(User::$current_user->uid, $goal->start, $goal->end);
     $goal->buildGoalDataUsingTrainingItems($training_items);
     RoutingEngine::getSmarty()->assign("goal", $goal);
     RoutingEngine::getSmarty()->assign("training_items", $training_items);
 }
Example #5
0
 public function view_user()
 {
     RoutingEngine::setPage("runnDAILY", "PV__300");
     RoutingEngine::getInstance()->registerParams("uid");
     if (!isset($_GET["uid"])) {
         Page::redirect("/community");
     }
     $uid = $_GET["uid"];
     //$routes = Route::getRoutesForUserInArray($uid, 50);
     $routes = Route::sql()->select("r_id, r_name, r_distance, r_creation, r_description")->where_eq("r_uid", $uid)->orderby("r_creation")->limit(50)->execute(false, true, "r_id");
     //$routes_js = json_encode_null($routes);
     RoutingEngine::getSmarty()->assign("routes", $routes);
     //RoutingEngine::getSmarty()->assign("routes_js", $routes_js);
     //$index_items = TrainingLog::getIndexItemsForUser($uid);
     $index_items = TrainingLog::sql()->select("r_name, t_rid, t_tid, t_time, t_distance, t_pace, t_date, t_comment")->leftjoin("routes", "r_id", "t_rid", false)->where_eq("t_uid", $uid)->orderby("t_date")->orderby("t_distance")->limit(50)->execute(false, true);
     //$json_data = TrainingLog::buildChartData($index_items);
     RoutingEngine::getSmarty()->assign("training_index_items", $index_items);
     //RoutingEngine::getSmarty()->assign("JSON_Chart_Data", $json_data);
     //var_dump(User::$current_user);
     RoutingEngine::getSmarty()->assign("user", User::fromUid($uid));
 }
 /**
  * Deletes a particular model.
  * If deletion is successful, the browser will be redirected to the 'admin' page.
  * @param integer $id the ID of the model to be deleted
  */
 public function actionDelete($id)
 {
     if ($_GET['group_id'] == 1) {
         //check exist course and test created by a trainer
         if (Course::model()->checkCourse($id) && Test::model()->checkTest($id)) {
             Yii::app()->user->setFlash('unsuccess', ' Can not delete a trainer.');
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
         // delete trainer
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         if (!isset($_GET['ajax'])) {
             Yii::app()->user->setFlash('success', 'You did delete a trainer when: <br>- Not exist course created by trainer.<br>- Not exist test created by trainer.');
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
     } elseif ($_GET['group_id'] == 2) {
         //Delete course trainee
         CourseTrainee::model()->deleteCourseTrainee($id);
         //Delete user test
         UserTest::model()->deleteUserTest($id);
         //Delete training log and training random question
         TrainingLog::model()->deleteTrainingLog($id);
         TrainingRandomquestion::model()->deleteTrainingRadomQuestion($id);
         //delete trainee
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         Yii::app()->user->setFlash('success', 'You did delete a trainee: <br>- Delete course trainee.<br>- Delete Training log and training random question.<br>- Delete user test and user answers.');
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
     } elseif ($_GET['group_id'] == 3) {
         // delete training manager
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         Yii::app()->user->setFlash('success', 'You did delete a training manager.');
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
     } elseif ($_GET['group_id'] == 4) {
         // delete team leader
         ATrainingTeam::deleteTeamleader($id);
         $this->loadModel($id)->delete();
         // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
         Yii::app()->user->setFlash('success', 'You did delete a team leader.');
         if (!isset($_GET['ajax'])) {
             $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin', 'group_id' => $_GET['group_id']));
         }
     }
 }
 /**
  * Returns the static model of the specified AR class.
  * Please note that you should have this exact method in all your CActiveRecord descendants!
  * @param string $className active record class name.
  * @return WTrainingLog the static model class
  */
 public static function model($className = __CLASS__)
 {
     return parent::model($className);
 }
Example #8
0
 function updatePercent()
 {
     $goal_data = TrainingLog::getItemsForUserForGoalPercent(User::$current_user->uid, $this->start, $this->end);
     $percents = array();
     $percent = 1;
     if (isset($this->metadata['dist_tot'])) {
         $percents['dist'] = $goal_data['dist'] / $this->metadata['dist_tot']['value'];
     }
     if (isset($this->metadata['pace_avg'])) {
         $percents['pace'] = $goal_data['pace'] / $goal_data['count'] / $this->metadata['pace_avg']['value'];
     }
     if (isset($this->metadata['time_tot'])) {
         $percents['time'] = $goal_data['time'] / 60.0 / $this->metadata['time_tot']['value'];
     }
     var_dump($percents);
     foreach ($percents as $item) {
         if ($item <= 1) {
             $percent = $percent * $item;
         }
     }
     $this->percent = $percent * 100;
     $stmt = Database::getDB()->prepare("\r\n\t\t\tUPDATE goals\r\n\t\t\tSET go_percent = ?\r\n\t\t\tWHERE go_id = ?\r\n\t\t");
     $stmt->bind_param("di", $this->percent, $this->id);
     $stmt->execute() or die($stmt->error);
     $stmt->close();
 }
Example #9
0
 public function summary()
 {
     RoutingEngine::setPage("runnDAILY Training Summary", "PV__300");
     $this_week = new DateRange();
     $this_week->getWeekRange();
     $data_this_week = TrainingLog::getItemsForUserForGoalPercent(User::$current_user->uid, $this_week->start, $this_week->end);
     $last_week = new DateRange();
     $last_week->getWeekRange("today", -1);
     $data_last_week = TrainingLog::getItemsForUserForGoalPercent(User::$current_user->uid, $last_week->start, $last_week->end);
     $overall = TrainingLog::getSummaryOverall(User::$current_user->uid);
     //var_dump($data_this_week, $data_last_week, $overall);
     RoutingEngine::getSmarty()->assign("this_week", $this_week);
     RoutingEngine::getSmarty()->assign("last_week", $last_week);
     RoutingEngine::getSmarty()->assign("overall", $overall);
     RoutingEngine::getSmarty()->assign("data_this_week", $data_this_week);
     RoutingEngine::getSmarty()->assign("data_last_week", $data_last_week);
     $output = RoutingEngine::getSmarty()->fetch("training/_summary.tpl");
     echo $output;
     die;
 }