Exemple #1
0
/**
 * Load level list from bd table mdl_rcommon_level
 * @return array with the loaded data
 */
function rcontent_level_list()
{
    global $CFG, $DB;
    $return[0] = '- ' . get_string('level', 'rcontent') . ' -';
    if ($records = rcommon_level::get_by_format('webcontent')) {
        foreach ($records as $r) {
            $return[$r->id] = $r->name . ' (' . $r->code . ')';
        }
    }
    return $return;
}
Exemple #2
0
 public static function add_update($record)
 {
     global $DB;
     if (empty($record->isbn)) {
         return false;
     }
     // Check that book name isn't larger than 255 characters
     if (core_text::strlen($record->name) > 255) {
         $record->name = core_text::substr($record->name, 0, 255);
     }
     // Check that book summary isn't larger than 1024 characters
     if (core_text::strlen($record->summary) > 1024) {
         $record->summary = core_text::substr($record->summary, 0, 1024);
     }
     $record->format = core_text::strtolower($record->format);
     $record->levelid = rcommon_level::get_create_by_code($record->levelid);
     // Test that de obligatory fields aren't empty
     $obligatoryarray = array('isbn', 'levelid', 'format', 'summary');
     foreach ($obligatoryarray as $value) {
         if (empty($record->{$value})) {
             throw new Exception('Required parameter <strong>' . $value . ' not found!</strong>');
         }
     }
     $record->timemodified = time();
     if (!($bookid = $DB->get_field('rcommon_books', 'id', array('isbn' => $record->isbn)))) {
         $record->timecreated = $record->timemodified;
         return $DB->insert_record('rcommon_books', $record);
     } else {
         $record->id = $bookid;
         if ($DB->update_record('rcommon_books', $record)) {
             return $bookid;
         }
     }
     return false;
 }