HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Beginners' Guides for ocPortal Development

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#66188 (In Topic #14148)
Avatar

Community saint

I thought I'd give this its own thread here, since it was hijacking a support thread earlier. I thought I'd share some ocPortal development guides, starting from the very basics. They're aimed at ocPortal Webmasters who probably don't know much about programming but who have a vague idea about ocPortal, Comcode, etc.

The first of my tutorial pages can be found under "Creating Miniblocks From Third-Party Code". It describes how to take some HTML code given out by a Web site for "embedding", in this case from OpenStreetMap.org, and turn it into a reusable ocPortal component called a "miniblock".

I've just finished uploading the second tutorial "More Useful Miniblocks Via Functions". It carries on from the previous tutorial, and extends the OpenStreetMap miniblock. The problem with the miniblock created in the first tutorial is that any parameters which we may want to fiddle with in the third-party HTML, eg. the longitude and latitude of our map, are stuck as they are. This tutorial introduces the idea of "functions", and shows how we can use them to query ocPortal options. We then split up the third-party HTML wherever we find a piece we want to replace (like a height), fill in these with ocPortal options rather than unchangable text, and rebuild the HTML string. A brief encounter is had with ocPortal translation strings, the OcCLE commandline and a really simple minimodule.
Back to the top
 
Posted
Rating:
#66205
Avatar

Community saint

You have a knack for explaining this stuff clearly, making something that otherwise would seem too difficult to even consider from the point of view of a neophyte, easy to follow.

I had a lot of fun following your tutorial and making this miniblock, and I look forward to more of this kind of tutorial when you can find the time.

It is most gratifying to learn about ocPortal’s possibilities for customization this way.

Many thanks Chris W.

Jean
Back to the top
 
Posted
Rating:
#66210
Avatar

Community saint

Code

echo "Hello?"


Shucks, forgot the 'World' … !!

 :thumbs:

Take my advice. I'm not using it!

View my working ocPortal site (version 9.x.x) at Anglo-Indian Portal
Back to the top
 
Posted
Rating:
#66287
Avatar

Community saint

Jean said

You have a knack for explaining this stuff clearly, making something that otherwise would seem too difficult to even consider from the point of view of a neophyte, easy to follow.

I had a lot of fun following your tutorial and making this miniblock, and I look forward to more of this kind of tutorial when you can find the time.

Thanks for the support :) I like writing documentation, for example I've written a lot of Ubuntu community documentation, but I find the hardest thing is that I write too much, which can make a relatively simple point look much more complicated simply because it takes me a few paragraphs to get the message across. Lots of time thus goes into cutting down, rewriting and restructuring things. Plus I never like to write anything that's misleadingly simple, in case someone uses it out of context for something more advanced than I intended. This makes coming up with explanations more difficult, as they need to be general while remain simple and to the point; but I enjoy the challenge :)

I've just made another tutorial about variables and state. I was going to try and press ahead towards making full blocks, but realised that they involve quite a few concepts that would be best introduced one at a time. Thus this latest tutorial still uses miniblocks as our familiar playground, but rather than using OpenStreetMap as our data source, we send a user's points to Google's Chart API which gives us pretty 3D pie charts. Enjoy :)
Back to the top
 
Posted
Rating:
#66324
Avatar

Honoured member

Hi,

ChrisW said

… but I find the hardest thing is that I write too much, which can make a relatively simple point look much more complicated simply because it takes me a few paragraphs to get the message across.
I know how hard that can be. Many years ago when I started official writing, I wrote an article of 6 pages A4, much to long. The next assignment was to bring the story back to 1 A4 with telling about the same as the 6 pages did.
Then I learned to compress the whole story in one good title that covers the load.

When I became one of the writers of a serial weekly lines of stories, I got with the first story to the editor, very nervous ofcourse, and hand it over to him. He got it, didn't read a word and give it to his secretary and said: "This can be printed for the next edition." But …" I started. He smiled and said: "I know you can write as I have seen you work, so why checked it?" Their goes my nervous breakdown.

So if you want to have a good compact story, try first to think about a tittle. Also the first3 lines of a story make that people read up or put it back on the tabel. And the last one, try to translate a story of 6 pages to another languages. Your looking differently to a story when translating, getting the essence of it, so you learn to find what the essence is if writing your own article.
Hope this helps,

Greetings Puran.

21-7-1955 - 24-10-2011 I hope she rest in peace and I hope to see you soon.  Puran
Back to the top
 
Posted
Rating:
#66333
Avatar

Community saint

