コード例 #1
0
ファイル: auction.php プロジェクト: notfoundsam/yahooauc
 public function action_edit($id = null, $one = null, $two = null)
 {
     $redirect = $two ? $one . '/' . $two : $one;
     $auction = Model_Auction::find($id);
     $val = Model_Auction::validate_edit();
     if ($val->run()) {
         $auction->item_count = Input::post('item_count');
         $auction->price = Input::post('price');
         $auction->memo = Input::post('memo');
         if (\Security::check_token() && $auction->save()) {
             Session::set_flash('success', e('Updated auction #' . $auction->auc_id));
             Response::redirect('admin/' . $redirect);
         } else {
             Session::set_flash('error', e('Could not update auction #' . $auction->auc_id));
         }
     } else {
         if (Input::method() == 'POST') {
             $auction->item_count = $val->validated('item_count');
             $auction->price = $val->validated('price');
             $auction->memo = $val->validated('memo');
             Session::set_flash('error', $val->error());
         }
         $this->template->set_global('auction', $auction, false);
     }
     $this->template->set_global('redirect', $redirect, false);
     $this->template->title = $auction->title;
     $this->template->content = View::forge('admin/auction/edit');
 }
コード例 #2
0
ファイル: won.php プロジェクト: notfoundsam/yahooauc
 public function action_index()
 {
     $data["subnav"] = array('index' => 'active');
     $data['items'] = Model_Auction::find('all', ['related' => ['user'], 'where' => ['part_id' => null, 'username' => 'vyacheslav']]);
     $this->template->title = 'Admin/won » Index';
     $this->template->content = View::forge('admin/won/index', $data);
 }
コード例 #3
0
ファイル: minutely.php プロジェクト: notfoundsam/yahooauc
 private static function check_won_at_time()
 {
     $interval = \Config::get('my.task.lot_update_interval');
     if (self::$LAST_CHECK_TIME < strtotime("-{$interval} minute")) {
         $auc_ids = [];
         $select = \DB::select('auc_id')->from('auctions')->order_by('id', 'desc')->limit(\Config::get('my.task.last_won_limit'))->execute()->as_array();
         $user_id = \DB::select('id')->from('users')->where('username', \Config::get('my.main_bidder'))->execute()->as_array();
         foreach ($select as $value) {
             $auc_ids[] = $value['auc_id'];
         }
         $val = \Model_Auction::validate();
         try {
             $browser = new \Browser();
             foreach ($browser->won(self::$PAGE_TO_UPDATE) as $auc_id) {
                 if (!in_array($auc_id, $auc_ids)) {
                     try {
                         $auc_xml = $browser->getXmlObject($auc_id);
                         $auc_values = [];
                         $auc_values['auc_id'] = (string) $auc_xml->Result->AuctionID;
                         $auc_values['title'] = (string) $auc_xml->Result->Title;
                         $auc_values['price'] = (int) $auc_xml->Result->Price;
                         $auc_values['won_date'] = \Date::create_from_string((string) $auc_xml->Result->EndTime, 'yahoo_date')->format('mysql');
                         $auc_values['user_id'] = $user_id[0]['id'];
                         $vendor_name = (string) $auc_xml->Result->Seller->Id;
                         $vendor_id = \DB::select('id')->from('vendors')->where('name', '=', $vendor_name)->execute()->as_array();
                         if (!empty($vendor_id)) {
                             $auc_values['vendor_id'] = $vendor_id[0]['id'];
                         } else {
                             if (\Model_Vendor::forge()->set(['name' => $vendor_name, 'by_now' => 0])->save()) {
                                 $vendor_id = \DB::select('id')->from('vendors')->where('name', '=', $vendor_name)->execute()->as_array();
                                 $auc_values['vendor_id'] = $vendor_id[0]['id'];
                             }
                         }
                         if ($val->run($auc_values)) {
                             \Model_Auction::forge()->set($auc_values)->save();
                         } else {
                             foreach ($val->error() as $value) {
                                 \Log::error('Validation error in task Minutely on method check_won_at_time : ' . $value);
                             }
                         }
                     } catch (\BrowserException $e) {
                         \Log::error("ID: " . $auc_id . " Error: " . $e->getMessage());
                     }
                 }
             }
         } catch (\BrowserLoginException $e) {
             \Log::error("Login error: " . $e->getMessage());
         } catch (\ParserException $e) {
             \Log::error("Parser error: " . $e->getMessage());
         }
         \Cache::set('yahoo.won_last_check', time());
     }
 }
コード例 #4
0
ファイル: api.php プロジェクト: notfoundsam/yahooauc
 public function post_createpart()
 {
     $result = '';
     $val_error = [];
     $combine_id = (int) \Input::post('combine_id');
     $ids = \Input::post('ids');
     if ($ids) {
         $part_id = null;
         if ($combine_id && \Model_part::find($combine_id)) {
             $part_id = $combine_id;
             $result = 'Part ID: ' . $part_id . ' was successfully updated';
         } else {
             $part = new \Model_part();
             if ($part->save()) {
                 $part_id = $part->id;
             }
             $result = 'Part ID: ' . $part_id . ' was successfully created';
         }
         foreach ($ids as $id) {
             $auction = \Model_Auction::find($id);
             $auction->part_id = $part_id;
             $auction->save();
         }
     } else {
         $val_error[] = 'Could not create new part';
     }
     $this->response(['result' => $result, 'error' => implode('<br>', (array) $val_error)]);
 }