/**
 * Basically a batch script to blindly send all current hubsite emails and 
 * contactable/subscribing status to Sendy @ lists.moodle.org.
 * 
 * This was created since running a long sync like this during a live upgrade 
 * would be a little too silly. Hub will update the list on demand whenever a 
 * site is modified.
 * 
 * @copyright  2014 Aparup Banerjee
 */
define('CLI_SCRIPT', true);
require '../../../../config.php';
require_once $CFG->libdir . '/clilib.php';
// cli only functions
// now get cli options
list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help'));
if ($unrecognized) {
    $unrecognized = implode("\n  ", $unrecognized);
    cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
}
if ($options['help']) {
    $help = "Execute subscribers sync to sendy on lists.moodle.org enmasse\n\nOptions:\n-h, --help            Print out this help\n\nExample:\n\$sudo -u vh-moodlenet /usr/bin/php local/hub/admin/cli/syncsubscribers_sendy.php\n";
    echo $help;
    die;
}
require $CFG->dirroot . '/local/hub/lib.php';
$hub = new local_hub();
raise_memory_limit(MEMORY_HUGE);
$sites = $hub->get_sites();
update_sendy_list_batch($sites);
Exemplo n.º 2
0
/**
 * Optionally subscribe/unsubscribe the contactemail to/from a sendy mailing list.
 * Loads all sites associated with the supplied site contactemail and passes them to update_sendy_list_batch().
 * This is necessary because the emailalert property may be different on the various sites associated with a given email.
 * We can't subscribe or unsubscribe them based on a single site's value.
 *
 * @todo tobe in local_hub class or not? its a helper function for now for any functional expansion..
 *
 * @param $site a row from hub_site_directory
 */
