public function get()
 {
     $x = Subscription::orderBy('created_at', 'desc')->get();
     $data['res'] = $x;
     $data['res_type'] = 'contact messages';
     return View::make('admin.result.master.subscriber', $data);
 }
Ejemplo n.º 2
0
 /**
  * Get the Nth most recent subscription for this user
  *
  * @param User    $user The user to get subscriptions for
  * @param integer $n    How far to count back
  *
  * @return Subscription a subscription or null
  */
 private function _getNthSub($user, $n)
 {
     $sub = new Subscription();
     $sub->subscriber = $user->id;
     $sub->orderBy('created DESC');
     $sub->limit($n - 1, 1);
     if ($sub->find(true)) {
         return $sub;
     } else {
         return null;
     }
 }
Ejemplo n.º 3
0
 private static function realBySubscribed($subscribedId, $offset, $limit)
 {
     $sub = new Subscription();
     $sub->subscribed = $subscribedId;
     $sub->whereAdd('subscriber != ' . $subscribedId);
     $sub->orderBy('created DESC');
     $sub->limit($offset, $limit);
     $sub->find();
     $subs = array();
     while ($sub->fetch()) {
         $subs[] = clone $sub;
     }
     return $subs;
 }
Ejemplo n.º 4
0
 /**
  * List of vats
  */
 public function liste()
 {
     $subscriptions = Subscription::orderBy('renew_at', 'ASC')->paginate(15);
     return View::make('subscription.liste', array('subscriptions' => $subscriptions));
 }
Ejemplo n.º 5
0
 private static function getSubscriptionIDs($get_type, $profile_id, $offset, $limit)
 {
     switch ($get_type) {
         case 'subscribed':
             $by_type = 'subscriber';
             break;
         case 'subscriber':
             $by_type = 'subscribed';
             break;
         default:
             throw new Exception('Bad type argument to getSubscriptionIDs');
     }
     $cacheKey = 'subscription:by-' . $by_type . ':' . $profile_id;
     $queryoffset = $offset;
     $querylimit = $limit;
     if ($offset + $limit <= self::CACHE_WINDOW) {
         // Oh, it seems it should be cached
         $ids = self::cacheGet($cacheKey);
         if (is_array($ids)) {
             return array_slice($ids, $offset, $limit);
         }
         // Being here indicates we didn't find anything cached
         // so we'll have to fill it up simultaneously
         $queryoffset = 0;
         $querylimit = self::CACHE_WINDOW;
     }
     $sub = new Subscription();
     $sub->{$by_type} = $profile_id;
     $sub->selectAdd($get_type);
     $sub->whereAdd("{$get_type} != {$profile_id}");
     $sub->orderBy('created DESC');
     $sub->limit($queryoffset, $querylimit);
     if (!$sub->find()) {
         return array();
     }
     $ids = $sub->fetchAll($get_type);
     // If we're simultaneously filling up cache, remember to slice
     if ($queryoffset === 0 && $querylimit === self::CACHE_WINDOW) {
         self::cacheSet($cacheKey, $ids);
         return array_slice($ids, $offset, $limit);
     }
     return $ids;
 }
Ejemplo n.º 6
0
 function subscriptions($apidata, $other_attr, $user_attr, $onlyIDs = false)
 {
     $this->auth_user = $apidata['user'];
     $user = $this->get_user($apidata['api_arg'], $apidata);
     if (!$user) {
         $this->clientError('Not Found', 404, $apidata['content-type']);
         return;
     }
     $page = $this->trimmed('page');
     if (!$page || !is_numeric($page)) {
         $page = 1;
     }
     $profile = $user->getProfile();
     if (!$profile) {
         $this->serverError(_('User has no profile.'));
         return;
     }
     $sub = new Subscription();
     $sub->{$user_attr} = $profile->id;
     $since = strtotime($this->trimmed('since'));
     if ($since) {
         $d = date('Y-m-d H:i:s', $since);
         $sub->whereAdd("created > '{$d}'");
     }
     $sub->orderBy('created DESC');
     if (!$onlyIDs) {
         $sub->limit(($page - 1) * 100, 100);
     }
     $others = array();
     if ($sub->find()) {
         while ($sub->fetch()) {
             $others[] = Profile::staticGet($sub->{$other_attr});
         }
     } else {
         // user has no followers
     }
     $type = $apidata['content-type'];
     $this->init_document($type);
     if ($onlyIDs) {
         $this->showIDs($others, $type);
     } else {
         $this->show_profiles($others, $type);
     }
     $this->end_document($type);
 }
Ejemplo n.º 7
0
 /**
  * [getRenewalSubscriptionData]
  * @return [json] [DT compatible object]
  */
 public function getNieuwsbrievenSubscriptionData($model = null)
 {
     $Model = 'Subscription';
     $num_skip = 0;
     $num_items = 10;
     $recordsTotal = 0;
     $recordsFiltered = 0;
     // check get vars
     if (isset($_GET['start'])) {
         $num_skip = (int) $_GET['start'];
     }
     if (isset($_GET['length'])) {
         $num_items = (int) $_GET['length'];
     }
     if (isset($_GET['search'])) {
         $search_value = $_GET['search']['value'];
     }
     $all_subscriptions = Subscription::orderBy('subscriptions.id', 'DESC')->where('subscriptions.service_id', '=', Config::get('eenvoudcrm.nieuwsbrieven_service_id'))->where('subscriptions.status_id', '!=', Config::get('eenvoudcrm.subscriptions_status_terminated.id'))->where('subscriptions.status_id', '!=', Config::get('eenvoudcrm.subscriptions_status_ended.id'));
     if ($model !== null) {
         $all_subscriptions->where('subscriptions.company_id', '=', $model->id);
         if (!empty($search_value)) {
             $all_subscriptions->join('services', 'subscriptions.service_id', '=', 'services.id')->whereRaw("(services.name LIKE '%" . $search_value . "%' OR subscriptions.description LIKE '%" . $search_value . "%')");
         }
     } else {
         if (!empty($search_value)) {
             $all_subscriptions->join('companies', 'company_id', '=', 'companies.id')->join('services', 'subscriptions.service_id', '=', 'services.id')->whereRaw("(services.name LIKE '%" . $search_value . "%' OR subscriptions.description LIKE '%" . $search_value . "%' OR companies.bedrijfsnaam LIKE '%" . $search_value . "%')");
         }
     }
     $recordsTotal = $all_subscriptions->count();
     $recordsFiltered = $recordsTotal;
     if ($num_skip > 0) {
         $all_subscriptions->skip($num_skip);
     }
     $all_subscriptions = $all_subscriptions->take($num_items)->get();
     $data = [];
     foreach ($all_subscriptions as $subscription) {
         // load relations
         $load_curr_company = $subscription->company;
         $load_curr_service = $subscription->service;
         $load_curr_category = $subscription->service->category;
         $load_curr_status = $subscription->status;
         $load_curr_period = $subscription->period;
         $curr_company = $subscription->company !== NULL ? (object) ['id' => $subscription->company_id, 'bedrijfsnaam' => utf8_encode($subscription->company->bedrijfsnaam)] : (object) null;
         $curr_service = $subscription->service !== NULL ? (object) ['id' => $subscription->service_id, 'category_id' => $subscription->category_id, 'name' => utf8_encode($subscription->service->name)] : (object) null;
         $curr_category = $subscription->service->category !== NULL ? (object) ['id' => $subscription->service->category_id, 'name' => utf8_encode($subscription->service->category->name)] : (object) null;
         $curr_status = $subscription->status !== NULL ? (object) ['id' => $subscription->status_id, 'description' => utf8_encode($subscription->status->description)] : (object) null;
         $curr_period = $subscription->period !== NULL ? (object) ['id' => $subscription->invoice_periods_id, 'description' => utf8_encode($subscription->period->description)] : (object) null;
         $data[] = (object) ['DT_RowId' => 'row_' . $subscription->id, 'subscriptions' => $subscription, 'companies' => $curr_company, 'service_categories' => $curr_category, 'services' => $curr_service, 'statuses' => $curr_status, 'invoice_periods' => $curr_period];
     }
     $ret = ['recordsTotal' => $recordsTotal, 'recordsFiltered' => $recordsFiltered, 'data' => $data, 'companies' => $this->getAllCompanies(), 'services' => $this->getAllServices(), 'service_categories' => $this->getAllServiceCategories(), 'statuses' => $this->getAllStatuses(), 'invoice_periods' => $this->getAllInvoicePeriods()];
     return Response::json($ret);
 }
Ejemplo n.º 8
0
 /**
  * [getSubscriptionData - Fetches subscription DB data and returns a json object compatible with DT]
  * @param  [string] $type   [processed/unprocessed values]
  * @return [json]           [DT compatible object]
  */
 public function getSubscriptionData($type, $company = null)
 {
     $Model = 'Subscription';
     $num_skip = 0;
     $num_items = 10;
     $recordsTotal = 0;
     $recordsFiltered = 0;
     // check get vars
     if (isset($_GET['start'])) {
         $num_skip = (int) $_GET['start'];
     }
     if (isset($_GET['length'])) {
         $num_items = (int) $_GET['length'];
     }
     if (isset($_GET['search'])) {
         $search_value = $_GET['search']['value'];
     }
     $terminated_id = Config::get('eenvoudcrm.subscriptions_status_terminated.id');
     $ended_id = Config::get('eenvoudcrm.subscriptions_status_ended.id');
     $all_subscriptions = Subscription::orderBy('subscriptions.id', 'DESC');
     if ($company !== null) {
         $all_subscriptions->where('subscriptions.company_id', '=', $company->id);
         if (!empty($search_value)) {
             $all_subscriptions->join('services', 'subscriptions.service_id', '=', 'services.id')->whereRaw("(services.name LIKE '%" . $search_value . "%' OR subscriptions.description LIKE '%" . $search_value . "%')");
         }
     } else {
         if (!empty($search_value)) {
             $all_subscriptions->join('companies', 'subscriptions.company_id', '=', 'companies.id')->join('services', 'subscriptions.service_id', '=', 'services.id')->whereRaw("(services.name LIKE '%" . $search_value . "%' OR subscriptions.description LIKE '%" . $search_value . "%' OR companies.bedrijfsnaam LIKE '%" . $search_value . "%')");
         }
     }
     if ($type === 'unprocessed') {
         $all_subscriptions->whereRaw('(subscriptions.invoice_id IS NULL AND subscriptions.status_id != ' . $terminated_id . ' AND subscriptions.status_id != ' . $ended_id . ')');
     } elseif ($type === 'processed') {
         $all_subscriptions->whereRaw('(subscriptions.invoice_id IS NOT NULL OR subscriptions.status_id = ' . $terminated_id . ' OR subscriptions.status_id = ' . $ended_id . ')');
     } else {
         error_log('Error: No type specified');
         return;
     }
     $recordsTotal = $all_subscriptions->count();
     $recordsFiltered = $recordsTotal;
     if ($num_skip > 0) {
         $all_subscriptions->skip($num_skip);
     }
     $all_subscriptions = $all_subscriptions->take($num_items)->get();
     $data = [];
     foreach ($all_subscriptions as $subscription) {
         // load relations
         $load_curr_company = $subscription->company;
         $load_curr_service = $subscription->service;
         $load_curr_category = $subscription->service->category;
         $load_curr_status = $subscription->status;
         $curr_company = $subscription->company !== NULL ? (object) ['id' => $subscription->company_id, 'bedrijfsnaam' => utf8_encode($subscription->company->bedrijfsnaam)] : (object) null;
         $curr_service = $subscription->service !== NULL ? (object) ['id' => $subscription->service_id, 'category_id' => $subscription->category_id, 'name' => utf8_encode($subscription->service->name)] : (object) null;
         $curr_category = $subscription->service->category !== NULL ? (object) ['id' => $subscription->service->category_id, 'name' => utf8_encode($subscription->service->category->name)] : (object) null;
         $curr_status = $subscription->status !== NULL ? (object) ['id' => $subscription->status_id, 'description' => utf8_encode($subscription->status->description)] : (object) null;
         $data[] = (object) ['DT_RowId' => 'row_' . $subscription->id, 'subscriptions' => $subscription, 'companies' => $curr_company, 'service_categories' => $curr_category, 'services' => $curr_service, 'statuses' => $curr_status];
     }
     $ret = ['recordsTotal' => $recordsTotal, 'recordsFiltered' => $recordsFiltered, 'data' => $data, 'companies' => $this->getAllCompanies(), 'services' => $this->getAllServices(), 'service_categories' => $this->getAllServiceCategories(), 'statuses' => $this->getAllStatuses()];
     return Response::json($ret);
 }