Readonly Joined Forms

Bauer

Well-Known Member
Ignore the entire first part of this post which is really meant as a reply to Jaanus for this post he made to me a while back. Move on to "THAT SAID"

While I understand the concept and wish I still had the health and spirit to get into helping out, it?s just not something I could do right now. I don?t mean to sound condescending to anyone who is having fun with it ? or to sound selfish - but I learned years ago that I cannot take on any more than I need to do. The stress of any sort of community involvement only makes my condition worst. It wasn?t an easy thing to do, but I?ve basically been forced into a near hermit-like existence. The old me is missed, but the new me was finally accepted as a part of life.

My days of playing in the sandboxes of cyberspace are long past. I still enjoy playing with the new technologies as they come out. But I don?t do it to with the intent of ?making money? off of it or even to be ?sociable?- I do it out of curousity and to ?keep up? with the technology. It?s ?a hobby?.

I don?t Twitter, I don?t chat, I don?t Skype, I don?t have a Facebook page ? hell, I don?t even have a cell phone (really!).

Yet all of the aforementioned technologies or innovations - I played with them extensively when they first emerged in their earliest beta stages. But like most everything else in my life, once something becomes ?mainstream?, it?s generally about the time I lose interest and move on.

THAT SAID, I worked today on solving my biggest bitch about Fabrik. (Joined tables always being included as ?editable? in forms.)

After spending nearly the entire day just diving into the Fabrik code and trying to better understand the design, I came up with a solution that required changes in 5 lines of code in 2 php files.

If you want to take my changes and post them as a GitHub ?pull request? ? please do so. But like I said, I have no intent becoming anything more than a beta tester - at least not at this time or the foreseeable near future.

The only part of this "new feature" that I didn?t do today ? (and am hoping I won?t have to do myself, if this gets added to the Fabrik core) ? is to add the one added parameter that would be needed in the ?Groups? configuration.

That parameter would be an additional yes/no element ? i.e. ?Read-Only: o No o Yes? (with the default of No)

I just manually added that ,"read only":"1" to the end of the params field in the #__fabrik_groups where I wanted to use this new feature. Generally it would be used only in Groups that were Joined Groups.

Anyhow ? here?s the changes I made.

In /components/com_fabrik/models/form.php ? in public function getGroupView($tmpl = '') ? just after the line

Code:
$groupParams = $groupModel->getParams();
Code:
// Bauer ADDED (at about line 3991?) ? reads Group ?readonly? param
  $ro = $groupParams->get('readonly');
Then at line 4139? I added the additional readonly parameter flag...

Code:
//$element = $elementModel->preRender($c, $elCount, $tmpl,);
  // Bauer ADDDED PARAM $ro (readonly)
  $element = $elementModel->preRender($c, $elCount, $tmpl, $ro);
THEN in /components/com_fabrik/models/element.php at line 1546 ? public function preRender($c, $elCount, $tmpl)

Code:
// Bauer ADDED last param as readonly flag            
  public function preRender($c, $elCount, $tmpl, $readonly = false)
and a few lines down this if/else was changed?
Code:
if (!$this->canUse())
  {
        $this->_editable = false;
  }
   else
  {
  // Bauer CHANGED          
  // $this->_editable = ($model->_editable) ? true : false;
  $this->_editable = (($model->_editable) && (!$readonly)) ? true : false;
  }
THAT?S IT! Now any Group flagged as ?readonly? in the params will have the elements shown as readonly ?details? instead of input elements.

BTW, when working on this today I ran across an ?out of memory? error numerous times (and I have memory set to 256M). I boiled that down to inside that same public function getGroupView($tmpl = '') function in /components/com_fabrik/models/form.php (line 4110?)

Code:
$elementModel->_form = $this;
Really? You want to reiterate the entire ?$this? object here? You might want to find an alternative to that one, as it's a real memory hog.
 
$elementModel->_form = $this;

This copies the object identifier during assignment, but they still point to the same object (in PHP5). I see a 12Kb bump avg before and after that line. If it was an object clone or deepcopy thats a different story. Not sure what's going on with your test case.

If you turn on Joomla debug, under the Profile section it will show you the mem usage as Joomla loads an individual page. I'd be interested to see what yours displays (of course you may have to bump up PHP max mem temporarily to get a chance to see it render). Or do you have some XDebug log excerpts to show this?
 

Attachments

  • jdebug.png
    jdebug.png
    47.5 KB · Views: 326
Made your tweaks and did a courtesy GIT request on your behalf
https://github.com/Fabrik/fabrik/pull/366
Thank you janon!

The memory thing was probably due to all the dumping I was doing during testing.

I got to thinking since posting this that this idea could be caried to a whole new level with the inclusion of template styled for each group. (More Group params needed but the "$tmpl" name param is already being passed in that function.)

It would be an easy way to make multi-form/group pages a little less bland - where the joined table data form, using a different template, could act as a page header.
 
I haven't tried this out yet. Has anyone else?

I hope it doesn't have the same issue I discovered today with the "solution" I posted earlier.

There was one little glaring omission I missed here.:rolleyes:

If a record was edited, and a joined group is set to "readonly", a new blank record was being inserted in the joined group and the record being edited received that new id as the linked value.

This was fixed with this code - in the processToDB() function of /components/com_fabrik/models/form.php

Insert just after the line...

$joinGroupTable = $joinGroup->getGroup();

// BAUER ADDED
$joinGroupParams = json_decode($joinGroupTable->params);
If (isset($joinGroupParams->read_only) && $joinGroupParams->read_only=='1') continue;

(This continues the loop while skipping any database processing of the "readonly" joined group.)
 
As far as I know, the solution I committed doesn't do that. But to be honest I haven't done a huge amount of testing. I just ran it through my standard "join torture test" form, and it seemed to display, create and edit OK. I was kind of hoping you'd test it for me. :)

So have you investigated the wonderful world of git branches yet? Once you grok the basics of branches, it becomes extremely easy to switch between branches for testing, development and merging of individual features independently of the master.

Also, if you create a separate branch (of your fork of our master) for each new feature you work on, you can then submit pull requests independently of each other. If you only work on a single fork, then any pull requests you submit will include all changes, which often means we can't accept that request, because accepting a request is a monolithic thing, we can't pick and choose which specific changes in a request we accept.

Yes, the learning curve for git is kinda steep, but there are plenty of basic tutoials out there, and it is well worth investing some time in, as it makes any kind of participation in an open source project 100x easier. Not just Fabrik, as the majority of OS projects these days have switched or are switching to github, or similar git based services. Including Joomla, btw.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top