Databases

Review database as a designer

We have looked at the database from the student perspective; now we’ll
review the controls available to the instructor.
  1. Click the Sample Database link on your Development Site. You will see 8 tabs: View list, View single, Search, Add entry, Export, Templates, Fields, and Presets. The first four tabs are the same in student view.
Picture
2. Click the Presets tab. Here are options to choose a template for your
    database, or to export/import a database you have created in zip
    format.

3. Click the Fields tab. See the four fields (Author, BookTitle, Date and
    Review) that the instructor defined for this database. These fields are
    filled out on the Add entry page, and displayed on the View single
    and View list pages.

4. Click the Templates tab and see 7 more sub-tabs. We will use 3: List
    template, which controls the View list page; Single template which
    controls View single, and Add template, which controls Add entry.
Picture
You will use all three templates to create layouts and define how the pages
for View list, View single and Add entry will display. Templates are
constructed with Field and Button tags (see Appendix A for detailed info).
Click the Single template tab. On the left side see a list of Fields created
manually by the instructor, and Buttons provided by default.
Picture
Picture
Fields are marked with double square-brackets [[field]] and are replaced by
manually submitted data. Actions and Other tags have double pound signs:
## ## to indicate the word will be replaced by an icon or a link that Moodle
provides. Labels are created from the field names you defined. Field names
should never be changed; but you can change the labels as you wish.

  • if a Template has a [[date]] field, the corresponding view will display the date, E.g., April 29, 1999.
  • if a Template has a ##user## tag, the view will display the name of the person logged in, E.g., “Chip Oreo” in the corresponding area.

Create a Database

  1. Click Turn Editing on button on the course homepage.
  2. In topic section 2, select Database from the Activities dropdown.
  3. Fill out the form:
  • Name: Book Reviews
  • Introduction: Please submit your book review here.
  4. Review and select options:
  • Set the Availability if needed.
  • Set the number of required entries, if needed. Users will see a reminder message displayed while viewing if they have not submitted the required number of entries.
  • You may also set the number of required entries users mustcomplete before they may view other user entries.
  • Set the Maximum number of entries users may complete.
  • Enable or Disable comments (If you set Comments to Yes, be sure to add the comments tag to the database templates later.)
  • Select whether to require approval from the instructor to make an entry public. (We will keep the default: No.)
  • Choose whether or not to rate and grade entries.
 
5. Review the Group Mode setting:
  • Select the desired setting (E.g., No groups).

The activity inherits the Group mode setting for the site. Since we selected
Visible groups, it is the default setting for all activities.

 6. Click Save and display. See that you are automatically taken to the
     Fields tab where you can begin to enter the fields for your database.
Picture
Add Fields

Fields are the building blocks of your database. You will begin by defining
the field names and field types.
For our book reviews database, we want to collect and share the following
information:
  • Student name
  • Publishing date
  • Book title
  • Author
  • Book review
Student names can be collected automatically with the ##user## tag,
therefore, we will not create a field for it. (If we created a field for it, students
would be required to type their names manually.)
The corresponding names for the fields we define will be:
  • Date
  • Book Title
  • Author
  • Review
Field names can never have spaces!

Add the Date field:

  1. From the Create a new field dropdown menu, select the field type Date.
Picture
2. Enter the following:
  •  Field name –keep it short and do not use spaces. For example, type:
           Date, or PublishDate.
  • Field description – describe this field in more detail. For example:
         date book was published. Only designers see the description.

3. Click the Add button.
Picture

Now you are ready to add the next field.


Self-paced exercise:

Add 3 more fields: Book Title (text field), Author (text field), and Review
(text area field). Select each one from the Create a new field dropdown
menu. Once added, you should have a screen similar to this one:
Picture
Here are step-by-step directions.
  1. Add a Text field (60 characters) for the book title.
  • Select Text from the dropdown menu.
  • Field name: Book Title
  • Field description: title of the book
  • Click Add
 
 2. Add another Text field for the author.
  • Select Text from the dropdown menu
  • Field name: Author
  • Field description: book author
  • Click Add
 
 3. Add a Text area field for the article review.
  • Select Text area from the dropdown menu
  • Field name: Review
  • Field description: book review
  • Click Add

These are the only fields we need.

Next, let’s look at the templates that have been automatically created for us
using our field names.

Review template presets

  1. Click the Templates tab. Next click the Add template tab. On the left, see a list of Available tags with your fields.
All of our fields have been populated in the Add template for us.
Picture
2. Click the Add entry tab and see how it corresponds to the Add
         template.
Picture
3. Click the Templates tab again and review the Single and List
         templates. They default templates look quite similar.

Add Sample entries

