Exemple #1
0
 /**
  * Processes customer statistics.
  *
  * @return void
  */
 public static function customer()
 {
     if (!($task = \Service_Statistic_Task::begin('customer'))) {
         return false;
     }
     $data = array();
     $date_ranges = \Service_Statistic_Task::date_ranges('customer');
     foreach ($date_ranges as $range) {
         $begin = \Date::create_from_string($range['begin'], 'mysql');
         $end = \Date::create_from_string($range['end'], 'mysql');
         $date = $begin->format('mysql_date');
         $data[$date] = array();
         $created = \Service_Customer_Statistic::created($begin, $end);
         foreach ($created as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'created', 'value' => $result['total']);
         }
         $deleted = \Service_Customer_Statistic::deleted($begin, $end);
         foreach ($deleted as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'deleted', 'value' => $result['total']);
         }
         $subscribed = \Service_Customer_Statistic::subscribed($begin, $end);
         foreach ($subscribed as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'subscribed', 'value' => $result['total']);
         }
         $unsubscribed = \Service_Customer_Statistic::unsubscribed($begin, $end);
         foreach ($unsubscribed as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'unsubscribed', 'value' => $result['total']);
         }
         $total = \Service_Customer_Statistic::total($end);
         foreach ($total as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'total', 'value' => $result['total']);
         }
         $total_active = \Service_Customer_Statistic::total_active($end);
         foreach ($total_active as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'total_active', 'value' => $result['total']);
         }
         $total_subscribed = \Service_Customer_Statistic::total_subscribed($end);
         foreach ($total_subscribed as $result) {
             $data[$date][] = array('seller_id' => $result['seller_id'], 'name' => 'total_subscribed', 'value' => $result['total']);
         }
     }
     // Save the queried results as statistics.
     foreach ($data as $date => $results) {
         $date = \Date::create_from_string($date, 'mysql_date');
         foreach ($results as $result) {
             $seller = \Service_Seller::find_one($result['seller_id']);
             if (!\Service_Statistic::create($seller, 'customer', $date, $result['name'], $result['value'])) {
                 \Service_Statistic_Task::end($task, 'failed', "Error creating customer.{$result['name']} statistic for seller {$seller->name}.");
                 return;
             }
         }
     }
     \Service_Statistic_Task::end($task);
     \Cli::write('Customer Statistical Calculations Complete', 'green');
 }
Exemple #2
0
 /**
  * Switches the active seller.
  * 
  * @param int $id Seller ID.
  *
  * @return void
  */
 public function action_switch($id = null)
 {
     if (!$id) {
         throw new HttpNotFoundException();
     }
     $seller = Service_Seller::find_one($id);
     if (!$seller) {
         throw new HttpNotFoundException();
     }
     Seller::set($seller);
     Session::set_alert('success', "You are now viewing as seller \"{$seller->name}\".");
     Response::redirect('/');
 }
Exemple #3
0
 /**
  * Generates sellers.
  *
  * @return void
  */
 protected static function sellers()
 {
     $date = date("Y-m-d H:i:s", self::BEGIN_DATETIME);
     $companies = array('Stella Labs, Inc', 'Star Point Industries');
     foreach ($companies as $company) {
         $seller = \Service_Seller::create($company, array('contact' => array('company_name' => $company, 'email' => 'support@' . \Inflector::friendly_title($company) . '.com', 'address' => mt_rand(1, 5000) . ' Quail Springs Pkwy', 'city' => 'Oklahoma City', 'state' => 'Oklahoma', 'zip' => mt_rand(10000, 99999), 'country' => 'US'), 'created_at' => $date));
         if ($seller) {
             self::$sellers[] = $seller;
             // Link the seller to the gateway.
             \Service_Gateway::link(self::$gateway, $seller);
         }
     }
     \Cli::write('Seller Simulation Complete', 'green');
 }
Exemple #4
0
 /**
  * POST Index action.
  *
  * @return void
  */
 public function post_index()
 {
     $this->get_index();
     $validator = Validation_Seller::create();
     if (!$validator->run()) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     $data = $validator->validated();
     if (!($seller = Service_Seller::create($data['name'], $data))) {
         Session::set_alert('error', 'There was an error adding the seller.');
         return;
     }
     Response::redirect($seller->link('switch'));
 }
Exemple #5
0
 /**
  * Updates a seller.
  *
  * @param int $id Seller ID.
  *
  * @return void
  */
 public function put_index($id = null)
 {
     if (!$id) {
         throw new HttpNotFoundException();
     }
     $seller = \Service_Seller::find_one($id);
     if (!$seller || $seller != \Seller::active()) {
         throw new HttpNotFoundException();
     }
     $validator = \Validation_Seller::update();
     if (!$validator->run(\Input::put())) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $seller = \Service_Seller::update($seller, $data);
     if (!$seller) {
         throw new HttpServerErrorException();
     }
     $this->response($seller);
 }
Exemple #6
0
 /**
  * Returns all sellers.
  *
  * @return array
  */
 public static function all()
 {
     return Service_Seller::find();
 }
Exemple #7
0
// Load in the Autoloader
require COREPATH . 'classes' . DIRECTORY_SEPARATOR . 'autoloader.php';
class_alias('Fuel\\Core\\Autoloader', 'Autoloader');
// Bootstrap the framework DO NOT edit this
require COREPATH . 'bootstrap.php';
Autoloader::add_classes(array('Controller' => APPPATH . 'classes/controller.php', 'Model' => APPPATH . 'classes/model.php', 'Pagination' => APPPATH . 'classes/pagination.php', 'Session' => APPPATH . 'classes/session.php', 'Inflector' => APPPATH . 'classes/inflector.php', 'Validation' => APPPATH . 'classes/validation.php', 'Validation_Error' => APPPATH . 'classes/validation/error.php', 'Api\\HttpErrorException' => APPPATH . '../modules/api/classes/httpexceptions.php', 'Api\\HttpBadRequestException' => APPPATH . '../modules/api/classes/httpexceptions.php', 'Api\\HttpNotFoundException' => APPPATH . '../modules/api/classes/httpexceptions.php', 'Api\\HttpServerErrorException' => APPPATH . '../modules/api/classes/httpexceptions.php'));
// Register the autoloader
Autoloader::register();
/**
 * Your environment.  Can be set to any of the following:
 *
 * Fuel::DEVELOPMENT
 * Fuel::TEST
 * Fuel::STAGING
 * Fuel::PRODUCTION
 */
Fuel::$env = isset($_SERVER['FUEL_ENV']) ? $_SERVER['FUEL_ENV'] : Fuel::DEVELOPMENT;
// Initialize the framework with the config file.
Fuel::init('config.php');
// Load the app helper functions.
require APPPATH . 'app.php';
if (!Fuel::$is_cli) {
    // Redirect to setup if no sellers exist.
    if (Input::server('REQUEST_URI') != '/setup') {
        $sellers = Service_Seller::find();
        if (empty($sellers)) {
            Response::redirect('setup');
        }
    }
}
Exemple #8
0
 /**
  * Calculates date ranges for a particular statistic ($name) based on the last time the task was run.
  *
  * @param string $name Statistic name.
  *
  * @return array
  */
 public static function date_ranges($name)
 {
     $current_time = Date::time()->get_timestamp();
     $last_task = self::last($name);
     if (!$last_task) {
         // Statistic $name has never been processed - use first seller as range's beginning.
         $last_task = Service_Seller::find_one(array('status' => 'all'));
     }
     $begin_time = strtotime($last_task->created_at);
     $end_time = strtotime('tomorrow', $begin_time) - 1;
     // Initial range is last time until end of its day.
     $ranges = array(array('begin' => Date::forge($begin_time)->format('mysql'), 'end' => Date::forge($end_time)->format('mysql')));
     // Add additional 1 day ranges up to the current time.
     while ($end_time < $current_time) {
         $begin_time = strtotime('midnight', strtotime('+1 Day', $end_time));
         $end_time = strtotime('tomorrow', $begin_time) - 1;
         $ranges[] = array('begin' => Date::forge($begin_time)->format('mysql'), 'end' => Date::forge($end_time)->format('mysql'));
     }
     return $ranges;
 }