Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['consultaImeis' => 'required']);
     $imeis = explode("\r\n", $request->get('consultaImeis'));
     $completeUnits = new Collection();
     foreach ($imeis as $imei) {
         $unidad = TrazabilidadMotorola::where('Codigo', $imei)->get();
         $old = false;
         if ($unidad->isEmpty()) {
             $unidad = TrazabilidadOld::where('Codigo', $imei)->get();
             $old = true;
         }
         if (!$unidad->isEmpty() && $imei != '') {
             $puesto = Puesto::where(['Nombre' => 'CFC', 'ConfigLinea_id' => $unidad->first()->ConfigLinea_id])->get();
             $codigoPuestos = CodigoPuesto::where('Puesto_id', $puesto->first()->Id)->get();
             $modeloInfo = ModeloInfo::where(['ConfigLinea_id' => $unidad->first()->ConfigLinea_id])->get();
             $codigoPuestoSimLock = $this->findInCollection($codigoPuestos, 'Nombre', 'sim_lock_nkey');
             if ($codigoPuestoSimLock != null) {
                 if ($old) {
                     $trazabilidadUnidad = TrazabilidadOld::where(['Unidad_id' => $unidad->first()->Unidad_id, 'CodigoPuesto_id' => $codigoPuestoSimLock->Id])->get();
                 } else {
                     $trazabilidadUnidad = TrazabilidadMotorola::where(['Unidad_id' => $unidad->first()->Unidad_id, 'CodigoPuesto_id' => $codigoPuestoSimLock->Id])->get();
                 }
                 $completeUnits->add($this->setUnitsCollection($imei, $trazabilidadUnidad, $modeloInfo));
             } else {
                 $completeUnits->add($this->setUnitsCollection($imei));
             }
         } elseif ($imei != '') {
             $completeUnits->add($this->setUnitsCollection($imei));
         }
     }
     return view('pages.sl_results', ['units' => $completeUnits]);
 }
Ejemplo n.º 2
0
 /**
  * Countable in cart.
  */
 public function it_additems(ItemInterface $item, ItemInterface $item2)
 {
     $collection = new Collection();
     $collection->add($item);
     $collection->add($item2);
     $this->addItems($collection)->shouldHaveCount(4);
 }
 public static function getIntialsStates()
 {
     $estados = new Collection();
     $estadoInicial = new Estado();
     $estadoInicial->nombreEstado = "Abierto";
     $estadoInicial->tipoEstado = 1;
     $estadoFinal = new Estado();
     $estadoFinal->nombreEstado = "Cerrado";
     $estadoFinal->tipoEstado = 2;
     $estados->add($estadoInicial);
     $estados->add($estadoFinal);
     return $estados;
 }
Ejemplo n.º 4
0
 public function create(Request $request, $student_id = null)
 {
     $message_types = $this->message_type->orderBy('message_type_name')->lists('message_type_name', 'id')->all();
     $schools = $this->school->lists('school_name', 'id')->all();
     if (isset($student_id)) {
         $student = $this->contact->find($student_id);
     } else {
         $student = null;
     }
     $all_contacts = $this->contact->allStudents();
     $contacts = array();
     foreach ($all_contacts as $contact) {
         $contacts[$contact->id] = $contact->name . ' ' . $contact->surname;
     }
     if ($request->input('message_id')) {
         $messages = Message::processIds($request->input('message_id'));
     } else {
         $selected = null;
     }
     $students = new Collection();
     $selected = array();
     if (isset($messages)) {
         foreach ($messages as $message) {
             $students->add($message->Contact);
             $selected[] = $message->Contact->id;
         }
         $students = $students->unique();
     }
     return view()->make('messages.create', compact('message_types', 'schools', 'contacts', 'student', 'selected'));
 }
 public function index()
 {
     $sections = Section::all();
     if (Auth::user()) {
         $cart = Auth::user()->cart;
     } else {
         $cart = new Collection();
         if (Session::has('cart')) {
             foreach (Session::get('cart') as $item) {
                 $elem = new Cart();
                 $elem->product_id = $item['product_id'];
                 $elem->amount = $item['qty'];
                 if (isset($item['options'])) {
                     $elem->options = $item['options'];
                 }
                 $cart->add($elem);
             }
         }
     }
     $total = 0;
     $options = new Collection();
     foreach ($cart as $item) {
         $total += $item->product->price * $item->amount;
         if ($item->options) {
             $values = explode(',', $item->options);
             foreach ($values as $value) {
                 $options->add(OptionValue::find($value));
             }
         }
     }
     return view('site.cart', compact('sections', 'total', 'cart', 'options'));
 }
