use return array() to put a 'type'=>'link' into that?

Snippets, useful things or other stuff here.

Moderator: alexandrleonenko

paragate
Master
Master
Posts: 151
Joined: Nov 13th, '14, 13:04
Location: Denmark, Odense

use return array() to put a 'type'=>'link' into that?

Postby paragate » May 17th, '17, 21:35

Hi,
I want to check if status in ecart is 2 and if then in the view customers/dashboard (recent orders lines)
i want a 'type'=>'link' instead of 'type'=>'label'. is it possible to use return array for that

Code: Select all

return array(
           
            // if paid the status is 2  put a 2 in video_check otherwise 0
            'IF(status = 2,
                2,
                0
            )'=>'video_check'
        );

Or do you have a good idea
many regards

ne_moj
Master
Master
Posts: 243
Joined: Jan 1st, '16, 14:11

Re: use return array() to put a 'type'=>'link' into that?

Postby ne_moj » May 18th, '17, 20:57

Hello Henrik

As you understand, you use the scratch Shopping Cart. But I did not understand what you want to do. It seems to me that you can put a simple "if" in the view customers/dashboard where you will check "status == 2" then you will perform certain actions. As I understand at the moment you want to make an additional field through the method _customFields()?

paragate
Master
Master
Posts: 151
Joined: Nov 13th, '14, 13:04
Location: Denmark, Odense

Re: use return array() to put a 'type'=>'link' into that?

Postby paragate » May 19th, '17, 08:02

Hi Sergey
Actually its very simple. I want to have a download link visible on ecart orderline when a user have paid
but the link shall only be visible for 24 hours.
What is the easiest method?

Code: Select all

$fields = ......;
echo CWidget::create('CDataForm', array(
            'model'                 => ....
            'fields' => ....


Regards

ne_moj
Master
Master
Posts: 243
Joined: Jan 1st, '16, 14:11

Re: use return array() to put a 'type'=>'link' into that?

Postby ne_moj » May 19th, '17, 08:44

Hello Henrik

As I understand the model will not be CDataForm, but CGridView

It is necessary to correct 2 files: model and view

1) Rule the model. A field that will determine whether the time has elapsed to display the link or not (for example took model Orders from ApPHP Shopping Cart):

Code: Select all

    protected function _customFields()
    {
.... // code
        return array(
.... // code
            "IF(
                ".CConfig::get('db.prefix').$this->_table.".payment_date != '0000-00-00 00:00:00' AND ".CConfig::get('db.prefix').$this->_table.".payment_date > '".CLocate::date('Y-m-d H:i:s', time() - 24 * 60 * 60, true)."', 1, 0
            )" => 'show_link'
        );
    }


2) The rule view. For you, the best approach is to use callback-function ('type' => 'label'):

Code: Select all

... //code (top file)
    function getShowLink($record, $params)
    {
        $isShowLink = $record['show_link'];

        if($isShowLink):
            $output = '<a href="_YOUR_LINK_'" class="" title="">_YOUR_TEXT_LINK_</a>';
        else:
            $output = '_YOUR_TEXT_NOT_LINK_';
        endif;

        return $output;
    }

.... // code

        echo CWidget::create('CGridView', array(
            'model'                 => ....
            'fields' => array(
...
               'show_link' = array('title'=>A::t('shoppingcart', 'Link'), 'type'=>'label', 'width'=>'80px', 'class'=>'center', 'headerClass'=>'center', 'isSortable'=>false, 'callback'=>array('function'=>'getShowLink', 'params'=>array()), 'htmlOptions'=>array())
            )


Regards


Return to “Snippets, Tutorials & Other Stuff”