public static function tables() { $dbt = jmodel('jma_table'); $dirs = glob(STORAGE_PATH . DS . 'dbjson' . DS . '*', GLOB_NOSORT); $rows = array(); if (count($dirs)) { foreach ($dirs as $dir) { $tmp = glob($dir . DS . '*', GLOB_NOSORT); $rows = array_merge($rows, $tmp); } } $tables = array(); if (count($rows)) { foreach ($rows as $row) { $tab = explode(DS, $row); $index = Arrays::last($tab); $ns = $tab[count($tab) - 2]; if (!strstr($index, 'jma_')) { $t = $dbt->where('name = ' . $index)->where('ns = ' . $ns)->first(true); if (is_null($t)) { $total = count(glob(STORAGE_PATH . DS . 'dbjson' . DS . $ns . DS . $index . DS . '*.row', GLOB_NOSORT)); $tables[$index]['count'] = $total; $data = jmodel($index, $ns)->fetch()->exec(); if (count($data)) { $first = Arrays::first($data); $fields = array_keys($first); $tables[$index]['fields'] = $fields; } else { $fields = array(); } self::structure($ns, $index, $fields); } } } } return $tables; }
public function join($model) { if (is_string($model)) { $model = jmodel($model); } return new self($model); }
public function getOfferOut($reseller_id, $offerout_id) { $collection = []; $offers = Model::Offerout()->where(['id', '=', $offerout_id])->exec(); foreach ($offers as $offer) { $item = []; $articles = Model::Articleout()->where(['offerout_id', '=', $offer['id']])->exec(); $item['id'] = $offer['id']; $item['status_id'] = $offer['status_id']; $item['date_creation'] = $offer['created_at']; $item['date_expiration_offerin'] = $offer['expiration_offerin']; $zip = isAke($offer, 'zip', false); if (false !== $zip) { $item['buyer']['zip'] = $zip; $company = Model::Company()->find($offer['company_id']); if ($company) { $item['buyer']['city'] = $company->city; $item['buyer']['is_pro'] = $company->is_pro; $item['buyer']['is_pro'] = $company->is_pro; $item['buyer']['name'] = $company->name; } $market = jmodel('segment')->find($offer['market']); if ($market) { $item['market']['id'] = $market->id; $item['market']['name'] = $market->name; $data = repo('segment')->getData($market->id); $icon = isAke($data, 'icon', null); $item['market']['icon'] = $icon; } $item['category_id'] = $offer['category']; if ($offer['category'] > 0) { $segCat = jmodel('segment')->find($offer['category']); $item['category_name'] = $segCat->name; $data = repo('segment')->getData($segCat->id); $icon = isAke($data, 'icon', null); $item['category_icon'] = $icon; } else { $item['category_name'] = 'autre'; $item['category_icon'] = 'fa fa-cubes'; } foreach ($articles as $article) { $it = $article; $seg = jmodel('segment')->find($article['item_id']); if ($seg) { $it['family'] = repo('segment')->getFamilyfromItem($article['item_id']); $it['name'] = $seg->name; $item['articles'][] = $it; } else { if ($article['item_id'] == 0) { $item['articles'][] = $article; } } } array_push($collection, $item); } } return current($collection); }
private function tableByName($name, $ns = 'core') { return jmodel($name, $ns); }
function deleteAction() { $table = request()->getTable(); $id = request()->getId(); if (!is_null($table) && !is_null($id)) { $permission = $table . '_json_delete'; $auth = auth()->can($permission); if (true === $auth || true === $this->isAdmin) { $row = jmodel($table)->find($id); if (empty($row)) { $this->forward('home', 'static'); } $infos = isAke($this->view->config['tables'], $table); $closure = isAke($infos, 'before_delete', false); if (false !== $closure && is_callable($closure)) { $closure(); } $crud = new c(jmodel($table)); $status = $crud->delete($id); $closure = isAke($infos, 'after_delete', false); if (false !== $closure && is_callable($closure)) { $closure(); } if (true === $status) { $this->forward('list'); } else { $this->forward('error', 'static'); } } else { $this->forward('forbidden', 'static'); } } else { $this->forward('home', 'static'); } }
public static function importJson($table) { $data = jmodel($table)->full()->orderById()->exec(); $db = self::instance(SITE_NAME, $table); foreach ($data as $row) { $insert = $db->addWithId($db->treatCast($row)); } dd($insert); }
function getOptionObject($row, $name, $default = null) { if ($row instanceof Container) { $databaseRow = $row->db(); if ($databaseRow instanceof DBJ) { $dbDb = $databaseRow->db; $dbTable = $databaseRow->table; $dbId = $row->id; $option = jmodel('optionobject')->where(['object_database', '=', $dbDb])->where(['object_table', '=', $dbTable])->where(['object_id', '=', $dbId])->where(['name', '=', $name])->first(true); return !$option ? $default : $option->value; } } return $default; }
public static function generate($model, $overwrite = false) { $file = APPLICATION_PATH . DS . 'models' . DS . 'CrudJson' . DS . ucfirst(Inflector::camelize($model)) . '.php'; if (!File::exists($file) || $overwrite) { $db = jmodel($model); $crud = new Crud($db); File::delete($file); $tplModel = fgc(__DIR__ . DS . 'Model.tpl'); $tplField = fgc(__DIR__ . DS . 'Field.tpl'); $fields = $crud->fields(); $singular = ucfirst($model); $plural = $singular . 's'; $default_order = $crud->pk(); $tplModel = str_replace(array('##singular##', '##plural##', '##default_order##'), array($singular, $plural, $default_order), $tplModel); $fieldsSection = ''; foreach ($fields as $field) { if ($field != $crud->pk()) { $label = substr($field, -3) == '_id' ? ucfirst(str_replace('_id', '', $field)) : ucfirst(Inflector::camelize($field)); $fieldsSection .= str_replace(array('##field##', '##label##'), array($field, $label), $tplField); } } $tplModel = str_replace('##fields##', $fieldsSection, $tplModel); File::put($file, $tplModel); } }