/** * Sets top-level bill information. */ public function createDoc() { $this->checkAttr('domdoc'); $this->setBillTitle(); $this->setBillSlug(); $bill = new Doc(); $bill->title = $this->title; $bill->slug = $this->slug; $bill->save(); try { $starter = new DocContent(); $starter->doc_id = $bill->id; $starter->content = $this->getBillMeta('legis-type') . ' ' . $this->getBillMeta('official-title'); $starter->save(); $bill->init_section = $starter->id; $bill->save(); $this->bill = $bill; $rootElement = $this->domdoc->getElementsByTagName($this->rootTag)->item(0); $c = 0; if (!is_object($rootElement)) { throw new Exception("Couldn't retrieve root element"); } foreach ($rootElement->childNodes as $child) { $this->saveChildren($child, $starter->id, $c++); } } catch (Exception $e) { $bill->delete(); $starter->delete(); throw new Exception($e->getMessage()); } return true; }
public function run() { $adminEmail = Config::get('madison.seeder.admin_email'); $adminPassword = Config::get('madison.seeder.admin_password'); // Login as admin to create docs $credentials = array('email' => $adminEmail, 'password' => $adminPassword); Auth::attempt($credentials); $admin = Auth::user(); $group = Group::where('id', '=', 1)->first(); // Create first doc $docSeedPath = app_path() . '/database/seeds/example.md'; if (file_exists($docSeedPath)) { $content = file_get_contents($docSeedPath); } else { $content = "New Document Content"; } $docOptions = array('title' => 'Example Document', 'content' => $content, 'sponsor' => $group->id, 'publish_state' => 'published', 'sponsorType' => Doc::SPONSOR_TYPE_GROUP); $document = Doc::createEmptyDocument($docOptions); //Set first doc as featured doc $featuredSetting = new Setting(); $featuredSetting->meta_key = 'featured-doc'; $featuredSetting->meta_value = $document->id; $featuredSetting->save(); // Create second doc $docSeedPath = app_path() . '/database/seeds/example2.md'; if (file_exists($docSeedPath)) { $content = file_get_contents($docSeedPath); } else { $content = "New Document Content"; } $docOptions = array('title' => 'Second Example Document', 'sponsor' => $group->id, 'publish_state' => 'published', 'sponsorType' => Doc::SPONSOR_TYPE_GROUP); $document = Doc::createEmptyDocument($docOptions); }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if (!Auth::check()) { return response('Unauthorized.', 403); } $user = Auth::user(); $doc = Doc::withTrashed()->find($request->doc); if (!$doc->canUserEdit($user)) { return response('Unauthorized.', 403); } return $next($request); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Doc::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'person_id' => $this->person_id, 'type_id' => $this->type_id, 'date' => $this->date, 'date_end' => $this->date_end, 'date_renewal' => $this->date_renewal, 'duration_months' => $this->duration_months, 'duration_days' => $this->duration_days, 'address_id' => $this->address_id, 'rec_status_id' => $this->rec_status_id, 'user_id' => $this->user_id, 'dc' => $this->dc]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'series', $this->series])->andFilterWhere(['like', 'num', $this->num])->andFilterWhere(['like', 'who_give', $this->who_give])->andFilterWhere(['like', 'note', $this->note]); return $dataProvider; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($request->doc) { $doc = Doc::find($request->doc); } else { $doc = Doc::findDocBySlug($request->slug); } $user = Auth::user(); if (!$doc->canUserView($user)) { if ($request->ajax()) { return response('Unauthorized.', 403); } else { return redirect()->guest('auth/login'); } } return $next($request); }
/** * 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'); }
/** * Get the validation rules that apply to the request. * * @return array */ public function rules() { return ['publish_state' => 'in:' . implode(',', Doc::validPublishStates()), 'discussion_state' => 'in:' . implode(',', Doc::validDiscussionStates())]; }
public function getAllSponsors() { $results = Doc::getAllValidSponsors(); return Response::json($results); }
public function getActions($docId) { $doc = Doc::where('id', $docId)->first(); if ($doc) { $skip_ids = $doc->sponsorIds; $actions = DocAction::where('doc_id', $docId)->whereNotIn('user_id', $skip_ids)->with('user')->orderBy('created_at')->get(); if ($actions) { if (Input::get('download') === 'csv') { $csv = Writer::createFromFileObject(new \SplTempFileObject()); $fields = array('first_name', 'last_name', 'email', 'quote', 'text', 'type', 'created_at'); // Headings. $csv->insertOne($fields); foreach ($actions as $action) { $actionRow = $action->toArray(); $actionRow['first_name'] = $actionRow['user']['fname']; $actionRow['last_name'] = $actionRow['user']['lname']; $actionRow['email'] = $actionRow['user']['email']; // Rearrange our columns $saveRow = array(); foreach ($fields as $field) { $saveRow[$field] = $actionRow[$field]; } $csv->insertOne($saveRow); } $csv->output('actions.csv'); return; } else { return Response::json($actions->toArray()); } } } return Response::notFound(); }
/** * @return \yii\db\ActiveQuery */ public function getDocs() { return $this->hasMany(Doc::className(), ['address_id' => 'id']); }
public static function getActive($num, $offset) { // Defaults to limit 10 because of the expense here. if (!$num) { $num = 10; } if (!$offset) { $offset = 0; } $docIds = \DB::select(\DB::raw("SELECT doc_id, SUM(num) AS total FROM (\n SELECT doc_id, COUNT(*) AS num\n FROM annotations\n GROUP BY doc_id\n UNION ALL\n SELECT doc_id, COUNT(*) AS num\n FROM comments\n GROUP BY doc_id\n UNION ALL\n SELECT annotations.doc_id, COUNT(*) AS num\n FROM annotation_comments\n INNER JOIN annotations\n ON annotation_comments.annotation_id = annotations.id\n GROUP BY doc_id\n\n ) total_count\n LEFT JOIN docs on doc_id = docs.id\n WHERE publish_state = 'published'\n AND docs.is_template != 1\n GROUP BY doc_id\n ORDER BY total DESC\n LIMIT :offset, :limit"), array(':offset' => $offset, ':limit' => $num)); $docArray = []; //Create array of [id => total] for each document foreach ($docIds as $docId) { $docArray[$docId->doc_id] = $docId->total; } $docs = false; if (count($docArray) > 0) { //Grab out most active documents $docs = Doc::getEager()->whereIn('id', array_keys($docArray))->get(); //Set the sort value to the total count foreach ($docs as $doc) { $doc->participationTotal = $docArray[$doc->id]; } //Sort by the sort value descending $docs = $docs->sortByDesc('participationTotal'); } return $docs; }
/** * @param null $type_id * @return \yii\db\ActiveQuery */ public function getDocs($type_id = null) { if ($type_id !== null) { return $this->hasMany(Doc::className(), ['person_id' => 'id'])->where('type_id=' . $type_id); } return $this->hasMany(Doc::className(), ['person_id' => 'id']); }
public function getAllStatuses() { $doc = Doc::with('statuses')->first(); $statuses = $doc->statuses; return Response::json($statuses); }
public function getFeatured() { $featuredSetting = Setting::where('meta_key', '=', 'featured-doc')->first(); if ($featuredSetting) { // Make sure our featured document can be viewed by the public. $featuredIds = explode(',', $featuredSetting->meta_value); $docs = Doc::with('categories')->with('userSponsors')->with('groupSponsors')->with('statuses')->with('dates')->whereIn('id', $featuredIds)->where('publish_state', '=', Doc::PUBLISH_STATE_PUBLISHED)->where('is_template', '!=', '1')->get(); if ($docs) { // Reorder based on our previous list. $tempDocs = array(); $orderList = array_flip($featuredIds); foreach ($docs as $key => $doc) { $tempDocs[(int) $orderList[$doc->id]] = $doc; } // If you set the key of an array value as we do above, // PHP will internally store the object as an associative // array (hash), not as a list, and will return the elements // in the order assigned, not by the key order. // This means our attempt to re-order the object will fail. // The line below will restore the order. Ugh. ksort($tempDocs); $docs = $tempDocs; } } // If we don't have a document, just find anything recent. if (empty($docs)) { $docs = array(Doc::with('categories')->with('userSponsors')->with('groupSponsors')->with('statuses')->with('dates')->where('publish_state', '=', Doc::PUBLISH_STATE_PUBLISHED)->where('is_template', '!=', '1')->orderBy('created_at', 'desc')->first()); } // If we still don't have a document, give up. if (empty($docs)) { return Response::make(null, 404); } $return_docs = array(); foreach ($docs as $key => $doc) { $doc->enableCounts(); $doc->enableSponsors(); $return_doc = $doc->toArray(); $return_doc['introtext'] = $doc->introtext()->first()['meta_value']; $return_doc['updated_at'] = date('c', strtotime($return_doc['updated_at'])); $return_doc['created_at'] = date('c', strtotime($return_doc['created_at'])); if (!$return_doc['thumbnail']) { $return_doc['thumbnail'] = '/img/default/default.jpg'; } $return_docs[] = $return_doc; } return Response::json($return_docs); }
Route::put('api/groups/verify/{groupId}', 'GroupsApiController@putVerify'); // User Login / Signup AJAX requests Route::get('api/user/login', 'UserManageApiController@getLogin'); Route::post('api/user/login', 'UserManageApiController@postLogin'); Route::get('api/user/signup', 'UserManageApiController@getSignup'); Route::post('api/user/signup', 'UserManageApiController@postSignup'); //Auth Token Route Route::get('/auth/token', 'AuthController@token'); Route::get('/api/user/login', 'AuthController@login'); Route::get('/api/user/logout', 'AuthController@logout'); /** * RSS Feed Route. */ Route::get('docs/feed', function () { //Grab all documents $docs = Doc::with('sponsor', 'content')->orderBy('updated_at', 'DESC')->take(20)->get(); $feed = Feed::make(); $feed->title = 'Madison Documents'; $feed->description = 'Latest 20 documents in Madison'; $feed->link = URL::to('rss'); $feed->pubdate = $docs->first()->updated_at; $feed->lang = 'en'; foreach ($docs as $doc) { $sponsor = $doc->sponsor->first(); if ($sponsor instanceof User) { $display_name = $sponsor->fname . ' ' . $sponsor->lname; } elseif ($sponsor instanceof Group) { $display_name = $sponsor->display_name; } else { $display_name = ''; }
/** * Finds the Doc model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Doc the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Doc::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }