// fix refactoring templates in AdminCustomerThreadsController

This commit is contained in:
lLefevre
2011-12-02 11:19:03 +00:00
parent a85c5d4cd2
commit 70fc45a18d
18 changed files with 1138 additions and 520 deletions
+30 -15
View File
@@ -27,34 +27,34 @@
class ContactCore extends ObjectModel
{
public $id;
public $id;
/** @var string Name */
public $name;
public $name;
/** @var string e-mail */
public $email;
public $email;
/** @var string Detailed description */
public $description;
public $description;
public $customer_service;
public $customer_service;
protected $fieldsRequired = array();
protected $fieldsSize = array('email' => 128);
protected $fieldsValidate = array('email' => 'isEmail', 'customer_service' => 'isBool');
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 32);
protected $fieldsValidateLang = array('name' => 'isGenericName', 'description' => 'isCleanHtml');
protected $fieldsRequired = array();
protected $fieldsSize = array('email' => 128);
protected $fieldsValidate = array('email' => 'isEmail', 'customer_service' => 'isBool');
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array('name' => 32);
protected $fieldsValidateLang = array('name' => 'isGenericName', 'description' => 'isCleanHtml');
protected $table = 'contact';
protected $identifier = 'id_contact';
protected $table = 'contact';
protected $identifier = 'id_contact';
public function getFields()
{
$this->validateFields();
$fields['email'] = pSQL($this->email);
$fields['customer_service'] = (int)($this->customer_service);
$fields['customer_service'] = (int)$this->customer_service;
return $fields;
}
@@ -76,7 +76,7 @@ class ContactCore extends ObjectModel
* @param Context
* @return array Contacts
*/
static public function getContacts($id_lang, Shop $shop = null)
public static function getContacts($id_lang, Shop $shop = null)
{
if (!$shop)
$shop = Context::getContext()->shop;
@@ -89,5 +89,20 @@ class ContactCore extends ObjectModel
ORDER BY `name` ASC';
return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
}
/**
* Return available categories contacts
* @return array Contacts
*/
public static function getCategoriesContacts()
{
return Db::getInstance()->executeS('
SELECT cl.*
FROM '._DB_PREFIX_.'contact ct
LEFT JOIN '._DB_PREFIX_.'contact_lang cl
ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)Context::getContext()->language->id.')
WHERE ct.customer_service = 1
');
}
}
+40 -15
View File
@@ -36,10 +36,10 @@ class CustomerMessageCore extends ObjectModel
public $user_agent;
public $private;
public $date_add;
protected $table = 'customer_message';
protected $identifier = 'id_customer_message';
protected $fieldsRequired = array('message');
protected $fieldsSize = array('message' => 65000);
protected $fieldsValidate = array('message' => 'isCleanHtml', 'id_employee' => 'isUnsignedId', 'ip_address' => 'isIp2Long');
@@ -47,29 +47,54 @@ class CustomerMessageCore extends ObjectModel
public function getFields()
{
$this->validateFields();
$fields['id_customer_thread'] = (int)($this->id_customer_thread);
$fields['id_employee'] = (int)($this->id_employee);
$fields['id_customer_thread'] = (int)$this->id_customer_thread;
$fields['id_employee'] = (int)$this->id_employee;
$fields['message'] = pSQL($this->message);
$fields['file_name'] = pSQL($this->file_name);
$fields['ip_address'] = (int)($this->ip_address);
$fields['ip_address'] = (int)$this->ip_address;
$fields['user_agent'] = pSQL($this->user_agent);
$fields['private'] = pSQL($this->private);
$fields['date_add'] = pSQL($this->date_add);
return $fields;
}
public static function getMessagesByOrderId($id_order, $private = true)
{
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_order = '.(int)$id_order.' AND '.(!$private ? 'cm.`private` = 0' : '').'
GROUP BY cm.id_customer_message
ORDER BY cm.date_add DESC');
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_order = '.(int)$id_order.'
AND '.(!$private ? 'cm.`private` = 0' : '').'
GROUP BY cm.id_customer_message
ORDER BY cm.date_add DESC
');
}
public static function getTotalCustomerMessages($where = null)
{
if (is_null($where))
return (int)Db::getInstance()->getValue('
SELECT COUNT(*)
FROM '._DB_PREFIX_.'customer_message
');
else
return (int)Db::getInstance()->getValue(sprintf('
SELECT COUNT(*)
FROM '._DB_PREFIX_.'customer_message
WHERE %s
', $where));
}
}
+113 -19
View File
@@ -1,6 +1,6 @@
<?php
/*
* 2007-2011 PrestaShop
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
@@ -39,24 +39,33 @@ class CustomerThreadCore extends ObjectModel
public $token;
public $date_add;
public $date_upd;
protected $table = 'customer_thread';
protected $identifier = 'id_customer_thread';
protected $fieldsRequired = array('id_lang', 'id_contact', 'token');
protected $fieldsSize = array('email' => 254);
protected $fieldsValidate = array('id_lang' => 'isUnsignedId', 'id_contact' => 'isUnsignedId', 'id_shop' => 'isUnsignedId', 'id_customer' => 'isUnsignedId',
'id_order' => 'isUnsignedId', 'id_product' => 'isUnsignedId', 'email' => 'isEmail', 'token' => 'isGenericName');
protected $fieldsValidate = array(
'id_lang' => 'isUnsignedId',
'id_contact' => 'isUnsignedId',
'id_shop' => 'isUnsignedId',
'id_customer' => 'isUnsignedId',
'id_order' => 'isUnsignedId',
'id_product' => 'isUnsignedId',
'email' => 'isEmail',
'token' => 'isGenericName'
);
public function getFields()
{
$this->validateFields();
$fields['id_lang'] = (int)($this->id_lang);
$fields['id_lang'] = (int)$this->id_lang;
$fields['id_shop'] = (int)$this->id_shop;
$fields['id_contact'] = (int)($this->id_contact);
$fields['id_customer'] = (int)($this->id_customer);
$fields['id_order'] = (int)($this->id_order);
$fields['id_product'] = (int)($this->id_product);
$fields['id_contact'] = (int)$this->id_contact;
$fields['id_customer'] = (int)$this->id_customer;
$fields['id_order'] = (int)$this->id_order;
$fields['id_product'] = (int)$this->id_product;
$fields['status'] = pSQL($this->status);
$fields['email'] = pSQL($this->email);
$fields['token'] = pSQL($this->token);
@@ -64,28 +73,113 @@ class CustomerThreadCore extends ObjectModel
$fields['date_upd'] = pSQL($this->date_upd);
return $fields;
}
public function delete()
{
if (!Validate::isUnsignedId($this->id))
return false;
Db::getInstance()->execute('DELETE FROM `'._DB_PREFIX_.'customer_message` WHERE `id_customer_thread` = '.(int)($this->id));
Db::getInstance()->execute('
DELETE FROM `'._DB_PREFIX_.'customer_message`
WHERE `id_customer_thread` = '.(int)$this->id
);
return (parent::delete());
}
public static function getCustomerMessages($id_customer)
{
return Db::getInstance()->executeS('
SELECT * FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'customer_message cm ON ct.id_customer_thread = cm.id_customer_thread
WHERE id_customer = '.(int)($id_customer));
SELECT *
FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'customer_message cm
ON ct.id_customer_thread = cm.id_customer_thread
WHERE id_customer = '.(int)$id_customer
);
}
public static function getIdCustomerThreadByEmailAndIdOrder($email, $id_order)
{
return Db::getInstance()->getValue('
SELECT cm.id_customer_thread FROM '._DB_PREFIX_.'customer_thread cm
WHERE cm.email = \''.pSQL($email).'\' AND cm.id_shop = '.(int)Context::getContext()->shop->getId(true).' AND cm.id_order = '.(int)$id_order.'');
SELECT cm.id_customer_thread
FROM '._DB_PREFIX_.'customer_thread cm
WHERE cm.email = \''.pSQL($email).'\'
AND cm.id_shop = '.(int)Context::getContext()->shop->getId(true).'
AND cm.id_order = '.(int)$id_order
);
}
public static function getContacts()
{
return Db::getInstance()->executeS('
SELECT cl.*, COUNT(*) as total, (
SELECT id_customer_thread
FROM '._DB_PREFIX_.'customer_thread ct2
WHERE status = "open" AND ct.id_contact = ct2.id_contact
ORDER BY date_upd ASC
LIMIT 1
) as id_customer_thread
FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'contact_lang cl
ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)Context::getContext()->language->id.')
WHERE ct.status = "open"
AND ct.id_contact IS NOT NULL
AND cl.id_contact IS NOT NULL
GROUP BY ct.id_contact HAVING COUNT(*) > 0
');
}
public static function getTotalCustomerThreads($where = null)
{
if (is_null($where))
return (int)Db::getInstance()->getValue('
SELECT COUNT(*)
FROM '._DB_PREFIX_.'customer_thread
');
else
return (int)Db::getInstance()->getValue(sprintf('
SELECT COUNT(*)
FROM '._DB_PREFIX_.'customer_thread
WHERE %s
', $where));
}
public static function getMessageCustomerThreads($id_customer_thread)
{
return Db::getInstance()->executeS('
SELECT ct.*, cm.*, cl.name subject, CONCAT(e.firstname, \' \', e.lastname) employee_name,
CONCAT(c.firstname, \' \', c.lastname) customer_name, c.firstname
FROM '._DB_PREFIX_.'customer_thread ct
LEFT JOIN '._DB_PREFIX_.'customer_message cm
ON (ct.id_customer_thread = cm.id_customer_thread)
LEFT JOIN '._DB_PREFIX_.'contact_lang cl
ON (cl.id_contact = ct.id_contact AND cl.id_lang = '.(int)Context::getContext()->language->id.')
LEFT JOIN '._DB_PREFIX_.'employee e
ON e.id_employee = cm.id_employee
LEFT JOIN '._DB_PREFIX_.'customer c
ON (IFNULL(ct.id_customer, ct.email) = IFNULL(c.id_customer, c.email))
WHERE ct.id_customer_thread = '.(int)$id_customer_thread.'
ORDER BY cm.date_add DESC
');
}
public static function getNextThread($id_customer_thread)
{
$context = Context::getContext();
return Db::getInstance()->getValue('
SELECT id_customer_thread
FROM '._DB_PREFIX_.'customer_thread ct
WHERE ct.status = "open"
AND ct.date_upd = (
SELECT date_add FROM '._DB_PREFIX_.'customer_message
WHERE (id_employee IS NULL OR id_employee = 0)
AND id_customer_thread = '.(int)$id_customer_thread.'
ORDER BY date_add DESC LIMIT 1
)
'.($context->cookie->{'customer_threadFilter_cl!id_contact'} ?
'AND ct.id_contact = '.(int)$context->cookie->{'customer_threadFilter_cl!id_contact'} : '').'
'.($context->cookie->{'customer_threadFilter_l!id_lang'} ?
'AND ct.id_lang = '.(int)$context->cookie->{'customer_threadFilter_l!id_lang'} : '').
' ORDER BY ct.date_upd ASC
');
}
}
+13
View File
@@ -121,6 +121,19 @@ class EmployeeCore extends ObjectModel
return parent::add($autodate, $null_values);
}
/**
* Return list of employees
*/
public static function getEmployees()
{
return Db::getInstance()->executeS('
SELECT `id_employee`, `firstname`, `lastname`
FROM `'._DB_PREFIX_.'employee`
WHERE `active` = 1
ORDER BY `lastname` ASC
');
}
/**
* Return employee instance from its e-mail (optionnaly check password)
*
+13
View File
@@ -604,6 +604,19 @@ class OrderCore extends ObjectModel
return $resultArray;
}
public static function getIdOrderProduct($id_customer, $id_product)
{
return (int)Db::getInstance()->getValue('
SELECT o.id_order
FROM '._DB_PREFIX_.'orders o
LEFT JOIN '._DB_PREFIX_.'order_detail od
ON o.id_order = od.id_order
WHERE o.id_customer = '.(int)$id_customer.'
AND od.product_id = '.(int)$id_product.'
ORDER BY o.date_add DESC
');
}
protected function setProductCustomizedDatas(&$product, $customized_datas)
{
$product['customizedDatas'] = null;