201 lines
6.8 KiB
PHP
201 lines
6.8 KiB
PHP
<?php
|
|
/**
|
|
* SOTESHOP/stQuestionPlugin
|
|
*
|
|
* Ten plik należy do aplikacji stQuestionPlugin opartej na licencji (Professional License SOTE).
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stQuestionPlugin
|
|
* @subpackage actions
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/sote (Professional License SOTE)
|
|
* @version $Id: actions.class.php 2113 2009-11-16 15:18:49Z pawel $
|
|
* @author Paweł Byszewski <pawel.byszewski@sote.pl>
|
|
*/
|
|
|
|
|
|
/**
|
|
* stQuestionBackend actions.
|
|
*
|
|
* @package stQuestionPlugin
|
|
* @subpackage actions
|
|
*/
|
|
class stQuestionBackendActions extends autostQuestionBackendActions
|
|
{
|
|
|
|
public function executeIndex()
|
|
{
|
|
return $this->redirect('stQuestionBackend/list');
|
|
}
|
|
|
|
public function executeSaveAndSend()
|
|
{
|
|
return $this->forward('stQuestionBackend', 'saveQuestions');
|
|
}
|
|
|
|
public function saveQuestions($question)
|
|
{
|
|
|
|
if($question->getEmail() && $this->hasRequestParameter('save_and_save'))
|
|
{
|
|
|
|
$this->sendMail($question);
|
|
$question->setQuestionStatus(QuestionStatusPeer::retriveDefaultCompleteStatus());
|
|
}
|
|
|
|
parent::saveQuestions($question);
|
|
}
|
|
|
|
public function sendMail($question)
|
|
{
|
|
|
|
$context = sfContext::getInstance();
|
|
|
|
|
|
|
|
$this->product = ProductPeer::retrieveByPK($question->getItemId());
|
|
|
|
if ($this->product){
|
|
|
|
stPluginHelper::addRouting('stQuestionLang', '/:lang/:url.html', 'stProduct', 'frontendShow', 'backend', array(), array('lang' => '[a-z]{2,2}'));
|
|
|
|
stPluginHelper::addRouting('stQuestion', '/:url.html', 'stProduct', 'frontendShow', 'backend');
|
|
|
|
sfLoader::loadHelpers(array('Helper','stUrl'));
|
|
|
|
$c = new Criteria();
|
|
$c->add(LanguagePeer::IS_DEFAULT, 1);
|
|
$default_lang = LanguagePeer::doSelectOne($c);
|
|
|
|
if (empty($default_lang)){
|
|
$c = new Criteria();
|
|
$c->add(LanguagePeer::ACTIVE, 1);
|
|
$default_lang = LanguagePeer::doSelectOne($c);
|
|
}
|
|
|
|
$culture = $default_lang->getLanguage();
|
|
|
|
$url = st_url_for('stProduct/frontendShow?url='.$this->product->getFriendlyUrl(), true, 'frontend', null, $culture, SF_ENVIRONMENT != 'dev', null);
|
|
|
|
|
|
$this->product_name = $this->product;
|
|
$this->product_code = $this->product->getCode();
|
|
$this->product_producer = $this->product->getProducer();
|
|
$this->product_category = $this->product->getCategory();
|
|
$this->friendly_url = $this->product->getFriendlyUrl();
|
|
|
|
} else {
|
|
$this->product_name = $question->getItemName();
|
|
}
|
|
|
|
$c = new Criteria();
|
|
|
|
$c->add(sfGuardUserPeer::USERNAME, $question->getEmail());
|
|
$c->addJoin(sfGuardUserPeer::ID,UserDataPeer::SF_GUARD_USER_ID);
|
|
$c->add(UserDataPeer::IS_BILLING,1);
|
|
$c->add(UserDataPeer::IS_DEFAULT,1);
|
|
$user = UserDataPeer::doSelectOne($c);
|
|
|
|
if ($user)
|
|
{
|
|
if ($user->getName() && $user->getSurname())
|
|
{
|
|
$this->username = $user->getName().' '.$user->getSurname();
|
|
} else {
|
|
$this->username = $question->getEmail();
|
|
}
|
|
|
|
} else {
|
|
$this->username = $question->getEmail();
|
|
}
|
|
|
|
if ($question->getType()=='depository')
|
|
{
|
|
$this->mail_subject=$context->getI18N()->__('Odpowiedź na pytanie o dostępnosc produktu:').' '.$this->product_name;
|
|
}
|
|
|
|
if ($question->getType()=='price')
|
|
{
|
|
$this->mail_subject=$context->getI18N()->__('Odpowiedź na pytanie o cenę produktu:').' '.$this->product_name;
|
|
}
|
|
|
|
$mail_config = stConfig::getInstance($this->getContext(), 'stMailAccountBackend');
|
|
|
|
$mailUserHtmlHead = stMailer::getHtmlMailDescription("top_question_answer");
|
|
$mailUserHtmlFoot = stMailer::getHtmlMailDescription("bottom_question_answer");
|
|
|
|
$mailHtmlHead = stMailer::getHtmlMailDescription("header");
|
|
$mailHtmlFoot = stMailer::getHtmlMailDescription("footer");
|
|
|
|
$sendHtmlMailMessage = stMailTemplate::render('sendHtml', array(
|
|
'question' => $question,
|
|
'product_name' => $this->product_name,
|
|
'product_code' => $this->product_code,
|
|
'product_producer' => $this->product_producer,
|
|
'product_category' => $this->product_category,
|
|
'friendly_url' => $this->friendly_url,
|
|
'user' => $this->username,
|
|
'product' => $this->product,
|
|
'head' => $mailHtmlHead,
|
|
'foot' => $mailHtmlFoot,
|
|
'user_head' => $mailUserHtmlHead,
|
|
'user_foot' => $mailUserHtmlFoot,
|
|
'mail_config' => $mail_config,
|
|
'mail_subject'=>$this->mail_subject,
|
|
'url'=>$url,
|
|
));
|
|
|
|
$sendPlainMailMessage = stMailTemplate::render('sendPlain', array(
|
|
'question' => $question,
|
|
'product_name' => $this->product_name,
|
|
'product_code' => $this->product_code,
|
|
'product_producer' => $this->product_producer,
|
|
'product_category' => $this->product_category,
|
|
'friendly_url' => $this->friendly_url,
|
|
'user' => $this->username,
|
|
'product' => $this->product,
|
|
'head' => $mailHtmlHead,
|
|
'foot' => $mailHtmlFoot,
|
|
'url'=>$url,
|
|
));
|
|
|
|
$mail = stMailer::getInstance();
|
|
return $mail->setSubject($this->mail_subject)->setHtmlMessage($sendHtmlMailMessage)->setPlainMessage($sendPlainMailMessage)->setTo($question->getEmail())->sendToClient();
|
|
}
|
|
|
|
/**
|
|
* Zapisywanie pokazywania zapytania przy dosteponosci
|
|
*
|
|
*/
|
|
protected function updateConfigFromRequest()
|
|
{
|
|
parent::updateConfigFromRequest();
|
|
|
|
$config = $this->getRequestParameter('config');
|
|
|
|
$this->config->set('depository_value', $config['depository_value']);
|
|
}
|
|
|
|
/**
|
|
* Filtr po statusie zapytania
|
|
*
|
|
* @param Criteria $c
|
|
*/
|
|
protected function addFiltersCriteria($c)
|
|
{
|
|
parent::addFiltersCriteria($c);
|
|
|
|
if (isset($this->filters['filter_question_status']) && !empty($this->filters['filter_question_status']))
|
|
{
|
|
$c->add(QuestionsPeer::QUESTION_STATUS_ID, $this->filters['filter_question_status']);
|
|
}
|
|
|
|
if (isset($this->filters['item_name']) && !empty($this->filters['item_name']))
|
|
{
|
|
$c->add(QuestionsPeer::ITEM_NAME, '%'.$this->filters['item_name'].'%', Criteria::LIKE);
|
|
}
|
|
}
|
|
}
|