Browse Source

Merge pull request #1671 from jloguercio/1.11.x

Added Works report table in MyStudents page - Refs BT#12212
José Loguercio 8 years ago
parent
commit
6c7c62c2b4

+ 6 - 1
main/inc/lib/extra_field.lib.php

@@ -126,6 +126,10 @@ class ExtraField extends Model
                 break;
             case 'skill':
                 $this->extraFieldType = EntityExtraField::SKILL_FIELD_TYPE;
+                break;
+            case 'work':
+                $this->extraFieldType = EntityExtraField::WORK_FIELD_TYPE;
+                break;
         }
 
         $this->pageUrl  = 'extra_fields.php?type='.$this->type;
@@ -154,7 +158,8 @@ class ExtraField extends Model
             'lp',
             'calendar_event',
             'lp_item',
-            'skill'
+            'skill',
+            'work'
         );
     }
 

+ 2 - 0
main/install/configuration.dist.php

@@ -277,3 +277,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE;
 // $_configuration['allow_course_introduction_low_security'] = false;
 // Prevents the duplicate upload in assignments
 // $_configuration['assignment_prevent_duplicate_upload'] = false;
+// Set ConsideredWorkingTime work extra field variable to show in MyStudents page works report
+// $_configuration['considered_working_time'] = 'work_time';

+ 56 - 0
main/mySpace/myStudents.php

@@ -1286,6 +1286,62 @@ if (!empty($student_id)) {
             }
         }
 
+        require_once '../work/work.lib.php';
+
+        $userworks = getWorkPerUser($student_id);
+        echo '
+            <div class="table-responsive">
+                <table class="table table-striped table-hover">
+                    <thead>
+                        <tr>
+                            <th>' . get_lang('Tasks') . '</th>
+                            <th class="text-center">' . get_lang('DocumentNumber') . '</th>
+                            <th class="text-center">' . get_lang('Note') . '</th>
+                            <th class="text-center">' . get_lang('HandedOut') . '</th>
+                            <th class="text-center">' . get_lang('HandOutDateLimit') . '</th>
+                            <th class="text-center">' . get_lang('ConsideredWorkingTime') . '</th>
+                        </tr>
+                    </thead>
+                    <tbody>
+        ';
+
+            foreach ($userworks as $work) {
+                $work = $work['work'];
+                foreach ($work->user_results as $key => $results) {
+                    echo '<tr>';
+                    echo '<td>' . $work->title . '</td>';
+                    $documentNumber = $key + 1;
+                    echo '<td class="text-center"><a href="' . api_get_path(WEB_CODE_PATH) . 'work/view.php?cidReq=' . $course_code . '&id_session=' . $sessionId .'&id=' . $results['id'] . '">(' . $documentNumber . ')</a></td>';
+                    $qualification = !empty($results['qualification']) ? $results['qualification'] : '-';
+                    echo '<td class="text-center">' . $qualification. '</td>';
+                    echo '<td class="text-center">' . $results['formatted_date']. '</td>';
+                    $assignment = get_work_assignment_by_id($work->id);
+                    echo '<td class="text-center">' . api_convert_and_format_date($assignment['expires_on']) . '</td>';
+
+                    $fieldValue = new ExtraFieldValue('work');
+                    $resultExtra = $fieldValue->getAllValuesForAnItem(
+                        $work->id,
+                        true
+                    );
+
+                    foreach ($resultExtra as $field) {
+                        $field = $field['value'];
+
+                        if (api_get_configuration_value('considered_working_time') == $field->getField()->getVariable()) {
+                            echo '<td class="text-center">' . $field->getValue() . '</td>';
+                        }
+                    }
+
+                    echo '</tr>';
+                }
+            }
+
+        echo '
+                    </tbody>
+                </table>
+            </div>
+        ';
+
         // line about other tools
         ?>
         <div class="table-responsive">

+ 1 - 1
main/work/edit_work.php

@@ -80,7 +80,7 @@ if (!empty($homework['ends_on'])) {
 }
 
 $defaults['add_to_calendar'] = isset($homework['add_to_calendar']) ? $homework['add_to_calendar'] : null;