Ejemplo n.º 6
0
 /**
  * So here's the deal with permissions... Suppose we have code
  * like the following:
  * 
  * @if( $user->hasPermission('edit', 'Employee') )
  *     <li><a href="/editEmployees">Edit Employees</a></li>
  * @endif
  * 
  * Now suppose a user can edit a SUBSET of employees... We still
  * want to display this button, but within this button we need
  * to limit the employees shown. So we need two different actions:
  * 
  *     can you edit ANYTHING?
  *     what can you edit?
  * 
  * To prevent "what can you edit" from returning the entire
  * database in the event that you actually can edit everything,
  * it needs to somehow be condensed. Maybe a query string?
  * 
  * 
  * 
  */
 public function hasPermission($action, $model)
 {
     // First, is $model an instance? If so, get the class name
     if (is_string($model)) {
         $modelName = $model;
         $modelInstance = null;
     } else {
         $modelName = get_class($model);
         $modelInstance = $model;
     }
     // Now get ALL permissions for this action on this model
     $permissions = Permission::where(function ($query) use($action) {
         $query->orWhere('action', $action)->orWhere('action', 'all');
     })->where(function ($query) use($modelName) {
         $query->orWhere('model', 'like', $modelName)->orWhere('model', '*');
     })->get();
     // Now see if we have a matching role
     // To start, see if we have a previously cached list of roles:
     if ($this->roleParents == null) {
         // We start with a list of this user's roles...
         $this->roleParents = $this->roles;
         // Then we iteratively get all parents
         foreach ($this->roleParents as $role) {
             if ($role->parent != null) {
                 $this->roleParents->add($role->parent);
             }
         }
     }
     if ($this->roleChildren == null) {
         // We start with a list of this user's roles...
         $this->roleChildren = $this->roles;
         // Then we need to recursively get all children
         $children = new Collection();
         foreach ($this->roles as $role) {
             $this->roleChildren = $this->roleChildren->merge($this->getAllChildren($role));
         }
         $this->roleChildren = $this->roleChildren->unique();
     }
     foreach ($permissions as $permission) {
         if ($permission->role_id == 0 || $this->roleParents->contains($permission->role) || $this->roleChildren->contains($permission->role) && $permission->trickle) {
             // So the user has a role that can perform the action on this model
             if ($modelInstance == null) {
                 // If we're looking at the model as a whole, we good
                 return true;
             } else {
                 // If we're looking at a specific model, we need to check the domain
                 $domain = json_decode($permission->domain);
                 if (is_array($domain)) {
                     if ($this->confirmDomain($domain, $modelInstance)) {
                         return true;
                     }
                 } else {
                     return true;
                 }
             }
         }
     }
     // Failed to find a valid permission
     return false;
 }
Ejemplo n.º 7
0
 /**
  * Create a collection of instances of the given model and persist them to the database.
  *
  * @param  integer $total
  * @param  array  $customValues
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function createMultiple($total, array $customValues = array())
 {
     $collection = new Collection();
     for ($i = 1; $i <= $total; $i++) {
         $collection->add($this->create($customValues));
     }
     return $collection;
 }
Ejemplo n.º 8
0
 /**
  * Return collection of tags related to the tagged model
  * TODO : I'm sure there is a faster way to build this, but
  * If anyone knows how to do that, me love you long time.
  *
  * @return Illuminate\Database\Eloquent\Collection
  */
 public function getTagsAttribute()
 {
     $tags = new Collection();
     foreach ($this->tagged as $tagged) {
         $tags->add($tagged->tag);
     }
     return $tags;
 }
Ejemplo n.º 9
0
 public function getAll()
 {
     $collection = new Collection();
     foreach ($this->readData() as $article) {
         $collection->add(new Article($article));
     }
     return $collection;
 }
Ejemplo n.º 10
0
 public function parents()
 {
     $parents = new Collection();
     $parent = $this;
     while ($parent = $parent->parent) {
         $parents->add($parent);
     }
     return $parents;
 }
