0

I have a website that has users with role "sellers". The website has a nodes/stores that belongs to the sellers.

So let's say I have 3 users and 10 nodes for their objects. The names will be fictive, just to explain better this specific task.

Users with role "sellers":

  1. John

  2. Mark

  3. Cindy

Nodes/stores

  1. John's store 1

  2. John's store 2

  3. John's store 3

  4. Mark's store 1

  5. Mark's store 2

  6. Mark's store 3

  7. Mark's store 4

  8. Cindy's store 1

  9. Cindy's store 2

  10. Cindy's store 3

Every seller will be able to login into the website and see his/her stores, but cannot create or edit a node/store. Only admin will do that. When creating these stores the admin will make author by the user name. For an example:

John's three stores nodes will have author as John, so the seller John when log into his user pages, will be able to see his stores. That's ok and already accomplished.

When John's wants to make some new offers will send a form that will be sent to the admin. The specific thing is, John will be able to select a drop down list with his stores (in this case 3) and select what stores will have this new offer, so on sending the email, the admin will know for which stores is the new offer.

How can I create this kind of drop down select list based on author id?

I have acknowledge with custom modules and lot's of hooks, so creating a custom form wont be difficult.

2

Code to fetch Stores of a user -- Replace node_type with your node type...

global $user;
$result = db_query('SELECT n.nid, n.title, n.created
FROM {node} n WHERE n.uid = :uid and type = :type', array(':uid' => $user->uid, ':type' => 'node_type'));
// Result is returned as a iterable object that returns a stdClass object on each iteration
foreach ($result as $record) {
  // Perform operations on $record->title, etc. here.
  // in this example the available data would be mapped to object properties:
  // $record->nid, $record->title, $record->created
}
  • Create a Custom Form -- Form API Reference
    • Create two fields
      1. Select Field - Options Source - Run a query against node table to get list of node id's given user id filtered by type and status of node
      2. Offer Request - Text Area
    • On Submit handler
    • Read Select Field Values , Offer Request Text
    • Send Email to admin using hook_mail
| improve this answer | |
  • Thank you for your answer. Some details are not clear to me. I've used the code, changed into the proper node_type and used print_r ($result) to see whats printing. I didnt find any result related with the node_type. – user2519032 Feb 18 '14 at 9:25
  • You need to make sure some nodes are assigned to logged in user in you content as Author... do print_r($record) inside for loop... – Anil Sagar Feb 18 '14 at 9:32
  • Later I've tried with adding the function ->fetchall(); and I can see the results as print_r, but if I put $result variable in '#options' => $result; the page has errors. EDIT, OK, I'll check that. – user2519032 Feb 18 '14 at 9:34
  • Excellent, I can see the results and they are displaying in drop down too. I've got still some errors, but I think I'm on a right way to complete this. Thank you again! – user2519032 Feb 18 '14 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.