Exemplo n.º 1
0
 /**
  * Store a newly created ad in storage.
  *
  * @return Response
  */
 public function store()
 {
     $directory = '/img/uploads/';
     $ad = new Ad();
     $ad->ad_type = Input::get('ad_type');
     $ad->ad_need = Input::get('ad_need');
     $ad->ad_title = Input::get('password');
     $ad->level = Input::get('level');
     if (Input::has('comp')) {
         $ad->comp = Input::get('comp');
     }
     $ad->genre = Input::get('genre');
     if (Input::has('date')) {
         $ad->date = Input::get('date');
     }
     if (Input::has('start_time')) {
         $ad->start_time = Input::get('start_time');
     }
     if (Input::has('end_time')) {
         $ad->end_time = Input::get('end_time');
     }
     if (Input::has('description')) {
         $ad->description = Input::get('description');
     }
     if (Input::has('equipment')) {
         $ad->equipment = Input::get('equipment');
     }
     $ad->venue_type = Input::get('venue_type');
     $ad->venue = Input::get('venue');
     $ad->address = Input::get('address');
     $ad->city = Input::get('city');
     $ad->state = Input::get('state');
     $ad->zip_code = Input::get('zip_code');
     $ad->user_id = Auth::id();
     if (Input::hasFile('ad_img')) {
         $file = Input::file('ad_img');
         $filename = Auth::id() . $file->getClientOriginalName();
         $file = $file->move(public_path() . $directory, $filename);
         $ad->ad_img = $directory . $filename;
     }
     if ($user->save()) {
         Session::flash('successMessage', 'You created an ad successfully');
         return Redirect::action('AdsController@show', Auth::id());
     } else {
         Session::flash('errorMessage', 'Could not save ad.');
         dd($user->getErrors()->toArray());
         return Redirect::action('UsersController@index')->withInput()->withErrors($ad->getErrors());
     }
 }
Exemplo n.º 2
0
 /**
  * Process the Meta table for campaign urls and create the
  * campaign from the corresponding URL
  */
 protected function importCampaigns()
 {
     $metas = \Meta::all(['prop = ?' => 'campImport']);
     $users = [];
     $orgs = [];
     foreach ($metas as $m) {
         $user = Usr::find($users, $m->propid, ['_id', 'org_id', 'email', 'meta']);
         $org = \Organization::find($orgs, $user->org_id);
         $categories = \Category::all(['org_id' => $org->_id], ['_id', 'name']);
         $categories = array_values($categories);
         $category = $categories[array_rand($categories)];
         // fetch ad info foreach URL
         $advert_id = $m->value['advert_id'];
         $comm = $m->value['campaign'] ?? $org->meta;
         if (!isset($comm['model']) || !isset($comm['rate'])) {
             continue;
         }
         $urls = $m->value['urls'];
         foreach ($urls as $url) {
             $ad = \Ad::first(['org_id' => $org->_id, 'url' => $url]);
             if ($ad) {
                 continue;
             }
             // already crawled URL may be due to failed cron earlier
             $data = Utils::fetchCampaign($url);
             $image = Utils::downloadImage($data['image']);
             if (!$image) {
                 $image = '';
             }
             $ad = new \Ad(['user_id' => $advert_id, 'org_id' => $org->_id, 'title' => $data['title'], 'description' => $data['description'], 'url' => $url, 'image' => $image, 'category' => [$category->_id], 'type' => 'article', 'live' => false, 'device' => ['ALL']]);
             if ($ad->validate()) {
                 $ad->save();
                 $rev = $comm['revenue'] ?? 1.25 * (double) $comm['rate'];
                 $commission = new \Commission(['ad_id' => $ad->_id, 'model' => $comm['model'], 'rate' => $comm['rate'], 'revenue' => round($rev, 6), 'coverage' => ['ALL']]);
                 $commission->save();
             } else {
                 var_dump($ad->getErrors());
             }
         }
         $msg = 'Campaigns imported for the user: ' . $user->email;
         $this->log($msg);
         $m->delete();
     }
 }