Overview

Namespaces

  • Composer
    • Autoload
  • Illuminate
    • Support
      • Contracts
      • Facades
  • Laravella
    • Crud
      • Exceptions
      • Facades
  • None
  • PHP

Classes

  • ComposerAutoloaderInit0812ead62c33200f1cfc491b452f7c6a
  • CreateActionsTable
  • CreateAssetsTable
  • CreateAuditTable
  • CreateDisplayTypesTable
  • CreateEventsTable
  • CreateFieldsTable
  • CreateKeyFieldsTable
  • CreateKeysTable
  • CreateKeyTypesTable
  • CreateLogsTable
  • CreateMenuPermissionsTable
  • CreateMenusTable
  • CreateObjectEventsTable
  • CreateObjectsTable
  • CreateOptionsTable
  • CreateOptionTypesTable
  • CreatePageAssetsTable
  • CreatePagesTable
  • CreateSeveritiesTable
  • CreateTablesTable
  • CreateUserGroupPermissionsTable
  • CreateUsergroupsTable
  • CreateUserPermissionsTable
  • CreateViewsTable
  • CreateWidgetTypesTable
  • DbApiController
  • DbController
  • Domain
  • field
  • foreignKey
  • Model
  • PageController
  • primaryKey
  • Record
  • Relation
  • Table
  • xxxxAddMcollectionMediaTable
  • xxxxCreateUsersTable

