Moodle theme customization - php

I am trying to customizing the course page in such way that once the student logged in he should see a button in the center of the screen course layout, i have set the basic requirements in the theme's config.php file. which is shown below.
'incourse' => array(
'file' => 'course.php',
'regions' => array(),
),
How can i add the button in the center of course layout
Button 1
which should take the student to his profile when he clicks it. what should be the code in the main-wrap contents.
<div id="region-main-wrap">
<div id="region-main">
<div class="region-content">
<?php echo $coursecontentheader; ?>
<?php echo $OUTPUT->main_content() ?>
<?php echo $coursecontentfooter; ?>
</div>
</div>
</div>

Firstly, the "incourse" layout is used by pages inside the course structure such as an activity landing page. If you want the actual course to change you will need to modify the "course" layout.
Secondly, the course content itself is rendered by $OUTPUT->main_content(). If you want to put your button above or below the course content you can add it above or below that line.
If you want the button to actually appear within the course somewhere you could try one of the following:
Add the button to your course directly within the HTML editor on the site
Add a div outside your course and position it over the course using absolute positioning in your CSS
Modify your course format directly (not advisable unless you really know what you are doing)

Related

Structuring CakePHP Views

Long time reader, first time poster :)
I'm just embarking on my first Cake app so hopefully you guys can help me on my way.
First question is about extending/including views. I realise the way the layouts/view work is to prevent code having to be repeated, but I can't get my head around how to set up what I want to do without some repetition.
My page layout consists, apart from header and footer, a left nav bar which I want Controllers to add themselves to if appropriate, and a top nav bar which will be populated by appropriate pages within the current controller.
I tried creating a view block from within the controller but it didn't work, I'm a bit stumped.
Here's what I have:
My default layout includes the sidebar, currently just hardcoded, and the content:
Layout default.ctp
<!DOCTYPE html>
<html>
<head>.....</head>
<body>
...
<div id='leftnav'>
This is where I want my left nav
I want controllers to be able to add themselves
here.
</div>
<?php echo $this->fetch('content'); ?>
</body>
</html>
Then my /Customer/index view:
View index.ctp
<?php $this->extend('common'); ?>
<h1>Customers</h1>
.... do stuff with customers .....
Which extends my /Customer/common view to bring in the top nav bar, each view has to include this extend line, it would be nice not to have to if there's a different way of doing this.
At the moment, the links are just fixed but I'd like the controller to be able to create these options.
View common.ctp
<?php
echo $this->Html->Link('index', "index")." ";
echo $this->Html->Link('find', 'find')." ";
echo $this->Html->Link('add', 'add')." ";
echo $this->Html->Link('details', 'details');
echo $this->Session->flash();
echo $this->fetch('content');
?>
Appreciate your help cheers! :D
I think you should just be able to put those links in your layout file. But you may have to re-write them as "$this->Html->link("Index",array("controller => $controller","action" => "index");" etc.
To get the current controller within the layout file you can say "$controller = $this->params['controller']".
right, after searching around I think I found a good way of doing at least one of these things.
For the top nav, where the links will be populated by the controller, I'll pass an array from the controller to view. Then, instead of having an ->extend in every view I'll create an element to turn the array into a nav bar, and ->fetch this in the layout.
This leads me onto my next question....
How much code is ok in a CakePHP Layout?
Hi you can use Cake PHP HTML Helper
https://book.cakephp.org/3/en/views/helpers/html.html#creating-links
echo $this->Html->link('Users List', ['controller' => 'Users','action' => 'index']);
Output will be look like this:
Users List

Social Engine render form issue

I'm adding some pages to default layout editor in SE4. What I do is just adding pages to core_pages table and editing core_content table to add a main container and a middle/right two columns layout. Everything works fine, but now I'm adding default Create Video page (videos_index_create) and I got some problems.
When I add this page via sql, I can obviously see and edit page layout by default layout editor. Actually, when I save changes these don't reflect to live page. If I go to the controller (Video/controllers/IndexController.php) and add
$this->_helper->content->setNoRender()
live page displays right sidebar and middle content, but with
$this->_helper->content->setEnabled()
it shows only the default video upload form.
So I edited create.tpl here
<?php if (($this->current_count >= $this->quota) && !empty($this->quota)):?>
<div class="tip">
<span>
<?php echo $this->translate('You have already uploaded the maximum number of videos allowed.');?>
<?php echo $this->translate('If you would like to upload a new video, please delete an old one first.', $this->url(array('action' => 'manage'), 'video_general'));?>
</span>
</div>
<br/>
<?php else:?>
<?php echo $this->form->render($this); ?>
<?php endif; ?>
Changing the else deleting the echo statement and adding a simple echo 'foo';. Now, live page shows properly my layout (middle+right) with default content ("foo").
I figured thus that the issue is about this line in controller:
$this->view->form = $form = new Video_Form_Video();
but I can't go further… this custom form class (Video/Form/Video.php) seems nothing special, I can't really figure out why its rendering crushes default layout render.
Any social engine expert right here to help me? :)
If its a Zend_Form I am pretty sure you should be doing:
<?php echo $this->form;?>
In your view not call render yourself.
If it is NOT a Zend_Form please post the code for the form it probably has some css or whatnot breaking your layout.

Filtering data from DB using several links delivered by PHP

