예제 #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $doc_id = $this->argument('doc_id');
     $filename = $this->argument('filename');
     $doc = Doc::where('id', $doc_id)->first();
     $this->info("Exporting activity for " . $doc->title);
     $annotations = Annotation::where('doc_id', $this->argument('doc_id'))->with('user')->with('comments')->get();
     $comments = Comment::where('doc_id', $this->argument('doc_id'))->with('user')->get();
     $headers = array("Created At", "Link", "Display Name", "Full Name", "Email", "Type", "Quote", "Text");
     $toExport = array();
     foreach ($annotations as $annotation) {
         $annotationArray = array();
         $annotationArray['date'] = $annotation->created_at;
         $annotationArray['link'] = URL::to('/') . $annotation->uri . '#annotation_' . $annotation->id;
         $annotationArray['display_name'] = $annotation->user->fname . " " . substr($annotation->user->lname, 0, 1);
         $annotationArray['full_name'] = $annotation->user->fname . " " . $annotation->user->lname;
         $annotationArray['email'] = $annotation->user->email;
         $annotationArray['type'] = 'Annotation';
         $annotationArray['quote'] = $annotation->quote;
         $annotationArray['text'] = $annotation->text;
         array_push($toExport, $annotationArray);
         foreach ($annotation->comments as $comment) {
             $user = User::find($comment->user_id);
             $commentArray = array();
             $commentArray['date'] = $comment->created_at;
             $commentArray['link'] = "";
             $commentArray['display_name'] = $user->fname . " " . substr($user->lname, 0, 1);
             $commentArray['full_name'] = $user->fname . " " . $user->lname;
             $commentArray['email'] = $user->email;
             $commentArray['type'] = "Annotation Comment";
             $commentArray['quote'] = "";
             $commentArray['text'] = $comment->text;
             array_push($toExport, $commentArray);
         }
     }
     foreach ($comments as $comment) {
         $commentArray = array();
         $commentArray['date'] = $comment->created_at;
         $commentArray['link'] = "";
         $commentArray['display_name'] = $comment->user->fname . " " . substr($comment->user->lname, 0, 1);
         $commentArray['full_name'] = $comment->user->fname . " " . $comment->user->lname;
         $commentArray['email'] = $comment->user->email;
         $commentArray['type'] = $comment->parent_id === null ? "Comment" : "Sub-comment";
         $commentArray['quote'] = "";
         $commentArray['text'] = $comment->text;
         array_push($toExport, $commentArray);
     }
     $this->info('Saving export to ' . $filename);
     $fp = fopen($filename, 'w');
     fputcsv($fp, $headers);
     foreach ($toExport as $row) {
         fputcsv($fp, $row);
     }
     fclose($fp);
     $this->info('Done.');
 }
예제 #2
0
 /**
  * 	Post route for creating / updating documents.
  */
 public function postDocs()
 {
     $user = Auth::user();
     if (!$user->can('admin_manage_documents')) {
         return Response::json($this->growlMessage("You do not have permission", 'error'));
     }
     //Creating new document
     $title = Input::get('title');
     $slug = str_replace(array(' ', '.'), array('-', ''), strtolower($title));
     // If the slug is taken
     if (Doc::where('slug', $slug)->count()) {
         $counter = 0;
         $tooMany = 10;
         do {
             if ($counter > $tooMany) {
                 return Response::json($this->growlMessage('Can\'t create document with that name, please try another.', 'error'));
             }
             $counter++;
             $new_slug = $slug . '-' . str_random(8);
         } while (Doc::where('slug', $new_slug)->count());
         $slug = $new_slug;
     }
     $doc_details = Input::all();
     $rules = array('title' => 'required');
     $validation = Validator::make($doc_details, $rules);
     if ($validation->fails()) {
         return Response::json($this->growlMessage('A valid title is required.', 'error'));
     }
     try {
         $doc = new Doc();
         $doc->title = $title;
         $doc->slug = $slug;
         $doc->save();
         $doc->sponsor()->sync(array($user->id));
         $starter = new DocContent();
         $starter->doc_id = $doc->id;
         $starter->content = "New Doc Content";
         $starter->save();
         $doc->init_section = $starter->id;
         $doc->save();
         $response = $this->growlMessage('Document created successfully', 'success');
         $response['doc'] = $doc->toArray();
         return Response::json($response);
     } catch (Exception $e) {
         return Response::json($this->growlMessage($e->getMessage(), 'error'));
     }
 }
