Jump to content

get custommer thread from database


ghost4life

Recommended Posts

Hi,

 

I've creadted a new controller, for a new page.

 

I need to get on the tpl the messages from the client but grouped by Token...

 

so I did (I get an old function that I changed for my needs)

 

 
<?php

class ServiceClientController extends FrontController {


    public $auth = true; // Utile si vous souhaitez que l'utilisateur qui visite cette page soit authentifier
    public $php_self = 'service-client';
    public $authRedirection = 'service-client';
    public $ssl = true;


    public static function getMessagesByIdCustommer($private = true) {
        $id_custommer = (int) $this->context->cookie->id_customer;
        return Db::getInstance()->executeS('
SELECT cm.*,
c.`firstname` AS cfirstname,
c.`lastname` AS clastname,
e.`firstname` AS efirstname,
e.`lastname` AS elastname,
(COUNT(cm.id_customer_message) = 0 AND ct.id_customer != 0) AS is_new_for_me
FROM `' . _DB_PREFIX_ . 'customer_message` cm
LEFT JOIN `' . _DB_PREFIX_ . 'customer_thread` ct
ON ct.`id_customer_thread` = cm.`id_customer_thread`
LEFT JOIN `' . _DB_PREFIX_ . 'customer` c
ON ct.`id_customer` = c.`id_customer`
LEFT OUTER JOIN `' . _DB_PREFIX_ . 'employee` e
ON e.`id_employee` = cm.`id_employee`
WHERE ct.id_custommer = ' . (int) $id_custommer . '
' . (!$private ? 'AND cm.`private` = 0' : '') . '
GROUP BY cm.token
ORDER BY cm.date_add DESC
');
    }


    public function initContent() {
        parent::initContent();


        $this->context->smarty->assign(array(
            'messages' => getMessagesByIdCustommer(false),
        ));
        $this->setTemplate(_PS_THEME_DIR_ . 'service-detail.tpl');
    }


}

The trouble I have is that I don't know how to call this function from my controller to the tpl.

 

I need to do a loop for displaying all threads.

 

Anykind of help will be much appreciate.

Edited by ghost4life (see edit history)
Link to comment
Share on other sites

hi, 

 

thanks for your reply,

 

i've tried to do a loop with the var message, but I do have an error

 

( ! ) Notice: Undefined index: messages in C:\wamp\www\beast\cache\smarty\compile\77\83\91\7783911f07df21f93d564de8226ebfb3aea02c56.file.service-client.tpl.php on line 68

 

 

Sorry for my poor english.

 

Cordialement,

 

Stan P.

Link to comment
Share on other sites

  • 2 weeks later...

I've tried like that but it does not work

 

Anykind of help will be much appreciated.

    public function initContent() {
        parent::initContent();
        $id_customer = $this->context->customer->id;
        $query = "SELECT * FROM `beast_customer_thread` WHERE `id_customer` = '{$id_customer}' GROUP BY `token`";
        $messages = mysql_query($query);
        $this->setTemplate(_PS_THEME_DIR_ . 'service-client.tpl');
    }
Link to comment
Share on other sites

I've tried like that also but with no success

 public function initContent() {
        parent::initContent();
        $id_customer = $this->context->customer->id;
        $sql = new DbQuery();
        $sql->select('*');
        $sql->from('customer_thread');
        $sql->where('`id_customer` = '.$id_customer);
        $sql->orderBy('token');
        return Db::getInstance()->executeS($sql);
        $this->setTemplate(_PS_THEME_DIR_ . 'service-client.tpl');
    }
Link to comment
Share on other sites

what you mean by "no success" ? you see some error?

 

btw. 

 

        return Db::getInstance()->executeS($sql);
        $this->setTemplate(_PS_THEME_DIR_ . 'service-client.tpl');\
 
everything after "return" will not be executed.
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...