示例#1
0
function theme_gourmet_get_html_for_settings(renderer_base $output, moodle_page $page)
{
    global $CFG, $USER, $DB;
    $return = new stdClass();
    $return->navbarclass = '';
    if (!empty($page->theme->settings->invert)) {
        $return->navbarclass .= ' navbar-inverse';
    }
    // get logos
    $theme = $page->theme;
    $logo = $theme->setting_file_url('logo', 'logo');
    if (empty($logo)) {
        $logo = $CFG->wwwroot . '/theme/gourmet/pix/gourmet_logo.png';
    }
    $clientlogo = '';
    $companycss = '';
    if ($companyid = iomad::is_company_user()) {
        $context = context_system::instance();
        if ($files = $DB->get_records('files', array('contextid' => $context->id, 'component' => 'theme_gourmet', 'filearea' => 'companylogo', 'itemid' => $companyid))) {
            // print_object($files);
            foreach ($files as $file) {
                if ($file->filename != '.') {
                    $clientlogo = $CFG->wwwroot . "/pluginfile.php/{$context->id}/theme_gourmet/companylogo/{$companyid}/{$file->filename}";
                }
            }
        }
        company_user::load_company();
        $companycss = ".header, .navbar { background: [[company:bgcolor_header]]; }\n                       .block .content { background: [[company:bgcolor_content]]; }";
        foreach ($USER->company as $key => $value) {
            if (isset($value)) {
                $companycss = preg_replace("/\\[\\[company:{$key}\\]\\]/", $value, $companycss);
            }
        }
    }
    /*
        $return->heading = '<div id="sitelogo">' . 
            '<a href="' . $CFG->wwwroot . '" ><img src="' . $logo . '" /></a></div>';
        $return->heading .= '<div id="siteheading">' . $output->page_heading() . '</div>';
    */
    if ($clientlogo) {
        $return->heading .= '<div id="clientlogo">' . '<a href="' . $CFG->wwwroot . '" ><img src="' . $clientlogo . '" /></a></div>';
    }
    $return->footnote = '';
    if (!empty($page->theme->settings->footnote)) {
        $return->footnote = '<div class="footnote text-center">' . $page->theme->settings->footnote . '</div>';
    }
    $return->companycss = $companycss;
    return $return;
}
示例#2
0
/**
 * This function creates the dynamic HTML needed for the 
 * layout and then passes it back in an object so it can
 * be echo'd to the page.
 *
 * This keeps the logic out of the layout files.
 */