If you click the View single or View list tabs, you will see empty pages, since
we have not added any entries yet. Add some sample entries:

  1. Click the Add entry tab and fill in the form:
  • Date: April l 3, 2008
  • Book Title: Cooking Wonders
  • Author: Dunkle Chocolate
  • Review: Great book!
    
 2. Click Save and add another.

    
 3. Add another entry.
  • Date: November 7, 2000
  • Book Title: Chocolat
  • Author: Joanne Harris
  • Review: A widow brings chocolate confections to a small village in France. Not everyone is pleased.
    
 4. Click Save and add another.
  • Date: March 6, 2008
  • Book Title: The Science of Chocolate
  • Author: Stephen T Beckett
  • Review: Describes the complete chocolate making process and how science plays a vital role.
    
 5. Click Save and view.

    
 6. You will be on the View single tab. To move between pages, click a
         page number or Previous/Next links.

    
 7. Click the View list tab, to see the list of entries added so far.

The templates control how the data is displayed. The data could look better!

Modify Single template

We will add the ##user## tag to know who submitted an entry, edit and
format the label text, and rearrange the order of fields.


Add User Name

  • Go to Templates > Single template.
  •  Enlarge the editor window.
  •  Add a row to the top of the table: click anywhere inside the first row; then click the Insert row before icon
Picture
  • Minimize the editor.
  • Click in the top cell left column, and type Submitted By:
  • Click in the right column and then click ##user## located in the Available tags area. (You may need to scroll down to find it.)
  • Highlight the right column of tags and align text left (Justify Left icon).
Picture
  • SAVE YOUR WORK!!! Click the Save template button.
WARNING! Don’t forget to save the template you are working on before
you switch views! If you forget to save, you will lose your work.

Edit and format labels

  • Change Date to Date Published.
  • Change Book Title to Book Title.
  • Highlight everything in the left column; then make bold and align text right (Justify Right icon).
  • Click the Save template button.
Picture
  • Click the View single tab and review your records.
  • Click the View list tab and see the labels are not formatted! Each template must be formatted separately.

Modifying a field name


In general, you should not change a fieldname. If you change the fieldname
text, e.g., change [[Date]] to [[ThisDate]] you will break your database.

If you must change a field name:
  1. Go to the Fields tab first and rename the field, e.g., from ‘Date’ to “ThisDate”.
  2. Then go to each Template and update each field [[Date]] to [[ThisDate]].

Modify List template

By default View list will list one entry after another, separated by a
horizontal rule. If you formatted the List template the same way you just
formatted the Single template, it would look similar to this example:
Picture

Another option is to modify the template to create a table structure. A table
format has the advantage of displaying more records at a time, and making
it easier to sort and find information. Here is an example in table format:
Picture
  • Click Templates > List template.
  • Erase everything in the Repeated Entry area: click anywhere inside the table, click the body tag in the Path selector (below the edit window), and then press the Erase or Delete key.
Picture
  • Insert a table in the Repeated entry area: click Insert Table and enter 1 Row and 5 Columns. Click OK.
  • Enter each tag, one-by-one: click inside the first cell to the left and then click the ##user## tag. Click inside the second cell and then click the [[Date]] field. Fill the remaining three cells in the same way: [ [Book Title] ], [ [Author ] ] ##more## ##comment##
Picture
  • Copy this table: click anywhere inside the table and then click the table tag from the Path selector. Next, select Edit > Copy.
  • Paste this table into the Header area. Click in the Header area and select Edit > Paste.
  • Replace each tag with corresponding label text: Submitted By; Date Published; Book Title; Author; More
Picture
  • Click Save template and review the View list tab. Check for typos, alignment and so on. You may decide you want to add color to the Header text.

Extra space between records


  1. If there is extra space between records, it is easy to fix.
  • Go to Templates > List template
  • In the Repeated entry area, switch to html source view by clicking the <> icon
  • Delete the extra break tags at the end: <br />
Picture
  • Click Save template and review View List tab again. (You may need
         to remove a <br> tag from the Header area as well.)

The Review field was not included on the View list template. With a table
format, fields with a large amount of text are not appropriate. Include
fields with large amounts of text in the View single template.
  • “more” is a direct link to the single view
  • “comment(s)” shows the number of comments entered in single view

Exercise: Modify the Add template

  1. Click the Add entry tab and review the New entry form.
     Now that you know how to modify templates, could you make the Add template look better? Perhaps you can
     make those changes on your own. Remember, Add template has no button tags, only fields, so you only
     need to edit and format what is already there.

Step-by-Step: Modify the Add template

  1. Go to Templates > Add template tab and enlarge the editor screen.
  2. Change Date to Date Published
  3. Change Book Title to Book Title
  4. Highlight everything in the right column and align the text left.
  5. Highlight everything in the left column, make it bold and align text right.
  6. Click Save Template button.
  7. Click the Add entry tab to see how much better it looks!