Ejemplo n.º 11
0
 public function stateAds(Emirate $emirate, CategoryRepository $categoryRepository)
 {
     //        return $emirate->advertisements->count();
     $products = new Collection();
     foreach ($emirate->advertisements as $ad) {
         $products->add($ad->product);
     }
     return view('pages.search', ['products' => $products, 'categories' => $categoryRepository->getFilterCats()]);
 }
Ejemplo n.º 12
0
 public function seedRandomTags($amount = 10)
 {
     $tags = new Collection();
     for ($i = 0; $i < $amount; ++$i) {
         $tag = app()->make(TagRepository::class)->findByNameOrCreate($this->faker->words(2, true));
         $tags->add($tag);
     }
     return $tags;
 }
Ejemplo n.º 13
0
 /**
  * Get names of jobtypes, which belongs to the schedule.
  *
  * @return string[] $jobNames
  */
 public function getTemplateEntries()
 {
     $jobNames = new Collection();
     $entries = $this->getEntries()->get();
     foreach ($entries as $entry) {
         $jobNames->add($entry->getJobType->jbtyp_title);
     }
     return $jobNames;
 }
Ejemplo n.º 14
0
 public function seedRandomTags($amount = 10)
 {
     $tags = new Collection();
     for ($i = 0; $i < $amount; ++$i) {
         $tag = Tag::findByNameOrCreate($this->faker->words(2, true), TagType::NEWS_TAG());
         $tags->add($tag);
     }
     return $tags;
 }
Ejemplo n.º 15
0
 public function haveSections($num = 10)
 {
     $faker = Faker::create();
     $sections = new Collection();
     for ($i = 0; $i < $num; $i++) {
         $name = $faker->unique()->sentence(2);
         $sections->add($this->sectionRepo->create(['name' => $name, 'slug_url' => \Str::slug($name), 'type' => $faker->randomElement(['page', 'blog']), 'menu_order' => rand(1, 10), 'menu' => rand(0, 1), 'published' => rand(0, 1)]));
     }
     return $sections;
 }
 public function executeSearch()
 {
     $keywords = Input::get('keywords');
     $id = Input::get('city');
     $hotels = Hotel::all();
     $searchhotel = new Collection();
     foreach ($hotels as $hotel) {
         $cityId = $hotel->city_id;
         if (!empty($id)) {
             if (Str::contains(Str::lower($hotel->name), Str::lower($keywords)) && $id == $cityId) {
                 $searchhotel->add($hotel);
             }
         } else {
             if (Str::contains(Str::lower($hotel->name), Str::lower($keywords))) {
                 $searchhotel->add($hotel);
             }
         }
     }
     return View::make('searchedHotels')->with('searchhotel', $searchhotel);
 }
Ejemplo n.º 17
0
 /**
  * Create dummy user data
  */
 public function __construct()
 {
     $faker = Faker::create();
     $collection = new Collection();
     // Create 10 dummy user objects
     for ($i = 0; $i < 10; $i++) {
         $user = new User(['name' => $faker->name, 'email' => $faker->email]);
         $collection->add($user);
     }
     $this->users = $collection;
 }
 /**
  * Get all the users who have been trained on a piece of equipment
  * @param string $deviceId
  * @return Collection
  */
 public function getUsersForEquipment($deviceId)
 {
     $users = new Collection();
     $inductionUsers = $this->model->with('user')->whereHas('user', function ($q) {
         $q->where('active', '=', true);
     })->where('trained', '!=', '')->where('key', $deviceId)->get();
     //Extract the users from the inductions and place into a new collection
     foreach ($inductionUsers as $inductedUser) {
         $users->add($inductedUser->user);
     }
     return $users;
 }
Ejemplo n.º 19
0
 public function executeSearch()
 {
     $keywords = Input::get('keywords');
     $users = User::all();
     $searchUsers = new Collection();
     foreach ($users as $u) {
         if (Str::contains(Str::lower($u->name), Str::lower($keywords))) {
             $searchUsers->add($u);
         }
     }
     return view('dump.searchUsers', compact('searchUsers'));
 }
 public function testBuildLink()
 {
     Config::shouldReceive('get')->with('andizzle/rest-framework::page_limit')->andReturn('5');
     REST::shouldReceive('getApiPrefix')->andReturn('api/v1');
     $serializer = new HyperlinkedJSONSerializer();
     $fooobj = new RESTModelStub();
     $fooobj->id = 1;
     $fooobj->root = 'roots';
     $collection = new Collection();
     $collection->add($fooobj);
     $this->assertEquals('api/v1/roots/1', $serializer->buildLink($fooobj));
     $this->assertEquals('api/v1/roots?ids=1', $serializer->buildLink($collection));
 }
 /**
  * @param $ids
  * @return Collection
  */
 public function findByIds($ids)
 {
     $media_list = new Collection();
     if (!is_array($ids)) {
         return $media_list;
     }
     foreach ($ids as $id) {
         $media = $this->model->find($id);
         if ($media) {
             $media_list->add($media);
         }
     }
     return $media_list;
 }
