当前位置: 首页>>代码示例>>PHP>>正文


PHP completion_info::count_user_data方法代码示例

本文整理汇总了PHP中completion_info::count_user_data方法的典型用法代码示例。如果您正苦于以下问题:PHP completion_info::count_user_data方法的具体用法?PHP completion_info::count_user_data怎么用?PHP completion_info::count_user_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在completion_info的用法示例。


在下文中一共展示了completion_info::count_user_data方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: foreach

 /**
  * Each module which defines definition_after_data() must call this method using parent::definition_after_data();
  */
 function definition_after_data()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     if ($id = $mform->getElementValue('update')) {
         $modulename = $mform->getElementValue('modulename');
         $instance = $mform->getElementValue('instance');
         if ($this->_features->gradecat) {
             $gradecat = false;
             if (!empty($CFG->enableoutcomes) and $this->_features->outcomes) {
                 $outcomes = grade_outcome::fetch_all_available($COURSE->id);
                 if (!empty($outcomes)) {
                     $gradecat = true;
                 }
             }
             $hasgradeitems = false;
             $items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $modulename, 'iteminstance' => $instance, 'courseid' => $COURSE->id));
             //will be no items if, for example, this activity supports ratings but rating aggregate type == no ratings
             if (!empty($items)) {
                 foreach ($items as $item) {
                     if (!empty($item->outcomeid)) {
                         $elname = 'outcome_' . $item->outcomeid;
                         if ($mform->elementExists($elname)) {
                             $mform->hardFreeze($elname);
                             // prevent removing of existing outcomes
                         }
                     } else {
                         $hasgradeitems = true;
                     }
                 }
                 foreach ($items as $item) {
                     if (is_bool($gradecat)) {
                         $gradecat = $item->categoryid;
                         continue;
                     }
                     if ($gradecat != $item->categoryid) {
                         //mixed categories
                         $gradecat = false;
                         break;
                     }
                 }
             }
             if (!$hasgradeitems && $mform->elementExists('gradepass')) {
                 // Remove form element 'Grade to pass' since there are no grade items (when rating not selected).
                 $mform->removeElement('gradepass');
             }
             if ($gradecat === false) {
                 // items and outcomes in different categories - remove the option
                 // TODO: add a "Mixed categories" text instead of removing elements with no explanation
                 if ($mform->elementExists('gradecat')) {
                     $mform->removeElement('gradecat');
                     if ($this->_features->rating && !$mform->elementExists('gradepass')) {
                         //if supports ratings then the max grade dropdown wasnt added so the grade box can be removed entirely
                         $mform->removeElement('modstandardgrade');
                     }
                 }
             }
         }
     }
     if ($COURSE->groupmodeforce) {
         if ($mform->elementExists('groupmode')) {
             $mform->hardFreeze('groupmode');
             // groupmode can not be changed if forced from course settings
         }
     }
     // Don't disable/remove groupingid if it is currently set to something,
     // otherwise you cannot turn it off at same time as turning off other
     // option (MDL-30764)
     if (empty($this->_cm) || !$this->_cm->groupingid) {
         if ($mform->elementExists('groupmode') && empty($COURSE->groupmodeforce)) {
             $mform->disabledIf('groupingid', 'groupmode', 'eq', NOGROUPS);
         } else {
             if (!$mform->elementExists('groupmode')) {
                 // Groupings have no use without groupmode.
                 if ($mform->elementExists('groupingid')) {
                     $mform->removeElement('groupingid');
                 }
             }
         }
     }
     // Completion: If necessary, freeze fields
     $completion = new completion_info($COURSE);
     if ($completion->is_enabled()) {
         // If anybody has completed the activity, these options will be 'locked'
         $completedcount = empty($this->_cm) ? 0 : $completion->count_user_data($this->_cm);
         $freeze = false;
         if (!$completedcount) {
             if ($mform->elementExists('unlockcompletion')) {
                 $mform->removeElement('unlockcompletion');
             }
             // Automatically set to unlocked (note: this is necessary
             // in order to make it recalculate completion once the option
             // is changed, maybe someone has completed it now)
             $mform->getElement('completionunlocked')->setValue(1);
         } else {
             // Has the element been unlocked, either by the button being pressed
             // in this request, or the field already being set from a previous one?
//.........这里部分代码省略.........
开发者ID:alanaipe2015,项目名称:moodle,代码行数:101,代码来源:moodleform_mod.php

示例2: test_count_user_data

 public function test_count_user_data()
 {
     global $DB;
     $this->mock_setup();
     $course = (object) array('id' => 13);
     $cm = (object) array('id' => 42);
     /** @var $DB PHPUnit_Framework_MockObject_MockObject */
     $DB->expects($this->at(0))->method('get_field_sql')->will($this->returnValue(666));
     $c = new completion_info($course);
     $this->assertEquals(666, $c->count_user_data($cm));
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:11,代码来源:completionlib_test.php

示例3: foreach

 /**
  * Each module which defines definition_after_data() must call this method using parent::definition_after_data();
  */
 function definition_after_data()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     if ($id = $mform->getElementValue('update')) {
         $modulename = $mform->getElementValue('modulename');
         $instance = $mform->getElementValue('instance');
         if ($this->_features->gradecat) {
             $gradecat = false;
             if (!empty($CFG->enableoutcomes) and $this->_features->outcomes) {
                 $outcomes = grade_outcome::fetch_all_available($COURSE->id);
                 if (!empty($outcomes)) {
                     $gradecat = true;
                 }
             }
             $items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $modulename, 'iteminstance' => $instance, 'courseid' => $COURSE->id));
             //will be no items if, for example, this activity supports ratings but rating aggregate type == no ratings
             if (!empty($items)) {
                 foreach ($items as $item) {
                     if (!empty($item->outcomeid)) {
                         $elname = 'outcome_' . $item->outcomeid;
                         if ($mform->elementExists($elname)) {
                             $mform->hardFreeze($elname);
                             // prevent removing of existing outcomes
                         }
                     }
                 }
                 foreach ($items as $item) {
                     if (is_bool($gradecat)) {
                         $gradecat = $item->categoryid;
                         continue;
                     }
                     if ($gradecat != $item->categoryid) {
                         //mixed categories
                         $gradecat = false;
                         break;
                     }
                 }
             }
             if ($gradecat === false) {
                 // items and outcomes in different categories - remove the option
                 // TODO: add a "Mixed categories" text instead of removing elements with no explanation
                 if ($mform->elementExists('gradecat')) {
                     $mform->removeElement('gradecat');
                     if ($this->_features->rating) {
                         //if supports ratings then the max grade dropdown wasnt added so the grade box can be removed entirely
                         $mform->removeElement('modstandardgrade');
                     }
                 }
             }
         }
     }
     if ($COURSE->groupmodeforce) {
         if ($mform->elementExists('groupmode')) {
             $mform->hardFreeze('groupmode');
             // groupmode can not be changed if forced from course settings
         }
     }
     // Don't disable/remove groupingid if it is currently set to something,
     // otherwise you cannot turn it off at same time as turning off other
     // option (MDL-30764)
     if (empty($this->_cm) || !$this->_cm->groupingid) {
         if ($mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly') and empty($COURSE->groupmodeforce)) {
             $mform->disabledIf('groupingid', 'groupmode', 'eq', NOGROUPS);
         } else {
             if (!$mform->elementExists('groupmode') and $mform->elementExists('groupmembersonly')) {
                 $mform->disabledIf('groupingid', 'groupmembersonly', 'notchecked');
             } else {
                 if (!$mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly')) {
                     // groupings have no use without groupmode or groupmembersonly
                     if ($mform->elementExists('groupingid')) {
                         $mform->removeElement('groupingid');
                     }
                 }
             }
         }
     }
     // Completion: If necessary, freeze fields
     $completion = new completion_info($COURSE);
     if ($completion->is_enabled()) {
         // If anybody has completed the activity, these options will be 'locked'
         $completedcount = empty($this->_cm) ? 0 : $completion->count_user_data($this->_cm);
         $freeze = false;
         if (!$completedcount) {
             if ($mform->elementExists('unlockcompletion')) {
                 $mform->removeElement('unlockcompletion');
             }
             // Automatically set to unlocked (note: this is necessary
             // in order to make it recalculate completion once the option
             // is changed, maybe someone has completed it now)
             $mform->getElement('completionunlocked')->setValue(1);
         } else {
             // Has the element been unlocked?
             if ($mform->exportValue('unlockcompletion')) {
                 // Yes, add in warning text and set the hidden variable
                 $mform->insertElementBefore($mform->createElement('static', 'completedunlocked', get_string('completedunlocked', 'completion'), get_string('completedunlockedtext', 'completion')), 'unlockcompletion');
                 $mform->removeElement('unlockcompletion');
//.........这里部分代码省略.........
开发者ID:Burick,项目名称:moodle,代码行数:101,代码来源:moodleform_mod.php

示例4: IgnoreWhitespaceExpectation

    function test_count_user_data() {
        global $DB;

        $course = (object)array('id'=>13);
        $cm = (object)array('id'=>42);

        /** @var $DB PHPUnit_Framework_MockObject_MockObject */
        $DB->expects($this->at(0))
            ->method('get_field_sql')
            ->will($this->returnValue(666));

/*
        $DB->expectOnce('get_field_sql',array(new IgnoreWhitespaceExpectation("SELECT
    COUNT(1)
FROM
    {course_modules_completion}
WHERE
    coursemoduleid=? AND completionstate<>0"),array(42)));
*/

        $c = new completion_info($course);
        $this->assertEquals(666, $c->count_user_data($cm));
    }
开发者ID:nigeli,项目名称:moodle,代码行数:23,代码来源:completionlib_test.php

示例5: array

 function test_count_user_data()
 {
     global $DB;
     $course = (object) array('id' => 13);
     $cm = (object) array('id' => 42);
     $DB->setReturnValue('get_field_sql', 666);
     $DB->expectOnce('get_field_sql', array(new IgnoreWhitespaceExpectation("SELECT\n    COUNT(1)\nFROM\n    {course_modules_completion}\nWHERE\n    coursemoduleid=? AND completionstate<>0"), array(42)));
     $c = new completion_info($course);
     $this->assertEqual(666, $c->count_user_data($cm));
     $DB->tally();
 }
开发者ID:vuchannguyen,项目名称:web,代码行数:11,代码来源:testcompletionlib.php

示例6: foreach

 /**
  * Each module which defines definition_after_data() must call this method using parent::definition_after_data();
  */
 function definition_after_data()
 {
     global $CFG, $COURSE;
     $mform =& $this->_form;
     if ($id = $mform->getElementValue('update')) {
         $modulename = $mform->getElementValue('modulename');
         $instance = $mform->getElementValue('instance');
         if ($this->_features->gradecat) {
             $gradecat = false;
             if (!empty($CFG->enableoutcomes) and $this->_features->outcomes) {
                 if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
                     $gradecat = true;
                 }
             }
             if ($items = grade_item::fetch_all(array('itemtype' => 'mod', 'itemmodule' => $modulename, 'iteminstance' => $instance, 'courseid' => $COURSE->id))) {
                 foreach ($items as $item) {
                     if (!empty($item->outcomeid)) {
                         $elname = 'outcome_' . $item->outcomeid;
                         if ($mform->elementExists($elname)) {
                             $mform->hardFreeze($elname);
                             // prevent removing of existing outcomes
                         }
                     }
                 }
                 foreach ($items as $item) {
                     if (is_bool($gradecat)) {
                         $gradecat = $item->categoryid;
                         continue;
                     }
                     if ($gradecat != $item->categoryid) {
                         //mixed categories
                         $gradecat = false;
                         break;
                     }
                 }
             }
             if ($gradecat === false) {
                 // items and outcomes in different categories - remove the option
                 // TODO: it might be better to add a "Mixed categories" text instead
                 if ($mform->elementExists('gradecat')) {
                     $mform->removeElement('gradecat');
                 }
             }
         }
     }
     if ($COURSE->groupmodeforce) {
         if ($mform->elementExists('groupmode')) {
             $mform->hardFreeze('groupmode');
             // groupmode can not be changed if forced from course settings
         }
     }
     if ($mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly') and empty($COURSE->groupmodeforce)) {
         $mform->disabledIf('groupingid', 'groupmode', 'eq', NOGROUPS);
     } else {
         if (!$mform->elementExists('groupmode') and $mform->elementExists('groupmembersonly')) {
             $mform->disabledIf('groupingid', 'groupmembersonly', 'notchecked');
         } else {
             if (!$mform->elementExists('groupmode') and !$mform->elementExists('groupmembersonly')) {
                 // groupings have no use without groupmode or groupmembersonly
                 if ($mform->elementExists('groupingid')) {
                     $mform->removeElement('groupingid');
                 }
             }
         }
     }
     // Completion: If necessary, freeze fields
     $completion = new completion_info($COURSE);
     if ($completion->is_enabled()) {
         // If anybody has completed the activity, these options will be 'locked'
         $completedcount = empty($this->_cm) ? 0 : $completion->count_user_data($this->_cm);
         $freeze = false;
         if (!$completedcount) {
             if ($mform->elementExists('unlockcompletion')) {
                 $mform->removeElement('unlockcompletion');
             }
         } else {
             // Has the element been unlocked?
             if ($mform->exportValue('unlockcompletion')) {
                 // Yes, add in warning text and set the hidden variable
                 $mform->insertElementBefore($mform->createElement('static', 'completedunlocked', get_string('completedunlocked', 'completion'), get_string('completedunlockedtext', 'completion')), 'unlockcompletion');
                 $mform->removeElement('unlockcompletion');
                 $mform->getElement('completionunlocked')->setValue(1);
             } else {
                 // No, add in the warning text with the count (now we know
                 // it) before the unlock button
                 $mform->insertElementBefore($mform->createElement('static', 'completedwarning', get_string('completedwarning', 'completion'), get_string('completedwarningtext', 'completion', $completedcount)), 'unlockcompletion');
                 $mform->setHelpButton('completedwarning', array('completionlocked', get_string('help_completionlocked', 'completion'), 'completion'));
                 $freeze = true;
             }
         }
         if ($freeze) {
             $mform->freeze('completion');
             if ($mform->elementExists('completionview')) {
                 $mform->freeze('completionview');
                 // don't use hardFreeze or checkbox value gets lost
             }
             if ($mform->elementExists('completionusegrade')) {
//.........这里部分代码省略.........
开发者ID:ajv,项目名称:Offline-Caching,代码行数:101,代码来源:moodleform_mod.php


注:本文中的completion_info::count_user_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。