Database tags

Tag Usage

The content of each field you create for your database and some special tags
listed below can be inserted into a template by the use of tags. Some tags are
automatically inserted. You can add or delete tags from a template.

Fields have the format [[fieldname]]. All other tags have the format
##sometag##.


Actions
  • Edit - ##edit## creates a clickable icon link that allows you to edit the current entry
  • Delete - ##delete## creates a link that allows to delete the current entry
  • Approve -##approve## create a link that lets the instructor to approve the current database entry
  • More - ##more## creates a link to the single view, which may contain more detailed info
  • More Url - ##moreurl## creates just the URL for the above link, useful for creating your own links

Other
  • User - ##user## creates a link to the user page of the user who submitted the entry, link text is their name
  • Comments - ##comments## creates a link to the view/edit comments page, the link text is the current number of comments (only appears if comments are turned on)
  • Time Added ##timeadded## records a time-stamp when database entry is submitted
  • Time Modified ##timemodified## records a time-stamp when database entry is modified

Fields (manually added)

  • Checkbox - create one or more checkboxes for user to choose from. Checkboxes default to their unchecked status and so people could submit without actively selecting one of the options.
  • Date - Allows users to enter a date by picking a day, month and year from a drop down list.
  • File - Asks users to upload a file from their computer. If it is an image file then the picture field may be a better choice.
  • Latitude/longitude -Users can enter a geographic location, by specifying the location's latitude and longitude.
  • Menu - The text entered in the options area will be presented as a drop-down list for the user to choose from. Each line becomes a different option.
  • Menu (Multi-select) -The text entered in the options area will be presented as a list for the user to choose from and each line become a different option. By holding down control or shift as they click, users will be able to select multiple options. This is a fairly advanced computer skill so it may be wise to use multiple checkboxes instead.
  • Number -Asks the user to enter a number. The number must be an integer, though it can be negative.
  • Picture - The user can upload an image file from their computer.
  • Radio buttons - Allows the user to choose one from a range of options. If the user doesn't select any of these options then they will be prompted to do so and can only submit the entry when one option is chosen.
  • Text - Users can enter text up to 60 characters in length.
  • Textarea -Allows users to enter a long piece of text including formatting similar to that found when creating forum posts.
  • Url - Ask the user to enter a URL. If you select autolink then the URL becomes a clickable link. If you also enter a forced name for the link then that text will be used for the hyperlink.

More Database


Database Process

Here is a basic process for adding a database activity. Be clear about the
purpose of your database. Decide the information (fields) you want, and the
fieldnames you will assign. If you change a fieldname later, you risk
breaking your database.

  1. Select Database from the Add an activity dropdown menu.
  2. Name your new database and enter an introduction on the Adding a new database page.
  3. Select the general options and the common module settings.
  4. Click the Save and display button at the bottom of the page.
  5. Define the fields or use a preset.
  6. Define the templates: view Templates > Single template and Templates > List template. If you make any changes, click Save template button.
  7. Add a couple of entries (Add entry tab).
  8. View the output: View single tab and View list tab.
  9. Edit templates as appropriate. (Add/delete tags; format; etc.)
  • Templates > Single template controls the look of View single
  • Templates > List template controls the look of View list
  • Templates > Add template controls the look of Add entry

Practice: Sample Database for file collection
Practice the process with this database activity.

Add a database

  1. Click Turn Editing on.
  2. Select Database from the Add an Activity menu.
  3. Type a Name: Healthy food files
  4. Enter an introduction: Submit one file about heal thy food.
  5. Save and display.

Add a field (File) to your new database

  1. Click Fields tab, then select File from the dropdown menu.
  2. Type short field name: File.
  3. Type Field description: this i s the student entry (No one will see the description, except designers.)

Modify templates

Add template (add some text)

  1. Go to the Templates > Add template tab. You will get a Default view that has been already been created for you.
     2. Type text above this table, E.g., Submit your file here so your students will know what to do. Toggle to HTML
         view < > to enter the text above the table. It is very difficult to do this otherwise! Then toggle back to HTML
         mode to format the text.
Picture
3. Click Save template.

Single template (add ##user## tag)

     4. Go to the Templates > Single template tab. You will see:
Picture
5. Change it to:
Picture
     6. Click Save template.

List template (add ##user## tag)

     7. Go to the Templates > List template tab. You will see:
Picture
    8. Change it to:
Picture
     9. Click Save template.


Add a couple of entries

  1. Click Add entry tab.
  2. Browse to folder on the desktop, find tarteTatin.doc and open.
  3. Enter the optional filename: Tarte Tatin.
  4. Click Save and add another.
  5. Browse to find HealthyFood.doc and open.
  6. Click Save and view.

View list and single pages

View list and single pages. Edit templates if necessary.