public function getAvailableOffsets() { $c_class = get_called_class(); if (!isset(self::$offset_meta[$c_class])) { $res = array(); $finder = $this->getFinder(); $db_fields = array_keys(fx::schema($finder->getTable())); foreach ($db_fields as $field) { $res[$field] = array('type' => self::OFFSET_FIELD); } foreach ($finder->relations() as $rel_name => $rel) { $res[$rel_name] = array('type' => self::OFFSET_RELATION, 'relation' => $rel); } foreach ($finder->getMultiLangFields() as $f) { $res[$f] = array('type' => self::OFFSET_LANG); } $entity_class = $c_class; $reflection = new \ReflectionClass($entity_class); $methods = $reflection->getMethods(); foreach ($methods as $method) { if ($method::IS_PUBLIC && preg_match("~^_get(.+)\$~", $method->name, $getter_offset)) { $getter_offset = fx::util()->camelToUnderscore($getter_offset[1]); $res[$getter_offset] = array('type' => self::OFFSET_GETTER, 'method' => $method->name); } } self::$offset_meta[$c_class] = fx::collection($res); } return self::$offset_meta[$c_class]; }
public function getAll() { static $all_modules_data = false; if ($all_modules_data === false) { $all_modules_data = fx::collection(); $vendor_dirs = glob(fx::path('@module/*')); foreach ($vendor_dirs as $vendor_dir) { if (!is_dir($vendor_dir)) { continue; } $vendor_name = fx::path()->fileName($vendor_dir); $vendor_modules = glob($vendor_dir . '/*'); foreach ($vendor_modules as $mod_dir) { if (!is_dir($mod_dir)) { continue; } $module_name = fx::path()->fileName($mod_dir); //fx::debug($vendor_name.'/'.$module_name); $module = array('vendor' => $vendor_name, 'name' => $module_name); $module_class = $vendor_name . "\\" . $module_name . "\\Module"; if (class_exists($module_class)) { $module['object'] = new $module_class(); } $all_modules_data[] = $module; } } } return $all_modules_data; }
public function build($data) { $index_by_parent = array(); $children_key = $this->childrenKey; $linkers = isset($data->linkers) ? $data->linkers : null; if ($linkers) { $this->linkers = $linkers; } foreach ($data as $item) { if (in_array($item['id'], $this->extraRootIds)) { continue; } $pid = $item[$this->parentKey]; if (!isset($index_by_parent[$pid])) { $index_by_parent[$pid] = $this->fork(); $index_by_parent[$pid]->addFilter($this->parentKey, $pid); } $index_by_parent[$pid][] = $item; } $non_root = array(); foreach ($data as $item) { if (isset($index_by_parent[$item['id']])) { if (isset($item[$children_key]) && $item[$children_key] instanceof \Floxim\Floxim\System\Collection) { $item[$children_key]->concat($index_by_parent[$item['id']]); } else { $item[$children_key] = $index_by_parent[$item['id']]; } $non_root = array_merge($non_root, $index_by_parent[$item['id']]->getValues('id')); } elseif (!isset($item[$children_key])) { $item[$children_key] = fx::collection(); } } $final_data = array(); foreach ($data as $index => $item) { if (in_array($item['id'], $non_root)) { if ($linkers && isset($linkers[$index])) { unset($linkers[$index]); } continue; } $final_data[$index] = $item; } $this->data = $final_data; //$this->data = $data->findRemove('id', $non_root)->getData(); if ($this->count() > 0) { $first_item = $this->first(); $this->addFilter($this->parentKey, $first_item[$this->parentKey]); } }
public function makeTree($parent_field = 'parent_id', $children_field = 'nested', $id_field = 'id') { $index_by_parent = array(); foreach ($this as $item) { $pid = $item[$parent_field]; if (!isset($index_by_parent[$pid])) { $index_by_parent[$pid] = fx::collection(); $index_by_parent[$pid]->is_sortable = $this->is_sortable; } $index_by_parent[$pid][] = $item; } foreach ($this as $item) { if (isset($index_by_parent[$item[$id_field]])) { $item[$children_field] = $index_by_parent[$item[$id_field]]; $this->findRemove($id_field, $index_by_parent[$item[$id_field]]->getValues($id_field)); } else { $item[$children_field] = null; } } return $this; }
/** * */ public function dumpSiteData($site_id = null, $target_file = null) { if (is_null($site_id)) { $site_id = fx::env('site_id'); } if (is_null($target_file)) { $dir = '@files/export/site_' . $site_id; fx::files()->mkdir($dir); $target_file = fx::path()->abs($dir . '/data.sql'); } // export the site fx::db()->dump(array('tables' => array('site'), 'where' => 'id = ' . $site_id, 'schema' => false, 'file' => $target_file)); // export infoblocks fx::db()->dump(array('tables' => array('infoblock'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true)); // export URL aliases fx::db()->dump(array('tables' => array('url_alias'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true)); // export infoblock_visual $infoblock_ids = fx::data('infoblock')->where('site_id', $site_id)->all()->getValues('id'); fx::db()->dump(array('tables' => array('infoblock_visual'), 'where' => 'infoblock_id IN (' . join(", ", $infoblock_ids) . ')', 'schema' => false, 'file' => $target_file, 'add' => true)); // export main content table fx::db()->dump(array('tables' => array('floxim_main_content'), 'where' => 'site_id = ' . $site_id, 'schema' => false, 'file' => $target_file, 'add' => true)); // get existing content items $items = fx::db()->getResults('select id, type from {{floxim_main_content}} where site_id = ' . $site_id); $tables = $this->getContentDumpTables(fx::collection($items)); foreach ($tables as $t => $item_ids) { if ($t === 'floxim_main_content') { continue; } // export content table fx::db()->dump(array('tables' => array($t), 'where' => 'id IN (' . join(',', $item_ids) . ')', 'schema' => false, 'file' => $target_file, 'add' => true)); } }
public static function loadFullDataForCache() { $finder = new static(); static::prepareFullDataForCacheFinder($finder); $all = $finder->all(); $res = array(); foreach ($all as $item) { $res[$item['id']] = $item; } return fx::collection($res); }
public function getAreaInfoblocks($area_id) { // do nothing if the areas are not loaded yet if (is_null($this->areas)) { return array(); } // or give them from cache if (isset($this->areas_cache[$area_id])) { return $this->areas_cache[$area_id]; } $area_blocks = isset($this->areas[$area_id]) ? $this->areas[$area_id] : array(); if (!$area_blocks || !(is_array($area_blocks) || $area_blocks instanceof \ArrayAccess)) { $area_blocks = array(); } $area_blocks = fx::collection($area_blocks)->sort(function ($a, $b) { $a_pos = $a->getPropInherited('visual.priority'); $b_pos = $b->getPropInherited('visual.priority'); return $a_pos - $b_pos; }); $area_blocks->findRemove(function ($ib) { return $ib->isDisabled(); }); $this->areas_cache[$area_id] = $area_blocks; return $area_blocks; }
/** * Get list of log files that aren't listed in the index * @param array $found */ public function getLost($found = array()) { $found = fx::collection($found)->getValues('id', 'id'); $files = glob($this->getDir() . "/log_*"); $res = array(); foreach ($files as $file) { preg_match("~log_([^\\.]+)~", $file, $id); $id = $id[1]; if (!isset($found[$id])) { $res[] = array('id' => $id, 'start' => filemtime($file), 'host' => '???', 'count_entries' => '???', 'method' => '???'); } } return $res; }