public function save() { $form = Form::load('logbook.views.AddBlogEntry'); if($form->validate()) { $auth = new Author(); $auth->clause('user_id',Application::current()->user()->id()); if($auth->id()) { $item = new Entry(); $item->parse(); $item->set('author_id',$auth->id()); if(!Application::param('entry_date')) $item->set('entry_date',date('Y-m-d H:i:s')); $item->synch(); Entry::setTagsAndSave($item,Application::param('entry_tags')); $group = new Group(); $group->noForeign(); $author_id = $item->get('author_id'); $entry_id = $item->get('entry_id'); if($groups = $group->fetch()) { foreach($groups as $group) { if(file_exists(Application::MANAGED_CODE.'lbk_default_access_'.$group->get('access_id'))) { $data = file_get_contents(Application::MANAGED_CODE.'lbk_default_access_'.$group->get('access_id')); $perms = unserialize($data); ManageGroupAccess::setPermissionsOnEntryForGroup($author_id,$entry_id,$group->id(),$perms); } } } Application::setUrlParam('author_id',Application::param('author_id')); Application::setUrlParam('entry_id',Application::param('entry_id')); LogbookAccess::publishLookupTables(); $this->redirectOnSave(); } else die('You are not an author!'); } }
protected function editAboutMe() { $form = Form::load('logbook.views.EditBlogAuthorDetails'); if($form->validate()) { $item = new Author(); $item->clause('user_id',Application::current()->user()->id()); $item->parse(); $item->synch(); Application::setParam('author_id',$item->id()); $this->redirectOnSave(); } }
/** * 创建指定数量的 Author 对象,并返回这些对象的 ID */ protected function _createAuthors($count) { $return = array(); for ($i = 0; $i < $count; $i++) { $author = new Author(array('name' => 'new author - ' . mt_rand())); $author->save(); $return[] = $author->id(); } return $return; }