Bläddra i källkod

#1904 Classes module: blocks with students on class page

Alex Trofimov 6 år sedan
förälder
incheckning
6efdd30ecc

+ 70 - 0
modules/boonex/classes/classes/BxClssDb.php

@@ -173,6 +173,76 @@ class BxClssDb extends BxBaseModTextDb
             ));
         }
     }
+
+    public function getStudentsInClass($aContentInfo, $iStart = 0, $iLimit = 1000)
+    {
+        if (!$aContentInfo)
+            return array();
+
+        if ($aContentInfo['allow_view_to'] < 0 && $oProfileContext = BxDolProfile::getInstance(abs($aContentInfo['allow_view_to']))) {
+            $oModule = BxDolModule::getInstance($oProfileContext->getModule());
+
+            if ($oModule && isset($oModule->_oConfig->CNF['OBJECT_CONNECTIONS'])) {
+                if (!($o = BxDolConnection::getObjectInstance($oModule->_oConfig->CNF['OBJECT_CONNECTIONS'])))
+                    return array();
+
+                // TODO: remake to use SQL parts
+                if (BX_CONNECTIONS_TYPE_MUTUAL == $o->getType())
+                    $a = $o->getConnectedContent($oProfileContext->id(), true, $iStart, $iLimit);
+                else
+                    $a = $o->getConnectedContent($oProfileContext->id(), false, $iStart, $iLimit);
+            }
+        }
+
+        if ($a && $aContentInfo['allow_view_to'] < 0)
+            $a = $this->_removeCourseAdminsFromProfilesArray(abs($aContentInfo['allow_view_to']), $a); // TODO: remake to add condition to query instead of postfiltering
+
+        return $a;
+    }
+
+    public function getStudentsInClassNotCompleted($aContentInfo, $iStart = 0, $iLimit = 1000)
+    {
+        $aAll = $this->getStudentsInClass($aContentInfo, $iStart, $iLimit);
+        $aCompleted = $this->getStudentsInClassCompleted($aContentInfo, $iStart, $iLimit);
+        return array_diff($aAll, $aCompleted);;
+    }
+
+    public function getStudentsInClassCompleted($aContentInfo, $iStart = 0, $iLimit = 1000)
+    {
+        if (!$aContentInfo)
+            return array();
+
+        $iCompletedWhen = (int)$aContentInfo['completed_when'];
+        if (!isset($this->_aStatuses[$iCompletedWhen]))
+            return array();
+
+        $sCompletedField = $this->_aStatuses[$iCompletedWhen];
+
+        $a = $this->getColumn("SELECT `student_profile_id` FROM `bx_classes_statuses` WHERE `class_id` = :class AND `$sCompletedField` != 0 LIMIT :start, :limit", array(
+            'class' => $aContentInfo['id'],
+            'start' => (int)$iStart,
+            'limit' => (int)$iLimit,
+        ));
+        if (!$a)
+            return array();
+
+        if ($aContentInfo['allow_view_to'] < 0)
+            $a = $this->_removeCourseAdminsFromProfilesArray(abs($aContentInfo['allow_view_to']), $a); // TODO: remake to add condition to query instead of postfiltering
+
+        return $a;
+    }
+
+    protected function _removeCourseAdminsFromProfilesArray($iProfileConextId, $a)
+    {
+        if ($oProfileContext = BxDolProfile::getInstance($iProfileConextId)) {
+            $oModule = BxDolModule::getInstance($oProfileContext->getModule());
+            if ($oModule && method_exists($oModule->_oDb, 'getAdmins')) {
+                $aAdmins = $oModule->_oDb->getAdmins($oProfileContext->id(), 0, 1000);
+                $a = array_diff($a, $aAdmins);
+            }
+        }
+        return $a;
+    }
 }
 
 /** @} */

+ 2 - 1
modules/boonex/classes/classes/BxClssFormEntry.php

@@ -212,7 +212,8 @@ class BxClssFormEntry extends BxBaseModTextFormEntry
         if (!$this->_bViewMode && isset($this->aInputs['module_id']) && !$this->aInputs['module_id']['values'])
             return MsgBox(_t('_bx_classes_txt_err_cant_add_class_without_modules'));
 
-        // TODO: check permission for adding to context
+        if (!$this->_oModule->serviceIsCourseAdmin($this->_oProfileContext->id()))
+            return MsgBox(_t('_sys_txt_access_denied'));
 
         return parent::getCode($bDynamicMode);
     }

+ 46 - 0
modules/boonex/classes/classes/BxClssModule.php

@@ -383,6 +383,52 @@ class BxClssModule extends BxBaseModTextModule
         ));
     }
 
