Drupal: crowdsource features

This codelet demonstrate different features required by a crowdsourcing site

Requires two roles 'requester' and 'bidder'.
This already include two Content types 'Request' and 'Bidder content',

1. create flags 'place a bid' (bidder can flag and unflag content on requester 's conten after flagged on this content bidder can post comment on flagged content of requester's), 'award bid' ( this flag appears on every users comments, Requester choose award bider from comments),
once requester flagged on comment the owner of that comment can post a content on requester 's content (see point 2).
'job complete' this flag for complete content and publish bidder awarded bidder content
thats all for flags.

2. links add on requester content display "view submitted content" this is visible only for requester who can review content, "submit content" only for awarded bidder who can submit content;

3 . rules. create rules Action:'A node has been flagged, under "Job is comple"'.
Condition:--
Actions: Execute custom php code (return _custom_publish_node($flagged_node)) see this method on CodeLet.

The idea was proposed by Nurul Islam from London, UK

Module Info

name = Custom
description = Customization and Featurs
core = 7.x
package = Custom

CodeLet: 

//$Id$

/**
* Implementation of _get_redirect_user
* @param unknown $profile_type_label
* @return string with links of profile type
*/
function _get_redirect_user($profile_type_label) {

switch ($profile_type_label) {
case 'Requester':
$ss__label = t('A Requester');
$ss__link = 'requester';
break;
case 'Bidder':
$ss__label = t('A Bidder');
$ss__link = 'bidder';
break;
}
return '' . l($ss__label, 'user/register/'. $ss__link) . '';
}

/**
* Implementation of hook_form_alter
* @param unknown $form
* @param unknown $form_state
* @param unknown $form_id
*/
function custom_form_alter(&$form, $form_state, $form_id) {
global $user;

switch ($form_id) {

case 'comment_node_request_content_form':

if(isset($form['']) && $form['']->type == 'request_content') {
if($form['']->uid != $user->uid) {
$sn__nid = $form['']->nid;
$result = db_select('flag_content', 'fc')
->fields('fc', array('fcid'))
->condition('content_type', 'node')
->condition('content_id', $sn__nid)
->condition('uid', $user->uid)
->orderBy('timestamp', 'DESC')
->execute();
$record = $result->fetchAssoc();
if(empty($record['fcid'])) {
$form['comment_body'][''] = 0;
$form['actions']['submit'][''] = 0;
}
}
}

break;
case 'bidder_content_node_form':
// hide combo box
$form['field_requesting_content']['und'][''] = '';
$form['field_requesting_content']['und'][''] = '';

$sn__nid = arg(3);
if(arg(2) != 'edit') {
if(empty($form['field_requesting_content']['und'][''])) {
$form['field_requesting_content']['und'][''] = array($sn__nid);
}

$query = db_select('comment', 'c');
$query->join('flag_content', 'fc', 'fc.content_id = c.cid');
$query->fields('c', array('nid'))
->condition('fc.fid', 4, '=')//hard coded award bid flag id
->condition('c.nid', $sn__nid, '=')
->condition('c.uid', $user->uid, '=');

$result = $query->execute();

$records = $result->fetchAssoc();
if(empty($records['nid'])) {
drupal_access_denied();
}
// query for bidder can add content of request once
$query = db_select('node', 'n');
$query->join('field_data_field_requesting_content', 'fc', 'fc.field_requesting_content_nid = n.nid');
$query->fields('fc', array('entity_id'))
->condition('n.nid', $sn__nid, '=')
->condition('n.type', 'request_content', '=');

$result = $query->execute();
$records = $result->fetchAssoc();

if(!empty($records['entity_id'])) {
drupal_goto('node/' . $records['entity_id'] . '/edit');
}

}

$form['field_requesting_content']['und'][''] = TRUE;

break;
case 'views_exposed_form':

if(isset($form['flagged']) && !empty($form['flagged'])) {
$form['flagged'][''][1] = 'Success';
$form['flagged'][''][0] = 'Fail';
}

break;

default:
;
break;
}
}

/**
* Implementation of completed node type (_custom_check_completed_node)
* @param int $sn__nid
* @return boolean
*/
function _custom_check_completed_node($sn__nid) {
global $user;
$query = db_select('node', 'n');
$query->join('flag_content', 'fc', 'fc.content_id = n.nid');
$query->fields('n', array('nid'))
->condition('fc.fid', 5, '=')//hard coded award bid flag id
->condition('fc.content_type', 'node', '=')
->condition('n.nid', $sn__nid, '=');

$result = $query->execute();

$records = $result->fetchAssoc();
if(empty($records['nid'])) {
return FALSE;
}
return TRUE;
}
/**
* Implementation of awarde node type (_custom_check_awarded_node)
* @param int $sn__nid
* @param int $sn__cid
* @return boolean
*/
function _custom_check_awarded_node($sn__nid, $sn__cid = NULL) {
global $user;

$query = db_select('comment', 'c');
$query->join('flag_content', 'fc', 'fc.content_id = c.cid');
$query->fields('c', array('nid'))
->condition('fc.fid', 4, '=')//hard coded award bid flag id
->condition('fc.content_type', 'comment', '=')
->condition('c.nid', $sn__nid, '=') ;
//->condition('c.uid', $user->uid, '=');
($sn__cid != NULL) ? $query->condition('fc.content_id', $sn__cid, '=') : '';

$result = $query->execute();
$records = $result->fetchAssoc();
if(empty($records['nid'])) {
return FALSE;
}
return TRUE;
}
/**
* Implementation of hook_node_view_alter
* @param unknown $build
*/
function custom_node_view_alter(&$build) {
global $user;
if($build[''] == 'request_content') {
$sn__nid = $build['body']['']->nid;
$build['']->content['bidder_content_link'] = array(
'' => l(t('View Submitted Content'), 'bidder-content/' . $sn__nid),
'' => 10,
);
$build['']->content['submit_content_link'] = array(
'' => l(t(' Submit Content'), 'node/add/bidder-content/' . $sn__nid),
'' => 12,
);

if(_custom_check_awarded_node($sn__nid)) {
foreach ($build['comments']['comments'] as $key => $value) {
if(!_custom_check_awarded_node($sn__nid, $key)) {
if(isset($build['comments']['comments'][$key]['links']['flag']))
unset($build['comments']['comments'][$key]['links']['flag']);

}
}
}

}
if($build[''] == 'bidder_content') {
$build['']->field_requesting_content['und'][0]['access'] = 1;
}
}
/**
* Implementation of publish a node
* publish content
* @param Object $node
*/
function _custom_publish_node($node) {

$sn__nid = $node->nid;
$query = db_select('node', 'n');
$query->join('field_data_field_requesting_content', 'fc', 'fc.field_requesting_content_nid = n.nid');
$query->fields('fc', array('entity_id'))
->condition('n.nid', $sn__nid, '=')
->condition('n.type', 'request_content', '=');

$result = $query->execute();
$records = $result->fetchAssoc();
if(!empty($records['entity_id'])) {
//Update
$num_updated = db_update('node') // Table name no longer needs {}
->fields(array(
'status' => 1,
))
->condition('nid', $records['entity_id'], '=')
->execute();

$num_updated = db_update('node_revision') // Table name no longer needs {}
->fields(array(
'status' => 1,
))
->condition('nid', $records['entity_id'], '=')
->execute();
}
}

Bidder can place a bid on content
Requester choose bidder and complete content
requester view content and bidder post content

By saru1683 on Wed, 09/10/2013 - 12:19pm

Add comment

Log in or register to post comments
QR code for this page URL This page URL
Feedback