Help a newbie with his first block.

Permalink
Hello all,
I have what seems to be a "working" Concrete 5 block that I created and would like it to be reviewed by a few others to suggest changes.

This is the first block that I've made in Concrete, so I'm still trying to figure everything out.

The Block's Purpose
I want admins/editors of a website to be able to easily insert degree requirements onto a page (I work for a college). Degrees are made up of groupings of courses (Business Core, Required Courses, Electives, Choose 1 of the following 5, etc.)

This block allows a user to insert a grouping of courses (All the Business Core courses), title the group, and give a short description/instruction to the website visitor. This block will be used multiple times on a single page.

See attached photo for an edit mode view.

The course descriptions are in a database. To make this process easier(?), I just created a new table called zCourseDescriptions into my Concrete5 database.

Course Descriptions are going to be used multiple times (hence the database) - I also need a way to update them, but that's likely a dashboard page and a discussion for another time.

Overall, the block works - but I'd like suggestions for making it better (security-wise, standards, etc.).

Here is the controller.php code
<?php
   class CourseBlockController extends BlockController {
      protected $btDescription = "Insert course requirements by entering course numbers.";
      protected $btName = "Course Description Widget";
      protected $btTable = 'btCourseDescriptions';
      protected $btInterfaceWidth = "350";
      protected $btInterfaceHeight = "350";
      function getCourseBlock() {
         // Fix group name for use in links and javascript show/hide function
         $replace = array(' ',',','.','!','@','#','$','%','^','|','\"','\'','+','?','/','\\','&','(',')');
         $gName = strtolower(trim(str_replace($replace,'-',$this->groupName)));
         // Create query based on block (user) input
         // Remove spaces, convert course numbers to uppercase
         $lookup = strtoupper(str_replace(' ','',$this->groupNumbers));
         // Replace , with ',' for correct query formatting.


Here is an example of the block in action (this is just a testing page for now):
http://www.smwc.edu/campus/faq/...

Attached is a zip file of the entire block.

2 Attachments

glockops
 
Remo replied on at Permalink Reply
Remo
1. You should prefix the names using your c5 community member name to make sure it's unique (see this pagehttp://www.concrete5.org/help/building_with_concrete5/developers/pa...

2. Use a model. Concrete5 is an MVC framework. Try not to skip the "M" and build a model. Check the "model" directory in concrete5, lots of examples there.