+    public function serviceBrowseStudentsInClass ($iClassId = 0, $iLimit = 1000, $aAdditionalParams = array())
+    {
+        return $this->_serviceBrowseStudentsInClass ($iClassId, 'getStudentsInClass', $iLimit);
+    }
+
+    public function serviceBrowseStudentsCompletedClass ($iClassId = 0, $iLimit = 1000, $aAdditionalParams = array())
+    {
+        return $this->_serviceBrowseStudentsInClass ($iClassId, 'getStudentsInClassCompleted', $iLimit);
+    }
+
+    public function serviceBrowseStudentsNotCompletedClass ($iClassId = 0, $iLimit = 1000, $aAdditionalParams = array())
+    {
+        return $this->_serviceBrowseStudentsInClass ($iClassId, 'getStudentsInClassNotCompleted', $iLimit);
+    }
+
+    protected function _serviceBrowseStudentsInClass ($iClassId, $sFunc, $iLimit = 1000, $aAdditionalParams = array())
+    {        
+        // set some vars
+        if (!$iClassId)
+            $iClassId = (int)bx_get('id');
+        if (!$iClassId)
+            return '';
+
+        $iLimit = (int)$iLimit;
+        if (!$iLimit)
+            $iLimit = 50;
+
+        $iStart = (int)bx_get('start');
+
+        if (!($aClass = $this->_oDb->getContentInfoById($iClassId)))
+            return '';
+
+        if ($aClass['allow_view_to'] >= 0)
+            return '';
+
+        if (!$this->serviceIsCourseAdmin(abs($aClass['allow_view_to'])))
+            return '';
+
+        // get students array
+        $a = $this->_oDb->$sFunc ($aClass, $iStart, $iLimit + 1);
+        if (!$a)
+            return '';
+
+        return $this->_serviceBrowseQuick($a, $iStart, $iLimit, $aAdditionalParams);
+    }
+
     public function serviceIsClassCompleted ($iClassId, $iProfileId = 0)
     {
         if (!$iProfileId)

+ 2 - 0
modules/boonex/classes/install/langs/en.xml

@@ -135,6 +135,8 @@
     <string name="_bx_classes_page_block_title_entry_context"><![CDATA[Classed in]]></string>
     <string name="_bx_classes_page_block_title_next_entry"><![CDATA[Next class]]></string>
     <string name="_bx_classes_page_block_title_prev_entry"><![CDATA[Previous class]]></string>
+    <string name="_bx_classes_page_block_title_entry_students_completed_class"><![CDATA[Passed students]]></string>
+    <string name="_bx_classes_page_block_title_entry_students_not_completed_class"><![CDATA[Not passed students]]></string>
 
     <string name="_bx_classes_menu_title_entry_attachments"><![CDATA[Form Attachments]]></string>
     <string name="_bx_classes_menu_set_title_entry_attachments"><![CDATA[Form Attachments]]></string>

+ 3 - 1
modules/boonex/classes/install/sql/enable.sql

@@ -59,7 +59,9 @@ INSERT INTO `sys_pages_blocks`(`object`, `cell_id`, `module`, `title_system`, `t
 ('bx_classes_view_entry', 3, 'bx_classes', '', '_bx_classes_page_block_title_entry_info', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:\"bx_classes\";s:6:\"method\";s:11:\"entity_info\";}', 0, 0, 1, 2),
 ('bx_classes_view_entry', 3, 'bx_classes', '', '_bx_classes_page_block_title_next_entry', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:10:"bx_classes";s:6:"method";s:10:"next_class";}', 0, 0, 1, 3),
 ('bx_classes_view_entry', 3, 'bx_classes', '', '_bx_classes_page_block_title_prev_entry', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:10:"bx_classes";s:6:"method";s:10:"prev_class";}', 0, 0, 0, 4),
-('bx_classes_view_entry', 3, 'bx_classes', '', '_bx_classes_page_block_title_entry_location', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:\"bx_classes\";s:6:\"method\";s:15:\"entity_location\";}', 0, 0, 0, 0),
+('bx_classes_view_entry', 3, 'bx_classes', '', '_bx_classes_page_block_title_entry_location', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:\"bx_classes\";s:6:\"method\";s:15:\"entity_location\";}', 0, 0, 0, 5),
+('bx_classes_view_entry', 3, 'bx_classes', '', '_bx_classes_page_block_title_entry_students_completed_class', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:10:"bx_classes";s:6:"method";s:31:"browse_students_completed_class";}', 0, 0, 1, 6),
+('bx_classes_view_entry', 3, 'bx_classes', '', '_bx_classes_page_block_title_entry_students_not_completed_class', 11, 2147483647, 'service', 'a:2:{s:6:"module";s:10:"bx_classes";s:6:"method";s:35:"browse_students_not_completed_class";}', 0, 0, 1, 7),
 ('bx_classes_view_entry', 2, 'bx_classes', '', '_bx_classes_page_block_title_entry_all_actions', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:\"bx_classes\";s:6:\"method\";s:18:\"entity_all_actions\";}', 0, 0, 1, 3),
 ('bx_classes_view_entry', 4, 'bx_classes', '', '_bx_classes_page_block_title_entry_actions', 13, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:\"bx_classes\";s:6:\"method\";s:14:\"entity_actions\";}', 0, 0, 0, 0),
 ('bx_classes_view_entry', 4, 'bx_classes', '', '_bx_classes_page_block_title_entry_social_sharing', 11, 2147483647, 'service', 'a:2:{s:6:\"module\";s:10:\"bx_classes\";s:6:\"method\";s:21:\"entity_social_sharing\";}', 0, 0, 0, 0),