Esempio n. 1
0
 /**
  * Make sure that several settings are set
  * for the rest of the class to use.
  *
  * Items that are set:
  *   course
  *   title
  *   config->taskorder
  *   config->display
  *   baseurl
  *   tasks
  *
  * @uses $CFG
  * @return void
  **/
 function specialization()
 {
     global $CFG, $COURSE;
     // Set the course
     $this->course = $COURSE;
     // Set title
     if (isset($this->config->title)) {
         $this->title = format_text($this->config->title, FORMAT_HTML);
     } else {
         if (isset($CFG->block_task_list_title)) {
             $this->title = format_text($CFG->block_task_list_title, FORMAT_HTML);
         }
     }
     if (!isset($this->config->taskorder)) {
         $this->config->taskorder = '';
     }
     if (!isset($this->config->categorywordwrap)) {
         $this->config->categorywordwrap = 45;
     }
     if (!isset($this->config->display) or $this->course->format != 'page') {
         $this->config->display = 'normal';
     }
     // Get the tasks
     if (!($this->tasks = get_records('block_task_list', 'instanceid', $this->instance->id))) {
         $this->tasks = array();
     }
 }
Esempio n. 2
0
function question_cwqpfs_to_update($categories = null)
{
    global $CFG;
    $tofix = array();
    $result = true;
    //any cats with questions picking from subcats?
    if (!($cwqpfs = get_records_sql_menu("SELECT DISTINCT qc.id, 1 " . "FROM {$CFG->prefix}question q, {$CFG->prefix}question_categories qc " . "WHERE q.qtype='random' AND qc.id = q.category AND " . sql_compare_text('q.questiontext') . " = '1'"))) {
        return array();
    } else {
        if ($categories === null) {
            $categories = get_records('question_categories');
        }
        $categorychildparents = array();
        foreach ($categories as $id => $category) {
            $categorychildparents[$category->course][$id] = $category->parent;
        }
        foreach ($categories as $id => $category) {
            if (FALSE !== array_key_exists($category->parent, $categorychildparents[$category->course])) {
                //this is not a top level cat
                continue;
                //go to next category
            } else {
                $tofix += question_cwqpfs_check_children($id, $categories, $categorychildparents[$category->course], $cwqpfs);
            }
        }
    }
    return $tofix;
}
Esempio n. 3
0
 function choice_get_response_data($choice, $cm, $groupmode)
 {
     global $CFG, $USER;
     $context = get_context_instance(CONTEXT_MODULE, $cm->id);
     /// Get the current group
     if ($groupmode > 0) {
         $currentgroup = groups_get_activity_group($cm);
     } else {
         $currentgroup = 0;
     }
     /// Initialise the returned array, which is a matrix:  $allresponses[responseid][userid] = responseobject
     $allresponses = array();
     /// First get all the users who have access here
     /// To start with we assume they are all "unanswered" then move them later
     $allresponses[0] = get_users_by_capability($context, 'mod/choice:choose', 'u.id, u.picture, u.firstname, u.lastname, u.idnumber', 'u.firstname ASC', '', '', $currentgroup, '', false, true);
     /// Get all the recorded responses for this choice
     $rawresponses = get_records('choice_answers', 'choiceid', $choice->id);
     /// Use the responses to move users into the correct column
     if ($rawresponses) {
         foreach ($rawresponses as $response) {
             if (isset($allresponses[0][$response->userid])) {
                 // This person is enrolled and in correct group
                 $allresponses[0][$response->userid]->timemodified = $response->timemodified;
                 $allresponses[$response->optionid][$response->userid] = clone $allresponses[0][$response->userid];
                 unset($allresponses[0][$response->userid]);
                 // Remove from unanswered column
             }
         }
     }
     return $allresponses;
 }
