public function create()
 {
     $response = array('success' => false);
     if (Request::ajax()) {
         $postData = Input::all();
         $tabletId = $postData['tabletId'];
         $economyValue = (double) $postData['economyValue'];
         $rules = array('tabletId' => array('required', 'not_in:0', 'exists:tablets,id'), 'economyValue' => array('required', 'numeric', 'min:0'));
         $messages = array('tabletId.required' => 'Please select a tablet.', 'tabletId.not_in' => 'Please select a tablet.', 'tabletId.exists' => 'An error occured. Please try later.', 'economyValue.required' => 'Please enter savings value.', 'economyValue.numeric' => 'Savings must be a numeric value. Ex: 90, 3.42', 'economyValue.min' => 'Savings must have a positive value.');
         $validator = Validator::make($postData, $rules, $messages);
         if ($validator->fails()) {
             $messages = $validator->messages();
             $response['tabletMsg'] = $messages->first('tabletId');
             $response['economyValueMsg'] = $messages->first('economyValue');
             return Response::json($response);
         }
         $tablet = Tablet::find($tabletId);
         if ($tablet->id) {
             $initialCurrentSum = $tablet->current_sum;
             $tablet->current_sum = $initialCurrentSum - $economyValue;
             $initialEconomies = $tablet->economies;
             $tablet->economies = $initialEconomies + $economyValue;
             $tablet->save();
             $response['success'] = true;
             Event::fire('economy.create.success', array($economyValue, $tabletId));
         }
     }
     return Response::json($response);
 }
 /**
  * Tablet close success page
  * @return string
  */
 public function closeSuccess()
 {
     if (Session::has('closedTabletId')) {
         $closedTabletId = Session::get('closedTabletId');
         $tablet = Tablet::find($closedTabletId);
         return View::make('tablet/close_success', array('tablet' => $tablet));
     }
     return Redirect::to('dashboard');
 }
Esempio n. 3
0

<?php 
/** @var TabletController $this */
/** @var Tablet $model */
$this->breadcrumbs = array($model->label(2) => array('index'), Yii::t('AweCrud.app', 'Create'));
$this->menu = array(array('label' => Yii::t('AweCrud.app', 'Manage'), 'icon' => 'list-alt', 'url' => array('admin')));
?>

<fieldset>
    <legend><?php 
echo Yii::t('AweCrud.app', 'Create') . ' ' . Tablet::label();
?>
</legend>
    <?php 
echo $this->renderPartial('_form', array('model' => $model));
?>
</fieldset>
 /**
  * Delete prediction action
  * @return string
  */
 public function delete()
 {
     $response = array('success' => false);
     if (Request::ajax()) {
         $predictionIds = Input::get('predictionIds');
         $tabletId = null;
         if ($predictionIds) {
             $predictionIdsArray = $this->_getPredictionIdsArray($predictionIds);
             foreach ($predictionIdsArray as $predictionId) {
                 $prediction = Prediction::find($predictionId);
                 if (!$tabletId) {
                     $tablet = Tablet::find($prediction->tablet_id);
                 }
                 $predictionExpenses = $prediction->expenses;
                 foreach ($predictionExpenses as $expense) {
                     $tablet->total_expenses = $tablet->total_expenses - $expense->value;
                     $tablet->current_sum = $tablet->current_sum + $expense->value;
                 }
                 $tablet->save();
             }
             Prediction::destroy($predictionIdsArray);
             $response['success'] = true;
         }
     }
     return Response::json($response);
 }
Esempio n. 5
0
<?php

