public static function store()
 {
     $params = $_POST;
     if ($params['ev'] == 'T') {
         $params['ev'] = True;
     } else {
         $params['ev'] = False;
     }
     $pokemon = new Pokemons(array('name' => $params['name'], 'ev' => $params['ev']));
     $stats = new Stats(array('cp' => $params['cp'], 'hp' => $params['hp'], 'weight' => $params['weight'], 'height' => $params['height'], 'candy' => $params['candy']));
     $pokemon->save();
     $stats->save();
     $joins = new Joins(array('pok_id' => $pokemon->id, 's_id' => $stats->id));
     $joins->save();
     Redirect::to('/Pokemons/' . $pokemon->id, array('message' => 'Pokemon lisätty tietokantaan!'));
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     try {
         $log = new Process();
         $log->name = "get-shares";
         $log->status = "running";
         $log->save();
         $filterDate = new DateTime('now');
         $filterDate->sub(new DateInterval('P1D'));
         //Load shares
         Link::where('date', '>', $filterDate)->chunk(100, function ($links) {
             foreach ($links as $value) {
                 $shares = $this->getSharesCount($value->final_url);
                 $ref = Stats::where('id_link', $value->id)->orderBy('created_at', 'DESC')->first();
                 if (!$ref) {
                     $ref = new stdClass();
                     $ref->total = 0;
                 }
                 $stat = new Stats();
                 $stat->id_link = $value->id;
                 $stat->facebook = $shares['facebook'] != null ? $shares['facebook'] : $value->facebook;
                 $stat->twitter = $shares['twitter'] != null ? $shares['twitter'] : $value->twitter;
                 $stat->linkedin = $shares['linkedin'] != null ? $shares['linkedin'] : $value->linkedin;
                 $stat->googleplus = $shares['googleplus'] != null ? $shares['googleplus'] : $value->googleplus;
                 $stat->total = $stat->facebook + $stat->twitter + $stat->linkedin + $stat->googleplus;
                 $stat->dif_total = $stat->total - $ref->total;
                 $stat->save();
                 $value->facebook = $stat->facebook;
                 $value->twitter = $stat->twitter;
                 $value->linkedin = $stat->linkedin;
                 $value->googleplus = $stat->googleplus;
                 $value->total = $stat->total;
                 $value->save();
             }
         });
         $log->status = "finished";
         $log->save();
     } catch (Exception $e) {
         $this->info($url);
         $this->info($e->getMessage());
     }
 }
Example #3
0
 /**
  * 统计日志保存更新stat_count
  */
 public function saveOrUpdate($data)
 {
     print_r($data);
     $stat = Stats::model()->findByAttributes(array('user_id' => $data['user_id']));
     if (empty($stat)) {
         $stat = new Stats();
         $stat->user_id = $data['user_id'];
         $stat->save();
     }
     /**
      * 添加统计日志
      */
     if (!empty($data['tag'])) {
         $statcount = new Statcount();
         $statcount->user_id = $data['user_id'];
         $statcount->url = $data['url'];
         $statcount->tag = $data['tag'];
         $statcount->save();
     }
     $this->updateStat();
 }
Example #4
0
// Check for page postback
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Get user input from form
    $YR = $_POST['YR'];
    $Fullname = $_POST['Fullname'];
    $GP = $_POST['GP'];
    $AB = $_POST['AB'];
    $R = $_POST['R'];
    $H = $_POST['H'];
    $HR = $_POST['HR'];
    $RBI = $_POST['RBI'];
    $Salary = $_POST['Salary'];
    $Bio = $_POST['Bio'];
    // Execute database query
    $stat = new Stats();
    $stat->YR = $YR;
    $stat->Fullname = $Fullname;
    $stat->GP = $GP;
    $stat->AB = $AB;
    $stat->R = $R;
    $stat->H = $H;
    $stat->HR = $HR;
    $stat->RBI = $RBI;
    $stat->Salary = $Salary;
    $stat->Bio = $Bio;
    $stat->save();
    // Redirect to site root
    redirect_to('.');
}
// Include page view
require_once VIEW_PATH . 'upsert.view.php';