CustomersEmailController.php 2.31 KB
<?php

namespace controllers;

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

class CustomersEmailController extends \Phalcon\Mvc\Controller
{
    public function initialize()
    {
        $this->view->setTemplateAfter('common');
    }

    function indexAction()
    {



        //Check if the user has uploaded files
        if ($this->request->hasFiles() == true) {
            //Print the real file names and their sizes
            foreach ($this->request->getUploadedFiles() as $file){
                //Move the file into the application
                $route = STORAGE_PATH.'temp/'.$file->getName();
                $file->moveTo($route);
            }
            $this->ServiceExcel->addFile($route);
            $result = $this->ServiceExcel->getRows();
            foreach($result as $row){
                $model = new \customersEmailList();
                $model->customers_id = $row[0];
                $model->email = $row[1];
                $model->name = $row[2];
                $model->project_id = $this->session->get('project-id');
                $model->save();
                if(isset($model->id)){
                    $event_model = new \eventEmail();
                    $event_info = new \eventInfo();
                    $data = $event_model::findFirst("name = 'welcome_letter' AND email_type = 'event' AND project_id = {$this->session->get('project-id')} ");
                    $template = $data->emailTemplates;
                    $template->text = $this->UTMParser->parse($data->toArray(), $template->toArray());
                    $this->MyMailer->SendForSelect($template, array($model->toArray()));
                    $event_info->event_id = $data->id;
                    $event_info->customer_id = $model->id;
                    $event_info->project_id = $this->session->get('project-id');
                    $event_info->save();
                }

            }

        }
    }


    public function getUsersLikeAction()
    {
        $like = $this->request->getPost('like', 'string', NULL );
        $users = $this->models->getCustomers()->getActiveUsers($like);
        $result = json_encode($users);
        $this->view->disableLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
        echo $result;
    }
}