Greetings,

Having just completed a RPG core rule book, I can relate. A lot of the game testing and proofreading and such dealt with overly confusing simple subjects simply because I put way too much description in.

The vew times I've submitted documentation, the one big ccritic is that I've always had a nack for over explaning. I seem to be cursed with taking a simple 5 step procedure and turning it into a 10 step excercise filled with sub-steps and the like….

Legends of Nor'Ova: A site powered by ocPortal; home of the Legends of Nor'Ova tabletop RPG wiki and community.

Like ocPortal? Want to thank Chris and gang somehow? Then help out in the chat room! It really needs your help! Just open it in a tab everytime you open your web browser, and when you hear a "ding", check it out!

"Those who want help should first be willing to give help."
Back to the top
 
Posted
Rating:
#66334
Avatar

Honoured member

Yeh Mythus,

Two points: First you tell the first part of your message so well that the second part (afther the …) wasn't needed, so this was a nice short message with a complete story.
Second: It's jumped to my mind that if you write on two sides of the paper and just read one site you have also a short story.
In general (I,m sorry if I am wrong) you're a story writer, and a good one to from what I have seen, but somehow you hide for some private reasons (Look at your avatar, no face) and things should be perfect and has all in it before you to publish it. I like to read books with a good storyline and exitement, no perfection, so I can get deep in it and read it in one blow, and I think you can write those books.

Greetings Puran.


Last edit: by Puran

21-7-1955 - 24-10-2011 I hope she rest in peace and I hope to see you soon.  Puran
Back to the top
 
Posted
Rating:
#66523
Avatar

Community saint

ChrisW said

I've just made another tutorial about variables and state. I was going to try and press ahead towards making full blocks, but realised that they involve quite a few concepts that would be best introduced one at a time. Thus this latest tutorial still uses miniblocks as our familiar playground, but rather than using OpenStreetMap as our data source, we send a user's points to Google's Chart API which gives us pretty 3D pie charts. Enjoy :)
Thank you Chris W for another fine tutorial.:thumbs:

The use of variables is definitely essential for making any kind of code meaningful and efficient. After going through this exercise, I was emboldened with better understanding to rewrite my adaptation of a recent block modification I did to the “main_leader_board.php” block. My purpose was to create a block that would only show the members of a specific group on the leader board report. On my first try I have assigned a fixed group id number to my code and although everything works fine, I can definitely see the potential for a better leader board block where this group id could be assigned through a variable within the block’s parameters allowing for multiple usage of the same block on the site referring to different groups within the community.

So here is a snippet of the code I've added to fill my query:
Code 1 use a fixed value for the group’s ID (works flawlessly)
Code 2 attempts to replace it with a variable.

When testing the variable as the only criteria for my search, it works without error, but combining two variables returns quotes placements errors no matter which combination I use. They are nested within the same statement and the quotes should reflect this, but I cannot seem to find the correct way to set my expression. My Internet searches returned nothing that made sense with my formula. I’ve looked through other ocp php files to find something similar but came out empty.

I know that this thread is not meant to be a course on the details of PHP coding, but I’m defeated by something that seemed quite easy to understand at first glance; ‘quotes’ surrounding variables within statements.:$

Code

<?php
/* This will use the existing foreach loop of the main_leader_board.php
 to querry the f_group_members table to find out if a member
 is on the list of a specific group membership */

// Code 1:  My first method does not use a variable for the gm_group_id query field search but a fixed value of 11

        $i=0;

        foreach ($rows as $member=>$points)
        {
            if ($i==$limit) break;

            $dbuserid=$GLOBALS['SITE_DB']->query('SELECT gm_group_id, gm_member_id FROM '.get_table_prefix().'f_group_members WHERE gm_group_id=11 AND gm_member_id='.strval($member));
            //My test to find out if my code works
                if (empty($dbuserid))
                  echo "The member was not found.<br>";
                }
                else
                {
                  echo "The Member was found.<br>";
                }
            //end of test

/* Code 2: Although this works fine for one group,
    using a variable for the group id would eventually make it possible to pass a different value through the blocks parameters */

        // variable initialized here
        $groupid=11;
        $i=0;

        foreach ($rows as $member=>$points)
        {
            if ($i==$limit) break;

            $dbuserid=$GLOBALS['SITE_DB']->query('SELECT gm_group_id, gm_member_id FROM '.get_table_prefix().'f_group_members WHERE gm_group_id='$groupid' AND gm_member_id='.strval($member));
            //My test to find out if my code works
                if (empty($dbuserid))
                  echo "The member was not found.<br>";
                }
                else
                {
                  echo "The Member was found.<br>";
                }
            //end of test
Back to the top
 
Posted
Rating:
#66535
Avatar

Community saint

Hi Jean, I think the problem you're having is on this line:

Code (php)

$dbuserid=$GLOBALS['SITE_DB']->query('SELECT gm_group_id, gm_member_id FROM '.get_table_prefix().'f_group_members WHERE gm_group_id='$groupid' AND gm_member_id='.strval($member));
 

Where you've said:

Code (php)

WHERE gm_group_id='$groupid' AND
There are actually 2 problems here. You've split your string up by putting quotes before and after $groupid, but you haven't said that these parts should be joined together. To do this you need to put a dot "." just after the first quote and just before the second quote, like this:

Code (php)

WHERE gm_group_id='.$groupid.' AND
This will join the start string, the end string and $groupid together. The second problem is that the $groupid variable is a number, but you need to be joining strings together. You can fix this by using strval($groupid) rather than just $groupid, like this:

Code (php)

WHERE gm_group_id='.strval($groupid).' AND
to make the whole line look like this:

Code (php)

$dbuserid=$GLOBALS['SITE_DB']->query('SELECT gm_group_id, gm_member_id FROM '.get_table_prefix().'f_group_members WHERE gm_group_id='.strval($groupid).' AND gm_member_id='.strval($member));
 

Over the weekend I wrote a couple more tutorials (I spent 10 hours on trains and needed something to do), one of which explains PHP's types (numbers, strings, etc.), including the "." operator and the need to use strval(). I'll upload them soon :)
Back to the top
 
Posted
Rating:
#66540
Avatar

Community saint

Thanks again for this great explanation, Chris W!

In one of my many trials, I was put off track when I used the syntax of .strval($member) for .strval($groupid) with its one dot. Got also put off by the fact that the variable ‘$groupid’ must be in quotes while .strval($member) does not have any. PHP must be like the French language where “Every rule has exceptions” lol!;)

Now I will be able to continue with this project and add this variable to the block’s parameter. I’ve done some trials before and got the parameter right, I think, but was unable to link it to the PHP code by just trying to copycat some of the logics on this file. It's clear I'm missing expertize, but I was just trying it by guessing at the code for the fun of it. I was so happy to have at least made this block work for what I needed and that's rewarding.

You have piqued my interest with your tutorials and it’s about time I follow the  Making an Addon - Tutorials and Introduction to programming about PHP, where I should look for answers before solicitting more help here.

I’ll look forward to your tutorials Chris W, Thanks!:)
Jean
Back to the top
 
Posted
Rating:
#66547
Avatar

Community saint

One minor clarification where you say "the variable "$groupid" must be in quotes while .strval($member) does not have any", this isn't quite right. The quotes before and after $groupid (or .strval($groupid). in the fixed version) are actually the end quote of the preceding string and the start quote of the following string. Here's a simplified example:

Code (php)

$b = 'abc'; // $b stores the string 'abc'

$c = 'a'.$b.'c'; // $c stores the string 'aabcc'
 
The first line has the simple string 'abc', but in the second line we want to include the value of the variable $b in the middle, rather than the letter b. We can't just write 'a$bc' since this isn't the string we want, instead we have to split the 'abc' string up, which means putting in more quotes to get 'a''b''c' which is the strings 'a', 'b' and 'c'. We then replace the string 'b' with the variable $b to get 'a'$b'c' (as you can see, the quotes are surrounding the a and the c, not the $b). Finally we put dots "." between the strings which joins them together (in a similar way to "+" adding together numbers). In your case the strings aren't simple letters like these, they're SQL queries, but PHP doesn't care what's inside the strings, it just does as it's told :)
Back to the top
 
Posted
Rating:
#66556
Avatar

Community saint

I now realize that I was not seing what was really there because of my lack of understanding. LOL!
Thanks for clarifying this Chris! This is good stuf.:thumbs:
Back to the top
 
Posted
Rating:
#66589
Avatar

Community saint

I've uploaded the next tutorial Understanding PHP and its Types. It doesn't build an ocPortal component like the previous ones, since I couldn't think of anything appropriate, but I thought it was important enough to come next. It may be a little heavy-going, but it's just reference material and doesn't need to be understood in-depth (after all, type theory and semantics are on-going areas of research), however it does explain the problem Jean was having, so it's still worth a read :)

Incidentally, the picture Jean posted is quite a good visual metaphor for how types work :)
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: