script

Wednesday, May 16, 2012

TYPO3 : Call repository of external extension in ext base

//parameters match with uid of table
$matchVal = 1;

//create object of repository that need to be called
$jobs = new Tx_Jobs_Domain_Repository_JobsRepository();   


//create query and get details of all properties under model
$query = $jobs->createQuery();
$cond = $query->equals("uid",$matchVal);
$query->matching($cond);


//for fetching just one property (only description will be fetched)
$row = $query->execute()->getFirst()->getDescription();
print_r($row);

//for fetching all property (All properties will be fetched)
$row = $query->execute()->getFirst();
print_r($row);

Thursday, May 10, 2012

Mapping template with fluid

TypoScript FLUIDTEMPLATE cObject

Without further ado, here's the page object that utilizes FLUIDTEMPLATE:
page = PAGE
page{
   typeNum = 0   
   10 = FLUIDTEMPLATE
   10 {
      partialRootPath = fileadmin/templates/partials/
      layoutRootPath = fileadmin/templates/layouts/
      file.stdWrap.cObject = CASE
      file.stdWrap.cObject {
         key.data = levelfield:-1, backend_layout_next_level, slide
         key.override.field = backend_layout
         default = TEXT
         default.value = fileadmin/templates/home.html
         2 = TEXT
         2.value = fileadmin/templates/sub.html
      }     
      variables {         
         left < styles.content.get
         left.select.where = colPos=1        
         content < styles.content.get        
         right < styles.content.get
         right.select.where = colPos=2        
      }

   }
}
 
OR SHORTER VERSION
 
page = PAGE
page {

    headerData.11 = HTML
    headerData.11.value = <link href="fileadmin/templates/css/style.css" rel="stylesheet"/>

  10 = FLUIDTEMPLATE
  10 {
            file = fileadmin/templates/fluid.html
            partialRootPath = fileadmin/templates/Partials
            layoutRootPath = fileadmin/templates/Layouts
            variables {
              pageTitle = TEXT
              pageTitle.data = page:title
              left < styles.content.getLeft
              normal < styles.content.get
              right < styles.content.getRight
          }
    }
} 
 
Notice the file selection is based on what the current BE grid is used, so you can define multiple layouts. Of course in order for this to work, you need to define a few backend grids and remember their UIDs because those are used as keys in the CASE cObject above.

Fluid/HTML Template

Next, let's look at the home.html which is used in this example:
<div id="wrap">
  <div id="menu">
    <f:cObject typoscriptObjectPath="lib.navigation" />
  </div>
  <div id="left">
    <f:format.html parseFuncTSPath="lib.parseFunc">{left}</f:format.html>
  </div>
  <div id="content">
    <f:format.html parseFuncTSPath="lib.parseFunc">{content}</f:format.html>
  </div>
  <div id="right">
    <f:format.html parseFuncTSPath="lib.parseFunc">{right}</f:format.html>
  </div>
</div>
As you can see, you can include other TS-defined objects inside your fluidtemplates as well!
This is pretty much all there is to it, the most interesting part of this, compared to TemplaVoila!, is that you can modify your HTML templates without the need to refresh (okay, apart from the 'clear cache' button that you are so used to click) or remap anything.
Also there is no additional tables, wizards or extensions, you use what you already get with the core. Enjoy!

Friday, May 4, 2012

Insert pagination using TYPO3 pagebrowse

1) Define this function of pagebrowse

public function getListGetPageBrowser($numberOfPages)
{
    // Get default configuration
    $conf = $GLOBALS['TSFE']->tmpl->setup['plugin.']['tx_pagebrowse_pi1.'];

    //Modify this configuration
    $conf += array( 'pageParameterName' => $this->prefixId . '|page', 'numberOfPages' => $numberOfPages,);
  
    // Get page browser
    $cObj = t3lib_div::makeInstance('tslib_cObj');
    /* @var $cObj tslib_cObj */
    $cObj->start(array(), '');
    return $cObj->cObjGetSingle('USER', $conf);
}
  
2)Logic of pagination where query built

// pagination logic start

if(isset($_GET['tx_property_pi1']['page']))
    $page=$_GET['tx_property_pi1']['page'];
else
    $page=0;

$no_of_records = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
$i = $page*$this->records_per_page;
$paginationStart = $page*$this->records_per_page+1;
$paginationEnd = ($paginationStart+$this->records_per_page-1 <= $no_of_records)?$paginationStart+$this->records_per_page-1:$no_of_records;
$pagin = ceil($no_of_records/$this->records_per_page);
$count = 0;
$record = $paginationStart;

//logic for pagination over


3)Fetch results one by one using while loop (code that need to put after code of step2)

while(($count<$this->records_per_page) && ($i<$no_of_records))
{
    mysql_data_seek($res,$i);
    $row = mysql_fetch_array($res);
    $i++;
    $count++;
    //Your code
}


//call function to display pagination
 echo $this->getListGetPageBrowser($pagin);

Thats it!!