public function __isset($key) { $check = Utils::token(); return $check != isake($this->_data, $key, $check); }
function deleteCascade(array $fields) { foreach ($fields as $field) { $val = isake($this->_data, $field, false); if (fnmatch('*_id', $field) && false !== $val) { $row = bigDb(str_replace('_id', '', $field))->find($val); if ($row) { $row->delete(); } } } return $this->delete(); }
public function __call($func, $args) { if (substr($func, 0, strlen('get')) == 'get') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, strlen('get')))); $field = Inflector::lower($uncamelizeMethod); $default = count($args) == 1 ? Arrays::first($args) : null; return isAke($this->_data, $field, $default); } elseif (substr($func, 0, strlen('set')) == 'set') { $uncamelizeMethod = Inflector::uncamelize(lcfirst(substr($func, strlen('set')))); $field = Inflector::lower($uncamelizeMethod); if (!empty($args)) { $val = Arrays::first($args); } else { $val = null; } $this->_data[$field] = $val; return $this; } else { $cb = isake($this->_events, $func, false); if (false !== $cb) { if ($cb instanceof Closure) { return call_user_func_array($cb, $args); } } dd("{$func} is not a model function of this object."); } }
public function delete() { $id = isake($this->_data, $this->_db->pk(), false); if (false !== $id) { return $this->_db->delete($id); } return false; }
public function aggregate($op, $field) { set_time_limit(0); $ops = [['$group' => ["_id" => ["_id" => '$' . $this->collection], "{$op}" => ['$' . $op => '$' . $field]]]]; $results = $this->getCollection()->aggregate($ops); $result = isake($results, 'result', []); if (!empty($result)) { $row = current($result); $val = isAke($row, $op, false); if (false !== $val) { return $val; } } return null; }
function getSegmentsByReseller($reseller) { $collection = []; if (is_object($reseller)) { $reseller = $reseller->id; } if (!is_numeric($reseller)) { throw new Exception('Reseller must be an instance of reseller or be an id'); } $relations = bigDb('segmentreseller')->where(['reseller_id', '=', $reseller])->exec(); if (!empty($relations)) { foreach ($relations as $relation) { $segment = isake($relation, 'segment_id', 0); if ($segment > 0) { array_push($collection, $segment); } } } return $collection; }
public function fiche($reseller_id, $account_id = null) { $return = []; if (is_null($account_id)) { $user = session('user')->getUser(); $account_id = (int) $user['id']; } $sid = $this->session_id(); $fiche = Model::Restodata()->where(['reseller_id', '=', (int) $reseller_id])->first(true); $ir = Save::get('infos.data.resto.' . $account_id . '.' . $sid); $oi = Save::get('offer.in.' . $account_id . '.' . $sid); if (!$ir) { $ir = []; } else { $ir = unserialize($ir); } if ($fiche) { $return = $fiche->toArray(); $jours = isAke($return, 'jours', []); $services = isAke($return, 'services', []); $return['extras'] = isAke($return, 'extras', []); if (!$oi) { $oi = serialize([]); } $datasPc = unserialize($oi); $restos = isAke($datasPc, 'restaurants', []); $jour = isAke($datasPc, 'jour', lib('time')->frenchDay()); $service = isAke($datasPc, 'service', 1); if (empty($restos)) { return $return; } $nc = $c = []; $categories = Model::Catalogcategory()->cursor(); foreach ($categories as $cat) { $pls = $return['carte'][$cat['id']]; $cpls = []; foreach ($pls as $segPlt) { $contraintesJour = isset($jours[$segPlt['id']]) ? $jours[$segPlt['id']] : []; $contraintesService = isset($services[$segPlt['id']]) ? $services[$segPlt['id']] : []; $add = true; if (!empty($contraintesJour)) { $add = in_array($jour, $contraintesJour); } if (!empty($contraintesService) && $add) { $add = in_array($service, $contraintesService); } if ($add) { $cpls[] = $segPlt; } } $nc[] = ['name' => $cat['name'], 'plats' => $cpls]; } $return['carte_ordonnee'] = $nc; foreach ($restos as $res) { if ($res['id'] == $reseller_id) { break; } } redis()->set('infos.restos.' . $account_id . '.' . $reseller_id, serialize($res)); $return['plats_choisis'] = isAke($res, 'plats_choisis', []); $ap = isAke($res, 'all_plats', []); if (!empty($return['plats_choisis'])) { $keyCache = sha1($reseller_id . $this->session_id() . 'platschoisis'); $cp = redis()->get($keyCache); if (!$cp) { $pc1 = $return['plats_choisis']; $pc2 = $tups = []; foreach ($pc1 as $pc11) { $plats = isAke($pc11, 'plats', []); $c = []; if (!empty($plats)) { foreach ($plats as $p) { $n = $p['catalog_name']; if (in_array($p['id'], $tups)) { continue; } $tups[] = $p['id']; $p['name'] = $n; $i = isset($ap[$p['id']]) ? $ap[$p['id']] : []; if (!isset($p['description'])) { $p['description'] = isAke($i, 'description', ''); } else { if (empty($p['description'])) { $p['description'] = isAke($i, 'description', ''); } } if (!isset($p['accompagnement'])) { $p['accompagnement'] = isAke($i, 'accompagnement', ''); } else { if (empty($p['accompagnement'])) { $p['accompagnement'] = isAke($i, 'accompagnement', ''); } } unset($p['catalog_name']); $c[] = $p; } $pc11['plats'] = $c; } else { if (in_array($pc11['id'], $tups)) { continue; } $tups[] = $pc11['id']; $pc11['plats'] = []; $i = isset($ap[$pc11['id']]) ? $ap[$pc11['id']] : []; $pt = $this->infoPlates($return, $pc11['id']); $pt['name'] = $pc11['catalog_name']; $pc11['plats'][] = $pt; } $pc2[] = $pc11; } $return['plats_choisis'] = $pc2; } else { $return['plats_choisis'] = unserialize($cp); // redis()->del($keyCache); } } unset($return['names']); unset($return['assocs']); $return['infos'] = isset($ir[$reseller_id]) ? $ir[$reseller_id] : []; $ap = isAke($return['infos'], 'all_plats', []); $orders = isake($return, 'orders', []); $collection = []; foreach ($ap as $idAp => $ap) { $ap = current($ap); $ordre = isset($orders[$idAp]) ? $orders[$idAp] : 1; $ap['ordre'] = $ordre; $collection[] = $ap; } $collection = lib('collection', [$collection])->sortBy('ordre')->toArray(); $return['infos']['all_plats'] = array_values($collection); if (!empty($account_id)) { Model::Restoview()->firstOrCreate(['date' => date('d-m-Y'), 'account_id' => (int) $account_id, 'reseller_id' => (int) $reseller_id]); } unset($return['all_plats']); } else { die('resto introuvable'); } unset($return['infos']); Save::setExpire('return.in.' . $account_id . '.' . $sid, $return, 120); $return['session_id'] = session_id(); return $return; }