1
bumciach
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/10/28 10:48

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Quote:

irmtfan wrote:

Huum why not use this in xoops_version.php ?
$modversion['dirmoduleadmin']   = XOOPS_ROOT_PATH '/' 'Frameworks/moduleclasses'
$modversion['icons16']          = XOOPS_URL '/' 'Frameworks/moduleclasses/icons/16'
$modversion['icons32']          = XOOPS_URL '/' 'Frameworks/moduleclasses/icons/32';



+1


And about my experience with Objects. For me the best topic was
https://xoops.org/modules/newbb/viewtopic.php?viewmode=flat&type=&topic_id=68782&forum=28
Trabis explanation was excellent and helped me a lot in understanding how the xoopsobject works. Thus after that I had more easy in analise rest of classes like:
https://xoops.org/modules/newbb/viewtopic.php?viewmode=flat&type=&topic_id=69368&forum=4
And also analysis of Catzwolf work helped in understanding how to use objects into xoops module - his modules code was very simple (too very simplified so sometimes multiplicate sql query though). But those codes are very old so should consider other examples.



2
bumciach
Re: Integrate a html file in the template of a module
  • 2013/10/11 12:28

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Did you try use path (not url) for file= attribute?



3
bumciach
Re: Learning PHP - free books
  • 2013/6/5 7:09

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


There are tons of presentation indeed. I like this:
Your code sucks, let's fix it - 10 simple tips more or less obvious but interesting
Lithium: The Framework for People Who Hate Frameworks - Note I do not promote this framework, but the presentation gives an interesting point of view on frameworks in general.



4
bumciach
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/29 12:58

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Quote:

