Showing posts with label zoo joomla extension. Show all posts
Showing posts with label zoo joomla extension. Show all posts

Tuesday, September 10, 2013

Zoo CSV Import - Assign fields automatically

Zoo is Joomla's one of the best CCK extension. It's flexible and powerful content application builder to manage your content. Zoo allows to import data in JASON or CSV format. Data import done in following 3 stages.
1) Upload CSV file.

2) Select delimiters.Type in the field separator and the field enclosure of the CSV file.

3) Assign the submission fields to the appropriate CSV files columns. Here you have to assign the data in your CSV file to an item type of the app.
1st & 2nd stage of data importing is very easy & straight forward where as 3rd stage will be depends on how many submission fields you have map to the appropriate CSV files columns. Its fine, if you have to map 4-5 fields but what if you wanna map 20-30 fields & you want to upload large data. This stage kills you. Here we have solution for you. You just have to override administrator/components/com_zoo/views/configuration/tmpl/importcsv.php file. Add a Auto Map button & some script on click of Auto Map button in the file. That's it. Lets add the button first. Put this code anywhere you want to see the Auto Map button on page.

Add the following Jquery script.
 
  $("#automap").click(function(){
  
    
    $("li.assign").each(function(){
      
      var catname = $(this).find("span.name").text();
           
      
      
      if($(this).find('select.assign option').filter(function () { return $(this).html().toLowerCase() == catname.toLowerCase(); }).val()){
       $(this).find('select.assign option').filter(function () { return $(this).html().toLowerCase() == catname.toLowerCase(); }).attr("selected","selected");
       //$(this).find('select.assign').css("border", "1px solid green");
      }else{
       $(this).find('select.assign option').each(function(){
         var crval = $(this).text().toLowerCase();
         catname = catname.toLowerCase();
         //console.log(crval.split(catname).length);
         
         if(crval.split(catname).length > 1 ){
           $(this).attr("selected","selected");
           $(this).closest("select.assign").css("border", "1px solid red");
           
         }else if(catname.split(crval).length > 1){
           $(this).attr("selected","selected");
           $(this).closest("select.assign").css("border", "1px solid red");
         }
       })
       
      }
      
    });
   
   
  });
  

Friday, October 26, 2012

How to render zoo records easily

Zoo - one of the most popular Joomla extension has a view which shows just a single record, that is of course full view. Zoo doesn't have a view which shows a list of records of particular submission type. So what if you want to show a list of zoo items of particular type in your extension.
You must be thinking what's the big deal, based on submission id just fetch the records & show it how you want. Wait a minute. Its not as easy as you think as Zoo uses JSON method to store record's which is quite difficult to render zoo elements. So its quite complicated to get zoo items details from database by executing queries.
Even if you manage it won't be robust cause to get related records from table you have to deal with hard coded 36 key string, which zoo uses as field identifier. So lets get away from this hassle.
Here is the snippet to render the details of zoo records quite easily.

$zapp = App::getInstance('zoo');
$items = $app->table->item->all(array('conditions' => 'id = '.$Zoo_Item_id));
//$Zoo_Item_id must be zoo item id of which you want to render details

foreach($items as $item)
{       
   foreach ($item->getElements() as $id => $element)
   {
      echo $element->render();
} }
Here you can see how we are showing Zoo related records in table. We have added link for full view of respective Zoo Item as well.

Sunday, October 7, 2012

How to construct link to edit single zoo record


I'm writing this post because its quite tricky to create a link which edits a zoo record based on zoo item id unless you know how exactly zoo construct hashes.
When we asked on zoo forum they didn't reply with the following solution. I must admit that zoo component is excellent but their support is very poor & you know zoo support is paid! Okay leave it & lets move to the link.
Stop thinking that I'll pass zoo id to the zoo's my submission menu link to create edit record link. What?? have you tried it?? Does it says Hashes did not match. Alright Don't worry you are the right place.
Its very easy, you just need to pass submission type of zoo item & zoo item id itself to the getSubmissionHash API which returns you respective hash for the item.

$zapp = App::getInstance('zoo');
$items = $zapp->table->item->all(array('conditions' => 'id =$zoo_item_id)); 
//$zoo_item_id must be zoo record id which you want to edit.
$type = $items[$item->id]->type;
// get submission type of item
$hashRelated = $zapp->submission->getSubmissionHash(1,$type, $item->id); 
 // Here is the exact hash for the record

$href = JRoute::_(JURI::Base()."index.php?option=com_zoo&view=submission&layout=submission&submission_id=1&type_id=$type&item_id=$item->id&submission_hash=$hashRelated"); // Construct link as zoo 

echo '<a href=".$href.">Edit Record</a>';