Ok i got a lot of Ideas on of it is to go a for me usually way.
The Framework defines some events that may be obviously helpful,
p.e.
onPrepareContent. So i could write a plugin that would
modify/overwrite the
&row-reference passed to that plugin-method.
Like this:
- Code: Select all
function MyOnPrepareContent( &$row, &$params, $page=0 ) {
$row = MyDecoratorFactory::getPressDecorator (&$row);
}
ok thats nothing spectaculous. But here it goes on:
class PressDecorator implements IContentDecorator {
protected $content
[...]
public function __construct(stdClass $content) {
$this->content = $content;
}
//and here some delegators with interceptors
public function __get($key) {
return $this->content->$key;
//or
switch($key) {
"title":
return "Mr & Mrs.".$this->content->title; //or some thing like that ;-)
break;
}
}
//i know there a some troubles with it
public function __set($key,$value) {
$this->content->$key = $value;
}
public function __call($meth,$params) {
[...and so on]
}
[...]
}
The
Decorator/Facade pattern is one way to do it.
If you could imagine,that you put a second $item to it.
Like this
- Code: Select all
public function loadPressContent() {
$db = JFactory::getDBO();
$this->presscontent = $db->setQuery("bla...");
}
for sure we would have to modify the interceptor method, too.
In this case the
com_content-component would recieve a content_item,
with all that nice stuff like, checkin,checkout,publish, [...],
and extended informations.
The next thing is to realize that, the current architecture of the
com_content component,
did not implement any plugin-Event for content
filtering, thats a issue i had to solve too. So in this case it is a
bit tricky, because there is no way until now to recieve the
resultArray of the com_content models, there is only a way to get
the single row, as far as i know.
Why?Imagine, you have a
multilanguage site. But the articles, published
in English would not be published in German or vice versa. So there
must be a kind of filter instance. the frist possiblity is to
modify
the query, com_content fires (that would be a stupid thing), the
second is to
modify the database class (second stupid thing).
So it would be nice to have a filter Event, where the whole result is
passed.
In that case third-party developers would be able to implement, there
on lists and logics in it. p.e.
- Code: Select all
[...]
function onMyWholeResultArray(&$array,$something_useful) {
$array = MyDecoratorFactory::getDecoratorList(&$array);
}
[...]
The
List-Class could implement interfaces like ArrayAccess & Iterator.
Than you let the List-Decide to return a value or not. That is very
cool, because you never had to modify foreach or while or for statements.
p.e.
- Code: Select all
[...]
foreach($decoratorList as $key=>$value) {
//do some tricky stuff...we donot know
}
-> decorator list
public function __construct($list) {
$myarray = array();
foreach($list as $key => &$value) {
if (method_exists($value,"isValid")) { //is this a content item?
if (($value->isValid())) {
$myarray[$key]= $value;
}
}
else
{
$myarray[$key] = $value;
}
}
$list = $myarray;
$this->list = $list;
$this->arraykeys = array_keys($list);
}
[...]
so
the specific decorator could descide, if it would be displayed in a blog-listing or not.
- Code: Select all
[...]
function isValid() {
if ($this->extracontent->englishOnly) {
return false; // so there is no way to display it, in a german site
}
}
[...]
Because, in my current project, we use a modified joomfish on a joomla1.5 as a own database class
i did the modification there, because
i don't want to touch the code of the com_content models,
but i think that this second improvement, would give us all more possibilities.
I've worked a long time with the
eclipse RCP-Framework and there were
extensionpoints defined,
in a extra xml file to that component. A quite nice thing. In fact the philosophy of the
Eclipse Project and its plugin-strategy is:
that everything is a plugin. I also thought about
PHP AOP to let an Aspect-Weaver do the job, so
the code of com_content, is
updateable, but in runtime would be intercepted
by an defined
Aspect.
ok what do you think?
how would you do this?
is there an issue i didn't thought of?
perhaps you got a better way?i would love it, if you would let me know your thoughts about it.
greets mario
*joomla is so cool*