예제 #3
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $docId = $this->argument('docId');
     $docs = new Collection();
     if (!is_null($docId)) {
         $doc = Doc::where('id', '=', $docId)->first();
         if (!$doc) {
             return $this->error("Invalid Document ID");
         }
         $docs->add($doc);
     } else {
         $rawDocs = DB::select(DB::raw("SELECT *\n\t\t\t\t\t   FROM docs\n\t\t\t\t\t  WHERE id NOT IN (\n\t\t\t\t\t\tSELECT doc_id \n\t\t\t\t\t\t  FROM doc_group\n\t\t\t\t\t UNION ALL\n\t\t\t\t\t\tSELECT doc_id\n\t\t\t\t\t\t  FROM doc_user\n\t\t\t\t\t)"), array());
         $docs = new Collection();
         foreach ($rawDocs as $raw) {
             $obj = new Doc();
             foreach ($raw as $key => $val) {
                 $obj->{$key} = $val;
             }
             $docs->add($obj);
         }
     }
     $sponsors = Doc::getAllValidSponsors();
     foreach ($docs as $doc) {
         $this->info("Document Title: {$doc->title}\n");
         foreach ($sponsors as $key => $sponsor) {
             $opt = $key + 1;
             $this->info("{$opt}) {$sponsor['display_name']}");
         }
         $selected = (int) $this->ask("Please select a sponsor: ") - 1;
         if (!isset($sponsors[$selected])) {
             $this->error("Invalid Selection");
             continue;
         }
         switch ($sponsors[$selected]['sponsor_type']) {
             case 'individual':
                 $doc->userSponsor()->sync(array($sponsors[$selected]['id']));
                 $this->info("Assigned Document to Independent Sponsor");
                 break;
             case 'group':
                 $doc->groupSponsor()->sync(array($sponsors[$selected]['id']));
                 $this->info("Assigned Document to Group Sponsor");
                 break;
         }
     }
 }
예제 #4
0
 /**
  *	Method to handle document RSS feeds.
  *
  *	@param string $slug
  *
  * @return view $feed->render()
  */
 public function getFeed($slug)
 {
     $doc = Doc::where('slug', $slug)->with('comments', 'annotations', 'userSponsor', 'groupSponsor')->first();
     $feed = Feed::make();
     $feed->title = $doc->title;
     $feed->description = "Activity feed for '" . $doc->title . "'";
     $feed->link = URL::to('docs/' . $slug);
     $feed->pubdate = $doc->updated_at;
     $feed->lang = 'en';
     $activities = $doc->comments->merge($doc->annotations);
     $activities = $activities->sort(function ($a, $b) {
         return strtotime($a['updated_at']) > strtotime($b['updated_at']) ? -1 : 1;
     });
     foreach ($activities as $activity) {
         $item = $activity->getFeedItem();
         array_push($feed->items, $item);
     }
     return $feed->render('atom');
 }
예제 #5
0
 public function deleteImage($docId)
 {
     $doc = Doc::where('id', $docId)->first();
     $image_path = public_path() . $doc->thumbnail;
     try {
         File::delete($image_path);
         $doc->thumbnail = null;
         $doc->save();
     } catch (Exception $e) {
         Log::error("Error deleting document featured image for document id {$docId}");
         Log::error($e);
     }
     return Response::json($this->growlMessage('Image deleted successfully', 'success'));
 }