function webquest_upgrade($oldversion)
{
    /// This function does anything necessary to upgrade
    /// older versions to match current functionality
    $status = true;
    global $CFG;
    if ($oldversion < 2007081222) {
        require_once $CFG->dirroot . '/backup/lib.php';
        //make the change into each course
        $courses = get_records("course");
        foreach ($courses as $course) {
            $newdir = "{$course->id}/{$CFG->moddata}/webquest";
            if (make_upload_directory($newdir)) {
                $olddir = "{$CFG->dataroot}/{$course->id}/{$CFG->moddata}/webquest/submissions";
                //chec k if the old directory exists
                if (is_dir($olddir)) {
                    $status = backup_copy_file($olddir, $CFG->dataroot . "/" . $newdir);
                }
                if ($status) {
                    fulldelete($olddir);
                }
            }
        }
    }
    return $status;
}
 function print_filter(&$mform)
 {
     global $CFG;
     $filter_categories = optional_param('filter_categories', 0, PARAM_INT);
     $reportclassname = 'report_' . $this->report->type;
     $reportclass = new $reportclassname($this->report);
     if ($this->report->type != 'sql') {
         $components = cr_unserialize($this->report->components);
         $conditions = $components['conditions'];
         $categorieslist = $reportclass->elements_by_conditions($conditions);
     } else {
         $categorieslist = array_keys(get_records('course'));
     }
     $courseoptions = array();
     $courseoptions[0] = get_string('choose');
     if (!empty($categorieslist)) {
         $categories = get_records_select('course_categories', 'id in (' . implode(',', $categorieslist) . ')');
         foreach ($categories as $c) {
             $courseoptions[$c->id] = format_string($c->name);
         }
     }
     $select =& $mform->addElement('select', 'filter_categories', get_string('category'), $courseoptions);
     $select->setMultiple(true);
     $mform->setType('filter_categories', PARAM_INT);
 }
/**
 *
 */
function scheduler_backup_one_mod($bf, $preferences, $scheduler)
{
    global $CFG;
    if (is_numeric($scheduler)) {
        $scheduler = get_record('scheduler', 'id', $scheduler);
    }
    $status = true;
    //Start mod
    $status = $status && fwrite($bf, start_tag('MOD', 3, true));
    //Print scheduler data
    fwrite($bf, full_tag('ID', 4, false, $scheduler->id));
    fwrite($bf, full_tag('MODTYPE', 4, false, 'scheduler'));
    fwrite($bf, full_tag('NAME', 4, false, $scheduler->name));
    fwrite($bf, full_tag('DESCRIPTION', 4, false, $scheduler->description));
    fwrite($bf, full_tag('TEACHER', 4, false, $scheduler->teacher));
    fwrite($bf, full_tag('SCALE', 4, false, $scheduler->scale));
    fwrite($bf, full_tag('STAFFROLENAME', 4, false, $scheduler->staffrolename));
    fwrite($bf, full_tag('SCHEDULERMODE', 4, false, $scheduler->schedulermode));
    fwrite($bf, full_tag('REUSEGUARDTIME', 4, false, $scheduler->reuseguardtime));
    fwrite($bf, full_tag('DEFAULTSLOTDURATION', 4, false, $scheduler->defaultslotduration));
    fwrite($bf, full_tag('ALLOWNOTIFICATIONS', 4, false, $scheduler->allownotifications));
    fwrite($bf, full_tag('TIMEMODIFIED', 4, false, $scheduler->timemodified));
    //if we've selected to backup users info, then execute backup_scheduler_slots and appointments
    if ($preferences->mods['scheduler']->userinfo) {
        $scheduler_slots = get_records('scheduler_slots', 'schedulerid', $scheduler->id, 'id');
        $status = $status && backup_scheduler_slots($bf, $preferences, $scheduler->id, $scheduler_slots);
        $status = $status && backup_scheduler_appointments($bf, $preferences, $scheduler_slots);
    }
    //End mod
    $status = $status && fwrite($bf, end_tag('MOD', 3, true));
    return $status;
}
Esempio n. 7
0
/**
* Create connection to an RQP server of required type if it does not already exist
*
* If the global array $remote_connections does not already have an entry for this
* server type then it randomly goes through the existing servers and tries to connect
* using rqp_connect(). The connection is then added to the $remote_connections array.
* If the function fails to connect to any server it returns false.
* @param string $typeid  The type of the RQP server
* @return boolean  Indicates success or failure
*
* @todo flag dead servers
*/
function remote_connect($typeid)
{
    global $remote_connections;
    if (!array_key_exists($typeid, $remote_connections)) {
        // get the available servers
        if (!($servers = get_records('question_rqp_servers', 'typeid', $typeid))) {
            // we don't have a server for this question type
            return false;
        }
        // put them in a random order
        shuffle($servers);
        // go through them and try to connect to each until we are successful
        foreach ($servers as $server) {
            if ($remote_connections[$typeid] = rqp_connect($server->url)) {
                break;
                // we have a connection
            } else {
                // We have a dead server here, should somehow flag that
            }
        }
    }
    // check that we did get a connection
    if (!$remote_connections[$typeid]) {
        unset($remote_connections[$typeid]);
        return false;
    }
    return true;
}
 function validation($data, $files)
 {
     global $db, $CFG;
     $errors = parent::validation($data, $files);
     if (!in_array($data['operator'], $this->allowedops)) {
         $errors['operator'] = get_string('error_operator', 'block_configurable_reports');
     }
     $columns = $db->MetaColumns($CFG->prefix . 'user');
     $usercolumns = array();
     foreach ($columns as $c) {
         $usercolumns[$c->name] = $c->name;
     }
     if ($profile = get_records('user_info_field')) {
         foreach ($profile as $p) {
             $usercolumns['profile_' . $p->shortname] = 'profile_' . $p->shortname;
         }
     }
     if (!in_array($data['field'], $usercolumns)) {
         $errors['field'] = get_string('error_field', 'block_configurable_reports');
     }
     if (!is_numeric($data['value']) && preg_match('/^(<|>)[^(<|>)]/i', $data['operator'])) {
         $errors['value'] = get_string('error_value_expected_integer', 'block_configurable_reports');
     }
     return $errors;
 }