-$form = getFormWork($form, $defaults);
+$form = getFormWork($form, $defaults, $workId);
 $form->addElement('hidden', 'work_id', $workId);
 $form->addButtonUpdate(get_lang('ModifyDirectory'));
 

+ 32 - 3
main/work/work.lib.php

@@ -191,6 +191,13 @@ function get_work_data_by_id($id, $courseId = null, $sessionId = null)
                 $work['show_content'] = '<img src="'.$work['show_url'].'"/>';
             }
         }
+
+        $fieldValue = new ExtraFieldValue('work');
+        $work['extra'] = $fieldValue->getAllValuesForAnItem(
+            $id,
+            true
+        );
+
     }
 
     return $work;
@@ -2061,10 +2068,11 @@ function get_work_user_list(
 
                 // Date.
                 $work_date = api_convert_and_format_date($work['sent_date']);
-                $date = date_to_str_ago($work['sent_date']). ' ' . $add_string . ' ' . $work_date;
+                $date = date_to_str_ago($work['sent_date']). ' ' . $work_date;
+                $work['formatted_date'] = $work_date . ' - ' . $add_string;
 
                 $work['sent_date_from_db'] = $work['sent_date'];
-                $work['sent_date'] = '<div class="work-date" title="'.$date.'">' . $work['sent_date'] . '</div>';
+                $work['sent_date'] = '<div class="work-date" title="'.$date.'">' . $add_string . ' - ' . $work['sent_date'] . '</div>';
 
                 // Actions.
                 $correction = '';
@@ -3838,6 +3846,12 @@ function addDir($formValues, $user_id, $courseInfo, $groupId, $session_id)
         $groupIid
     );
 
+    // Added the new Work ID to the extra field values
+    $formValues['item_id'] = $workTable->getIid();
+
+    $workFieldValue = new ExtraFieldValue('work');
+    $workFieldValue->saveFieldValues($formValues);
+
     if (api_get_course_setting('email_alert_students_on_new_homework') == 1) {
         send_email_on_homework_creation(
             $course_id,
@@ -3899,6 +3913,9 @@ function updateWork($workId, $params, $courseInfo, $sessionId = 0)
             )
         )
     );
+
+    $workFieldValue = new ExtraFieldValue('work');
+    $workFieldValue->saveFieldValues($params);
 }
 
 /**
@@ -4180,9 +4197,10 @@ function deleteWorkItem($item_id, $courseInfo)
 /**
  * @param FormValidator $form
  * @param array $defaults
+ * @param integer $workId
  * @return FormValidator
  */
-function getFormWork($form, $defaults = array())
+function getFormWork($form, $defaults = array(), $workId = 0)
 {
     $sessionId = api_get_session_id();
     if (!empty($defaults)) {
@@ -4267,6 +4285,17 @@ function getFormWork($form, $defaults = array())
     $form->addElement('checkbox', 'add_to_calendar', null, get_lang('AddToCalendar'));
     $form->addElement('select', 'allow_text_assignment', get_lang('DocumentType'), getUploadDocumentType());
 
+    //Extra fields
+    $extra_field = new ExtraField('work');
+    $extra = $extra_field->addElements($form, $workId);
+
+    $htmlHeadXtra[] = '
+        <script>
+        $(function() {
+            ' . $extra['jquery_ready_content'] . '
+        });
+        </script>';
+
     $form->addHtml('</div>');
 
     if (isset($defaults['enableExpiryDate']) && isset($defaults['enableEndDate'])) {

+ 1 - 0
src/Chamilo/CoreBundle/Entity/ExtraField.php

@@ -25,6 +25,7 @@ class ExtraField extends BaseAttribute
     const LP_FIELD_TYPE = 6;
     const LP_ITEM_FIELD_TYPE = 7;
     const SKILL_FIELD_TYPE = 8;
+    const WORK_FIELD_TYPE = 9;
 
     /**
      * @var integer