Le mirroring des dépôts vers Github est maintenant natif dans Gitlab (et donc Framagit). Merci de passer à la fonction native pour que nous puissions couper notre solution maison. Détails sur https://docs.gitlab.com/ee/workflow/repository_mirroring.html#pushing-to-a-remote-repository (pensez à supprimer le webhook de notre solution maison).

Commit 56f2910c by Cyrille37

Dashboard widget "projets" #62

parent 98d0762e
......@@ -146,6 +146,31 @@ class CommunityProject
}
}
public static function get_projects()
{
if( UserRoleController::isStudent() )
{
$current_user = wp_get_current_user();
$author = $current_user->ID ;
}
else
$author = null ;
return get_posts( array(
'author' => $author,
'numberposts' => 1000,
'category' => 0,
'orderby' => 'date',
'order' => 'DESC',
'include' => array(),
'exclude' => array(),
'meta_key' => '',
'meta_value' =>'',
'post_type' => ProjectCustomTypeCreator::CPT,
'suppress_filters' => true
));
}
}
new CommunityProject();
......@@ -15,17 +15,33 @@ class DashboardWidget
public function wp_dashboard_setup()
{
if( UserRoleController::isStudent() )
{
$title = 'Mes projets' ;
}
else
{
$title = 'Les projets' ;
}
wp_add_dashboard_widget(
self::SLUG, // Widget slug.
'Mes projets', // Title.
$title, // Title.
array( $this, 'display_widget' ) // Display function.
);
}
public function display_widget()
{
$projects = CommunityProject::get_projects();
/*
*/
// Display whatever it is you want to show.
echo "Hello World, I'm a great Dashboard Widget";
ob_start();
include __DIR__.'/templates/dashboard.php';
echo ob_get_clean();
}
}
......@@ -4,16 +4,18 @@ namespace CommunityProject ;
class ProjectCustomTypeCreator
{
const CPT = 'project' ;
public function __construct()
{
add_action( 'add_meta_boxes', array( $this, 'custom_field_meta_boxe' ) );
add_action( 'add_meta_boxes', array( $this, 'custom_field_meta_box' ) );
}
/**
* Add custom field to project custom type
*/
function custom_field_meta_boxe()
function custom_field_meta_box()
{
add_meta_box(
'budget',
......@@ -44,7 +46,7 @@ class ProjectCustomTypeCreator
function create_project_post_type()
{
register_post_type( 'project',
register_post_type( self::CPT,
[
'labels' => [
'name' => __('Projets'),
......
......@@ -6,6 +6,18 @@ class UserRoleController
{
const STUDENT_ROLE = 'student_role' ;
public static function isStudent()
{
if( ! is_user_logged_in() )
return false ;
$current_user = wp_get_current_user();
if( in_array( self::STUDENT_ROLE, $current_user->roles ) )
return true ;
return false ;
}
function set_user_role_permission()
{
// TODO: https://framagit.org/Artefacts/CommunityVoice/issues/61
......@@ -14,42 +26,42 @@ class UserRoleController
$this->grant_all_project_permission( get_role( 'administrator' ) );
}
function grant_all_project_permission( $role )
{
$role->add_cap( 'edit_projects' );
$role->add_cap( 'delete_projects' );
$role->add_cap( 'publish_projects' );
$role->add_cap( 'edit_project' );
$role->add_cap( 'read_project' );
$role->add_cap( 'delete_project' );
$role->add_cap( 'read_projects' );
$role->add_cap( 'edit_others_projects' );
$role->add_cap( 'delete_others_projects' );
$role->add_cap( 'read_private_projects' );
}
function grant_all_project_permission( $role )
{
$role->add_cap( 'edit_projects' );
$role->add_cap( 'delete_projects' );
$role->add_cap( 'publish_projects' );
$role->add_cap( 'edit_project' );
$role->add_cap( 'read_project' );
$role->add_cap( 'delete_project' );
$role->add_cap( 'read_projects' );
$role->add_cap( 'edit_others_projects' );
$role->add_cap( 'delete_others_projects' );
$role->add_cap( 'read_private_projects' );
}
function create_student_role()
{
add_role(
self::STUDENT_ROLE,
'Etudiant',
[
'delete_posts' => false,
'edit_posts' => false,
'edit_projects' => true,
'delete_projects' => false,
'publish_projects' => true,
'read_private_projects' => false,
'edit_project' => true,
'read_project' => false,
'delete_project' => false,
'upload_files' => true,
'read' => true,
'level_1' => true
function create_student_role()
{
add_role(
self::STUDENT_ROLE,
'Etudiant',
[
'delete_posts' => false,
'edit_posts' => false,
'edit_projects' => true,
'delete_projects' => false,
'publish_projects' => true,
'read_private_projects' => false,
'edit_project' => true,
'read_project' => false,
'delete_project' => false,
'upload_files' => true,
'read' => true,
'level_1' => true
]
);
}
);
}
}
<?php
/**
* Available variables :
* - $projects : the array of WP_Post objects
WP_Post Object
(
[ID] => 1424
[post_author] => 3
[post_date] => 2017-09-18 15:18:10
[post_date_gmt] => 2017-09-18 13:18:10
[post_content] =>
[post_title] => Mon Projet
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => mon-projet
[to_ping] =>
[pinged] =>
[post_modified] => 2017-09-18 15:18:10
[post_modified_gmt] => 2017-09-18 13:18:10
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://univ-tours-bpe.localhost/?post_type=project&#038;p=1424
[menu_order] => 0
[post_type] => project
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
*/
if( count($projects) == 0 )
{
?>
<p>Vous n'avez aucun projet.</p>
<?php
}
else
{
?>
<div id="published-posts" class="activity-block">
<ul>
<?php
foreach( $projects as $project )
{
?>
<li>
<span><?php echo get_post_time(get_option('time_format'), false, $project, true);?></span>
<?php edit_post_link( $project->post_title, '', '', $project->ID, '' ); ?>
</li>
<?php
}
?>
</ul>
</div>
<?php
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment