Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Content ID and Position Number Assignment  (Read 4734 times)

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Content ID and Position Number Assignment
« on: January 31, 2008, 05:45:09 pm »

In answer to the question:
How does sNews assign ID and Position numbers to its content and how are they used?

sNews 1.6 has five types of content-related data, each stored in their respective database tables:

- The articles table stores the data related to three of them - article, page and extra content only.
- The categories table stores the data related to the 4th, categories only.
- The comments table stores the data related to the 5th, comments only.

The settings table contains pre-set, mostly editable (from settings panels) data that serve as variable values system-wide.

Content ID Numbers:
All content types are identified by an ID number when it gets saved to and stored in its respective dbase table.
These ID numbers are automatically assigned by MySQL, using MySQL's built-in "auto-increment" function.
When you start out with your first category... or article/page/extra... or comment, the first one gets assigned an ID of "1" in its respective table since it is the first one. Each entry saved thereafter gets the next "incremented" number... 2, followed by 3, followed by 4... and so on.
The ID number stays with the data entry it is assigned to forever. If that entry is deleted, its ID number is also gone for ever with it.
MySQL keeps using the next incremental number after the last one assigned.

Position Numbers for Article, Page or Extra Content:
Each of these content types is assigned a "position" number when saved to the dbase articles table.
The "position" number is used to tell the difference between an article, a page, or an extra content.
The function(s) in snews.php decide what content will be displayed by retrieving and checking the content position number for the content being requested. If the content being requested is an article, then the function(s) will check to see if it the article has a position number of 1 and, if it does, will display it.
If the content being requested is a page, the function(s) checks if the page has a position number 3 and if it has that position number, the content gets displayed.

Extra Content Position Numbers
Extra contents stored in the articles table are identified in a similar fashion. All extra contents are assigned a position number of 2.
When you view the position number for an extra content - in the data row within the article table itself (using phpMyAdmin) - you'll notice that it will have 3 digits instead of one.
- The first digit "2" identifies it as as "extra"-type content.
- The 2nd digit identifies it as being assigned to an article or page - 1 for an article or 2 for a page.
- The 3rd digit identifies whether it is assigned to an article on the "Home" (0), or to an article under a specific category... in which case the 3rd digit will be the ID number of the category to which it is assigned.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

bikoz

  • Jr. Member
  • **
  • Karma: 3
  • Posts: 66
Re: Content ID and Position Number Assignment
« Reply #1 on: January 31, 2008, 06:29:28 pm »

First thing: thank you for the explaination.

- The 2nd digit identifies it as being assigned to an article or page - 1 for an article or 2 for a page.

I'm lost: how can I assign an Extra to an article? Did you mean "Category" instead?

Quote
- The 3rd digit identifies whether it is assigned to an article on the "Home" (0), or to an article under a specific category... in which case the 3rd digit will be the ID number of the category to which it is assigned.

Does 'Home' here refers to 'All' categories (or pages) in to the dropdown list in the form?

Another question: I've just created a new Extra and it has a category of -1. Is this supposed to mean something like "undefined"?

Last thing: I've noticed that Extras can become Pages (and vice-versa) if you switch the Position in the form (during an edit, not at creation time if I remember well). Is that normal, i.e. by design?


« Last Edit: January 31, 2008, 07:38:01 pm by bikoz »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: Content ID and Position Number Assignment
« Reply #2 on: January 31, 2008, 09:20:23 pm »

Quote from: bikoz
- The 2nd digit identifies it as being assigned to an article or page - 1 for an article or 2 for a page.
I'm lost: how can I assign an Extra to an article? Did you mean "Category" instead?

You cannot assign (position) an extra to a specific article, but sNews generates an article page (not an actual page in the same way a real single page is created). When you assign articles "Home", then  they will accumulate on the default "Home page"... if you have the articles function-name set to display 3 or 5 articles... then it will display 3 or 5 articles there. The same thing happens when you assign an article to a category... an articles 'page' gets created and all articles assigned to that category will accumulate on that category's articles page. In all these cases... the 2nd digit in the extra's 3-digit number will be "1". Now (I know this can be confusing...) if you assign the extra to a specific page you created... then the 2nd digit will be a "2"... no matter what category the page is in.

Quote from: bikoz
Quote from: keyrocks
- The 3rd digit identifies whether it is assigned to an article on the "Home" (0), or to an article under a specific category... in which case the 3rd digit will be the ID number of the category to which it is assigned.
Does 'Home' here refers to 'All' categories (or pages) in to the dropdown list in the form?

"Home" is treated as if it was a category, even though it isn't really a category like the ones we create by name. So, "0" is used to identify Home... and all categories we create by name then get assigned numbers starting from "1" and going up from there.

Quote from: bikoz
Another question: I've just created a new Extra and it has a category of -1. Is this supposed to mean something like "undefined"?

Yes. Whenever you create an extra without assigning it to anywhere... it will be visible everywhere and is referred to as "All extra contents". Also, when you do this... you'll notice that the "position" number becomes a single-digit one... just "2"... because... since we did not say it was to a specific page or category... there is no need to have a differential reference to page (vs a category's article page) or a category. Only the 1st digit is needed to recognize that it is... indeed... an "Extra".

Quote from: bikoz
Last thing: I've noticed that Extras can become Pages (and vice-versa) if you switch the Position in the form (during an edit, not at creation time if I remember well). Is that normal, i.e. by design?

I do not know if this was done "by design" or not but it probably was. However, if you change the position of an "Extra" to that of a "Page", it will become an "Uncategorised Page". In order to have it display somewhere as a page, you would then Edit it from the Edit Pages list and then assign it to be displayed somewhere. At least that's how it appears to work for me.   ;D

Finally... I should note that I am not the absolute "expert" on how all this works. I've just explained it as best I can since I cannot find an explanation anywhere else. So... please keep in mind that my interpretation of how this all works is open to correction or further clarification by anyone else.  ;)
« Last Edit: January 31, 2008, 09:25:58 pm by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

bikoz

  • Jr. Member
  • **
  • Karma: 3
  • Posts: 66
Re: Content ID and Position Number Assignment
« Reply #3 on: January 31, 2008, 09:40:42 pm »

Quote from: Keyrocks
You cannot assign (position) an extra to a specific article, but sNews generates an article page (not an actual page in the same way a real single page is created). When you assign articles "Home", then  they will accumulate on the default "Home page"... if you have the articles function-name set to display 3 or 5 articles... then it will display 3 or 5 articles there. The same thing happens when you assign an article to a category... an articles 'page' gets created and all articles assigned to that category will accumulate on that category's articles page. In all these cases... the 2nd digit in the extra's 3-digit number will be "1". Now (I know this can be confusing...) if you assign the extra to a specific page you created... then the 2nd digit will be a "2"... no matter what category the page is in.

I think I'll have to re-read this paragraph 10 times before I understand, but whatever happens to my brain I thank you for clarifying this point. (I imagine a normal person don't need to know this kind of thing, but I'm curious to death, sorry :-)


Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6020
  • Semantically Challenged
    • snews.ca
Re: Content ID and Position Number Assignment
« Reply #4 on: January 31, 2008, 10:54:40 pm »

I think I'll have to re-read this paragraph 10 times before I understand, but whatever happens to my brain I thank you for clarifying this point. (I imagine a normal person don't need to know this kind of thing, but I'm curious to death, sorry :-)

No need to apologise. It wasn't easy for me to explain... not having done it before... but it was a learning exercise for me as well.  :)
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

centered

  • Guest
Re: Content ID and Position Number Assignment
« Reply #5 on: January 31, 2008, 11:36:18 pm »

To fully understand function extra, read up on Mika's Developer Edition:
Quote
      - example 1: $r['position'] = 2133 (category dependancy)
         - first number: 2 -> "extra" position (note: "article" is at the position 1, "page" is at the position 3)
         - second number: 1 -> category dependant flag (if the second number is 2, that would define "page" dependancy)
         - rest of the numbers: 33 -> category id (category which this extra is dependant on)
      - example 2: $r['position'] = 22105 (page dependancy)
         - first number: (see above)
         - second number: 2 -> page dependant flag
         - rest of the numbers: 105 -> page id (page which this extra is dependant on)
      - example 3: $r['position'] = 20 (home dependancy)
         - first number: (see above)
         - second number: 0 -> "home" has hardcoded ID set to zero
      - example 4: (no dependancy)
         - $r['category'] = -1
         - second number of position value must not be 2

I read this myself a few times to get it, then decided to write my own extra function.... http://snewscms.com/forum/index.php?topic=6742.0

I'm lost: how can I assign an Extra to an article? Did you mean "Category" instead?

Currently you cannot assign an extra to an article, it would be nice but I am guessing it wouldn't be too hard to do with what we have now.  A page is essentially an article...
« Last Edit: January 31, 2008, 11:39:14 pm by equilni »
Logged

bikoz

  • Jr. Member
  • **
  • Karma: 3
  • Posts: 66
Re: Content ID and Position Number Assignment
« Reply #6 on: January 31, 2008, 11:48:55 pm »

To fully understand function extra, read up on Mika's Developer Edition:
Quote
      - example 1: $r['position'] = 2133 (category dependancy)
         - first number: 2 -> "extra" position (note: "article" is at the position 1, "page" is at the position 3)
         - second number: 1 -> category dependant flag (if the second number is 2, that would define "page" dependancy)
         - rest of the numbers: 33 -> category id (category which this extra is dependant on)
      - example 2: $r['position'] = 22105 (page dependancy)
         - first number: (see above)
         - second number: 2 -> page dependant flag
         - rest of the numbers: 105 -> page id (page which this extra is dependant on)
      - example 3: $r['position'] = 20 (home dependancy)
         - first number: (see above)
         - second number: 0 -> "home" has hardcoded ID set to zero
      - example 4: (no dependancy)
         - $r['category'] = -1
         - second number of position value must not be 2

I read this myself a few times to get it, then decided to write my own extra function.... http://snewscms.com/forum/index.php?topic=6742.0

Thanks a lot! I see the light now  ;-)
Logged