本文整理汇总了PHP中Note::tags方法的典型用法代码示例。如果您正苦于以下问题:PHP Note::tags方法的具体用法?PHP Note::tags怎么用?PHP Note::tags使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Note
的用法示例。
在下文中一共展示了Note::tags方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: registerUser
/**
* This function will create a new user object and return the newly created user object.
*
* @param array $userInfo This should have the properties: username, firstname, lastname, password, ui_language
*
* @return mixed
*/
public function registerUser(array $userInfo, $userLanguage)
{
$user = \User::create($userInfo);
//make the first user an admin
if (\User::all()->count() <= 1) {
$user->is_admin = 1;
}
// Trim trailing whitespace from user first and last name.
$user->firstname = trim($user->firstname);
$user->lastname = trim($user->lastname);
$user->save();
\Setting::create(['ui_language' => $userLanguage, 'user_id' => $user->id]);
/* Add welcome note to user - create notebook, tag and note */
//$notebookCreate = Notebook::create(array('title' => Lang::get('notebooks.welcome_notebook_title')));
$notebookCreate = new \Notebook();
$notebookCreate->title = Lang::get('notebooks.welcome_notebook_title');
$notebookCreate->save();
$notebookCreate->users()->attach($user->id, ['umask' => \PaperworkHelpers::UMASK_OWNER]);
//$tagCreate = Tag::create(array('title' => Lang::get('notebooks.welcome_note_tag'), 'visibility' => 0));
$tagCreate = new \Tag();
$tagCreate->title = Lang::get('notebooks.welcome_note_tag');
$tagCreate->visibility = 0;
$tagCreate->user_id = $user->id;
$tagCreate->save();
//$tagCreate->users()->attach($user->id);
$noteCreate = new \Note();
$versionCreate = new \Version(['title' => Lang::get('notebooks.welcome_note_title'), 'content' => Lang::get('notebooks.welcome_note_content'), 'content_preview' => mb_substr(strip_tags(Lang::get('notebooks.welcome_note_content')), 0, 255), 'user_id' => $user->id]);
$versionCreate->save();
$noteCreate->version()->associate($versionCreate);
$noteCreate->notebook_id = $notebookCreate->id;
$noteCreate->save();
$noteCreate->users()->attach($user->id, ['umask' => \PaperworkHelpers::UMASK_OWNER]);
$noteCreate->tags()->sync([$tagCreate->id]);
return $user;
}
示例2: processTag
/**
* Fetch tags from xml['tag']
*
* @param $xmlNote
* @param \Note $noteInstance
*/
protected function processTag($xmlNote, $noteInstance)
{
$tagsIds = [];
// Can be single element if 1 tag
if (!is_array($xmlNote['tag'])) {
$xmlNote['tag'] = [$xmlNote['tag']];
}
foreach ($xmlNote['tag'] as $tag) {
$tagCreate = $this->createTag($tag);
$tagsIds[] = $tagCreate->id;
}
$noteInstance->tags()->sync($tagsIds);
}
示例3: store
public function store($notebookId)
{
$newNote = Input::json();
$note = new Note();
$notebook = User::find(Auth::user()->id)->notebooks()->select('notebooks.id', 'notebooks.type', 'notebooks.title')->where('notebooks.id', '=', $notebookId)->wherePivot('umask', '>', PaperworkHelpers::UMASK_READONLY)->whereNull('notebooks.deleted_at')->first();
if (is_null($notebook)) {
return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_NOTFOUND, []);
}
$version = new Version(['title' => $newNote->get("title"), 'content' => $newNote->get("content"), 'content_preview' => $newNote->get("content_preview"), 'user_id' => Auth::user()->id]);
$version->save();
$note->version()->associate($version);
$note->notebook_id = $notebookId;
$version->save();
$note->save();
// TODO: Should we inherit the umask from the notebook?
$note->users()->attach(Auth::user()->id, array('umask' => PaperworkHelpers::UMASK_OWNER));
$tagIds = ApiTagsController::createOrGetTags($newNote->get('tags'), $note->id, PaperworkHelpers::UMASK_OWNER);
if (!is_null($tagIds)) {
$note->tags()->sync($tagIds);
}
return PaperworkHelpers::apiResponse(PaperworkHelpers::STATUS_SUCCESS, $note);
}
示例4: checkSandstormUsers
public function checkSandstormUsers()
{
if (Config::get('paperwork.emergency_export') && DB::table('migrations')->where('batch', '=', 1)->count() == Config::get('paperwork.emergency_export_count')) {
$credentials = ["username" => "sandstorm_dummy", "password" => "sandstorm_dummy"];
if (Auth::attempt($credentials)) {
$settings = Setting::where('user_id', '=', Auth::user()->id)->first();
Session::put('ui_language', $settings->ui_language);
return View::make('user.emergency_export');
}
} else {
// get permission via HTTP_X_SANDSTORM header
$sandstorm_permissions = $_SERVER['HTTP_X_SANDSTORM_PERMISSIONS'];
// Only when we are admin, we check and create users
if ($sandstorm_permissions == "admin,write,read") {
// check for admin user
if (User::where('username', '=', 'sandstorm_admin')->count() == 0) {
$sandstorm_admin = User::create(Input::except('_token', 'password_confirmation', 'ui_language'));
if ($sandstorm_admin) {
//make the first user an admin
$sandstorm_admin->firstname = "sandstorm_admin";
$sandstorm_admin->lastname = " ";
$sandstorm_admin->username = "sandstorm_admin";
$sandstorm_admin->password = "sandstorm_admin";
$sandstorm_admin->is_admin = 1;
$sandstorm_admin->save();
$setting_sandstorm_admin = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_admin->id]);
}
} else {
$sandstorm_admin = User::where('username', '=', 'sandstorm_admin');
}
// Then the read & write user
if (User::where('username', '=', 'sandstorm_readwrite')->count() == 0) {
$sandstorm_readwrite = User::create(Input::except('_token', 'password_confirmation', 'ui_language'));
if ($sandstorm_readwrite) {
$sandstorm_readwrite->firstname = "sandstorm_readwrite";
$sandstorm_readwrite->lastname = " ";
$sandstorm_readwrite->username = "sandstorm_readwrite";
$sandstorm_readwrite->password = "sandstorm_readwrite";
$sandstorm_readwrite->save();
$setting_sandstorm_readwrite = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_readwrite->id]);
}
} else {
$sandstorm_readwrite = User::where('username', '=', 'sandstorm_readwrite');
}
// Then the read only user
if (User::where('username', '=', 'sandstorm_readonly')->count() == 0) {
$sandstorm_readonly = User::create(Input::except('_token', 'password_confirmation', 'ui_language'));
if ($sandstorm_readonly) {
$sandstorm_readonly->firstname = "sandstorm_readonly";
$sandstorm_readonly->lastname = " ";
$sandstorm_readonly->username = "sandstorm_readonly";
$sandstorm_readonly->password = "sandstorm_readonly";
$sandstorm_readonly->save();
$setting_sandstorm_readonly = Setting::create(['ui_language' => 'en', 'user_id' => $sandstorm_readonly->id]);
}
} else {
$sandstorm_readonly = User::where('username', '=', 'sandstorm_readonly');
}
}
// Now that the required users are there we create the default
if (Notebook::all()->count() == 0 && Tag::all()->count() == 0 && Note::all()->count() == 0) {
// Notebook ...
$notebookCreate = new Notebook();
$notebookCreate->title = Lang::get('notebooks.welcome_notebook_title');
$notebookCreate->save();
$notebookCreate->users()->attach($sandstorm_readonly->id, ['umask' => PaperworkHelpers::UMASK_READONLY]);
$notebookCreate->users()->attach($sandstorm_readwrite->id, ['umask' => PaperworkHelpers::UMASK_READWRITE]);
$notebookCreate->users()->attach($sandstorm_admin->id, ['umask' => PaperworkHelpers::UMASK_OWNER]);
// Tag ...
$tagCreate = new Tag();
$tagCreate->title = Lang::get('notebooks.welcome_note_tag');
$tagCreate->visibility = 1;
$tagCreate->user_id = $sandstorm_admin->id;
$tagCreate->save();
// Note ...
$noteCreate = new Note();
$versionCreate = new Version(['title' => Lang::get('notebooks.welcome_note_title'), 'content' => Lang::get('notebooks.welcome_note_content'), 'content_preview' => mb_substr(strip_tags(Lang::get('notebooks.welcome_note_content')), 0, 255), 'user_id' => $sandstorm_admin->id]);
$versionCreate->save();
$noteCreate->version()->associate($versionCreate);
$noteCreate->notebook_id = $notebookCreate->id;
$noteCreate->save();
$noteCreate->users()->attach($sandstorm_readonly->id, ['umask' => PaperworkHelpers::UMASK_READONLY]);
$noteCreate->users()->attach($sandstorm_readwrite->id, ['umask' => PaperworkHelpers::UMASK_READWRITE]);
$noteCreate->users()->attach($sandstorm_admin->id, ['umask' => PaperworkHelpers::UMASK_OWNER]);
$noteCreate->tags()->sync([$tagCreate->id]);
}
// login
if ($sandstorm_permissions == "read") {
$credentials = ["username" => "sandstorm_readonly", "password" => "sandstorm_readonly"];
}
if ($sandstorm_permissions == "write,read") {
$credentials = ["username" => "sandstorm_readwrite", "password" => "sandstorm_readwrite"];
}
if ($sandstorm_permissions == "admin,write,read") {
$credentials = ["username" => "sandstorm_admin", "password" => "sandstorm_admin"];
}
if (Auth::attempt($credentials)) {
$settings = Setting::where('user_id', '=', Auth::user()->id)->first();
Session::put('ui_language', $settings->ui_language);
return Redirect::route("/");
//.........这里部分代码省略.........