1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
<?php defined('BASEPATH') or exit('No direct script access allowed');
class Application_model extends BaseModel { public function __construct() { $this->table = strtolower(substr(__CLASS__, 0, -strlen('_model'))); parent::$sort_field = false; }
public static function get_data($via = 'home') { $model = self::whereRaw('(nominee_submitted = 1 OR nominator_submitted = 1)')->where('deleted', 0); if (self::$sort_field) { $model->orderBy('sort', 'asc'); } $model->orderBy('created_at', 'desc')->orderBy('id', 'desc');
if ($via == 'webadmin') { return $model->get(); } else if ($via == 'home') { return $model->where('status', 1)->get(); } }
public function Application_file() { return $this->hasMany(Application_file_model::class, 'application_id'); }
public function get_related_data() { return self::whereRaw('(' . $_SESSION['member_id'] . ' IN(owner_member_id, nominee_member_id, nominator_member_id))')->where('deleted', 0)->get(); }
public static function get_index_data_by_paginate_and_searching($page, $per_page, $searches, $via = 'home') { $model = self::whereRaw('(nominee_submitted = 1 OR nominator_submitted = 1)')->where('deleted', 0); if (self::$sort_field) { $model->orderBy('sort', 'asc'); } $model->orderBy('created_at', 'desc')->orderBy('id', 'desc'); if ($via == 'webadmin') { $languages = Master_type_code_model::get_data_by_type_code('LANGUAGE');
foreach ($searches as $key => $value) { if (!empty($value) || $value != null) { if ($key == 'status' || strpos($key, '_id') !== false) { $model->where($key, $value); } else if (substr($key, -1) == '_') { $whereRaw = '('; foreach ($languages as $lang) { $whereRaw .= $key . $lang['code'] . ' LIKE \'%' . $value . '%\'' . ' OR '; } $whereRaw = substr($whereRaw, 0, -strlen(' OR ')) . ')';
$model->whereRaw($whereRaw); } else { $model->where($key, 'like', '%' . $value . '%'); } } } $temp_model['total'] = $model->count(); $temp_model['model'] = $model->forPage($page, $per_page)->get(); return $temp_model; } } }
|