Join MultiplyOpen a Free ShopSign InHelp
MultiplyLogo
SEARCH

Hendro Wicaksono Personal Website

Blog EntryFeb 21, '12 6:18 AM
for everyone
Oke saya punya kasus begini. Saya ingin ketika user login, ditampilkan daftar artikel yang hanya diinput oleh user tersebut. User tersebut tidak bisa mengedit dokumen yang bukan hak nya. Oke begini caranya. Note: ingat modul views dan cck diasumsikan sudah terinstall ya.

1. membatasi user hanya bisa mengedit node yang diinput olehnya. Berarti mainin permission di drupal.

2. Membuat daftar artikel (node) yang diinput oleh user yang bersangkutan. Jawabannya ada di http://stackoverflow.com/questions/2569867/drupal-views-display-recent-nodes-created-by-user-on-profile-page. Untuk mudahnya saya kutip disini:
 

ok, the answer involves creating a drupal view, so you will need the views module and although simple, the answer is lengthy. please bear with me through this... :) (i am actually doing this on a test site as i write the instructions, to make sure i dont miss anything...)

i assume that you know how to download and install the views module. make sure you also enable the views-ui module.

  1. go to site building->views->add.
  2. put "recent_posts_by_user" for view name, "recent posts by user" for description and "node" for view type. hit next.
  3. under the "default" view type, on the "fields" block, hit the "+" sign.
  4. under "groups" select node, then check the "node type", "node title" and "node updated date" fields. hit the "add" button below the list.
  5. under basic settings block (on the left), click on the "10" for "items for display" and change to "5" or however many items you want per page, and hit "update"
  6. under "use pager", click on "no" and "full pager" or "mini pager" and hit "update" again.
  7. under style, hit "unformatted" and change it to "table" set all fields to sortable, then choose the "updated date" as "default sort", then on "default sort order", select "descending". hit update.
  8. hit "save" to save your progress thus far.

default view is done. YAY! lets add the block

  1. now on the drop-down that says "page", select "block" and hit "add display".
  2. hit "arguments" (block title on the center of the screen)
  3. hit "override" and "update"
  4. hit the "+" sign to the right of "arguments"
  5. on the "groups" drop down, select "user" and select "user id". hit "add"
  6. under "Action to take if argument is not present", select the last option "provide default argument", select "user id from url" and check "Also look for a node and use the node author"
  7. under "validator", select "user" and "Allow both numeric UIDs and string usernames"
  8. under "Action to take if argument does not validate" select "hide view/page not found (404)"
  9. hit "update" then "save"

view is created now lets make sure it shows up on the right pages.

  1. go to site building->blocks, search for the "recent posts by user" block and hit "configure"
  2. scroll all the way to the bottom and select "Show on only the listed pages." and put in "users/*" under the "pages" text area
  3. hit "save block"
  4. now find the "recent posts by user" block again and set it to "content bottom" region (or any other region your theme has available).
  5. hit "save blocks"

DONE! Not rocket-science, but lengthy process... drupal 6 views is so much better than drupal 5! :)

now go visit a user page http://site/users/username and see the table show up there!

hit me up if you still have questions about views.

enjoy


3. Setelah dua langkah diatas, user tersebut masih bisa melihat node orang lain meski tidak bisa mengedit. Untuk itu perlu sedikit ditambahkan coding di views di bagian header kemudian pilih tipe PHP (modul PHP Filter harus diaktifkan) dan isikan dengan:

<?php
$clu = explode ("/", $_GET['q']);
global $user;
if ($user->uid) {
    // User is logged in.
    if ($user->name != $clu[2]) {
        die ('Maaf ga boleh ya');
        # atau alternatif lainnya refer ke halaman index
        #header("location: ".$_SERVER['PHP_SELF']."");

    }

}
?>

Selamat mencoba :)

1 Comment
mahasiswidudul wrote on Feb 21
Wah, kebetulan nin lagi mendalami drupal... Keren nih... Kalo versi 7 berlaku sama gak om? Oia, boleh minta link tag tutorial drupalnya di blog nya ini om? Makasi :)
Add a Comment