Beispiel #1
0
 /**
  * @param $query
  * @param string $keyword
  * @param int $filterBy
  * @return mixed
  */
 public function scopeSearch($query, $keyword = '', $filterBy = 0)
 {
     if (!empty($filterBy)) {
         if (!is_array($filterBy) && !empty($keyword)) {
             $query->where($filterBy, 'LIKE', "%{$keyword}%");
         } else {
             foreach ($filterBy as $key => $field) {
                 if ($field['name'] == 'search_id' && !empty($field['value'])) {
                     //find by ID
                     $query->where('id', $field['value']);
                     break;
                 }
                 $searchField = "";
                 if (strpos($field['name'], 'search__') !== FALSE) {
                     $searchField = explode_end('__', $field['name']);
                 }
                 if ($searchField) {
                     if ($searchField == 'filterBy') {
                         if (!empty($keyword)) {
                             if (strpos($field['value'], 'scope') !== FALSE) {
                                 $scopeFunction = strtolower(substr($field['value'], 5));
                                 $query->{$scopeFunction}($keyword);
                             } elseif (strpos($field['value'], 'translated') !== FALSE) {
                                 $translationField = strtolower(substr($field['value'], 10));
                                 $query->findTranslate($translationField, $keyword);
                             } else {
                                 $query->where($field['value'], 'like', "%{$keyword}%");
                             }
                         }
                     } elseif ($searchField == 'status') {
                         if ($field['value'] != 'all') {
                             $query->where('status', (bool) $field['value']);
                         }
                     } elseif ($searchField != 'keyword' && $field['value']) {
                         if ($field['value'] != 'all') {
                             $query->where($searchField, $field['value']);
                         }
                     }
                 }
             }
         }
     }
     if (method_exists($this, 'adapterFilter')) {
         $query = $this->adapterFilter($query);
     }
     $query->relation();
     return $query;
 }
Beispiel #2
0
 public function link()
 {
     return '<td><a target="_blank" href="' . url($this->value) . '">' . str_limit(explode_end('/', $this->value), 20) . '</a></td>';
 }
Beispiel #3
0
 protected function handle_file_upload($uploaded_file, $name, $size, $type, $error, $index = null, $content_range = null)
 {
     // $fileName = uniqueString().".".$fileExtention;
     $fileName = $this->get_file_name($uploaded_file, $name, $size, $type, $error, $index, $content_range);
     $fileExtention = explode_end($fileName, ".");
     $file = new \stdClass();
     $file->name = uniqueString() . "." . $fileExtention;
     $file->size = $this->fix_integer_overflow(intval($size));
     $file->type = $type;
     if ($this->validate($uploaded_file, $file, $error, $index)) {
         $this->handle_form_data($file, $index);
         $upload_dir = $this->get_upload_path();
         if (!is_dir($upload_dir)) {
             mkdir($upload_dir, $this->options['mkdir_mode'], true);
         }
         $file_path = $this->get_upload_path($file->name);
         $append_file = $content_range && is_file($file_path) && $file->size > $this->get_file_size($file_path);
         if ($uploaded_file && is_uploaded_file($uploaded_file)) {
             // multipart/formdata uploads (POST method uploads)
             if ($append_file) {
                 file_put_contents($file_path, fopen($uploaded_file, 'r'), FILE_APPEND);
             } else {
                 // pr($upload_dir);
                 // pr($file->name, 1);
                 // pr($file_path, 1);
                 // move_uploaded_file($uploaded_file, $file_path);
                 // $fileExtention  = explode_end($file->name, ".");
                 // $fileName = uniqueString().".".$fileExtention;
                 // $file->name = $fileName;
                 $uploadFile = Input::file('files');
                 $MyFTP = new MyFTP('choilive');
                 $uploadSuccess = $MyFTP->uploadFtp($this->options['upload_dir'], $uploaded_file, $file->name);
             }
         } else {
             // Non-multipart uploads (PUT method support)
             file_put_contents($file_path, fopen('php://input', 'r'), $append_file ? FILE_APPEND : 0);
         }
         $file_size = $this->get_file_size($file_path, $append_file);
         if ($file_size === $file->size) {
             $file->url = $this->get_download_url($file->name);
             if ($this->is_valid_image_file($file_path)) {
                 $this->handle_image_file($file_path, $file);
             }
         } else {
             $file->size = $file_size;
             if (!$content_range && $this->options['discard_aborted_uploads']) {
                 unlink($file_path);
                 $file->error = $this->get_error_message('abort');
             }
         }
         $this->set_additional_file_properties($file);
     }
     return $file;
 }