New Extensions for Reports

Discussion in 'Extensions' started by Mac, Mar 17, 2016.

  1. Mac

    Mac New Member

    Joined:
    Mar 17, 2016
    Messages:
    4
    Likes Received:
    1
    S.E:
    2020-03-03 22:43:28
    L.T:
    Regular
    L.C:
    3
    Hi All,

    I want to make a extension for reports using jasper yii extension http://www.yiiframework.com/extension/yiijasper/

    I search forum and find that i have to make a controller for this, Is any body please guide me the right steps to make that extension.

    Any help will be highly appreciated.

    Thanks!
     
    nadworks likes this.
  2. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,587
    Likes Received:
    2,459
    @Mac - You can create your own controller in mailwizz, and simply place your logic there, so you can have a Jasper_reportsController.php file and put your login in it, like:
    PHP:
    class Jasper_reportsController extends Controller 
    {
        public function 
    init()
        {
            
    parent::init();
            
    // make sure we load the extension
            
    Yii::import('ext.YiiJasper.*');
        }
        public function 
    actionIndex()  
        {
             
    $pages '1-4';
             
    $re = new JasperReport('/reports/samples/AllAccounts');
             
    $re->exec();
              echo 
    $re->toHTML($pages); //Page 1 to 4
        
    }
    }
     
  3. Mac

    Mac New Member

    Joined:
    Mar 17, 2016
    Messages:
    4
    Likes Received:
    1
    S.E:
    2020-03-03 22:43:28
    L.T:
    Regular
    L.C:
    3
    Hello Twisted,

    Thanks for your reply and codes.

    I created a controller file and put it "apps/backend/controllers" folder.

    Now my problem is how can i access that file, how can i create a Menu Item to access that controller.

    Thanks a lot!!!
     
  4. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,587
    Likes Received:
    2,459
    @Mac - You should be able to access it at a url like: http://www.domain.com/backend/index.php/jasper_reports
    As for putting it in menu, it's simple, inspired from: https://forum.mailwizz.com/threads/customer-area-menu-items.6/, (read that article too)
    you can create and use an extension to accomplish this:
    PHP:
    <?php defined('MW_PATH') || exit('No direct script access allowed');

    class 
    CustomMenuItemsExt extends ExtensionInit
    {
        
    // name of the extension as shown in the backend panel
        
    public $name 'Custom menu items';
        
    // description of the extension as shown in backend panel
        
    public $description 'Add new links in the menus';
        
    // current version of this extension
        
    public $version '1.0';

        
    // the author name
        
    public $author 'Your name';
        
    // author website
        
    public $website 'http://www.website.com/';
        
    // contact email address
        
    public $email 'your.email@domain.com';
        
    // in which apps this extension is allowed to run
        
    public $allowedApps = array('customer''backend');

        
    // can this extension be deleted? this only applies to core extensions.
        
    protected $_canBeDeleted true;
        
    // can this extension be disabled? this only applies to core extensions.
        
    protected $_canBeDisabled true;

        
    // run the extension, this is mandatory
        
    public function run()
        {
            if (
    $this->isAppName('backend')) {
                
    Yii::app()->hooks->addFilter('backend_left_navigation_menu_items', function($items){
                    
    $items['jasper_reports']  = array(
                        
    'name'   => Yii::t('app''Jasper reports'),
                        
    'icon'   => 'glyphicon-book',
                        
    'active' => 'jasper_reports',
                        
    'route'  => array('jasper_reports/index'),
                    );
                    return 
    $items;
                });
            }
        }
    }
     
  5. Mac

    Mac New Member

    Joined:
    Mar 17, 2016
    Messages:
    4
    Likes Received:
    1
    S.E:
    2020-03-03 22:43:28
    L.T:
    Regular
    L.C:
    3
    Hello Twisted,

    Thanks for the codes, i am able to run the controller, but i have now more issue, the below code
    PHP:
    public function actionIndex()
        {
             
    $pages '1-4';
             
    $re = new JasperReport('/reports/samples/AllAccounts');
             
    $re->exec();
              echo 
    $re->toHTML($pages); //Page 1 to 4
            //echo 'hi';
        
    }
    is not running but when i comment this code and just simple echo 'hi' its show 'hi' without layout.

    I placed the 'YiiJasper' extension folder in "apps/extensions" and configured it like as per document.

    Please check debug mode screenshot in attachment.

    Whats wrong there, please guide.

    Thanks!
     

    Attached Files:

    Last edited: Mar 19, 2016
  6. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,587
    Likes Received:
    2,459
    @Mac - seems Yii::import('ext.YiiJasper.*'); is not valid. Try Yii::import('root.apps.extensions.YiiJasper.*'); or simply require the JasperReport.php class directly using the absolute path.
     
  7. Mac

    Mac New Member

    Joined:
    Mar 17, 2016
    Messages:
    4
    Likes Received:
    1
    S.E:
    2020-03-03 22:43:28
    L.T:
    Regular
    L.C:
    3
    Thanks for your inputs, Yes now its seams to working but its have another issue, please check screen shot.

    I think its a "path" problem.

    Thanks for all your help, really appreciated.
     

    Attached Files:

  8. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,587
    Likes Received:
    2,459
    It's a timeout issue, basically the report generating takes too much time.
    Just increase your PHP timeout limit to a few minutes, by default it's 30 seconds i believe, then try again.
     
  9. mwz.publitech

    mwz.publitech New Member

    Joined:
    Nov 9, 2016
    Messages:
    21
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    4
  10. mwz.publitech

    mwz.publitech New Member

    Joined:
    Nov 9, 2016
    Messages:
    21
    Likes Received:
    0
    S.E:
    Expired
    L.T:
    Regular
    L.C:
    4
  11. twisted1919

    twisted1919 Administrator Staff Member

    Joined:
    Dec 27, 2014
    Messages:
    10,587
    Likes Received:
    2,459
    @mwz.publitech - The file is located at /apps/frontend/views/campaigns_reports/login.php and the translation should be done in the campaign_reports.php file ;)
     
  12. nadworks

    nadworks Member

    Joined:
    Apr 20, 2015
    Messages:
    154
    Likes Received:
    20
    S.E:
    2020-06-16 18:31:29
    L.T:
    Regular
    L.C:
    3

Share This Page