function update_sendy_list($site)
{
    $hub = new local_hub();
    $sites = $hub->get_sites(array('contactemail' => $site->contactemail));
    update_sendy_list_batch($sites);
}
Exemplo n.º 3
0
    $sites = null;
    $options = array();
    if (!empty($fromform)) {
        if ($fromform->trusted != 'all') {
            $options['trusted'] = $fromform->trusted;
        }
        if ($fromform->countrycode != 'all') {
            $options['countrycode'] = $fromform->countrycode;
        }
        if ($fromform->language != 'all') {
            $options['language'] = $fromform->language;
        }
        //get courses
        $options['search'] = $search;
        $limitnum = MAXSITES;
        $sites = $hub->get_sites($options, $limitfrom, $limitnum);
        $limitfrom = $limitfrom + MAXSITES;
        $sitestotal = $hub->get_sites($options, 0, 0, true);
        if ($sitestotal > $limitfrom) {
            $urlparams = (array) $fromform;
            $urlparams['limitfrom'] = $limitfrom;
            $urlparams['submitbutton'] = 1;
            $urlparams['sesskey'] = sesskey();
            $managesitesurl = new moodle_url('/local/hub/admin/managesites.php', $urlparams);
            $moresiteshtml = html_writer::link($managesitesurl, 'More sites');
        }
    }
    //(search, none language, no onlyvisible)
    $contenthtml = $renderer->site_list($sites, true);
}
echo $OUTPUT->header();
Exemplo n.º 4
0
 public function definition()
 {
     global $CFG;
     $strrequired = get_string('required');
     $mform =& $this->_form;
     //set default value
     $search = $this->_customdata['search'];
     if (isset($this->_customdata['coverage'])) {
         $coverage = $this->_customdata['coverage'];
     } else {
         $coverage = 'all';
     }
     if (isset($this->_customdata['licence'])) {
         $licence = $this->_customdata['licence'];
     } else {
         $licence = 'all';
     }
     if (isset($this->_customdata['subject'])) {
         $subject = $this->_customdata['subject'];
     } else {
         $subject = 'all';
     }
     if (isset($this->_customdata['audience'])) {
         $audience = $this->_customdata['audience'];
     } else {
         $audience = 'all';
     }
     if (isset($this->_customdata['language'])) {
         $language = $this->_customdata['language'];
     } else {
         $language = current_language();
     }
     if (isset($this->_customdata['educationallevel'])) {
         $educationallevel = $this->_customdata['educationallevel'];
     } else {
         $educationallevel = 'all';
     }
     if (isset($this->_customdata['visibility'])) {
         $visibility = $this->_customdata['visibility'];
     } else {
         $visibility = COURSEVISIBILITY_NOTVISIBLE;
     }
     if (isset($this->_customdata['downloadable'])) {
         $downloadable = $this->_customdata['downloadable'];
     } else {
         $downloadable = 1;
     }
     if (isset($this->_customdata['siteid'])) {
         $siteid = $this->_customdata['siteid'];
     } else {
         $siteid = 'all';
     }
     if (isset($this->_customdata['lastmodified'])) {
         $lastmodified = $this->_customdata['lastmodified'];
     } else {
         $lastmodified = HUB_LASTMODIFIED_WEEK;
     }
     if (isset($this->_customdata['orderby'])) {
         $orderby = $this->_customdata['orderby'];
     } else {
         $orderby = 'newest';
     }
     $mform->addElement('header', 'site', get_string('search', 'local_hub'));
     $options = array(0 => get_string('enrollable', 'local_hub'), 1 => get_string('downloadable', 'local_hub'));
     if (key_exists('adminform', $this->_customdata)) {
         $options = array('all' => get_string('any')) + $options;
     }
     $mform->addElement('select', 'downloadable', get_string('enroldownload', 'local_hub'), $options);
     $mform->addHelpButton('downloadable', 'enroldownload', 'local_hub');
     $mform->setDefault('downloadable', $downloadable);
     //visible field
     //Note: doesn't matter if form html is hacked, index script does not return any invisible courses
     if (key_exists('adminform', $this->_customdata)) {
         $options = array();
         $options[COURSEVISIBILITY_ALL] = get_string('visibilityall', 'local_hub');
         $options[COURSEVISIBILITY_VISIBLE] = get_string('visibilityyes', 'local_hub');
         $options[COURSEVISIBILITY_NOTVISIBLE] = get_string('visibilityno', 'local_hub');
         $mform->addElement('select', 'visibility', get_string('visibility', 'local_hub'), $options);
         $mform->setDefault('visibility', $visibility);
         unset($options);
         $mform->addHelpButton('visibility', 'visibility', 'local_hub');
     }
     $options = array();
     $options['all'] = get_string('any');
     $options[HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub');
     $options[HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub');
     $options[HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub');
     $mform->addElement('select', 'audience', get_string('audience', 'local_hub'), $options);
     $mform->setDefault('audience', $audience);
     unset($options);
     $mform->addHelpButton('audience', 'audience', 'local_hub');
     if (key_exists('adminform', $this->_customdata)) {
         $options = array();
         $options['all'] = '-';
         $options[HUB_LASTMODIFIED_WEEK] = get_string('periodweek', 'local_hub');
         $options[HUB_LASTMODIFIED_FORTEENNIGHT] = get_string('periodforteennight', 'local_hub');
         $options[HUB_LASTMODIFIED_MONTH] = get_string('periodmonth', 'local_hub');
         $mform->addElement('select', 'lastmodified', get_string('lastmodified', 'local_hub'), $options);
         $mform->setDefault('lastmodified', $lastmodified);
         unset($options);
         $mform->addHelpButton('lastmodified', 'lastmodified', 'local_hub');
     }
     $options = array();
     $options['all'] = get_string('any');
     $options[HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub');
     $options[HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub');
     $options[HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub');
     $options[HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub');
     $options[HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub');
     $options[HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub');
     $options[HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub');
     $mform->addElement('select', 'educationallevel', get_string('educationallevel', 'local_hub'), $options);
     $mform->setDefault('educationallevel', $educationallevel);
     unset($options);
     $mform->addHelpButton('educationallevel', 'educationallevel', 'local_hub');
     require_once $CFG->dirroot . "/course/publish/lib.php";
     $publicationmanager = new course_publish_manager();
     $options = $publicationmanager->get_sorted_subjects();
     foreach ($options as $key => &$option) {
         $keylength = strlen($key);
         if ($keylength == 10) {
             $option = "  " . $option;
         } else {
             if ($keylength == 12) {
                 $option = "    " . $option;
             }
         }
     }
     $options = array_merge(array('all' => get_string('any')), $options);
     $mform->addElement('select', 'subject', get_string('subject', 'hub'), $options);
     $mform->setDefault('subject', $subject);
     unset($options);
     $mform->addHelpButton('subject', 'subject', 'local_hub');
     $this->init_javascript_enhancement('subject', 'smartselect', array('selectablecategories' => true, 'mode' => 'compact'));
     require_once $CFG->libdir . "/licenselib.php";
     $licensemanager = new license_manager();
     $licences = $licensemanager->get_licenses();
     $options = array();
     $options['all'] = get_string('any');
     foreach ($licences as $license) {
         $options[$license->shortname] = get_string($license->shortname, 'license');
     }
     $mform->addElement('select', 'licence', get_string('license'), $options);
     unset($options);
     $mform->addHelpButton('licence', 'licence', 'local_hub');
     $mform->setDefault('licence', $licence);
     //search for only language that exist in the course DB
     require_once $CFG->dirroot . "/local/hub/lib.php";
     $hub = new local_hub();
     $courseslanguages = $hub->get_courses_languages();
     $alllanguages = get_string_manager()->get_list_of_languages();
     $languages = array();
     foreach ($courseslanguages as $languagecode => $lang) {
         if (isset($alllanguages[$languagecode])) {
             $languages[$languagecode] = $alllanguages[$languagecode];
         }
     }
     asort($languages, SORT_LOCALE_STRING);
     $languages = array_merge(array('all' => get_string('any')), $languages);
     $mform->addElement('select', 'language', get_string('language'), $languages);
     $mform->setDefault('language', $language);
     $mform->addHelpButton('language', 'language', 'local_hub');
     $mform->addElement('select', 'orderby', get_string('orderby', 'local_hub'), array('newest' => get_string('orderbynewest', 'local_hub'), 'eldest' => get_string('orderbyeldest', 'local_hub'), 'fullname' => get_string('orderbyname', 'local_hub'), 'publisher' => get_string('orderbypublisher', 'local_hub'), 'ratingaverage' => get_string('orderbyratingaverage', 'local_hub')));
     $mform->setDefault('orderby', $orderby);
     $mform->setType('orderby', PARAM_ALPHA);
     $mform->addHelpButton('orderby', 'orderby', 'local_hub');
     $mform->setAdvanced('audience');
     $mform->setAdvanced('educationallevel');
     $mform->setAdvanced('subject');
     $mform->setAdvanced('licence');
     $mform->setAdvanced('language');
     $mform->setAdvanced('orderby');
     if (key_exists('adminform', $this->_customdata)) {
         if ($hub->get_sites(array(), 0, 0, true) < 100) {
             // field not humanly usable over 100 sites.
             $sites = $hub->get_sites();
             $siteids = array();
             foreach ($sites as $site) {
                 $siteids[$site->id] = $site->name;
             }
             asort($siteids, SORT_LOCALE_STRING);
             $siteids = array('all' => get_string('any')) + $siteids;
             $mform->addElement('select', 'siteid', get_string('site', 'local_hub'), $siteids);
             $mform->setDefault('siteid', $siteid);
             $mform->addHelpButton('siteid', 'site', 'local_hub');
         }
     }
     $mform->addElement('text', 'search', get_string('keywords', 'local_hub'));
     $mform->setType('search', PARAM_ALPHANUMEXT);
     $mform->addHelpButton('search', 'keywords', 'local_hub');
     $mform->setDefault('search', $search);
     $mform->addElement('submit', 'submitbutton', get_string('search', 'local_hub'));
 }
Exemplo n.º 5
0
}
$mform = new hub_search_stolen_secret();
if ($data = $mform->get_data()) {
    $sites = array();
    //search site
    if (!empty($data->secret)) {
        //by token
        $site = $hub->get_site_by_secret($data->secret);
        if (!empty($site)) {
            $search = $data->secret;
            $sites[] = $site;
        }
    } else {
        if (!empty($data->sitename)) {
            //by site name
            $sites = $hub->get_sites(array('search' => $data->sitename));
            $search = $data->sitename;
        }
    }
}
/// OUTPUT
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('stolensecret', 'local_hub'));
if (!empty($confirmmsg)) {
    echo $confirmmsg;
}
$mform->display();
if (isset($sites)) {
    if (empty($sites)) {
        echo get_string('nosite', 'local_hub');
    } else {
Exemplo n.º 6
0
 /**
  * TODO: not in use yet, will be prompt to change
  * Get sites
  * @return array sites
  */
 public static function get_sites($search, $options = array())
 {
     global $DB;
     // Ensure the current user is allowed to run this function
     $context = context_system::instance();
     self::validate_context($context);
     require_capability('local/hub:view', $context);
     //TODO: will need to be change for hub:siteview
     //hub:view should concern only courses
     $params = self::validate_parameters(self::get_sites_parameters(), array('search' => $search, 'options' => $options));
     $cleanedoptions = $params['options'];
     $cleanedoptions['search'] = $params['search'];
     $cleanedoptions['onlyvisible'] = true;
     $hub = new local_hub();
     $sites = $hub->get_sites($cleanedoptions);
     //create result
     $result = array();
     foreach ($sites as $site) {
         $siteinfo = array();
         $siteinfo['id'] = $site->id;
         $siteinfo['name'] = $site->name;
         $siteinfo['url'] = $site->url;
         $result[] = $siteinfo;
     }
     return $result;
 }