Esempio n. 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Customer();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Customer'])) {
         $model->attributes = $_POST['Customer'];
         if ($model->save()) {
             // Comprobamos si existe la lista de envio de todos los clientes
             if (count(Mailist::model()->findByAttributes(array('Name' => 'Todos los clientes', 'UserID' => Yii::app()->user->ID)))) {
                 // Si existe la lista añadimos el nuevo cliente
                 $ListID = Mailist::model()->findByAttributes(array('Name' => 'Todos los clientes'))->ID;
                 $modelCustomerList = new CustomerList();
                 $modelCustomerList->UserID = Yii::app()->user->ID;
                 $modelCustomerList->ListID = $ListID;
                 $modelCustomerList->CustomerID = $model->ID;
                 $modelCustomerList->save();
             } else {
                 // Si no existe la lista la creamos y añadimos el cliente nuevo
                 $modelMailist = new Mailist();
                 $modelMailist->Name = "Todos los clientes";
                 $modelMailist->UserID = Yii::app()->user->ID;
                 if ($modelMailist->save()) {
                     $modelCustomerList = new CustomerList();
                     $modelCustomerList->UserID = Yii::app()->user->ID;
                     $modelCustomerList->ListID = $modelMailist->ID;
                     $modelCustomerList->CustomerID = $model->ID;
                     $modelCustomerList->save();
                 }
             }
             $this->redirect(array('admin'));
         }
     }
     $this->render('create', array('model' => $model));
 }
    public function addCustomer($name)
    {
        foreach ($this->_observers as $obs) {
            $obs->onChanged($this, $name);
        }
    }
    public function addObserver($observer)
    {
        $this->_observers[] = $observer;
    }
}
class CustomerListLogger implements Observer
{
    public function onChanged($sender, $args)
    {
        echo 'Logger:' . $args . ' Customer has been added to the list' . PHP_EOL;
    }
}
class CustomerListUpdate implements Observer
{
    public function onChanged($sender, $args)
    {
        echo 'MySQL update: insert ' . $args . ' into Customer table ' . PHP_EOL;
        echo '--------------------' . PHP_EOL;
    }
}
$cl = new CustomerList();
$cl->addObserver(new CustomerListLogger());
$cl->addObserver(new CustomerListUpdate());
$cl->addCustomer('Jack');
$cl->addCustomer('Lee');
Esempio n. 3
0
 public function actionSend($id)
 {
     $model = Mail::model()->findByPK($id);
     $modelList = CustomerList::model()->findAllByAttributes(array("ListID" => $model->ListID));
     foreach ($modelList as $receiver) {
         //echo $receiver->customer->Email;
         Functions::sendMail("*****@*****.**", $receiver->customer->Email, $model->Name, $model->Text);
     }
     $model->LastSent = date("Y-m-d");
     $model->save();
 }
Esempio n. 4
0
 public function actionDeleteCustomer()
 {
     $model = CustomerList::model()->findByAttributes(array("CustomerID" => $_POST["newEmail"], "ListID" => $_POST["listID"]));
     $modelList = Mailist::model()->findByPK($model->ListID);
     if ($model->delete()) {
         echo "<p class='jqueryOk'>Cliente borrado de la lista.</p>";
         $this->renderPartial('_emailist', array('model' => $modelList));
     } else {
         echo "<p class='jqueryError'>Error borrando el cliente. Intentalo de nuevo por favor.</p>";
         $this->renderPartial('_emailist', array('model' => $modelList));
     }
 }
Esempio n. 5
0
<?php

$criteria = new CDbCriteria();
$criteria->condition = "UserID = :userid";
$criteria->params = array(':userid' => Yii::app()->user->ID);
$modelCustomers = Customer::model()->findAll($criteria);
?>

<ul style="list-style-type:none;padding-left:0.5em;">
	
	<li><input type="checkbox" class="customerEmailAll" value="0" /> Seleccionar todos<br /><br /></li>

<?php 
foreach ($modelCustomers as $customer) {
    $checked = count(CustomerList::model()->findAllByAttributes(array("ListID" => $model->ID, "CustomerID" => $customer->ID))) > 0 ? "checked" : "";
    ?>
	
	<li><input type="checkbox" class="customerEmail" <?php 
    echo $checked;
    ?>
 value="<?php 
    echo $customer->ID;
    ?>
" /> <?php 
    echo $customer->Email;
    ?>
 (<?php 
    echo $customer->FullName;
    ?>
)</li>