Esempio n. 1
0
 /**
  * (non-PHPdoc)
  * @see EPDBObject::loadSummaryFields()
  */
 public function loadSummaryFields($summaryFields = null)
 {
     if (is_null($summaryFields)) {
         $summaryFields = array('courses', 'terms', 'students', 'active');
     } else {
         $summaryFields = (array) $summaryFields;
     }
     $fields = array();
     if (in_array('courses', $summaryFields)) {
         $fields['courses'] = EPCourse::count(array('org_id' => $this->getId()));
     }
     if (in_array('terms', $summaryFields)) {
         $fields['terms'] = EPTerm::count(array('org_id' => $this->getId()));
     }
     $dbr = wfGetDB(DB_SLAVE);
     if (in_array('students', $summaryFields)) {
         $termIds = EPTerm::selectFields('id', array('org_id' => $this->getId()));
         if (count($termIds) > 0) {
             $fields['students'] = $dbr->select('ep_students_per_term', 'COUNT(*) AS rowcount', array('spt_term_id' => $termIds));
             $fields['students'] = $fields['students']->fetchObject()->rowcount;
         } else {
             $fields['students'] = 0;
         }
     }
     if (in_array('active', $summaryFields)) {
         $now = wfGetDB(DB_SLAVE)->addQuotes(wfTimestampNow());
         $fields['active'] = EPTerm::has(array('org_id' => $this->getId(), 'end >= ' . $now, 'start <= ' . $now));
     }
     $this->setFields($fields);
 }
 /**
  * Gets the summary data.
  *
  * @since 0.1
  *
  * @param EPCourse $course
  *
  * @return array
  */
 protected function getSummaryData(EPDBObject $course)
 {
     $stats = array();
     $stats['name'] = htmlspecialchars($course->getField('name'));
     $org = EPOrg::selectFieldsRow('name', array('id' => $course->getField('org_id')));
     $stats['org'] = Linker::linkKnown(SpecialPage::getTitleFor('Institution', $org), htmlspecialchars($org));
     $stats['status'] = wfMsgHtml($course->getField('active') ? 'ep-course-active' : 'ep-course-inactive');
     $lang = $this->getLanguage();
     $stats['students'] = htmlspecialchars($lang->formatNum($course->getField('students')));
     $termCount = EPTerm::count(array('course_id' => $course->getId()));
     $stats['terms'] = htmlspecialchars($lang->formatNum($termCount));
     if ($termCount > 0) {
         $stats['terms'] = Linker::linkKnown(SpecialPage::getTitleFor('Terms'), $stats['terms'], array(), array('course_id' => $course->getId()));
     }
     $stats['instructors'] = $this->getInstructorsList($course) . $this->getInstructorControls($course);
     return $stats;
 }