function theme_bootstrap_html_for_settings($PAGE)
{
    global $CFG, $DB, $USER, $SITE;
    $settings = $PAGE->theme->settings;
    $html = new stdClass();
    if ($settings->inversenavbar == true) {
        $html->navbarclass = 'navbar navbar-inverse';
    } else {
        $html->navbarclass = 'navbar navbar-default';
    }
    $fluid = !empty($PAGE->layout_options['fluid']);
    if ($fluid || $settings->fluidwidth == true) {
        $html->containerclass = 'container-fluid';
    } else {
        $html->containerclass = 'container';
    }
    $html->brandfontlink = theme_bootstrap_brand_font_link($settings);
    // get logos
    $theme = $PAGE->theme;
    $logo = $theme->setting_file_url('logo', 'logo');
    if (empty($logo)) {
        $logo = $CFG->wwwroot . '/theme/iomad/pix/iomad_logo.png';
    }
    $clientlogo = '';
    $companycss = '';
    if ($companyid = iomad::is_company_user()) {
        $context = context_system::instance();
        if ($files = $DB->get_records('files', array('contextid' => $context->id, 'component' => 'theme_iomad', 'filearea' => 'companylogo', 'itemid' => $companyid))) {
            foreach ($files as $file) {
                if ($file->filename != '.') {
                    $clientlogo = $CFG->wwwroot . "/pluginfile.php/{$context->id}/theme_iomad/companylogo/{$companyid}/{$file->filename}";
                }
            }
        }
        company_user::load_company();
        $companycss = ".header, .navbar { background: [[company:bgcolor_header]]; }\n                       .block .content { background: [[company:bgcolor_content]]; }";
        foreach ($USER->company as $key => $value) {
            if (isset($value)) {
                $companycss = preg_replace("/\\[\\[company:{$key}\\]\\]/", $value, $companycss);
            }
        }
    }
    $html->heading = '<div id="sitelogo">' . '<a href="' . $CFG->wwwroot . '" ><img src="' . $logo . '" /></a></div>';
    $html->heading .= '<div id="siteheading"><span>' . $SITE->fullname . '</span></div>';
    if ($clientlogo) {
        $html->heading .= '<div id="clientlogo">' . '<a href="' . $CFG->wwwroot . '" ><img src="' . $clientlogo . '" /></a></div>';
    }
    $html->footnote = '';
    if (!empty($page->theme->settings->footnote)) {
        $html->footnote = '<div class="footnote text-center">' . $PAGE->theme->settings->footnote . '</div>';
    }
    $html->companycss = $companycss;
    return $html;
}
示例#3
0
 public static function is_company_user()
 {
     return iomad::is_company_user();
 }
 /**
  * Loads the courses in Moodle into the navigation.
  *
  * @global moodle_database $DB
  * @param string|array $categoryids An array containing categories to load courses
  *                     for, OR null to load courses for all categories.
  * @return array An array of navigation_nodes one for each course
  */
 protected function load_all_courses($categoryids = null)
 {
     global $CFG, $DB, $SITE, $USER;
     // Work out the limit of courses.
     $limit = 20;
     if (!empty($CFG->navcourselimit)) {
         $limit = $CFG->navcourselimit;
     }
     $toload = empty($CFG->navshowallcourses) ? self::LOAD_ROOT_CATEGORIES : self::LOAD_ALL_CATEGORIES;
     // If we are going to show all courses AND we are showing categories then
     // to save us repeated DB calls load all of the categories now
     if ($this->show_categories()) {
         $this->load_all_categories($toload);
     }
     // Will be the return of our efforts
     $coursenodes = array();
     // Check if we need to show categories.
     if ($this->show_categories()) {
         // IOMAD - If not logged in, don't show any courses in the navigation.
         if (!isloggedin()) {
             return array();
         }
         if (iomad::is_company_user()) {
             $companyid = iomad::get_my_companyid(context_system::instance());
             $sharedsql = " AND ( c.id IN (\n                                   SELECT courseid FROM {company_course}\n                                   WHERE companyid = {$companyid})\n                               OR c.id IN (\n                                   SELECT courseid FROM {iomad_courses}\n                                   WHERE shared=1)\n                               OR c.id IN (\n                                   SELECT courseid FROM {company_shared_courses}\n                                   WHERE companyid = {$companyid})) ";
         } else {
             if (!is_siteadmin()) {
                 $sharedsql = " AND c.id IN (select courseid FROM {iomad_courses} WHERE shared=1) ";
             } else {
                 $sharedsql = "";
             }
         }
         // Hmmm we need to show categories... this is going to be painful.
         // We now need to fetch up to $limit courses for each category to
         // be displayed.
         if ($categoryids !== null) {
             if (!is_array($categoryids)) {
                 $categoryids = array($categoryids);
             }
             list($categorywhere, $categoryparams) = $DB->get_in_or_equal($categoryids, SQL_PARAMS_NAMED, 'cc');
             $categorywhere = 'WHERE cc.id ' . $categorywhere;
         } else {
             if ($toload == self::LOAD_ROOT_CATEGORIES) {
                 $categorywhere = 'WHERE cc.depth = 1 OR cc.depth = 2';
                 $categoryparams = array();
             } else {
                 $categorywhere = '';
                 $categoryparams = array();
             }
         }
         // First up we are going to get the categories that we are going to
         // need so that we can determine how best to load the courses from them.
         // IOMAD - Add $sharedsql after $categorywhere to hide other company
         // categories.
         $sql = "SELECT cc.id, COUNT(c.id) AS coursecount\n                        FROM {course_categories} cc\n                    LEFT JOIN {course} c ON c.category = cc.id\n                            {$categorywhere}\n                            {$sharedsql}\n                    GROUP BY cc.id";
         $categories = $DB->get_recordset_sql($sql, $categoryparams);
         $fullfetch = array();
         $partfetch = array();
         foreach ($categories as $category) {
             if (!$this->can_add_more_courses_to_category($category->id)) {
                 continue;
             }
             if ($category->coursecount > $limit * 5) {
                 $partfetch[] = $category->id;
             } else {
                 if ($category->coursecount > 0) {
                     $fullfetch[] = $category->id;
                 }
             }
         }
         $categories->close();
         if (count($fullfetch)) {
             // First up fetch all of the courses in categories where we know that we are going to
             // need the majority of courses.
             list($categoryids, $categoryparams) = $DB->get_in_or_equal($fullfetch, SQL_PARAMS_NAMED, 'lcategory');
             $ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
             $ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
             $categoryparams['contextlevel'] = CONTEXT_COURSE;
             $sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category {$ccselect}\n                            FROM {course} c\n                                {$ccjoin}\n                            WHERE c.category {$categoryids}\n                        ORDER BY c.sortorder ASC";
             $coursesrs = $DB->get_recordset_sql($sql, $categoryparams);
             foreach ($coursesrs as $course) {
                 if ($course->id == $SITE->id) {
                     // This should not be necessary, frontpage is not in any category.
                     continue;
                 }
                 if (array_key_exists($course->id, $this->addedcourses)) {
                     // It is probably better to not include the already loaded courses
                     // directly in SQL because inequalities may confuse query optimisers
                     // and may interfere with query caching.
                     continue;
                 }
                 if (!$this->can_add_more_courses_to_category($course->category)) {
                     continue;
                 }
                 context_helper::preload_from_record($course);
                 if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
                     continue;
                 }
                 $coursenodes[$course->id] = $this->add_course($course);
             }
             $coursesrs->close();
         }
         if (count($partfetch)) {
             // Next we will work our way through the categories where we will likely only need a small
             // proportion of the courses.
             foreach ($partfetch as $categoryid) {
                 $ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
                 $ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
                 $sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category {$ccselect}\n                                FROM {course} c\n                                    {$ccjoin}\n                                WHERE c.category = :categoryid\n                            ORDER BY c.sortorder ASC";
                 $courseparams = array('categoryid' => $categoryid, 'contextlevel' => CONTEXT_COURSE);
                 $coursesrs = $DB->get_recordset_sql($sql, $courseparams, 0, $limit * 5);
                 foreach ($coursesrs as $course) {
                     if ($course->id == $SITE->id) {
                         // This should not be necessary, frontpage is not in any category.
                         continue;
                     }
                     if (array_key_exists($course->id, $this->addedcourses)) {
                         // It is probably better to not include the already loaded courses
                         // directly in SQL because inequalities may confuse query optimisers
                         // and may interfere with query caching.
                         // This also helps to respect expected $limit on repeated executions.
                         continue;
                     }
                     if (!$this->can_add_more_courses_to_category($course->category)) {
                         break;
                     }
                     context_helper::preload_from_record($course);
                     if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
                         continue;
                     }
                     $coursenodes[$course->id] = $this->add_course($course);
                 }
                 $coursesrs->close();
             }
         }
     } else {
         // Prepare the SQL to load the courses and their contexts
         list($courseids, $courseparams) = $DB->get_in_or_equal(array_keys($this->addedcourses), SQL_PARAMS_NAMED, 'lc', false);
         $ccselect = ', ' . context_helper::get_preload_record_columns_sql('ctx');
         $ccjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)";
         $courseparams['contextlevel'] = CONTEXT_COURSE;
         $sql = "SELECT c.id, c.sortorder, c.visible, c.fullname, c.shortname, c.category {$ccselect}\n                        FROM {course} c\n                            {$ccjoin}\n                        WHERE c.id {$courseids}\n                    ORDER BY c.sortorder ASC";
         $coursesrs = $DB->get_recordset_sql($sql, $courseparams);
         foreach ($coursesrs as $course) {
             if ($course->id == $SITE->id) {
                 // frotpage is not wanted here
                 continue;
             }
             if ($this->page->course && $this->page->course->id == $course->id) {
                 // Don't include the currentcourse in this nodelist - it's displayed in the Current course node
                 continue;
             }
             context_helper::preload_from_record($course);
             if (!$course->visible && !is_role_switched($course->id) && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id))) {
                 continue;
             }
             $coursenodes[$course->id] = $this->add_course($course);
             if (count($coursenodes) >= $limit) {
                 break;
             }
         }
         $coursesrs->close();
     }
     return $coursenodes;
 }
