예제 #1
0
 /**
  * 	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;
 }
예제 #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));
     $doc_details = Input::all();
     $rules = array('title' => 'required');
     $validation = Validator::make($doc_details, $rules);
     if ($validation->fails()) {
         die($validation);
         return Redirect::to('dashboard/docs')->withInput()->withErrors($validation);
     }
     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();
         return Response::json($this->growlMessage('Document created successfully', 'success'));
     } catch (Exception $e) {
         return Response::json($this->growlMessage($e->getMessage(), 'error'));
     }
 }
예제 #3
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'));
     }
 }
예제 #4
0
 public function saveDoc($doc_name, $doc_description, $doc_url, $doc_author, $subject_id, $doc_scribd_id, $doc_type, $doc_path, $doc_author_name)
 {
     $doc_data = Subject::model()->findByAttributes(array('subject_id' => $subject_id));
     $doc_model = new Doc();
     $doc_model->doc_name = $doc_name;
     $doc_model->doc_description = $doc_description;
     $doc_model->doc_url = $doc_url;
     $doc_model->subject_type = $doc_data->subject_type;
     $doc_model->doc_path = $doc_path;
     $doc_model->subject_faculty = $doc_data->subject_faculty;
     $doc_model->subject_dept = $doc_data->subject_dept;
     $doc_model->subject_general_faculty_id = $doc_data->subject_general_faculty_id;
     $doc_model->doc_scribd_id = $doc_scribd_id;
     $doc_model->doc_type = $doc_type;
     $doc_model->doc_status = 1;
     $doc_model->doc_author_name = $doc_author_name;
     $doc_model->doc_author = $doc_author;
     $doc_model->save(FALSE);
     $doc_subject = new SubjectDoc();
     $doc_subject->doc_id = $doc_model->doc_id;
     $doc_subject->doc_type = $doc_model->doc_type;
     $doc_subject->subject_id = $subject_id;
     $doc_subject->active = 1;
     $doc_subject->save(FALSE);
 }
예제 #5
0
파일: Doc.php 프로젝트: iaincollins/madison
 public static function createEmptyDocument(array $params)
 {
     $defaults = array('content' => "New Document Content", 'sponsor' => null, 'sponsorType' => null);
     $params = array_replace_recursive($defaults, $params);
     if (is_null($params['sponsor'])) {
         throw new \Exception("Sponsor Param Required");
     }
     $document = new Doc();
     DB::transaction(function () use($document, $params) {
         $document->title = $params['title'];
         $document->save();
         switch ($params['sponsorType']) {
             case static::SPONSOR_TYPE_INDIVIDUAL:
                 $document->userSponsor()->sync(array($params['sponsor']));
                 break;
             case static::SPONSOR_TYPE_GROUP:
                 $document->groupSponsor()->sync(array($params['sponsor']));
                 break;
             default:
                 throw new \Exception("Invalid Sponsor Type");
         }
         $template = new DocContent();
         $template->doc_id = $document->id;
         $template->content = "New Document Content";
         $template->save();
         $document->init_section = $template->id;
         $document->save();
     });
     Event::fire(MadisonEvent::NEW_DOCUMENT, $document);
     return $document;
 }