Ejemplo n.º 22
0
 public function getUserverifications()
 {
     $user = Auth::user();
     if (!$user->can('admin_verify_users')) {
         return Redirect::to('/dashboard')->with('message', "You do not have permission");
     }
     $users = UserMeta::where('meta_key', '=', UserMeta::TYPE_INDEPENDENT_SPONSOR)->where('meta_value', '=', '0')->get();
     $userResults = new Collection();
     foreach ($users as $userMeta) {
         $userObj = $userMeta->user()->first();
         $userResults->add($userObj);
     }
     $data = array('page_id' => 'verify_user_sponsor', 'page_title' => 'Verify Independent Sponsors', 'requests' => $userResults);
     return View::make('dashboard.verify-independent', $data);
 }
 public function show($id)
 {
     $orderDetails = OrderProduct::where('order_id', $id)->get();
     $order = Order::find($id);
     $options = new Collection();
     foreach ($orderDetails as $detail) {
         if ($detail->options) {
             $values = explode(',', $detail->options);
             foreach ($values as $value) {
                 $options->add(OptionValue::find($value));
             }
         }
     }
     return view('site.showOrder', compact('orderDetails', 'order', 'options'));
 }
 protected function findGenreId($name, $title)
 {
     $genres = $this->genre->findByName(trim($name));
     if ($genres->isEmpty()) {
         if (empty($name)) {
             return 1;
         }
         $genre = $this->genre->create(['name' => $name]);
         $this->newGenres->add($name);
         return $genre->id;
     }
     if ($genres->count() > 1) {
         $this->info(Lang::get('commands.iffe.more-that-one-genre-found', ['name' => $name, 'title' => $title]));
     }
     return $genres->first()->id;
 }
Ejemplo n.º 25
0
 public function videoSearch()
 {
     $keywords = Input::get('keywords');
     $group = Input::get('group');
     $searchResult = new Collection();
     $videos = Video::orderBy('created_at', 'desc')->get();
     if ($keywords != '') {
         foreach ($videos as $video) {
             if (Str::contains(Str::lower($video->title), Str::lower($keywords))) {
                 $searchResult->add($video);
             }
         }
     } else {
         $searchResult = $videos;
     }
     return view('bushido::admin.videoSearch')->with('videos', $searchResult)->with('group', $group);
 }
 /**
  * 获取某人服务列表
  *
  * @return json
  */
 public function postList()
 {
     $uid = Input::get('uid');
     $user_id = Input::get('user');
     $pageSize = Input::get('count', 10);
     $limit = $pageSize + 1;
     $offset = '';
     $hasMore = 0;
     $orderWhere = '`M`.`user_id` = ' . $user_id;
     $total = 0;
     //按页码分页
     if (Input::has('by_no')) {
         $page = abs(Input::get('by_no', 1));
         $page > 1 || ($page = 1);
         $offset = ' OFFSET ' . $pageSize * ($page - 1);
         //按id分页,
     } elseif (Input::has('by_id')) {
         $lastId = Input::get('by_id');
         if ($lastId > 0) {
             $orderWhere .= ' AND `M`.`id` < ' . $lastId;
         }
     }
     // GROUP BY `M`.`services_id`
     $sql = "SELECT *\n                FROM `o2omobile_my_services` AS `M`\n\n                WHERE {$orderWhere}  AND `M`.deleted_at is NULL\n                ORDER BY `M`.`created_at` DESC\n                LIMIT {$limit}\n                {$offset}";
     $myserviceids = DB::select($sql);
     $collection = new Collection();
     foreach ($myserviceids as $myservice) {
         $collection->add(with(new MyService())->fill((array) $myservice));
     }
     $myservices = array();
     if (!empty($collection)) {
         if (count($collection) > $pageSize) {
             $hasMore = 1;
             $collection->pop();
             //弹出最后一条
         }
         //格式化
         foreach ($collection as $myservice) {
             $myservices[] = $myservice->formatToApi();
         }
     }
     //endif
     $return = array('total' => $total, 'count' => count($myservices) < $pageSize ? count($myservices) : $pageSize, 'more' => $hasMore, 'services' => $myservices);
     return $this->json($return);
 }