示例#5
0
         OR
         c.shortname like :searchkey2
         OR
         c.summary like :searchkey3
         OR
         css.short_description like :searchkey4
         OR
         css.long_description like :searchkey5
        )
    ';
    for ($i = 1; $i < 6; $i++) {
        $sqlparams['searchkey' . $i] = '%' . $searchkey . '%';
    }
}
// Deal with company specific and shared courses.
if (iomad::is_company_user()) {
    // Get the company courses and the company shared courses.
    $company = company::get_company_byuserid($USER->id);
    $sharedsql = " AND ( c.id in ( select courseid from {company_course} where companyid= {$company->id})\n\t               or c.id in ( select courseid from {iomad_courses} where shared=1)\n\t               or c.id in ( select courseid from {company_shared_courses} where companyid = {$company->id})) ";
} else {
    if (is_siteadmin() || iomad::has_capability('block/iomad_company_admin:company_view_all', context_system::instance())) {
        $sharedsql = "";
    } else {
        $sharedsql = " AND c.id in ( select courseid from {iomad_courses} where shared=1) ";
    }
}
if (count($sqlparams)) {
    echo '<a href="?tag=&q=">' . get_string('remove_filter', 'block_iomad_commerce') . '</a>';
}
echo "</ul>";
echo get_string('search', 'block_iomad_commerce');