Exemplo n.º 1
0
 /**
  * (non-PHPdoc)
  * @see EPDBObject::loadSummaryFields()
  */
 public function loadSummaryFields($summaryFields = null)
 {
     if (is_null($summaryFields)) {
         $summaryFields = array('courses', 'students', 'active', 'instructors', 'oas', 'cas');
     } else {
         $summaryFields = (array) $summaryFields;
     }
     $fields = array();
     if (in_array('courses', $summaryFields)) {
         $fields['courses'] = EPCourse::count(array('org_id' => $this->getId()));
     }
     $dbr = wfGetDB(DB_SLAVE);
     if (in_array('students', $summaryFields)) {
         $courseIds = EPCourse::selectFields('id', array('org_id' => $this->getId()));
         if (count($courseIds) > 0) {
             $fields['students'] = $dbr->select('ep_students_per_course', 'COUNT(*) AS rowcount', array('spc_course_id' => $courseIds));
             $fields['students'] = $fields['students']->fetchObject()->rowcount;
         } else {
             $fields['students'] = 0;
         }
     }
     if (in_array('active', $summaryFields)) {
         $now = wfGetDB(DB_SLAVE)->addQuotes(wfTimestampNow());
         $fields['active'] = EPCourse::has(array('org_id' => $this->getId(), 'end >= ' . $now, 'start <= ' . $now));
     }
     $courseFields = array();
     $upInstructors = in_array('instructors', $summaryFields);
     $upOas = in_array('oas', $summaryFields);
     if ($upInstructors) {
         $courseFields[] = 'instructors';
         $fields['instructors'] = 0;
     }
     if ($upOas) {
         $courseFields[] = 'online_ambs';
         $fields['online_ambs'] = 0;
     }
     if (count($courseFields) > 0) {
         $courses = EPCourse::select($courseFields, array('org_id' => $this->getId()));
         foreach ($courses as $course) {
             // TODO: foreach set field: count and add to fields[name]
         }
     }
     $this->setFields($fields);
 }
Exemplo n.º 2
0
 /**
  * (non-PHPdoc)
  * @see EPEditAction::getFormFields()
  * @return array
  */
 protected function getFormFields()
 {
     $fields = parent::getFormFields();
     $orgOptions = EPOrg::getOrgOptions();
     $fields['name'] = array('type' => 'text', 'label-message' => 'ep-course-edit-name', 'required' => true);
     $mcs = EPCourse::selectFields('mc', array(), array('DISTINCT'));
     if ($this->getRequest()->getCheck('newname')) {
         $newName = $this->getRequest()->getText('newname');
         $mcs = array_merge(array($newName => $newName), $mcs);
     } else {
         $mcs = array_merge(array('' => ''), $mcs);
     }
     $fields['mc'] = array('class' => 'EPHTMLCombobox', 'label-message' => 'ep-course-edit-mc', 'required' => true, 'options' => array_combine($mcs, $mcs));
     $fields['org_id'] = array('type' => 'select', 'label-message' => 'ep-course-edit-org', 'required' => true, 'options' => $orgOptions, 'validation-callback' => function ($value, array $alldata = null) use($orgOptions) {
         return in_array((int) $value, array_values($orgOptions)) ? true : wfMsg('ep-course-invalid-org');
     });
     $fields['token'] = array('type' => 'text', 'label-message' => 'ep-course-edit-token', 'maxlength' => 255, 'size' => 20, 'validation-callback' => function ($value, array $alldata = null) {
         $strLen = strlen($value);
         return $strLen !== 0 && $strLen < 2 ? wfMsgExt('ep-course-invalid-token', 'parsemag', 2) : true;
     });
     $fields['term'] = array('type' => 'text', 'label-message' => 'ep-course-edit-term', 'required' => true);
     $fields['start'] = array('class' => 'EPHTMLDateField', 'label-message' => 'ep-course-edit-start', 'required' => true);
     $fields['end'] = array('class' => 'EPHTMLDateField', 'label-message' => 'ep-course-edit-end', 'required' => true);
     $fieldFields = EPCourse::selectFields('field', array(), array('DISTINCT'));
     $fieldFields = array_merge(array('' => ''), $fieldFields);
     $fields['field'] = array('class' => 'EPHTMLCombobox', 'label-message' => 'ep-course-edit-field', 'required' => true, 'options' => array_combine($fieldFields, $fieldFields));
     $levels = EPCourse::selectFields('level', array(), array('DISTINCT'));
     $levels = array_merge(array('' => ''), $levels);
     $fields['level'] = array('class' => 'EPHTMLCombobox', 'label-message' => 'ep-course-edit-level', 'required' => true, 'options' => array_combine($levels, $levels));
     $langOptions = EPUtils::getLanguageOptions($this->getLanguage()->getCode());
     $fields['lang'] = array('type' => 'select', 'label-message' => 'ep-course-edit-lang', 'maxlength' => 255, 'required' => true, 'options' => $langOptions, 'validation-callback' => function ($value, array $alldata = null) use($langOptions) {
         return in_array($value, $langOptions) ? true : wfMsg('ep-course-invalid-lang');
     });
     $fields['description'] = array('type' => 'textarea', 'label-message' => 'ep-course-edit-description', 'required' => true, 'validation-callback' => function ($value, array $alldata = null) {
         return strlen($value) < 10 ? wfMsgExt('ep-course-invalid-description', 'parsemag', 10) : true;
     }, 'rows' => 10, 'id' => 'wpTextbox1');
     return $this->processFormFields($fields);
 }
Exemplo n.º 3
0
 /**
  * (non-PHPdoc)
  * @see EPPager::getFilterOptions()
  */
 protected function getFilterOptions()
 {
     $options = array();
     $options['org_id'] = array('type' => 'select', 'options' => array_merge(array('' => ''), EPOrg::getOrgOptions(EPOrg::select(array('name', 'id')))), 'value' => '', 'datatype' => 'int');
     $terms = EPCourse::selectFields('term', array(), array('DISTINCT'), array(), true);
     natcasesort($terms);
     $terms = array_merge(array(''), $terms);
     $terms = array_combine($terms, $terms);
     $options['term'] = array('type' => 'select', 'options' => $terms, 'value' => '');
     //		$options['lang'] = array(
     //			'type' => 'select',
     //			'options' => EPUtils::getLanguageOptions( $this->getLanguage()->getCode() ),
     //			'value' => '',
     //		);
     $options['status'] = array('type' => 'select', 'options' => array_merge(array('' => ''), EPCourse::getStatuses()), 'value' => 'current');
     return $options;
 }