56 Posts
Saturn2888
10 years ago
7
Topic

Hi all! I've been using Seblod for 3 months now and haven't yet found a way to get the CCK_Rendering version of an "Article (Related)" field. Does anyone know how?


If I do:

   $article =& JTable::getInstance("content");
   $articleId = 5;
   $article->load($articleId);


I can get an article, but in the introtext field, all I get is the ::cck::35::/cck:: information. Is it possible to convert this to a valid CCK array or object?


Thanks!

Get a Book for SEBLOD
4 Posts
Clément Wam
10 years ago
1
Level 1

Hi Saturn2888, I have the same issue. Did you find a solution ?

Thanks

56 Posts
Saturn2888
10 years ago
0
Level 2

I completely re-did how I was pulling values. Since I'm using the Standard storage method now instead of Custom -> introtext, I had to re-think it. In the Seblod template's index.php file, you can have it roll through a function that loops through your $cck variable and positions and is able to pull in all values.

I was able to set it up where when ->value is an article id, I just pass that to an array I created where the article id is the associative array value.

This is how I'm getting all related fields (via index.php):


   function getAllFields($cck) {
     $fields = array();
     $fieldNames = $cck->getFields('template', '', false);

     foreach ($fieldNames as $fieldName) { // All CCK fields
       $cckValue = $cck->get($fieldName)->value;

       if (is_array($cckValue)) { // Article (Related) or GroupX
         foreach ($cckValue as $cckRelatedArticleField) {
           if (is_object($cckRelatedArticleField)) { // Article (Related)
             $fields[$fieldName][$cckRelatedArticleField->name] = $cckRelatedArticleField->value;
           } else { // GroupX
             foreach ($cckRelatedArticleField as $i => $cckGroupXField) {
               $fields[$fieldName][$i][$cckGroupXField->name] = $cckGroupXField->value;
             }
           }
         }
       } else {
         $fields[$fieldName] = $cckValue;
       }
     }

     return $fields;
   }

449 Posts
gebeer
10 years ago
0
Level 1

Hello Saturn2888 and Clément Wam,


I, too, would be interested in a solution.


It would be great if that functionality could be implemented into the related article field as an additional option in the "Processing" section of that field.


MAybe we should file a feature request on the tracker, what do you think?

56 Posts
Saturn2888
10 years ago
1
Level 1

Yeah, I figured out 2 solutions. One I was using long before posting this, the other I got recently. Neither solution is native. I tried my hardest to create a CCK_Rendering object from the article ID, but I was unable to even though Seblod does it somehow to create the $cck var in the view.


One of my solutions was to parse the introtext field using regex and pulling the values from it. It's not perfect, but it has worked for me so far.


The other solution was to create an HTML comment at the top of the view and put the ->value or ->text fields in there encoded into JSON. Then in the view of my article, I would parse for <!--{ to }--> and JSON decode the contents to get me those variables.


Both ways have their downfalls in terms of what you have access to and how much parsing is necessary.

4 Posts
Clément Wam
10 years ago
0
Level 2

Hello,


I finally do the same with a sql query and a parsing :

$cck_path = JPATH_BASE . DS . 'components' . DS . 'com_cck';
if (file_exists($cck_path) && JComponentHelper::isEnabled('com_cck', true)):

// get text
       $db =& JFactory::getDBO();
       $query = "SELECT `introtext` FROM `#__content` WHERE `id` =" . $this->item->id;
       $db->setQuery($query);
       $text = $db->loadResult();
// Force parsing plugin if SEBLOD is used
if($this->config['parse_plugins'] == false) :
// clean sting
$parsed = array("::introtext::", "::/introtext::<br />", "::fulltext::", "::/fulltext::");
$fulltext = str_replace($parsed, "", $text);
$fulltext = preg_replace('%::cck::.+?::/cck::<br />%i','',$fulltext);
endif;  
endif;

56 Posts
Saturn2888
10 years ago
1
Level 1

I've done some more work on this, it seems to be impossible to pull in fields saved using the Standard storage method. I dunno how Seblod does it, but the key seems to be this static call: CCK_Document::getInstance( 'html' );


Doing so gets you what is essentially a $cck var, but there's no way to alter the article ID for it as far as I can tell.

26 Posts
isometriq
9 years ago
0
Level 2

Hello guys, just found this post and I think have the same issue:
http://www.seblod.com/community/forums/forms-content-types/cck-rendering-helper#post17434

There should be a shared programming interface that the Seblod core AND the developer use. This is a very important feature that should be there.

Like I described in my post, the functionality seem to be "jammed" in the CCK content plugin. One could take parts of the code to create a helper, but it's unclean and prone to future problems. However that may be a short-term solution...

Get a Book for SEBLOD