/** @var TabletController $this */
/** @var Tablet $model */
$this->breadcrumbs = array('Tablets' => array('index'), Yii::t('AweCrud.app', 'Manage'));
$this->menu = array(array('label' => Yii::t('AweCrud.app', 'List') . ' ' . Tablet::label(2), 'icon' => 'list', 'url' => array('index')), array('label' => Yii::t('AweCrud.app', 'Create') . ' ' . Tablet::label(), 'icon' => 'plus', 'url' => array('create')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('tablet-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>

<fieldset>
    <legend>
        <?php 
echo Yii::t('AweCrud.app', 'Manage');
?>
 <?php 
echo Tablet::label(2);
?>
    </legend>

<?php 
$this->widget('bootstrap.widgets.TbGridView', array('id' => 'tablet-grid', 'type' => 'striped condensed', 'dataProvider' => $model->search(), 'filter' => $model, 'afterAjaxUpdate' => 'reInstallDatepicker', 'columns' => array('nombre', array('name' => 'imagen', 'type' => 'image', 'value' => 'isset($data->imagen) ? $data->imagen : null', 'htmlOptions' => array('width' => '50'), 'filter' => false), 'alt_imagen', array('name' => 'visible', 'value' => '($data->visible == 0) ? Yii::t(\'AweCrud.app\', \'No\') : Yii::t(\'AweCrud.app\', \'Yes\')', 'filter' => array('0' => Yii::t('AweCrud.app', 'No'), '1' => Yii::t('AweCrud.app', 'Yes'))), array('class' => 'bootstrap.widgets.TbButtonColumn'))));
Yii::app()->clientScript->registerScript('for-date-picker', "\n    function reInstallDatepicker(id, data){\n        \n    }\n\n    ");
?>
</fieldset>
Esempio n. 6
0
    public $number;
    public $RAM;
    public $CPU;
    public $modGSM = "TRUE";
    public $OS;
    public function call($abonent)
    {
        if ($this->modGSM) {
            echo "Calling to " . $abonent . " from" . $this->number . "<br>";
        }
        echo "I am not able to call, please send me email.";
    }
}
class Phone extends mobile
{
}
$nokia = new Phone();
$nokia->number = "+380954801117";
$nokia->call("Mike");
class Tablet extends mobile
{
    public $modGSM = "FALSE";
}
$lg = new Tablet();
if ($nokia instanceof mobile) {
    echo "nokia is Phone";
}
if ($nokia instanceof Tablet) {
    echo "Are you sure?";
}
$lg->call(12345);
 /**
  * Get current tablet
  * @return Tablet
  */
 protected function _getCurrentTablet()
 {
     $userId = $this->_getCurrentUser()->id;
     $tablet = new Tablet();
     return $tablet->loadByUserId($userId);
 }
Esempio n. 8
0
    if ($prediction->id) {
        $tablet = $prediction->tablet;
        $tablet->current_sum = $tablet->current_sum - $expense->value;
        $tablet->save();
    }
});
/**
 * Update Prediction value upon expense.create.success
 */
Event::listen('expense.create.success', function ($expense) {
    $predictionId = $expense->prediction_id;
    $prediction = Prediction::find($predictionId);
    if ($prediction->id) {
        $currentValue = (double) $prediction->value;
        $expenseValue = (double) $expense->value;
        $prediction->value = $currentValue - $expenseValue;
        $prediction->save();
    }
});
/**
 * Update current_sum on Tablet upon income.create.success
 */
Event::listen('income.create.success', function ($incomeValue, $tabletId) {
    $tablet = Tablet::find($tabletId);
    if ($tablet->id) {
        $oldCurrentSum = $tablet->current_sum;
        $newCurrentSum = $oldCurrentSum + $incomeValue;
        $tablet->current_sum = $newCurrentSum;
        $tablet->save();
    }
});
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id, $modelClass = __CLASS__)
 {
     $model = Tablet::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Esempio n. 10
0
 /**
  * Load active tablet by user_id
  * @param int $userId
  * @return Tablet
  */
 public function loadByUserId($userId)
 {
     $userId = (int) $userId;
     return Tablet::where('user_id', $userId)->where('is_active', 1)->first();
 }
Esempio n. 11
0
<?php

/** @var TabletController $this */
/** @var Tablet $model */
$this->breadcrumbs = array('Tablets' => array('index'), $model->id);
$this->menu = array(array('label' => Yii::t('AweCrud.app', 'Create') . ' ' . Tablet::label(), 'icon' => 'plus', 'url' => array('create')), array('label' => Yii::t('AweCrud.app', 'Update'), 'icon' => 'pencil', 'url' => array('update', 'id' => $model->id)), array('label' => Yii::t('AweCrud.app', 'Delete'), 'icon' => 'trash', 'url' => '#', 'linkOptions' => array('submit' => array('delete', 'id' => $model->id), 'confirm' => Yii::t('AweCrud.app', 'Are you sure you want to delete this item?'))), array('label' => Yii::t('AweCrud.app', 'Manage'), 'icon' => 'list-alt', 'url' => array('admin')));
?>

<fieldset>
    <legend><?php 
echo Yii::t('AweCrud.app', 'View') . ' ' . Tablet::label();
?>
 <?php 
echo CHtml::encode($model);
?>
</legend>

<?php 
$this->widget('bootstrap.widgets.TbDetailView', array('data' => $model, 'attributes' => array('id', 'nombre', array('name' => 'imagen', 'type' => 'image'), 'alt_imagen', array('name' => 'visible', 'type' => 'boolean'))));
?>
</fieldset>