protected function execute($arguments = array(), $options = array())
  {

    if (!$options['go']) 
      $this->logBlock('Running in dry mode, no files will be created.', 'ERROR');

    $pdf_dir  = sfConfig::get('sf_data_dir').sfConfig::get("app_rockstep_pdf_dir");
    $html_dir = sfConfig::get('sf_data_dir').sfConfig::get("app_rockstep_html2pdf_dir");

    // get PDF file-info
    $pdf = array();
    $weeds = array('.', '..','.DS_Store'); 
    $directory = array_diff(scandir($pdf_dir), $weeds); 
    foreach( $directory as $id => $filename ) {
      if (is_file($pdf_dir.$filename)) {
        $info     = pathinfo($filename);
        $basename =  basename($filename,'.'.$info['extension']);
        $timestamp = filemtime($pdf_dir.$filename);
        $pdf[$basename] = $timestamp;
      }
    }
    
    // get HTML files and compare to PDF
    $files2process = array();
    $weeds = array('.', '..','.DS_Store'); 
    $directory = array_diff(scandir($html_dir), $weeds); 

    if (!$options['force']) {
      $this->logBlock(sprintf("Checking %d files in %s", count($directory), $html_dir), 'COMMENT');
    } else {
      $this->logBlock(sprintf("Processing all %d files from %s", count($directory), $html_dir), 'COMMENT');
    }

    foreach( $directory as $id => $filename ) {
      if (is_file($html_dir.$filename)) {
        //$info     = pathinfo($filename);
        $basename = basename($filename,'.pdf.html'); //.$info['extension']);        
        if (!$options['force']) {
          if (array_key_exists($basename, $pdf)) {
            if ($pdf[$basename] >= filemtime($html_dir.$filename)) {
              continue; // pdf is up to date
            }
          }
        }
        $files2process[$html_dir.$filename] = $pdf_dir.$basename.'.pdf';
      }
    }
    
    // process PDF
    $error = 0; $success = 0;
    if (count($files2process) == 0) {
      $this->logBlock('Everything is up to date.', 'INFO');
    } else {
      $this->logBlock(sprintf("%d files to process", count($files2process)), 'INFO');
      foreach ($files2process as $html_path => $pdf_path) {
        
          $css = '/backend/pdf/kursliste.css';
          $format = 'A4-L';

        /*
        if (strpos($html_path, 'Absenzen') !== false ) {
          $css = '/backend/pdf/kursliste.css';
          $format = 'A4-L';
        } else {
          $css = '/backend/pdf/class_etat.css';
          $format = 'A4-L';
        }
        */
        
        if ($options['go']) 
          Swingmachine::mpdf($html_path, $pdf_path, $css, $format);
        $this->logSection('file+', sprintf("%s", basename($pdf_path)));
        $success++;
      }
        
      if ($error > 0) {
        $this->logBlock(sprintf('An error occured. No idea what went wrong. Sorry.', $error, $success), 'ERROR');
      } else {
        $this->logBlock(sprintf('%d PDF files created', $success), 'INFO');
      }

    }
    
  }
Ejemplo n.º 2
0
public function generateKurslistePDF($download = null)
{
          $filename = $this->getKurslisteFilename();
          $html2pdf_dir = sfConfig::get('sf_data_dir').sfConfig::get('app_rockstep_html2pdf_dir');
          $css = '/backend/pdf/kursliste.css';
          $format = 'A4-L';
          Swingmachine::mpdf($html2pdf_dir.$filename.'.html', $filename, $css, $format, $download);

          return true;
}