Exemplo n.º 1
0
 /**
  * Return true if all API Key are still enable
  *
  * @param Collection $keys
  * @return bool
  */
 protected function isEnabledKey(Collection $keys)
 {
     // count keys with enable value and compare it to total keys number
     $enabledKeys = $keys->filter(function ($item) {
         return $item->enabled == 1;
     })->count();
     if ($enabledKeys == $keys->count() && $keys->count() != 0) {
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * Return the total number of rows in the table.
  * @return int
  */
 public function totalItems()
 {
     if ($this->paginator) {
         return $this->paginator->total();
     }
     return $this->items->count();
 }
Exemplo n.º 3
0
 /**
  * Render the likes into a string.
  *
  * @param Collection $likesCollection  The likes to render.
  *
  * @param string     $viewAllLikesLink The link to view all of the likes for the content.
  *
  * @return string
  */
 public function render(Collection $likesCollection, $viewAllLikesLink)
 {
     $numLikesToList = $this->settings->get('posts.likes_to_show', 3);
     $numOtherLikes = $likesCollection->count() - $numLikesToList;
     $userId = $this->guard->user()->getAuthIdentifier();
     $likes = [];
     $likesCollection = $likesCollection->filter(function (Like $like) use(&$likes, &$numLikesToList, $userId) {
         if ($like->user->id === $userId) {
             $like->user->name = $this->lang->get('likes.current_user');
             $likes[] = $like;
             $numLikesToList--;
             return false;
         }
         return true;
     });
     $numLikesInCollection = $likesCollection->count();
     if ($numLikesInCollection > 0 && $numLikesToList > 0) {
         if ($numLikesInCollection < $numLikesToList) {
             $numLikesToList = $numLikesInCollection;
         }
         $randomLikes = $likesCollection->random($numLikesToList);
         if (!is_array($randomLikes)) {
             // random returns a single model if $numLikesToList is 1...
             $randomLikes = array($randomLikes);
         }
         foreach ($randomLikes as $key => $like) {
             $likes[] = $like;
         }
     }
     return $this->viewFactory->make('likes.list', compact('numOtherLikes', 'likes', 'viewAllLikesLink'))->render();
 }
Exemplo n.º 4
0
 /**
  * Gets meta data
  *
  * @param string $key
  * @param null|mixed $default
  * @param bool $raw
  * @return Collection
  */
 public function getMeta($key, $default = null, $raw = false)
 {
     $meta = $this->meta()->where('key', $key)->get();
     if ($raw) {
         $collection = $meta;
     } else {
         $collection = new Collection();
         foreach ($meta as $m) {
             $collection->put($m->id, $m->value);
         }
     }
     if (0 == $collection->count()) {
         return $default;
     }
     return $collection->count() <= 1 ? $collection->first() : $collection;
 }
Exemplo n.º 5
0
 /**
  * performFail.
  *
  * @author Casper Rasmussen <*****@*****.**>
  * @return void
  */
 private function performFail()
 {
     $this->failedCarbons->prepend(new Carbon());
     if ($this->failedCarbons->count() > 3) {
         $this->failedCarbons->pop();
     }
 }
Exemplo n.º 6
0
 /**
  * Get array of nested responses in "execute" response
  *
  * @param array $executeResponse
  * @return array
  */
 protected function getResponses(array $executeResponse)
 {
     if (isset($executeResponse['error'])) {
         return array_fill(0, $this->requests->count(), $executeResponse['error']);
     }
     $errors = isset($executeResponse['execute_errors']) ? $executeResponse['execute_errors'] : [];
     return array_map(function ($response) use(&$errors) {
         return $response ?: array_shift($errors);
     }, $executeResponse['response']);
 }
Exemplo n.º 7
0
 /**
  * Sends a push message
  *
  * @param string $title
  * @param string $message
  * @param Collection $users
  */
 public function send($title, $message, $users)
 {
     if ($users->count() == 0) {
         PastPush::create(['title' => $title, 'message' => $message]);
     }
     foreach ($users->chunk($this->batchSize) as $userBatch) {
         $registrationIds = $this->getRegistrationIds($userBatch);
         $response = $this->sendNotifications($title, $message, $registrationIds);
         $this->logPushNotification($title, $message, $response, $userBatch);
     }
 }
Exemplo n.º 8
0
 /**
  * Calculate the pagination data
  *
  * @param  \Illuminate\Database\Eloquent\Collection $records
  * @param  integer                                  $total
  * @param  integer                                  $page
  * @param  integer                                  %from
  * @return array
  */
 public function getPagination($records, $total, $page, $from)
 {
     $to = $from + $records->count();
     $last = ceil($total / $this->perPage);
     $prev = $page - 1;
     $next = $page + 1;
     if ($prev < 1) {
         $prev = 1;
     }
     if ($next > $last) {
         $next = $last;
     }
     return compact('from', 'to', 'total', 'next', 'prev');
 }
Exemplo n.º 9
0
 /**
  * @param Builder $builder
  * @param Collection $tags
  * @return Builder
  */
 public function scopeTaggedWith(Builder $builder, Collection $tags)
 {
     /** @var MorphToMany $relation */
     $relation = $this->tags();
     $key = $this->getTable() . '.' . $this->getKeyName();
     if ($tags->count()) {
         $builder->join($relation->getTable(), function ($join) use($relation, $key, $tags) {
             $join->on($relation->getForeignKey(), '=', $key);
             $join->where($relation->getMorphType(), '=', $relation->getMorphClass());
             $join->whereIn($relation->getOtherKey(), $tags->keys()->toArray());
         });
     } else {
         $builder->whereNull($this->getTable());
     }
     return $builder;
 }
 public function postUpdate($tournament)
 {
     if ($tournament->user != Auth::user()->id) {
         return Redirect::to('tournaments');
     }
     $tournament->name = Input::get('name');
     $maps = array_keys(Input::get('maps', []));
     $players = array_keys(Input::get('players.ids', []));
     $names = array_keys(Input::get('players.names', []));
     if (is_null($tournament->name)) {
         return Redirect::back();
     }
     $total = count($names) + count($players);
     if (ceil($total / 2) != count($maps)) {
         return Redirect::back();
     }
     $tournament->save();
     $tournament->maps()->detach();
     foreach ($maps as $map) {
         $tournament->maps()->attach($map);
     }
     $tournament->players()->detach();
     foreach ($players as $player) {
         $tournament->players()->attach($player);
     }
     $scenarii = new Collection();
     $tournament->maps->each(function ($map) use(&$scenarii, $tournament) {
         if ($scenarii->count() < 2) {
             $scenarii = Scenario::where('season', Carbon::now()->year)->get()->shuffle();
         }
         $map->scenarii($tournament)->attach($scenarii->pop()->id, ['tournament' => $tournament->id]);
         $map->scenarii($tournament)->attach($scenarii->pop()->id, ['tournament' => $tournament->id]);
     });
     foreach ($names as $name) {
         $player = new Player();
         $player->name = $name;
         $player->user = Auth::user()->id;
         $player->save();
         $tournament->players()->attach($player->id);
     }
     if ($total % 2 != 0) {
         $tournament->players()->attach(User::fantom()->id);
     }
     return Redirect::to('tournaments/' . $tournament->id);
 }
Exemplo n.º 11
0
 public function searchResultFormat(Collection $result)
 {
     $cp = new CoursePresenter();
     $html = "";
     if ($result->count() == 0) {
         $html .= "<tr>" . "  <td>1</td>" . "  <td>沒有課程</td>" . "  <td>阿飄教授</td>" . "  <td>幽靈學院</td>" . "  <td>沒有學分</td>" . "  <td>沒有評鑑</td>" . "  <td>1200</td>" . "  <td>X</td>" . "</tr>";
     } else {
         foreach ($result as $key => $course) {
             $counter = $key + 1;
             $html .= "<tr>" . "  <td> {$counter} </td>" . "  <td><a href='/course/" . $course->id . "'>" . $course->course_nameCH . "</a></td>" . "  <td>" . $course->professor . "</td>" . "  <td>";
             $html .= $cp->getDepartmantNameByCode($course->course_department);
             $html .= "  </td>" . "  <td>";
             $html .= $cp->getGradeNameByNum($course->course_grade);
             $html .= "  </td>" . "  <td>" . $course->judge_people . "</td>" . "  <td>" . $course->current_rank . "</td>" . "  <td>" . $course->time1 . "</td>" . "  <td>" . $course->time2 . "</td>" . "  <td>" . $course->place . "</td>" . "  <td id='pinArea" . $course->id . "'><a href='#searching' class='glyphicon glyphicon-pushpin' onclick='pinAjax(" . $course->id . ", 1)'></a></td>";
             $html .= "</tr>";
         }
         return $html;
     }
     return $html;
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function index(Request $request, $id = null)
 {
     $projects = $this->employee->listProjectUserBelong();
     if ($id == null) {
         $id = Project::pluck('id');
     }
     $detailfeatures = array();
     $features = Project::find($id)->features()->get();
     $detailfeatures = new Collection();
     foreach ($features as $key_fea => $value_fea) {
         $detaiFeas = $value_fea->detailfeatures()->get();
         foreach ($detaiFeas as $key => $value) {
             $detailfeatures->add($value);
         }
     }
     $page = Input::get('page') == NULL ? 1 : Input::get('page');
     $path = $request->url;
     $count = $detailfeatures->count();
     $pagiDetailfeatures = new \Illuminate\Pagination\LengthAwarePaginator($detailfeatures, $count, 5, $page);
     $pagiDetailfeatures->setPath($path);
     $detailfeatures = $detailfeatures->slice($pagiDetailfeatures->firstItem() - 1, 5);
     return view('manageproject.manageproject', compact('projects', 'detailfeatures', 'pagiDetailfeatures'));
 }
Exemplo n.º 13
0
 /**
  * @param Page       $page
  * @param Section    $section
  * @param Collection $content
  * @return mixed
  */
 public function renderSection(Page $page, Section $section, Collection $content)
 {
     $isContentMode = Session::get('mode') == 'content';
     $isModePublic = $section->isPublic();
     // Dispatch all the blocks in this section
     $blocks = array();
     foreach ($content as $item) {
         if ($item->section_id == $section->id) {
             $blocks[] = $this->renderContent($item);
         }
     }
     if (!$content->count() || implode('', $blocks) === '') {
         return;
     }
     if ($isContentMode) {
         // Build the form for adding a content block in this section
         $fb = App::make('Boyhagemann\\Content\\Controller\\ContentController')->init('create')->getFormBuilder();
         $fb->url(URL::route('admin.content.store'));
         $fb->defaults(array('section_id' => $section->id, 'page_id' => $section->page_id));
         $form = $fb->build();
     }
     Event::fire('content.dispatch.renderSection', array(&$blocks, $section, $page, $isContentMode, $isModePublic));
     return View::make('content::section', compact('blocks', 'section', 'form', 'isContentMode', 'isModePublic'));
 }
Exemplo n.º 14
0
 public function processEmail($message)
 {
     if (Email::where('gmail_uid', $message->id)->count() == 0) {
         $mail = new Email();
         $service = Mailbox::getGmailService();
         $user = '******';
         try {
             $message_data = $service->users_messages->get($user, $message->id);
         } catch (Exception $e) {
             print 'An error occurred: ' . $e->getMessage();
         }
         foreach ($message_data->getPayload()->headers as $header) {
             if ($header['name'] == 'Subject') {
                 $mail->subject = $header['value'];
             }
             if ($header['name'] == 'Cc') {
                 $mail->cc = $header['value'];
             }
             if ($header['name'] == 'From') {
                 $from_pos = strpos($header['value'], "<");
                 $from_name = substr($header['value'], 0, $from_pos);
                 $from_address = substr($header['value'], $from_pos + 1, -1);
                 $mail->sender_name = $from_name;
                 $mail->sender_address = $from_address;
             }
             if ($header['name'] == 'Date') {
                 $mail->received_at = Carbon::createFromFormat('D, d M Y H:i:s T', $header['value']);
             }
         }
         $mail->mailbox_id = $this->id;
         $attachments = new Collection();
         if ($message_data->getPayload()->body['size'] == 0) {
             foreach ($message_data->getPayload()->parts as $part) {
                 if (count($part->parts) > 0) {
                     foreach ($part->parts as $subpart) {
                         if ($subpart->mimeType == 'text/html') {
                             $mail->mimetype = 'text/html';
                             $mail->content = base64_decode(strtr($subpart->getBody()->data, '-_,', '+/='));
                         }
                     }
                 }
                 if ($part->mimeType == 'text/html') {
                     $mail->mimetype = 'text/html';
                     $mail->content = base64_decode(strtr($part->getBody()->data, '-_,', '+/='));
                 }
                 if ($part['filename'] != '') {
                     $attachment_data = $service->users_messages_attachments->get("me", $message->id, $part->getBody()->attachmentId);
                     $file_raw_data = base64_decode(strtr($attachment_data->data, array('-' => '+', '_' => '/')));
                     $stored_filename = $message->id . '-' . time() . '-' . $part['filename'];
                     $fh = fopen(public_path() . "/email_attachments/" . $stored_filename, "w+");
                     fwrite($fh, $file_raw_data);
                     fclose($fh);
                     $attachment = new EmailAttachment();
                     $attachment->file_path = "email_attachments/" . $stored_filename;
                     $attachment->file_name = $part['filename'];
                     $attachment->save();
                     $attachments->push($attachment);
                 }
             }
             if (!$mail->content) {
                 foreach ($message_data->getPayload()->parts as $part) {
                     if ($part->mimeType == 'text/plain') {
                         $mail->mimetype = 'text/plain';
                         $mail->content = base64_decode(strtr($part->getBody()->data, '-_,', '+/='));
                     }
                 }
             }
         } else {
             $mail->mimetype = 'text/plain';
             $mail->content = base64_decode(strtr($message_data->getPayload()->body['data'], '-_,', '+/='));
         }
         $mail->gmail_uid = $message->id;
         $mail->save();
         if ($attachments->count() > 0) {
             foreach ($attachments as $a) {
                 $a->email_id = $mail->id;
                 $a->save();
             }
         }
         $mail->matchToPatient();
         $mail->addProcessedLabel();
     }
 }
Exemplo n.º 15
0
 public static function choose_from_collection(\Illuminate\Database\Eloquent\Collection $collection)
 {
     assert($collection->count(), 'Collection empty!');
     return $collection->get($collection->keys()[mt_rand() % $collection->count()]);
 }
Exemplo n.º 16
0
 public static function addTagsToCollection(Collection $collection)
 {
     for ($i = 0; $i < $collection->count(); $i++) {
         $collection[$i]["tags"] = $collection[$i]->tagged;
     }
 }
Exemplo n.º 17
0
 /**
  * Generates a JSON response with a count
  *
  * @param   Collection   $collection 
  * @param                $data
  * @return  JsonResponse : merged $data and count value
  */
 public function respondWithCount(Collection $collection, $data)
 {
     $response = array_merge($data, ['count' => $collection->count()]);
     return $this->respond($response);
 }
 /**
  * Get an instance of the ProgressBar helper.
  *
  * @param Collection $models
  *
  * @return ProgressBar
  */
 protected function getProgressBar(Collection $models)
 {
     $output = $this->output ?: new NullOutput();
     $progress = new ProgressBar($output, $models->count());
     return $progress;
 }
Exemplo n.º 19
0
 /**
  * Check if more data exists at reader
  *
  * @return mixed
  */
 public function moreDataExists()
 {
     return $this->collection->count() > 0 ? true : false;
 }
Exemplo n.º 20
0
 /**
  * FormContentClear constructor. Pass content records collection object inside (can be empty collection)
  * @param Content|Collection $records
  */
 public function __construct($records)
 {
     $this->_records = $records;
     $this->count = $this->_records->count();
     parent::__construct();
 }
Exemplo n.º 21
0
 /**
  * Display one or more prospects.
  *
  * @note We're using the 'table()' function which expects an array
  *       of arrays (i.e. rows of data items/fields)
  *
  * @param Collection $prospects
  * @param bool $forceList
  * @param int $maxLen
  */
 protected function showProspects($prospects, $forceList = false, $maxLen = 76)
 {
     if (empty($prospects) || $prospects->isEmpty()) {
         $this->info('No prospect records to display');
         return;
     }
     if ($prospects->count() > 1 || $forceList) {
         $rows = $prospects->toArray();
         $this->table(array_keys($rows[0]), $rows);
     } else {
         $prospect = $prospects->first();
         $data = $prospect->toArray();
         $rows = [];
         foreach ($data as $k => $v) {
             $rows[] = [$k, is_string($v) ? str_limit($v, $maxLen) : $v];
         }
         $this->table(['field', 'value'], $rows);
     }
     $this->info('');
     // Print a blank line
 }
Exemplo n.º 22
0
 /**
  * Match the eagerly loaded results to their parents.
  *
  * @param Eloquent[] $models
  * @param Collection $results
  * @param string     $relation
  *
  * @return array
  */
 public function match(array $models, Collection $results, $relation)
 {
     if ($results->count() === 0) {
         return $models;
     }
     $dictionary = $this->buildDictionary($results);
     $properties = $this->getProperties();
     // Once we have the dictionary we can simply spin through the parent models to
     // link them up with their children using the keyed dictionary to make the
     // matching very convenient and easy work. Then we'll just return them.
     foreach ($models as $model) {
         $key = $model->getAttribute($this->localKey);
         if (array_key_exists($key, $dictionary)) {
             $value = $this->getRelationValue($dictionary, $key, 'many');
             $model->getPropertyFactory()->setPropertyValues($properties, $value);
         } else {
             $model->getPropertyFactory()->setPropertyValues($properties, null);
         }
     }
     return $models;
 }