Ejemplo n.º 27
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $docId = $this->argument('docId');
     $docs = new Collection();
     if (!is_null($docId)) {
         $doc = Doc::where('id', '=', $docId)->first();
         if (!$doc) {
             return $this->error("Invalid Document ID");
         }
         $docs->add($doc);
     } else {
         $rawDocs = DB::select(DB::raw("SELECT *\n\t\t\t\t\t   FROM docs\n\t\t\t\t\t  WHERE id NOT IN (\n\t\t\t\t\t\tSELECT doc_id \n\t\t\t\t\t\t  FROM doc_group\n\t\t\t\t\t UNION ALL\n\t\t\t\t\t\tSELECT doc_id\n\t\t\t\t\t\t  FROM doc_user\n\t\t\t\t\t)"), array());
         $docs = new Collection();
         foreach ($rawDocs as $raw) {
             $obj = new Doc();
             foreach ($raw as $key => $val) {
                 $obj->{$key} = $val;
             }
             $docs->add($obj);
         }
     }
     $sponsors = Doc::getAllValidSponsors();
     foreach ($docs as $doc) {
         $this->info("Document Title: {$doc->title}\n");
         foreach ($sponsors as $key => $sponsor) {
             $opt = $key + 1;
             $this->info("{$opt}) {$sponsor['display_name']}");
         }
         $selected = (int) $this->ask("Please select a sponsor: ") - 1;
         if (!isset($sponsors[$selected])) {
             $this->error("Invalid Selection");
             continue;
         }
         switch ($sponsors[$selected]['sponsor_type']) {
             case 'individual':
                 $doc->userSponsor()->sync(array($sponsors[$selected]['id']));
                 $this->info("Assigned Document to Independent Sponsor");
                 break;
             case 'group':
                 $doc->groupSponsor()->sync(array($sponsors[$selected]['id']));
                 $this->info("Assigned Document to Group Sponsor");
                 break;
         }
     }
 }
Ejemplo n.º 28
0
 /**
  * Show the form for creating a new resource.
  *
  *
  */
 public function familiars(Request $request)
 {
     $depth = $request->query('n', 1);
     $neo4j = DB::connection('neo4j');
     /** @var $neo4j Connection */
     $client = $neo4j->getClient();
     /** @var $client Client */
     //Знаю что так нельзя, но нормально параметр вставить у меня не получилось - матюкается neo4j
     $cql = 'MATCH (x:users)-[friendship*' . $depth . ']-(y) WHERE id(x) = {id} RETURN y';
     $query = new Query($client, $cql, ['id' => Auth::user()->id]);
     $result = $query->getResultSet();
     $results = new Collection();
     foreach ($result as $row) {
         /** @var $row Row */
         $results->add(new User($row['y']->getProperties()));
     }
     return response()->json(['items' => $results->toArray()]);
 }
Ejemplo n.º 29
0
 public function global_search($search)
 {
     $results = new Collection();
     $terms = explode(' ', $search);
     if (!count($terms)) {
         return $results;
     }
     foreach ($terms as &$term) {
         $term = '%' . $term . '%';
     }
     foreach (Config::get('core::linkable_models') as $model => $uri) {
         $Model = App::make($model);
         $Model->search($terms)->each(function ($result) use($results) {
             $results->add($result);
         });
     }
     return $results;
 }
Ejemplo n.º 30
0
 /**
  * Create recombined array with set fields
  *
  * @param Collection $data
  */
 public static function var_set(Collection $data)
 {
     $collection = new EloquentCollection();
     $model = get_class($data->first());
     foreach ($data as $item) {
         $origin = static::arrayValuesToString($item->getOriginal());
         $new = [];
         foreach ($model::$export_fields as $field => $properties) {
             if (isset($properties['relation'])) {
                 $method = $properties['relation']['method'];
                 $display = isset($properties['relation']['display']) ? $properties['relation']['display'] : null;
                 $new[] = static::getRelationItems($item, $method, $display);
             } else {
                 $new[] = $item->{$field};
             }
         }
         $collection->add($new);
     }
     return $collection->toArray();
 }