Esempio n. 9
0
function backup_slideshow_captions($bf, $preferences, $slideshow)
{
    global $CFG;
    $status = true;
    $slideshow_captions = get_records("slideshow_captions", "slideshow", $slideshow->instance);
    //If there is captions
    if ($slideshow_captions) {
        //Write start tag
        $status = fwrite($bf, start_tag("CAPTIONS", 4, true));
        //Iterate over each caption
        foreach ($slideshow_captions as $sli_cap) {
            //Start caption
            $status = fwrite($bf, start_tag("CAPTION", 5, true));
            //Print caption contents
            fwrite($bf, full_tag("ID", 6, false, $sli_cap->id));
            fwrite($bf, full_tag("SLIDESHOW", 6, false, $sli_cap->slideshow));
            fwrite($bf, full_tag("IMAGE", 6, false, $sli_cap->image));
            fwrite($bf, full_tag("TITLE", 6, false, $sli_cap->title));
            fwrite($bf, full_tag("CAPTION", 6, false, $sli_cap->caption));
            //End submission
            $status = fwrite($bf, end_tag("CAPTION", 5, true));
        }
        //Write end tag
        $status = fwrite($bf, end_tag("CAPTIONS", 4, true));
    }
    return $status;
}
Esempio n. 10
0
function backup_chat_messages($bf, $preferences, $chat)
{
    global $CFG;
    $status = true;
    $chat_messages = get_records("chat_messages", "chatid", $chat, "id");
    //If there is messages
    if ($chat_messages) {
        //Write start tag
        $status = fwrite($bf, start_tag("MESSAGES", 4, true));
        //Iterate over each message
        foreach ($chat_messages as $cha_mes) {
            //Start message
            $status = fwrite($bf, start_tag("MESSAGE", 5, true));
            //Print message contents
            fwrite($bf, full_tag("ID", 6, false, $cha_mes->id));
            fwrite($bf, full_tag("USERID", 6, false, $cha_mes->userid));
            fwrite($bf, full_tag("GROUPID", 6, false, $cha_mes->groupid));
            fwrite($bf, full_tag("SYSTEM", 6, false, $cha_mes->system));
            fwrite($bf, full_tag("MESSAGE_TEXT", 6, false, $cha_mes->message));
            fwrite($bf, full_tag("TIMESTAMP", 6, false, $cha_mes->timestamp));
            //End submission
            $status = fwrite($bf, end_tag("MESSAGE", 5, true));
        }
        //Write end tag
        $status = fwrite($bf, end_tag("MESSAGES", 4, true));
    }
    return $status;
}
Esempio n. 11
0
function backup_adobeconnect_meeting_groups($bf, $preferences, $adobeconnectid)
{
    global $CFG;
    // Set status to false because there must be at least one meeting instance
    $status = false;
    // Go through all of the meeting instances and backup each group's meeting
    if ($meetgroups = get_records("adobeconnect_meeting_groups", 'instanceid', $adobeconnectid)) {
        if ($meetgroups) {
            //Write start tag
            $status = fwrite($bf, start_tag("MEETINGGROUPS", 4, true));
            //Iterate over each meeting instance
            foreach ($meetgroups as $meetgroup) {
                //Start of meeting group instance
                $status = fwrite($bf, start_tag("MEETINGGROUP", 5, true));
                fwrite($bf, full_tag("ID", 6, false, $meetgroup->id));
                fwrite($bf, full_tag("INSTANCEID", 6, false, $meetgroup->instanceid));
                fwrite($bf, full_tag("MEETINGSCOID", 6, false, $meetgroup->meetingscoid));
                fwrite($bf, full_tag("GROUPID", 6, false, $meetgroup->groupid));
                //End of meeting group instance
                $status = fwrite($bf, end_tag("MEETINGGROUP", 5, true));
            }
            //Write end tag
            $status = fwrite($bf, end_tag("MEETINGGROUPS", 4, true));
        }
    }
    return $status;
}
function backup_book_chapters($bf, $preferences, $book)
{
    global $CFG;
    $status = true;
    //Print book's chapters
    if ($chapters = get_records('book_chapters', 'bookid', $book->id, 'id')) {
        //Write start tag
        $status = fwrite($bf, start_tag('CHAPTERS', 4, true));
        foreach ($chapters as $ch) {
            //Start chapter
            fwrite($bf, start_tag('CHAPTER', 5, true));
            //Print chapter data
            fwrite($bf, full_tag('ID', 6, false, $ch->id));
            fwrite($bf, full_tag('PAGENUM', 6, false, $ch->pagenum));
            fwrite($bf, full_tag('SUBCHAPTER', 6, false, $ch->subchapter));
            fwrite($bf, full_tag('TITLE', 6, false, $ch->title));
            fwrite($bf, full_tag('CONTENT', 6, false, $ch->content));
            fwrite($bf, full_tag('HIDDEN', 6, false, $ch->hidden));
            fwrite($bf, full_tag('TIMECREATED', 6, false, $ch->timecreated));
            fwrite($bf, full_tag('TIMEMODIFIED', 6, false, $ch->timemodified));
            fwrite($bf, full_tag('IMPORTSRC', 6, false, $ch->importsrc));
            //End chapter
            $status = fwrite($bf, end_tag('CHAPTER', 5, true));
        }
        //Write end tag
        $status = fwrite($bf, end_tag('CHAPTERS', 4, true));
    }
    return $status;
}
function backup_map_locations($bf, $preferences, $map)
{
    global $CFG;
    $status = true;
    $map_locations = get_records("map_locations", "mapid", $map, "id");
    //If there is locations
    if ($map_locations) {
        //Write start tag
        $status = fwrite($bf, start_tag("LOCATIONS", 4, true));
        //Iterate over each answer
        foreach ($map_locations as $map_location) {
            //Start answer
            $status = fwrite($bf, start_tag("LOCATION", 5, true));
            //Print location contents
            fwrite($bf, full_tag("ID", 6, false, $map_location->id));
            fwrite($bf, full_tag("USERID", 6, false, $map_location->userid));
            fwrite($bf, full_tag("TITLE", 6, false, $map_location->title));
            fwrite($bf, full_tag("SHOWCODE", 6, false, $map_location->showcode));
            fwrite($bf, full_tag("LATITUDE", 6, false, $map_location->latitude));
            fwrite($bf, full_tag("LONGITUDE", 6, false, $map_location->longitude));
            fwrite($bf, full_tag("ADDRESS", 6, false, $map_location->address));
            fwrite($bf, full_tag("CITY", 6, false, $map_location->city));
            fwrite($bf, full_tag("STATE", 6, false, $map_location->state));
            fwrite($bf, full_tag("COUNTRY", 6, false, $map_location->country));
            fwrite($bf, full_tag("TEXT", 6, false, $map_location->text));
            fwrite($bf, full_tag("TIMEMODIFIED", 6, false, $map_location->timemodified));
            //End answer
            $status = fwrite($bf, end_tag("LOCATION", 5, true));
        }
        //Write end tag
        $status = fwrite($bf, end_tag("LOCATIONS", 4, true));
    }
    return $status;
}
function block_exabis_eportfolio_print_extcomments($itemid)
{
    $stredit = get_string('edit');
    $strdelete = get_string('delete');
    $comments = get_records("block_exabeporitemcomm", "itemid", $itemid, 'timemodified DESC');
    if (!$comments) {
        return;
    }
    foreach ($comments as $comment) {
        $user = get_record('user', 'id', $comment->userid);
        echo '<table cellspacing="0" class="forumpost blogpost blog" width="100%">';
        echo '<tr class="header"><td class="picture left">';
        print_user_picture($comment->userid, SITEID, $user->picture);
        echo '</td>';
        echo '<td class="topic starter"><div class="author">';
        $fullname = fullname($user, $comment->userid);
        $by = new object();
        $by->name = $fullname;
        $by->date = userdate($comment->timemodified);
        print_string('bynameondate', 'forum', $by);
        echo '</div></td></tr>';
        echo '<tr><td class="left side">';
        echo '</td><td class="content">' . "\n";
        echo format_text($comment->entry);
        echo '</td></tr></table>' . "\n\n";
    }
}
Esempio n. 15
0
function glossary_rss_feeds()
{
    global $CFG;
    $status = true;
    //Check CFG->enablerssfeeds
    if (empty($CFG->enablerssfeeds)) {
        debugging("DISABLED (admin variables)");
        //Check CFG->glossary_enablerssfeeds
    } else {
        if (empty($CFG->glossary_enablerssfeeds)) {
            debugging("DISABLED (module configuration)");
            //It's working so we start...
        } else {
            //Iterate over all glossaries
            if ($glossaries = get_records("glossary")) {
                foreach ($glossaries as $glossary) {
                    if (!empty($glossary->rsstype) && !empty($glossary->rssarticles) && $status) {
                        $filename = rss_file_name('glossary', $glossary);
                        // RSS file
                        //First let's make sure there is work to do by checking existing files
                        if (file_exists($filename)) {
                            if ($lastmodified = filemtime($filename)) {
                                if (!glossary_rss_newstuff($glossary, $lastmodified)) {
                                    continue;
                                }
                            }
                        }
                        //Ignore hidden forums
                        if (!instance_is_visible('glossary', $glossary)) {
                            if (file_exists($filename)) {
                                @unlink($filename);
                            }
                            continue;
                        }
                        mtrace("Updating RSS feed for " . format_string($glossary->name, true) . ", ID: {$glossary->id}");
                        //Get the XML contents
                        $result = glossary_rss_feed($glossary);
                        //Save the XML contents to file
                        if (!empty($result)) {
                            $status = rss_save_file("glossary", $glossary, $result);
                        }
                        //Some debug...
                        if (debugging()) {
                            if (empty($result)) {
                                echo "ID: {$glossary->id}-> (empty) ";
                            } else {
                                if (!empty($status)) {
                                    echo "ID: {$glossary->id}-> OK ";
                                } else {
                                    echo "ID: {$glossary->id}-> FAIL ";
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return $status;
}
 /**
  * Constructor - basic setup
  *
  * @param int $pagemenuid Page menu instance ID
  * @param array $links Page menu link records that belong to this page menu
  * @param array $data Link data for the links
  * @param int $firstlinkid First link ID
  * @return void
  **/
 public function __construct($pagemenuid, $links = NULL, $data = NULL, $firstlinkid = false)
 {
     $this->pagemenuid = $pagemenuid;
     if ($links === NULL) {
         $links = get_records('pagemenu_links', 'pagemenuid', $this->pagemenuid);
     }
     if (!$firstlinkid) {
         $firstlinkid = pagemenu_get_first_linkid($this->pagemenuid);
     }
     if ($data === NULL) {
         if (!empty($links)) {
             $data = pagemenu_get_link_data($links);
         } else {
             $data = array();
         }
     }
     if (!empty($links) and !empty($firstlinkid)) {
         $linkid = $firstlinkid;
         while ($linkid) {
             if (array_key_exists($linkid, $data)) {
                 $datum = $data[$linkid];
             } else {
                 $datum = NULL;
             }
             $link = $links[$linkid];
             $linkid = $link->nextid;
             $this->links[$link->id] = mod_pagemenu_link::factory($link->type, $link, $datum);
         }
     }
     $this->init();
 }
 /**
  *	Sharing Cart ブロック内でのアイテム表示順の通し番号を振りなおす
  */
 public static function renumber($user_id = NULL)
 {
     if (empty($user_id)) {
         $user_id = $GLOBALS['USER']->id;
     }
     if ($records = get_records('sharing_cart', 'user', $user_id)) {
         $tree = array();
         foreach ($records as $record) {
             if (!isset($tree[$record->tree])) {
                 $tree[$record->tree] = array();
             }
             $tree[$record->tree][] = $record;
         }
         foreach ($tree as $items) {
             usort($items, array(__CLASS__, 'renumber_cmp'));
             foreach ($items as $i => $item) {
                 $item->sort = $i;
                 $item->text = addslashes($item->text);
                 if (!update_record('sharing_cart', $item)) {
                     return FALSE;
                 }
             }
         }
     }
     return TRUE;
 }
Esempio n. 18
0
 function validation($data, $files)
 {
     $errors = parent::validation($data, $files);
     $foundcourses = null;
     $foundreqcourses = null;
     if (!empty($data['shortname'])) {
         $foundcourses = get_records('course', 'shortname', $data['shortname']);
         $foundreqcourses = get_records('course_request', 'shortname', $data['shortname']);
     }
     if (!empty($foundreqcourses)) {
         if (!empty($foundcourses)) {
             $foundcourses = array_merge($foundcourses, $foundreqcourses);
         } else {
             $foundcourses = $foundreqcourses;
         }
     }
     if (!empty($foundcourses)) {
         foreach ($foundcourses as $foundcourse) {
             if (!empty($foundcourse->requester)) {
                 $pending = 1;
                 $foundcoursenames[] = $foundcourse->fullname . ' [*]';
             } else {
                 $foundcoursenames[] = $foundcourse->fullname;
             }
         }
         $foundcoursenamestring = implode(',', $foundcoursenames);
         $errors['shortname'] = get_string('shortnametaken', '', $foundcoursenamestring);
         if (!empty($pending)) {
             $errors['shortname'] .= get_string('starpending');
         }
     }
     return $errors;
 }
Esempio n. 19
0
 function __construct($data)
 {
     global $COURSE;
     parent::__construct($data);
     $this->type = 'datarecord';
     $this->fields = array();
     // fields are only used for pointing a data record
     $datainstances = get_records('data', 'course', $COURSE->id, '', 'id,name');
     foreach ($datainstances as $data) {
         $dataopts[] = $data->name;
     }
     unset($field);
     $field->name = 'key';
     $field->type = 'list';
     $field->options = $datainstances;
     $field->admin = true;
     $this->fields['key'] = $field;
     unset($field);
     $field->name = 'key';
     $field->type = 'list';
     $field->options = 'list';
     $field->admin = true;
     $this->fields['key'] = $field;
     $this->datasource = array('USER/id', 'USER/login', 'COURSE/id', 'COURSE/shortname', 'COURSE/category');
     unset($field);
     $field->name = 'keysource';
     $field->type = 'list';
     $field->options = $sourceopts;
     $field->admin = true;
     $this->fields['keysource'] = $field;
 }
Esempio n. 20
0
function backup_journal_entries($bf, $preferences, $journal)
{
    global $CFG;
    $status = true;
    $journal_entries = get_records("journal_entries", "journal", $journal, "id");
    //If there is entries
    if ($journal_entries) {
        //Write start tag
        $status = fwrite($bf, start_tag("ENTRIES", 4, true));
        //Iterate over each entry
        foreach ($journal_entries as $jou_ent) {
            //Start entry
            $status = fwrite($bf, start_tag("ENTRY", 5, true));
            //Print journal_entries contents
            fwrite($bf, full_tag("ID", 6, false, $jou_ent->id));
            fwrite($bf, full_tag("USERID", 6, false, $jou_ent->userid));
            fwrite($bf, full_tag("MODIFIED", 6, false, $jou_ent->modified));
            fwrite($bf, full_tag("TEXT", 6, false, $jou_ent->text));
            fwrite($bf, full_tag("FORMAT", 6, false, $jou_ent->format));
            fwrite($bf, full_tag("RATING", 6, false, $jou_ent->rating));
            fwrite($bf, full_tag("ENTRYCOMMENT", 6, false, $jou_ent->entrycomment));
            fwrite($bf, full_tag("TEACHER", 6, false, $jou_ent->teacher));
            fwrite($bf, full_tag("TIMEMARKED", 6, false, $jou_ent->timemarked));
            fwrite($bf, full_tag("MAILED", 6, false, $jou_ent->mailed));
            //End entry
            $status = fwrite($bf, end_tag("ENTRY", 5, true));
        }
        //Write end tag
        $status = fwrite($bf, end_tag("ENTRIES", 4, true));
    }
    return $status;
}
function backup_certificate_issues($bf, $preferences, $certificateid)
{
    global $CFG;
    $status = true;
    $certificate_issues = get_records("certificate_issues", "certificateid", $certificateid);
    //If there is issues
    if ($certificate_issues) {
        //Write start tag
        $status = fwrite($bf, start_tag("ISSUES", 4, true));
        //Iterate over each issue
        foreach ($certificate_issues as $cert_iss) {
            //Start issues
            $status = fwrite($bf, start_tag("ISSUE", 5, true));
            //Print viewed contents
            fwrite($bf, full_tag("ID", 6, false, $cert_iss->id));
            fwrite($bf, full_tag("CERTIFICATEID", 6, false, $cert_iss->certificateid));
            fwrite($bf, full_tag("USERID", 6, false, $cert_iss->userid));
            fwrite($bf, full_tag("TIMECREATED", 6, false, $cert_iss->timecreated));
            fwrite($bf, full_tag("STUDENTNAME", 6, false, $cert_iss->studentname));
            fwrite($bf, full_tag("CODE", 6, false, $cert_iss->code));
            fwrite($bf, full_tag("CLASSNAME", 6, false, $cert_iss->classname));
            fwrite($bf, full_tag("CERTDATE", 6, false, $cert_iss->certdate));
            fwrite($bf, full_tag("SENT", 6, false, $cert_iss->sent));
            fwrite($bf, full_tag("MAILED", 6, false, $cert_iss->mailed));
            fwrite($bf, full_tag("CREDITS", 6, false, $cert_iss->credits));
            fwrite($bf, full_tag("GRADE", 6, false, $cert_iss->grade));
            //End viewed
            $status = fwrite($bf, end_tag("ISSUE", 5, true));
        }
        //Write end tag
        $status = fwrite($bf, end_tag("ISSUES", 4, true));
    }
    return $status;
}
Esempio n. 22
0
 /**
  *
  */
 function Post($post_id = null)
 {
     $this->exists = false;
     // Parameter passed, assume an existing post
     if ($post_id != null) {
         if ($post = get_record('weblog_posts', 'ident', $post_id)) {
             $this->ident = $post->ident;
             $this->owner = $post->owner;
             $this->blog_id = $post->weblog;
             $this->access = $post->access;
             $this->posted = $post->posted;
             $this->title = $post->title;
             $this->body = $post->body;
             // Get the weblog context
             $this->weblog = run('weblogs:instance', array('user_id' => $this->owner, 'blog_id' => $this->blog_id));
             // Does the requested id exist
             $this->exists = true;
         }
         if ($post_tags = get_records('tags', 'tagtype', 'weblog', 'ref', $post_id)) {
             // An aray of Tag objects
             foreach ($post_tags as $tag) {
                 $this->tags[] = $tag->ident;
             }
         }
         if ($post_comments = get_records('weblog_comments', 'post_id', $post_id)) {
             foreach ($post_comments as $comment) {
                 $this->comments[] = $comment->ident;
             }
         }
     }
 }
Esempio n. 23
0
 function get_string($key)
 {
     global $USER;
     static $strings, $fallback;
     if (!isset($strings)) {
         $s = get_records('podcaster_language', 'language', $USER->lang);
         $strings = array();
         foreach ($s as $str) {
             $strings[$str->name] = $str->value;
         }
         if ($USER->lang != 'en_utf8') {
             $fallback = array();
             $f = get_records('podcaster_language', 'language', 'en_utf8');
             foreach ($f as $str) {
                 $fallback[$str->name] = $str->value;
             }
         } else {
             $fallback = $strings;
         }
     }
     if (!isset($strings[$key])) {
         if (isset($fallback[$key])) {
             return $fallback[$key];
         }
         return '[[' . $key . ']]';
     }
     return $strings[$key];
 }
function quizcopy_add_instance(&$quizcopy)
{
    $cmid = $quizcopy->quiz;
    $name = $quizcopy->name;
    $cm = get_coursemodule_from_id('quiz', $cmid);
    if (!($quiz = get_record('quiz', 'id', $cm->instance))) {
        print_error('error', 'quizcopy');
    }
    $origquiz = $quiz->id;
    unset($quiz->id);
    // remove single quote to prevent SQL errors (nadavkav 11-6-11)
    $quiz->name = str_replace("'", '', $name);
    $quiz->intro = str_replace("'", '', $quiz->intro);
    if (!($quiz->id = insert_record('quiz', $quiz))) {
        print_error('error', 'quizcopy');
    }
    $newquestions = array();
    if (!is_null($quiz->questions) && !empty($quiz->questions)) {
        $questions = explode(',', $quiz->questions);
        foreach ($questions as $question) {
            $newquestions[] = $question;
            if ($question != 0) {
                if (!($instance_object = get_record('quiz_question_instances', 'quiz', $origquiz, 'question', $question))) {
                    print_error('error', 'quizcopy');
                }
                unset($instance_object->id);
                $instance_object->quiz = $quiz->id;
                if (!insert_record('quiz_question_instances', $instance_object)) {
                    print_error('error', 'quizcopy');
                }
            }
        }
    }
    if ($feedbacks = get_records('quiz_feedback', 'quizid', $origquiz, 'maxgrade DESC')) {
        $i = 0;
        $quiz->feedbacktext = array();
        $quiz->feedbackboundaries = array();
        foreach ($feedbacks as $feedback) {
            $quiz->feedbacktext[$i] = $feedback->feedbacktext;
            $quiz->feedbackboundaries[$i] = $feedback->mingrade;
            $quiz->feedbackboundaries[$i - 1] = $feedback->maxgrade;
            $i++;
        }
        $quiz->feedbackboundarycount = $i - 1;
    }
    $quiz->questions = implode(',', $newquestions);
    if (!update_record('quiz', $quiz)) {
        print_error('error', 'quizcopy');
    }
    $quizcopy->timecreated = time();
    $quizcopy->module = $cm->module;
    $quizcopy->modulename = 'quiz';
    $quizcopy->visible = $cm->visible;
    $quizcopy->groupmode = $cm->groupmode;
    $quizcopy->groupmembersonly = $cm->groupmembersonly;
    $quizcopy->module = $cm->module;
    quiz_after_add_or_update($quiz);
    return $quiz->id;
}
Esempio n. 25
0
/**
 * Gets data linking a grouping to each group it contains.
 * @param int $groupingid The ID of the grouping.
 * @return array | false An array of grouping-group records, or false on error.
 */
function groups_get_groups_in_grouping_records($groupingid)
{
    if (!$groupingid) {
        return false;
    }
    $grouping_groups = get_records('groups_groupings_groups', 'groupingid ', $groupingid, '', $fields = 'id, groupid, timeadded');
    return $grouping_groups;
}
Esempio n. 26
0
/**
 * Get all tags from the records
 *
 * @param string $tag_types_csv (optional, default value is "default". If '*' is passed, tags of any type will be returned).
 * @param string $sort an order to sort the results in (optional, a valid SQL ORDER BY parameter).
 * @param string $fields a comma separated list of fields to return
 *   (optional, by default 'id, tagtype, name, rawname, flag'). The first field will be used as key for the
 *   array so must be a unique field such as 'id'.
 */
function get_all_tags($tag_types_csv = "default", $sort = 'name ASC', $fields = DEFAULT_TAG_TABLE_FIELDS)
{
    if ($tag_types_csv == '*') {
        return get_records('tag', '', '', $sort, $fields);
    }
    $tag_types_csv_with_apos = "'" . str_replace(',', "','", $tag_types_csv) . "'";
    return get_records_list('tag', 'tagtype', $tag_types_csv_with_apos, $sort, $fields);
}
/**
* part of search engine API
*
*/
function assignment_iterator()
{
    if ($assignments = get_records('assignment')) {
        return $assignments;
    } else {
        return array();
    }
}
/**
* part of standard API
*
*/
function label_iterator()
{
    //trick to leave search indexer functionality intact, but allow
    //this document to only use the below function to return info
    //to be searched
    $labels = get_records('label');
    return $labels;
}
 function execute($data, $user, $courseid)
 {
     $courses = get_records('course', 'category', $data->categoryid);
     if ($courses) {
         return array_keys($courses);
     }
     return array();
 }
Esempio n. 30
0
 public function testDelegatesToCollectionTable()
 {
     $params = array('foobar' => true);
     $limit = 5;
     $collection = new Collection();
     $this->collectionTable->expects($this->once())->method('findBy')->with($params, $limit)->will($this->returnValue(array($collection)));
     $this->assertEquals(array($collection), get_records('Collection', $params, $limit));
 }