Functions

  • action
  • app
  • app_path
  • array_add
  • array_build
  • array_divide
  • array_dot
  • array_except
  • array_fetch
  • array_first
  • array_flatten
  • array_forget
  • array_get
  • array_only
  • array_pluck
  • array_pull
  • array_set
  • array_sort
  • asset
  • base_path
  • camel_case
  • class_basename
  • csrf_token
  • dd
  • e
  • ends_with
  • head
  • last
  • link_to
  • link_to_action
  • link_to_asset
  • link_to_route
  • object_get
  • public_path
  • route
  • secure_asset
  • secure_url
  • snake_case
  • starts_with
  • storage_path
  • str_contains
  • str_finish
  • str_is
  • str_plural
  • str_random
  • str_singular
  • studly_case
  • trans
  • trans_choice
  • url
  • value
  • with
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: /**
  4:  * Description of generic Model
  5:  *
  6:  * @author Victor
  7:  */
  8: class Model extends Eloquent {
  9: 
 10:     protected $metaData = null;
 11:     protected $primaryKey = "id";
 12:     protected $guarded = array('id');
 13: 
 14:     /**
 15:      * A way to overload the constructor. Use this to instantiate the class.
 16:      * 
 17:      * @param type $tableName
 18:      */
 19:     public static function getInstance()
 20:     {
 21:         $a = func_get_args(); 
 22:         $i = func_num_args();
 23:         
 24:         $tmpInstance = new static;
 25:         
 26:         if (method_exists($tmpInstance, $f='getInstance'.$i)) { 
 27:             return call_user_func_array(array($tmpInstance,$f),$a); 
 28:         } 
 29:     }
 30: 
 31:     /**
 32:      * A way to overload the constructor. Use this to instantiate the class.
 33:      * 
 34:      * @param type $tableName
 35:      */
 36:     private static function getInstance1($tableName = null)
 37:     {
 38:         $model = new Model(array(), $tableName);
 39:         return $model;
 40:     }
 41: 
 42:     /**
 43:      * A way to overload the constructor. Use this to instantiate the class.
 44:      * 
 45:      * @param type $tableName
 46:      */
 47:     private static function getInstance2($attributes, $tableName = null)
 48:     {
 49:         $model = new Model($attributes, $tableName);
 50:         return $model;
 51:     }
 52: 
 53:     /**
 54:      * Create a new Eloquent model instance.
 55:      *
 56:      * @param  array  $attributes
 57:      * @param  tableName  $tableName
 58:      * 
 59:      * @return void
 60:      */
 61:     function __construct() 
 62:     { 
 63:         $a = func_get_args(); 
 64:         $i = func_num_args(); 
 65:         if (method_exists($this,$f='__construct'.$i)) { 
 66:             call_user_func_array(array($this,$f),$a); 
 67:         } 
 68:     } 
 69: 
 70:     private function __construct1(array $attributes = array()) 
 71:     { 
 72:         parent::__construct($attributes);
 73:     } 
 74:     
 75:     private function __construct2(array $attributes = array(), $table = null) 
 76:     { 
 77:         $this->table = $table;
 78:         $this->setTable($table);
 79:         $this->setMetaData($table);
 80:         $this->setGuarded(array($this->metaData['table']['pk_name']));
 81:         parent::__construct($attributes);
 82:     } 
 83:         
 84:     
 85:     /**
 86:      * Get the table associated with the model.
 87:      *
 88:      * @return string
 89:      */
 90:     public function getTable()
 91:     {
 92:         if (isset($this->table))
 93:             return $this->table;
 94: 
 95:         return null;
 96:     }
 97: 
 98:     /**
 99:      * 
100:      * @param type $table
101:      * @param type $customKey
102:      * @return type
103:      */
104:     public function setHasOne($table, $customKey)
105:     {
106:         return $this->hasOne($table, $customKey);
107:     }
108: 
109:     /**
110:      * 
111:      * @param type $table
112:      * @param type $customKey
113:      * @return type
114:      */
115:     public function setHasMany($table, $customKey)
116:     {
117:         return $this->hasMany($table, $customKey);
118:     }
119: 
120:     /**
121:      * 
122:      * @param type $table
123:      * @param type $customKey
124:      * @return type
125:      */
126:     public function setBelongsTo($table, $customKey)
127:     {
128:         return $this->belongsTo($table, $customKey);
129:     }
130: 
131:     /**
132:      * 
133:      * @param type $table
134:      * @param type $pivotTable
135:      * @param type $remoteId
136:      * @param type $localId
137:      * @return type
138:      */
139:     public function setBelongsToMany($table, $pivotTable, $remoteId, $localId)
140:     {
141:         return $this->belongsToMany($table, $pivotTable, $remoteId, $localId);
142:     }
143: 
144:     public function setGuarded($guardedA)
145:     {
146:         $this->guarded = $guardedA;
147:     }
148: 
149:     public function getA()
150:     {
151:         
152:     }
153: 
154:     /**
155:      * Insert a new record
156:      */
157:     public function insertRec()
158:     {
159:         $fields = $this->metaData['fields_array'];
160: 
161:         $updateA = array();
162:         foreach ($fields as $field)
163:         {
164:             if ($this->isFillable($field['name']))
165:             {
166:                 $updateA[$field['name']] = Input::get($field['name']);
167:             }
168:         }
169: 
170:         $id = DB::table($this->table)->insertGetId($updateA);
171: 
172:         return $id;
173:     }
174: 
175:     /**
176:      * Create an array of key values from http GET data
177:      * 
178:      * @param type $fields
179:      */
180:     private function __editGet($fields)
181:     {
182:         $updateA = array();
183:         foreach ($fields as $field)
184:         {
185:             if ($this->isFillable($field['name']))
186:             {
187:                 $updateA[$field['name']] = Input::get($field['name']);
188:             }
189:         }
190:         return $updateA;
191:     }
192: 
193:     /**
194:      * Create an array of key values from http GET data
195:      * 
196:      * @param type $fields
197:      * @param type $json
198:      */
199:     private function __editJson($fields, $json)
200:     {
201:         die;
202: 
203:         $updateA = array();
204:         //print_r($json);
205:         $json = iconv("windows-1250", "UTF-8", $json);
206:         $input = json_decode($json);
207:         foreach ($fields as $field)
208:         {
209:             if ($this->isFillable($field['name']) && isset($input[$field['name']]))
210:             {
211:                 $updateA[$field['name']] = $input[$field['name']];
212:             }
213:         }
214:         return $updateA;
215:     }
216: 
217:     /**
218:      * Update a record
219:      * 
220:      * @param type $pkValue
221:      * @return \Model
222:      */
223:     public function editRec($pkValue, $json = null)
224:     {
225: 
226:         $pkName = $this->metaData['table']['pk_name'];
227: 
228:         $fields = $this->metaData['fields_array'];
229: 
230:         if (empty($json))
231:         {
232:             $updateA = $this->__editGet($fields);
233:         }
234:         else
235:         {
236:             $updateA = $this->__editJson($fields, $json);
237:         }
238: 
239:         //print_r($updateA);
240:         DB::table($this->table)->where($pkName, '=', $pkValue)->update($updateA);
241: 
242:         return $this;
243:     }
244: 
245:     /**
246:      * Setter for table
247:      * 
248:      * @param type $tableName
249:      */
250:     public function setTable($tableName)
251:     {
252:         $this->table = $tableName;
253:     }
254: 
255:     /**
256:      * Setter for metaData
257:      * 
258:      * @param type $tableName
259:      */
260:     public function setMetaData($tableName)
261:     {
262:         $this->metaData = Table::getTableMeta($tableName);
263:     }
264: 
265:     /**
266:      * Getter for metaData
267:      * 
268:      * @return type
269:      */
270:     public function getMetaData()
271:     {
272:         return $this->metaData;
273:     }
274: 
275: }
276: 
277: ?>
278: 
crud API documentation generated by ApiGen 2.8.0