Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Expansion | Organization member priority #65

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ npm-debug.log
/media/users/admin/private_message
/media/import
/media/blogs/forums
.DS_Store
2 changes: 2 additions & 0 deletions inc/_core/model/__core.install.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
org_url VARCHAR(2000) NULL,
org_accept ENUM( 'yes', 'owner', 'no' ) COLLATE ascii_general_ci NOT NULL DEFAULT 'owner',
org_perm_role ENUM( 'owner and member', 'owner' ) COLLATE ascii_general_ci NOT NULL DEFAULT 'owner and member',
org_perm_priority ENUM( 'owner and member', 'owner' ) COLLATE ascii_general_ci NOT NULL DEFAULT 'owner and member',
PRIMARY KEY ( org_ID ),
UNIQUE org_name ( org_name )
) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ),
Expand All @@ -193,6 +194,7 @@
uorg_org_ID INT(11) UNSIGNED NOT NULL,
uorg_accepted TINYINT(1) DEFAULT 0,
uorg_role VARCHAR(255) NULL,
uorg_priority INT(11) NULL,
PRIMARY KEY ( uorg_user_ID, uorg_org_ID )
) ENGINE = innodb DEFAULT CHARSET = $db_storage_charset" ),

Expand Down
13 changes: 13 additions & 0 deletions inc/users/model/_organization.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class Organization extends DataObject
*/
var $perm_role = 'owner and member';

/**
* Edit Priority
* @var string: 'owner and member', 'owner'
*/
var $perm_priority = 'owner and member';

