本文整理汇总了PHP中UserRole::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP UserRole::factory方法的具体用法?PHP UserRole::factory怎么用?PHP UserRole::factory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserRole
的用法示例。
在下文中一共展示了UserRole::factory方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
public function edit($cid, $title)
{
$cid = (int) $cid;
$content = Content::factory($cid);
if (!$this->user->can_edit_content($content)) {
$this->templatemanager->notify_next("You don't have enough permissions to edit this content!", 'failure');
redirect('administration/dashboard');
}
$page = $content->page->limit(1)->get();
$roles = UserRole::factory()->get();
$ctypes = ContentType::factory()->get();
if (!$page->exists()) {
show_error("No page exists!");
}
/*if (!$content->exists())
{
$html = $page->body()->find('div[id='.trim($title).']', 0)->innertext;
//var_dump($html); die;
$content->div = $title;
$content->contents = $html;
$content->editor_id = $this->user->id;
$content->save(array($page));
}//*/
$divs = $page->get_div_ids();
//$this->templatemanager->assign("css_file", $css_file);
$this->templatemanager->assign("content", $content);
$this->templatemanager->assign("divs", $divs);
$this->templatemanager->assign("page", $page);
$this->templatemanager->assign("roles", $roles);
$this->templatemanager->assign("types", $ctypes);
$suffix = strtolower($content->contenttype->get()->classname);
$this->templatemanager->set_title("Edit Content");
$this->templatemanager->show_template("contents_edit_" . $suffix);
}
示例2: permissions_for
public function permissions_for($id)
{
//require login
if (!$this->loginmanager->is_logged_in()) {
redirect($this->loginmanager->login_url);
}
$role = UserRole::factory((int) $id);
$arr = array();
$perms = $role->permission->get();
foreach ($perms as $p) {
$arr[] = $p->key;
}
echo json_encode($arr);
}
示例3: remove
public function remove($id)
{
$id = (int) $id;
$role = UserRole::factory($id);
if ($role->name == 'Administrator') {
$this->templatemanager->notify_next(__("You can't remove \"Administrator\" role."), "failure");
redirect('administration/userroles');
} else {
if ($this->user->is_related_to($role)) {
$this->templatemanager->notify_next(__("You can't remove the role you're in."), "failure");
redirect('administration/userroles');
} else {
$role->delete();
$this->templatemanager->notify_next(__("User role is removed successfully."), "success");
redirect('administration/userroles');
}
}
}
示例4: add
public function add($based_on_page_id = null)
{
if (!empty($based_on_page_id)) {
$oldpage = Page::factory()->get_by_id($based_on_page_id);
} else {
$oldpage = null;
}
if (!$this->user->can('add_pages')) {
$this->templatemanager->notify_next("You don't have enough permissions to add new page!", 'failure');
redirect('administration/dashboard');
}
//$divs = $page->get_div_ids();
//$contents = $page->content->get();
$users = User::factory()->get();
$roles = UserRole::factory()->get();
$this->templatemanager->assign("oldPage", $oldpage);
$this->templatemanager->assign("users", $users);
$this->templatemanager->assign("roles", $roles);
$this->templatemanager->assign("files", File::get_templates());
//$this->templatemanager->assign("divs", $divs);
$this->templatemanager->set_title("Add New Page");
$this->templatemanager->show_template("pages_edit");
}
示例5: save
public function save($id = null)
{
$this->load->helper('email');
if (!empty($id)) {
$id = (int) $id;
}
if (!$this->user->can('manage_users') && $id !== $this->user->id) {
$this->templatemanager->notify_next("You are not allowed to edit users!", 'failure');
redirect('administration/dashboard');
}
//get user from db (or instantiate new user obj)
if (empty($id)) {
$user = new User();
} else {
$user = User::factory()->get_by_id($id);
}
$user->name = $this->input->post('name');
if ($this->user->can('manage_users')) {
$user->active = (bool) $this->input->post('active');
}
//check name
if (empty($user->name) || strlen($user->name) < 5) {
$this->templatemanager->notify_next(__("Name can not be empty or shorter than 5 characters."), 'failure');
redirect('administration/users/' . (empty($id) ? 'add' : 'edit/' . $id));
}
$role_id = $this->input->post('userrole_id');
//get role
if ($this->user->can('manage_users') && !empty($role_id)) {
$role = UserRole::factory((int) $role_id);
} else {
$role = $this->user->userrole->get();
}
//other data
$email = trim($this->input->post('email'));
//check e-mail
if (!valid_email($email)) {
$this->templatemanager->notify_next(__("Entered e-mail address was not valid."), 'failure');
redirect('administration/users/' . (empty($id) ? 'add' : 'edit/' . $id));
} else {
$user->email = $email;
}
//get, check and update password
$password = trim($this->input->post('password'));
$password2 = trim($this->input->post('password2'));
if (empty($id) && empty($password) && empty($password2)) {
$this->templatemanager->notify_next(__("When creating new user you must specify his password!"), 'failure');
redirect('administration/users/' . (empty($id) ? 'add' : 'edit/' . $id));
}
if (!empty($password)) {
if ($password != $password2) {
$this->templatemanager->notify_next(__("Passwords differ!"), 'failure');
redirect('administration/users/' . (empty($id) ? 'add' : 'edit/' . $id));
} else {
//if ($user->id != 1)
$user->password = $password;
//else
// $this->templatemanager->notify_next("Changing administrator password is disabled in the demo!", 'information');
}
}
//prepare for upload
$config['upload_path'] = './iu-resources/uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg';
$config['max_size'] = '512';
$config['max_width'] = '1024';
$config['max_height'] = '1024';
$config['encrypt_name'] = true;
$this->load->library('upload', $config);
//upload profile picture
if (!empty($_FILES['picture']['name'])) {
if (!$this->upload->do_upload('picture')) {
show_error($this->upload->display_errors());
} else {
$data = $this->upload->data();
$im = image_create_from_file($config['upload_path'] . $data['file_name']);
$im = image_resize($im, 150);
image_to_file($im, $config['upload_path'] . $data['file_name']);
$user->picture = $data['file_name'];
}
}
//save user
$user->save(array($role));
//save user and role
//permissions
$perms_arr = $this->input->post('permissions');
$perms = Permission::factory()->where_in('id', $perms_arr)->get();
$user->delete(Permission::factory()->get()->all);
$user->save($perms->all);
//notify user
if ($this->user->id != $id) {
$this->templatemanager->notify_next(__("User is saved successfully."), "success");
} else {
$this->templatemanager->notify_next(__("Profile is updated successfully."), "success");
}
if ($this->loginmanager->is_editor()) {
redirect('administration/users');
}
//go back to previous page
if (empty($_SERVER['HTTP_REFERER'])) {
redirect('administration/users');
} else {
//.........这里部分代码省略.........
示例6: is_editor
public function is_editor()
{
return $this->is_administrator() || $this->has_level(UserRole::factory()->get_by_name('editor')->access_level);
}
示例7: saveadmin
public function saveadmin()
{
//we cannot save admin if database config file is empty
if (!is_db_conf_empty()) {
//if config file exists, load libraries
$this->load->database();
$this->load->library('datamapper');
DataMapper::$config['prefix'] = $this->db->dbprefix;
} else {
redirect("setup/help/database-config-missing");
}
//now create the mofo admin
$role = UserRole::factory()->where('name', 'Administrator')->limit(1)->get();
$user = new User();
$perms = Permission::factory()->get();
$name = $this->input->post('name');
$email = $this->input->post('email');
if (empty($name)) {
$this->saveadmin_error("You need to specify administrator's name.");
} else {
if (empty($email)) {
$this->saveadmin_error("You need to specify administrator's e-mail address.");
} else {
$user->name = $name;
$user->email = $email;
$user->active = 1;
$password = trim($this->input->post('password'));
$password2 = trim($this->input->post('password2'));
if (empty($password)) {
$this->saveadmin_error("You must enter administrator's password.");
} else {
if ($password != $password2) {
$this->saveadmin_error("Entered passwords differ.");
} else {
$user->password = $password;
$user->save(array($role, $perms->all));
redirect("setup/finish");
}
}
}
}
}