Пример #1
0
 public function register($data)
 {
     Source::where('email', $data['email'])->where('email_confirmed', false)->delete();
     $source = new Source(['email' => $data['email'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'password' => $data['password'], 'gender_id' => $data['gender_id']]);
     $source->save();
     $invoice = ['email' => $data['email'], 'first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'gender_id' => $data['gender_id'], 'country_id' => config('shop.default_country_id')];
     $shipping = $invoice;
     $invoice['address_kind_id'] = config('shop.invoice_address_kind_id');
     $shipping['address_kind_id'] = config('shop.shipping_address_kind_id');
     $invoice_address = new SourceAddress($invoice);
     $shipping_address = new SourceAddress($shipping);
     $source->source_addresses()->saveMany([$invoice_address, $shipping_address]);
     return $source;
 }
Пример #2
0
 public function getPostsFromSource($source)
 {
     $this->info("Getting posts from [ " . $source . " ]");
     // Check if it's a valid source
     if (!Source::has($source)) {
         throw new Exception("Given Shorthand is not for a valid source", 1);
     }
     // If exists, proceed
     $source = Source::where('shorthand', $source)->first();
     // get post links
     $postLinks = (new PostListGetter($source))->getList();
     // get details for each link
     foreach ($postLinks as $key => $link) {
         $this->info('Getting details for link: ' . $link);
         $details = (new PostDetailsGetter($source, $link))->getDetails();
         if ($details) {
             if (!$source->hasPublished($details['url'])) {
                 // save
                 // queue image for processing
                 // save the post
                 $post = Post::create($details);
                 // associate the post to a source
                 $post->source()->associate($source)->save();
                 // extract and process images (if any);
                 (new \App\ContentProcessors\ImageProcessors\MainProcessor($post))->process();
                 // process text
                 (new \App\ContentProcessors\TextProcessors\MainProcessor($post))->process();
             } else {
                 $this->info('This post is already in the database');
             }
         } else {
             $this->info('could not extract content from this url');
         }
         // if Post::has($details), skip
         // otherwise,
         //  1- Post::store($details) (without image)
         //  2- Cache Image and Store in Image model, with post ID;
     }
 }
Пример #3
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     return Source::where('status', '!=', 'deleted')->get();
 }
Пример #4
0
 static function has($shorthand)
 {
     return Source::where('shorthand', $shorthand)->count() > 0;
 }