irmtfan wrote:
for example assume you want to store those objects like this:
$articles $article_handler->getObjects$criteria ); 
foreach (
$articles as $art) { 
  if(!empty(
$_POST["article_title"]) $art->setVar('title'$_POST["article_title"]); 
  
// echo $art->getVar('category_name');
  
$article_handler->insert($arttrue); // error because category_name is not exist.
}

so you have to write insert function too.


No. Only if I use explicitly:
$art->setVar('category_name'$_POST["category_name"])


then the insert() method return error.

Do print_r($art) after every $art->setVar() method (or $art->setFormVars)
and you will see that only those fields in $art object are flagged '[changed]=>1'
Only flaged values pass through insert() method.
Unless something has changed above xoops 3.5.4.

Quote:

side note: it is better to use getAll instead of getObjects because getObjects will be deprecated in next versions.


Good to know.



5
bumciach
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/29 8:41

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Quote:

irmtfan wrote:

@bumciach:
I am sure 2 simple queries is better than one JOIN.

but I am not sure about that when tables are more than 2 like 3, 4, 5 or more.


if I need to get data from only two tables then, in most cases I use the method you described.
In my experience. The more tables including the use of JOIN is simpler (less code). But I did not do benchmarks.


Quote:

Then it will not help you to reduce queries.


I had something else in mind

Suppouse we have two tables in db
CREATE TABLE mod_mymodule_articles (
  
article_id int(11unsigned NOT NULL auto_increment,
  
category_id mediumint(8unsigned NOT NULL default 0,
  
title varchar(50NOT NULL default '',
  
bodytext TEXT NOT NULL,
  
PRIMARY KEY  (article_id)
);
CREATE TABLE mod_mymodule_categories (
  
category_id mediumint(8unsigned NOT NULL auto_increment,
  
name varchar(50NOT NULL default '',
  
descr TEXT NOT NULL,
  
PRIMARY KEY  (category_id)
);


So...

class mymoduleArticleHandler extends XoopsPersistableObjectHandler 

  function &
getObjects($args
  { 
      
$sql "SELECT t2.name AS category_name, t1.* FROM {$this->table} t1, LEFT JOIN {$this->MODULE_X->getHandler('category')->table} t2 ON t2.category_id = t1.category_id";


We get records from DB by handler, but we access to them by object mymoduleArticle class

class mymoduleArticle extends XoopsObject
{
    
/**
     * initialize variables for the object
     */
    
function __construct()
    {
        
$this->initVar("article_id"XOBJ_DTYPE_INTnullfalse);
        
$this->initVar("category_id"XOBJ_DTYPE_INTnullfalse);
        
$this->initVar("title"XOBJ_DTYPE_TXTBOXnullfalse);
        
$this->initVar("bodytext"XOBJ_DTYPE_TXTBOXnullfalse);
        
//additional fields eg from other tables
        
$this->initVar("category_name"XOBJ_DTYPE_TXTBOXnullfalse); //this is need to get value from JOIN query 'SELECT t2.name AS category_name [...]'                
    
}
}


Usage:

$articles $article_handler->getObjects$criteria );
foreach (
$articles as $art) {
  echo 
$art->getVar('title');
  echo 
$art->getVar('category_name'); 
}


This is useful especially if in many places (and even in other modules) to get a list of titles with the name of the category. Note that in this scope we don't need all fields from joined table (mod_mymodule_categories).
In other case problably more accurate will be reference to both class (mymoduleArticle and mymoduleCategory) - you still have mymoduleCategory class with defined fields, so does not make sense to duplicate those fields in the mymoduleArticle class.



6
bumciach
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/27 9:55

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Quote:

irmtfan wrote:
Therefore because this standard has to be basic I did not add special needs (eg: special queries like joining).


I know. But I think those needs are rather common. So it would be good to mention something about join queries or best practise how use handlers/helpers to get data from two and more tables from DB. Even in the basic guideline.

Quote:
the most important thing is not adding a hard-coded table name


You are right. As I said, my example was very simplified. I have wrote this code from scratch in a minute (but I use similar in my modules, but none of them are ready enought to publish and are very very specific). So I didn't bother to write a complete query, but how to handle data. Sorry, I should have wrote more accurate code in example to be more clear.

I keep to the principle that even if I have to put a SQL query in code explicitly, do it only in the handler classes. Database query shouldn't be in many files.

Back to examples. How is more efficient? IMO It all depends on your specific requirements. If I have to display at once interconnected data from more than two tables, and reuse it in many places. For me, simpler is to add more code to the handler class to handle the join query. I think there is no big problem that one of the handlers do extra job.

Quote:
If you are very tight for using only one query you should add one field category_name to articles table.

I mean add variable initialized for the object (mymoduleArticles) not to add field into table (articles) in database.



7
bumciach
Re: How to write an standard module for xoops (div table, pagination , sort, order)
  • 2013/5/24 12:09

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Nice job.

How about joining tables?

Quote:

irmtfan wrote:
Then you should create a class for each table and in the future any access to database will be done by using those classes.


For example: displays list articles with category names.

Easy way:
1 - read articles from database by using article class
2 - for every article object do access to database by using category class
cons: duplicating queries to database - the more articles, the more requests for categories

In XoopsObject class there is getByLink() method. Using this method, we can build a query to the joined tables (by joint handlers of two classes). But it is difficult way, especially if we join more than two tables.

In more complex tasks I do this (simplified example):


class mymoduleArticleHandler extends XoopsPersistableObjectHandler
{
  function &
getObjects($args)
  {
      
$sql 'SELECT t2.name AS category_name, t1.* FROM mymodule_article t1, LEFT JOIN mymodule_category t2 ON [...]'//need add initVar('category_name') to Article class 
      
      
if($array $this->db->fetchArray($this->db->query($sql))){
            
$article $this->create(false); //for every record from db we create article Object; we don't preparing the new object to insert to database, so $isNew Flag the new objects must be false
          
$article->assignVars($array); // 'fill' Article object with data from joined tables
          
$ret[] = $article//collect every object to $ret array
      
}
      
      return 
$ret;
  }
}



8
bumciach
Multiselect checkboxes
  • 2012/12/5 14:34

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


In my projects I prefer use lists of checkboxes above select multiple. So, I extends XoopsFormCheckBox class to render this approach:http://www.1stwebdesigns.com/blog/development/multiple-select-with-checkboxes-and-jquery


But I was looking for additional improvements to the very long (filtering, autocomplete, etc.) list of options lately.
I have found some interesting jquery widgets.
http://loudev.com/
http://quasipartikel.at/multiselect/
http://harvesthq.github.com/chosen/

Pros:
- at first glance you can see what options are selected (there is no need to scroll through a long list to find out that two or three options have been selected)
- replacement for the standard <select> with multiple attribute on browser side (no need for major changes in the modules code)

Cons:
- sometimes there is no possibility to enable javascript (or script errors because of eg. updating/changeing browser in future - developer must take an action). So you are left with a standard <select> which is worse than a even simple checkbox list mentioned at the beginning.

Are you using any other solution?



9
bumciach
Re: Latest Publisher module?
  • 2012/11/28 15:02

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Quote:

bumciach wrote:
Type 'Any (OR)' and 'Exact Match' works as expected. But 'All (AND)' displays the same results as 'Any (OR)' what is wrong. More over only first keyword is highlighting (except 'Exact Match').


My bad. I forget that I have changed settings 'min keyword length' meanwhile. So one of keywords was simple ignored.



10
bumciach
Re: Latest Publisher module?
  • 2012/11/28 12:41

  • bumciach

  • Not too shy to talk

  • Posts: 153

  • Since: 2007/6/25


Quote:

trabis wrote:

I've made the class thinking on reusability. There are some differences from the original class. Check it out. If you like it we could schedule it for addition in Xoops 2.6.

Good job! I like this class.

But...
Type 'Any (OR)' and 'Exact Match' works as expected. But 'All (AND)' displays the same results as 'Any (OR)' what is wrong. More over only first keyword is highlighting (except 'Exact Match'). I start track it down and try fix in svn.

And I have some thoughts about search system (xoops in general), but it's another topic.

And (fresh install from xoops svn)
Fatal error: Call to protected method PublisherItem::assignOtherProperties() from context 'PublisherItemHandler' on line 1075

Quote:
BI've never used Transifex so I don't know. What is the best for you? Committing directly to svn is fine for me.


Neither do I use Transifex. I haven't been too active on the forum last times and only briefly read about Transifex. So I preferred to ask.




TopTop
(1) 2 3 4 ... 14 »



Login

Who's Online

102 user(s) are online (63 user(s) are browsing Support Forums)


Members: 1


Guests: 101


Heil,

more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits