Пример #1
0
 public function filter()
 {
     if (!isset($this->user) || !$this->user || $this->user == parent::ANONYMOUS_USER) {
         return Response::json(['error' => true, 'error_description' => 'Permission denied'], 401);
     }
     if (!$this->user->can('item_delete')) {
         return Response::json(['error' => true, 'error_description' => 'Permission denied'], 401);
     }
     //$company_id = Request::segment(3);
     $company_id = Input::get('company_id');
     $id = Request::segment(3);
     $company = Company::with('items')->find($company_id);
     if (!$company) {
         return Response::json(['error' => true, 'error_description' => 'Company not found'], 400);
     }
     $find = 0;
     foreach ($company->items as $item) {
         if ($item->id == $id) {
             $find = 1;
         }
     }
     if (!$find) {
         return Response::json(['error' => true, 'error_description' => 'Permission denied'], 401);
     }
 }
Пример #2
0
 public function getIndex()
 {
     $contactsWithoutCompaniesCount = Contact::withoutCompanies()->count();
     $contactsByCountries = [];
     $rows = Country::with('contacts')->get();
     foreach ($rows as $row) {
         $obj = new StdClass();
         $obj->label = $row->title;
         $obj->value = $row->contacts->count();
         $contactsByCountries[] = $obj;
     }
     $contactsByCompanies = [];
     $rows = Company::with('contacts')->get();
     foreach ($rows as $row) {
         $obj = new StdClass();
         $obj->label = $row->title;
         $obj->value = $row->contacts->count();
         $contactsByCompanies[] = $obj;
     }
     $contactsCount = Contact::count();
     $companiesCount = Company::count();
     $countriesCount = Country::count();
     $data = compact('contactsWithoutCompaniesCount', 'contactsByCompanies', 'contactsByCountries', 'contactsCount', 'companiesCount', 'countriesCount');
     return View::make('admin.index', $data);
 }
Пример #3
0
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index()
 {
     $access_token = Util::getAccessToken();
     $user = User::findUserByToken($access_token);
     if ($user->hasRole('admin')) {
         $bookmarks = BookmarkObject::all();
         foreach ($bookmarks as $bookmark) {
             if ($bookmark->type == 'item') {
                 $bookmark->object = Item::with(array('company', 'tags', 'categories'))->find($bookmark->object_id);
             } elseif ($bookmark->type == 'company') {
                 $bookmark->object = Company::with(array('tags'))->find($bookmark->object_id);
             }
         }
     } else {
         $bookmarks = BookmarkObject::where('user_id', $user->id)->get();
         foreach ($bookmarks as $bookmark) {
             if ($bookmark->type == 'item') {
                 $bookmark->object = Item::with(array('company', 'tags'))->find($bookmark->object_id);
             } elseif ($bookmark->type == 'company') {
                 $bookmark->object = Company::with(array('tags'))->find($bookmark->object_id);
             }
         }
     }
     return Response::json(array('success_code' => 'OK', 'data' => $bookmarks->toArray()));
 }
Пример #4
0
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $company = Company::with('categories', 'tags')->find($id);
     if (!$company) {
         return Response::json(array('error_code' => '404', 'error_message' => 'Company not found'), 404);
     }
     $company->items_count = $company->items()->get()->count();
     return Response::json(array('success_code' => 'OK', 'data' => $company->toArray()));
 }