/**
* Constructor
*
Expand All @@ -68,6 +74,7 @@ function __construct( $db_row = NULL )
$this->url = $db_row->org_url;
$this->accept = $db_row->org_accept;
$this->perm_role = $db_row->org_perm_role;
$this->perm_priority = $db_row->org_perm_priority;
}
else
{ // Set default organization data for new object:
Expand Down Expand Up @@ -145,6 +152,9 @@ function load_from_Request()
// Edit Role Permission:
param( 'org_perm_role', 'string' );
$this->set_from_Request( 'perm_role' );

param( 'org_perm_priority', 'string' );
$this->set_from_Request( 'perm_priority' );

return ! param_errors_detected();
}
Expand Down Expand Up @@ -195,6 +205,9 @@ function get_users( $order_by = 'user_id', $accepted_only = false )
case 'org_role':
$users_SQL->ORDER_BY( 'uorg_role ASC, user_ID ASC' );
break;
case 'org_priority':
$users_SQL->ORDER_BY( 'uorg_priority ASC, user_ID ASC' );
break;
case 'username':
$users_SQL->ORDER_BY( 'user_login ASC, user_ID ASC' );
break;
Expand Down
16 changes: 13 additions & 3 deletions inc/users/model/_user.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,8 @@ function load_from_Request()
$organizations = param( 'organizations', 'array:string' );
$org_roles = param( 'org_roles', 'array:string' );
$this->update_organizations( $organizations, $org_roles );
$org_priorities = param( 'org_priorities', 'array:string' );
$this->update_organizations( $organizations, $org_priorities );
// ---- Organizations / END ----


Expand Down Expand Up @@ -6750,7 +6752,7 @@ function get_organizations_data()
{ // Get the organizations from DB
global $DB;
$SQL = new SQL();
$SQL->SELECT( 'org_ID, org_name, uorg_accepted, uorg_role' );
$SQL->SELECT( 'org_ID, org_name, uorg_accepted, uorg_role, uorg_priority' );
$SQL->FROM( 'T_users__user_org' );
$SQL->FROM_add( 'INNER JOIN T_users__organization ON org_ID = uorg_org_ID' );
$SQL->WHERE( 'uorg_user_ID = '.$DB->quote( $this->ID ) );
Expand All @@ -6763,6 +6765,7 @@ function get_organizations_data()
'name' => $organization->org_name,
'accepted' => $organization->uorg_accepted,
'role' => $organization->uorg_role,
'priority' => $organization->uorg_priority,
);
}
}
Expand Down Expand Up @@ -6851,10 +6854,17 @@ function update_organizations( $organization_IDs, $organization_roles = array(),

if( count( $insert_orgs ) > 0 )
{ // Insert new records with user-org relations
$insert_org_SQL = 'REPLACE INTO T_users__user_org ( uorg_user_ID, uorg_org_ID, uorg_accepted, uorg_role ) VALUES ';
$insert_org_SQL = 'REPLACE INTO T_users__user_org ( uorg_user_ID, uorg_org_ID, uorg_accepted, uorg_role, uorg_priority ) VALUES ';
$o = 0;
foreach( $insert_orgs as $insert_org_ID => $insert_org_role )
{
$insert_orgs_priority = '0';

if( isset( $curr_orgs[ $insert_org_ID ] ) && isset( $curr_orgs[ $insert_org_ID ]['priority'] ) )
{ // If we are updating - Don't change the accept status
$insert_orgs_priority = $curr_orgs[ $insert_org_ID ]['priority'];
}

if( isset( $curr_orgs[ $insert_org_ID ] ) )
{ // If we are updating - Don't change the accept status
$insert_orgs_accepted = $curr_orgs[ $insert_org_ID ]['accepted'];
Expand All @@ -6879,7 +6889,7 @@ function update_organizations( $organization_IDs, $organization_roles = array(),
{ // separator
$insert_org_SQL .= ', ';
}
$insert_org_SQL .= '( '.$this->ID.', '.$DB->quote( $insert_org_ID ).', '.$insert_orgs_accepted.', '.$DB->quote( $insert_org_role ).' )';
$insert_org_SQL .= '( '.$this->ID.', '.$DB->quote( $insert_org_ID ).', '.$insert_orgs_accepted.', '.$DB->quote( $insert_org_role ).', '.$DB->quote( $insert_org_priority ).' )';
$o++;
}
$DB->query( $insert_org_SQL );
Expand Down
15 changes: 14 additions & 1 deletion inc/users/model/_user.funcs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5219,6 +5219,7 @@ function users_results_block( $params = array() )
'display_nickname' => true,
'display_name' => true,
'display_role' => false,
'display_priority' => false,
'display_gender' => true,
'display_country' => true,
'display_region' => false,
Expand Down Expand Up @@ -5426,6 +5427,7 @@ function users_results( & $UserList, $params = array() )
'display_name' => true,
'order_name' => 'user_lastname, user_firstname',
'display_role' => false,
'display_priority' => false,
'display_gender' => true,
'display_country' => true,
'display_country_type' => 'both', // 'both', 'flag', 'name'
Expand Down Expand Up @@ -5597,6 +5599,17 @@ function users_results( & $UserList, $params = array() )
);
}

if( $params['display_priority'] )
{ // Display organizational role
$UserList->cols[] = array(
'th' => T_('Priority'),
'th_class' => 'small',
'td_class' => 'small',
'order' => 'uorg_priority',
'td' => '<a href="#" style="font-weight: 700;" onclick="return user_edit( '.intval( $params['org_ID'] ).', $user_ID$ )">$uorg_priority$</a>',
);
}

if( $params['display_gender'] )
{ // Display gender
$UserList->cols[] = array(
Expand Down Expand Up @@ -6420,4 +6433,4 @@ function get_PasswordDriver( $driver_code = '' )
return $PasswordDriver;
}

?>
?>
2 changes: 1 addition & 1 deletion inc/users/model/_userquery.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ function where_organization( $org_ID )
}

// Join Organization table
$this->SELECT_add( ', uorg_org_ID, uorg_accepted, uorg_role' );
$this->SELECT_add( ', uorg_org_ID, uorg_accepted, uorg_role, uorg_priority' );
$this->FROM_add( 'INNER JOIN T_users__user_org ON uorg_user_ID = user_ID AND uorg_org_ID = '.$DB->quote( $org_ID ) );
}

Expand Down
5 changes: 3 additions & 2 deletions inc/users/organizations.ctrl.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,12 +229,13 @@

$accepted = param( 'accepted', 'string', '1' );
$role = param( 'role', 'string', '' );
$priority = param( 'priority', 'integer', NULL );
$edit_mode = param( 'edit_mode', 'boolean' );

if( ! param_errors_detected() )
{ // Link user only when request has no errors:
$result = $DB->query( 'REPLACE INTO T_users__user_org ( uorg_user_ID, uorg_org_ID, uorg_accepted, uorg_role )
VALUES ( '.$login_User->ID.', '.$edited_Organization->ID.', '.$accepted.', '.$DB->quote( $role ).' ) ' );
$result = $DB->query( 'REPLACE INTO T_users__user_org ( uorg_user_ID, uorg_org_ID, uorg_accepted, uorg_role, uorg_priority )
VALUES ( '.$login_User->ID.', '.$edited_Organization->ID.', '.$accepted.', '.$DB->quote( $role ).', '.$DB->quote( $priority ).' ) ' );
if( $result )
{ // Display a message after successful linking:
if( $edit_mode )
Expand Down
9 changes: 8 additions & 1 deletion inc/users/views/_organization.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@
array( 'owner', T_('can be edited by organization owner only') )
), T_('Role in organization'), true );

$Form->radio( 'org_perm_priority', $edited_Organization->get( 'perm_priority' ),
array(
array( 'owner and member', T_('can be edited by user and organization owner') ),
array( 'owner', T_('can be edited by organization owner only') )
), T_('Priority in organization'), true );


$buttons = array();
if( $current_User->check_perm( 'orgs', 'edit', false, $edited_Organization ) )
Expand Down Expand Up @@ -95,6 +101,7 @@
'page_url' => get_dispctrl_url( 'organizations', 'action=edit&amp;org_ID='.$edited_Organization->ID ),
'display_orgstatus' => true,
'display_role' => true,
'display_role' => true,
'display_ID' => false,
'display_btn_adduser' => false,
'display_btn_addgroup' => false,
Expand All @@ -118,4 +125,4 @@

// AJAX changing of an accept status of organizations for each user
echo_user_organization_js();
?>
?>
2 changes: 1 addition & 1 deletion inc/users/views/_organization.view.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// Create result set:
$SQL = new SQL();
$SQL->SELECT( 'SQL_NO_CACHE org_ID, org_owner_user_ID, org_name, org_url, org_accept, org_perm_role, user_login, COUNT( uorg_user_ID ) AS members_count' );
$SQL->SELECT( 'SQL_NO_CACHE org_ID, org_owner_user_ID, org_name, org_url, org_accept, org_perm_role, org_perm_priority, user_login, COUNT( uorg_user_ID ) AS members_count' );
$SQL->FROM( 'T_users__organization' );
$SQL->FROM_add( 'INNER JOIN T_users ON org_owner_user_ID = user_ID' );
$SQL->FROM_add( 'LEFT JOIN T_users__user_org ON uorg_org_ID = org_ID' );
Expand Down
2 changes: 2 additions & 0 deletions inc/users/views/_organization_user.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@

$Form->text_input( 'role', '', 32, T_('Role'), '', array( 'maxlength' => 255 ) );

$Form->text_input( 'priority', '', 32, T_('Priority'), '', array( 'maxlength' => 255, 'type' => 'number' ) );

$buttons = array();
if( $current_User->check_perm( 'orgs', 'edit', false, $edited_Organization ) )
{ // Display a button to update the poll question only if current user has a permission:
Expand Down
9 changes: 9 additions & 0 deletions inc/users/views/_organization_user_edit.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@
$Form->info_field( T_('Role'), $org_data[$org_ID]['role'] );
}

if( ( $edited_Organization->owner_user_ID == $current_User->ID ) || ( $edited_Organization->perm_priority == 'owner and member' && $org_data[$org_ID]['accepted'] ) )
{ // Display edit field if current user has a permission to edit role:
$Form->text_input( 'priority', $org_data[$org_ID]['priority'], 32, T_('Priority'), '', array( 'maxlength' => 255, 'type' => 'number' ) );
}
else
{ // Otherwise display info field with role value:
$Form->info_field( T_('Priority'), $org_data[$org_ID]['priority'] );
}

$buttons = array();
if( $current_User->check_perm( 'orgs', 'edit', false, $edited_Organization ) )
{ // Display a button to update the poll question only if current user has a permission:
Expand Down
11 changes: 11 additions & 0 deletions inc/users/views/_user_identity.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -415,9 +415,11 @@
else
{ // Allow to update the organization fields
$perm_edit_org_role = false;
$perm_edit_org_priority = false;
if( ! empty( $org_ID ) )
{
$perm_edit_org_role = ( $user_Organization->owner_user_ID == $current_User->ID ) || ( $user_Organization->perm_role == 'owner and member' && $org_data['accepted'] );
$perm_edit_org_priority = ( $user_Organization->owner_user_ID == $current_User->ID ) || ( $user_Organization->perm_priority == 'owner and member' && $org_data['accepted'] );
}

$Form->output = false;
Expand All @@ -431,6 +433,15 @@
{
$org_role_input = ( empty( $org_data['role'] ) ? '' : ' &nbsp; <strong>'.T_('Role').':</strong> '.$org_data['role'] ).' &nbsp; ';
}
if( $perm_edit_org_priority )
{
$org_priority_input = ' &nbsp; <strong>'.T_('Role').':</strong> '.
$Form->text_input( 'org_priorities[]', $org_data['priority'], 20, '', '', array( 'maxlength' => 255 ) ).' &nbsp; ';
}
else
{
$org_priority_input = ( empty( $org_data['priority'] ) ? '' : ' &nbsp; <strong>'.T_('Priority').':</strong> '.$org_data['priority'] ).' &nbsp; ';
}
$Form->switch_layout( NULL );
$Form->output = true;

Expand Down
17 changes: 15 additions & 2 deletions inc/widgets/widgets/_org_members.widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ function get_param_definitions( $params )
'type' => 'checkbox',
'defaultvalue' => 1,
),
'display_priority' => array(
'label' => T_('Priority in organization'),
'note' => T_('Check this to display the priority of the members in the organization'),
'type' => 'checkbox',
'defaultvalue' => 1,
),
'display_icons' => array(
'label' => T_('Contact icons'),
'note' => T_('Check this to display icons for User Field URLs with an icon.'),
Expand Down Expand Up @@ -287,7 +293,14 @@ function display( $params )
$organizations_data = $org_User->get_organizations_data();
echo '<div class="evo_org_role text-muted">'.$organizations_data[$org_ID]['role'].'</div>';
}


// Organizational priority
if( $this->disp_params['display_priority'] == 1 )
{
$organizations_data = $org_User->get_organizations_data();
echo '<div class="evo_org_priority text-muted">'.$organizations_data[$org_ID]['priority'].'</div>';
}

if( $this->disp_params['display_icons'] )
{ // Display user links as icons
$url_fields = $org_User->userfields_by_type( 'url' );
Expand Down Expand Up @@ -358,4 +371,4 @@ function get_cache_keys()
}
}

?>
?>
1 change: 1 addition & 0 deletions install/_functions_create.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function create_default_data()
'group_ID' => $admins_Group->ID,
'org_IDs' => $user_org_IDs,
'org_roles' => array( 'King of Spades' ),
'org_priorities' => array( 0 ),
'fields' => array(
'Micro bio' => 'I am the demo administrator of this site.'."\n".'I love having so much power!',
'Website' => 'http://b2evolution.net/',
Expand Down
6 changes: 4 additions & 2 deletions install/_functions_evoupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6304,12 +6304,13 @@ function insert_basic_widgets_9408( $blog_id, $initial_install = false, $kind =
set_upgrade_checkpoint( '11380' );
}

if( $old_db_version < 11390 )
if( $old_db_version < 11390 )// Version?
{ // part 18.i trunk aka 11th part of "i7"

task_begin( 'Upgrading table of relations users with organizations... ' );
$DB->query( 'ALTER TABLE T_users__user_org
ADD COLUMN uorg_role VARCHAR(255) NULL' );
ADD COLUMN uorg_role VARCHAR(255) NULL
ADD COLUMN uorg_priority INT(11) NULL' );
task_end();

set_upgrade_checkpoint( '11390' );
Expand Down Expand Up @@ -7301,6 +7302,7 @@ function add_basic_widget_11670( $blog_ID, $container_name, $code, $type, $order
if( upg_task_start( 11705, 'Upgrading users organization table...' ) )
{ // part of 6.7.0
db_add_col( 'T_users__organization', 'org_perm_role', "ENUM('owner and member', 'owner') COLLATE ascii_general_ci NOT NULL DEFAULT 'owner and member' AFTER org_accept" );
db_add_col( 'T_users__organization', 'org_perm_priority', "ENUM('owner and member', 'owner') COLLATE ascii_general_ci NOT NULL DEFAULT 'owner and member' AFTER org_perm_role" );
upg_task_end();
}

Expand Down