UPDATE
I've solved by myself this problem. It wasn't a problem at all, just because lack of experience.
Everything went from a misunderstanding of the $_GET variable and for what can be used, and PHP data types as well. When I did read twice the PHP documentation, I understood that it is actually an array and I could put several variables and pass several parameters through it, as it is persistent.
From there, the rest was piece of cake. With a single include and a bunch of functions I can do all the database petitions and output them as I want!
I'm glad I've been able to solve it by myself, and thanks to Passerby, who made me think about how I was managing the $_GET variable.
I had to redo this question because last one was a dull brick of text. Let's simplify.
Let's say I have a fruit DB with 'n' items. The cols are the following:
Name of the fruit.
Country of origin.
Color.
On the index.php I have sidebar.php with links and a content.php with some text into it. Like this:
<!--html code here-->
<?php include('includes/content.php') ?>
<?php include('includes/sidebar.php') ?>
<!--more html code here-->
The links of the sidebar.php are like these:
Browse by country
Browse by color
etcetera.
searchDB.php is generated with the same layout than index.php with this difference:
<!--html code here-->
<div id="content">
<?php include('functions/fruit_list.php') ?>
</div>
<?php include('includes/sidebar.php') ?>
<!--more html code here-->
inside fruit_list.php there's a script that shows all countries into the content <div>
once you click on 'browse by country'. It generates some hyperlinks as well which I'm unable to manage or figure how to link them to a function, or somewhere that allows me to go one level deeper (for instance if you click into 'Japan', I'd like to list all fruits from Japan).
If possible, the new generated list (all fruits from Japan), should be on the same content div.
Any ideas? Thoughts? I have a wrong approach to do this?

Drupal: How to display block/region in views page?

I have a views page that contains a listing of one of my content type. I used views-view-list--<name of my view>.tpl to theme the page. However, the region/blocks that I defined are not displaying. In other pages it works fine, but on the views page it does not. I'm trying to display a user login block in my defined region.
Please tell me how to access my user login block or my region to display on my views.
Your help is greatly appreciated. I'm using drupal 6 by the way.
Best regards,
Think i ran into something similar yesterday. I was trying to print a region, for example
<?php print $footer ?>
but inside a tpl file that came from views - and for whatever reason, it doesn't output the region from one of the views tpl files.
I used this code:
<?php print theme('blocks', footer); // change "footer" to the name of your region ?>
As I am writing this, a safer and maybe recommended way in D7 would be:
<?php
$region = block_get_blocks_by_region('footer') //first define the block;
print render($region) // then print the block;
?>
I tried #Garry but I got some errors back from Drupal. Please see here
Hope this helps someone down the line.
Any page in drupal have page template based on url or content type . So you have to create right page template for your page where views page/block to be displayed. I'm assuming that you are using page template based on url
This worked for me, except the syntax above needs semi-colons after (); for example print render($region); otherwise thank you for this answer
This is how the snippet will work for Drupal 7 with Bootstrap - HTML tags, considering that the 'billboard' region host an ad:
<aside class="col-xs-0 col-sm-12 role="banner">
<?php
$region = block_get_blocks_by_region('billboard');
print render($region);
?>
</aside>

use common template for all pages of website

ok, the title did not make much sense but this is what i am planning to do. I have designed a template for my website, with head body and div for specific stuff and everything. The website consists of header file, footer file, right-side column, header dropdown menu and a main body which would be present beneath the header dropdown menu, to the left of the right-side column, and above the footer. Right now there is some content is this main body area. What i am trying to achieve is that whenever any link is clicked on any of the other parts of the webpage, i want that content to be displayed in this main body. Right now i am copying this template to each and every page, but I want to keep this standard template as index.php and then replace main body content based on the link clicked. This is a php based website. Are there any examples where i can see how this can be achieved? or is there any standard procedure to do this. Please guide me, Thanks.
Here's a very simple way to do this:
index.php
<?php
function putPage($page) {
// put a list of allowed pages here
$allowed = array('page1', 'page2');
$page = trim($page);
$page = (in_array($page, $allowed)) ? $page : 'home';
echo #file_get_contents('.\html\\' . $page . '.html');
}
?>
<html>
<head>
<title>Title</title>
<!-- put stylesheets, js files, etc. here -->
</head>
<body>
<!-- you can have a nav bar or something here -->
<div class="navbar">
Page 1 Page 2
</div>
<?php putPage($_GET['page']); ?>
<!-- put a footer here -->
</body>
</html>
Then just put .html pages with the contents in an html subfolder.
The script will fetch them and insert them in the body.
There are a few ways you can achieve this. Off hand the two obvious ones I would say are:
Ajax to obtain content with event handlers attached to links/buttons/menus that produce maincontent specific to the request.
This requires server and client side scripting to achieve.
w3 ajax
Or alternatively use mod_rewrite with apache to determine what content to load in index.php page. For example with mod rewrite you may have a link http://www.site.com/subject/content/item# as a link structure. This could translate to www.site.com/index.php?subject=&content=&id= And these GET values would allow you to determine what to display in main content area.
This requires server side scripting and configuration of apache or (any web server with similar functionality to mod_rewrite).
mod_rewrite - apache
I use this:
<?php
$pag = array(1 => 'Home.php', 3 => '2.php');
echo require $pag[(int)#$_GET['p'] | 1];
?>
This is called either a Template View as far as you build your link specific HTML completely in PHP. You create a page layout template containing some wildcards. You load the template into a string and use string replacements or XML functions (more fancy but only suggestive if transformation is more complex).
Otherwise it is called Two Step View where you create the page layout template (as above) and a specific template for the links. Now first load the link specific template, put your dynamic content into (same techniques as above), load the page layout template and put the previous transformed specific template into.

Categories