public function __construct($config) { if (empty($config['order_sql'])) { $config['order_sql'] = 'date DESC'; } return parent::__construct($config); }
function __construct($config) { $return = parent::__construct($config); /** @todo this is mock */ $this->items = array('post' => new content_types_item($this, $config, array('id' => 1, 'name' => 'post', 'module' => 'content'), true), 'comment' => new content_types_item($this, $config, array('id' => 2, 'name' => 'comment', 'module' => 'content'), true)); $this->convert2array(); return $return; }
/** * Update item field/s indirect * @param array data * 1) 'param' => $value - indirect * 2) 'param1', 'param2' - directly from item */ function update_fields(array $data) { if (($t = array_keys($data)) && is_int($t[0])) { $bak = $data; $data = array(); foreach ($bak as $key) { $data[$key] = $this->get_data($key); } } $this->container->update_item_fields($this->id, $data); }
/** * Load stuff * @return $this */ function load_attachs() { $this->attachs = $this->get_attach_model()->set_where("pid = %d", $this->model->id)->with_deps($this->deps); if ($this->with_ctype && ($ctype = $this->model->get_ctype_id())) { $this->attachs->where('ctype_id', $ctype); } $this->load_attachs_before(); $this->attachs->load(); $this->load_attachs_after(); return $this->attachs; }
/** * @param boolean load/or just return collection */ protected function _load($load = true) { $this->collection->clear(); if ($this->_where) { $this->collection->set_where($this->_where); } if ($this->_order) { $this->collection->set_order($this->_order); } return $load ? $this->collection->load() : $this->collection; }
/** * render|update|create model model ... * @param InputInterface $input * @param OutputInterface $output * @return int|null|void * @throws \tf_exception */ protected function execute(InputInterface $input, OutputInterface $output) { //require('../_tests/loader.php'); $core = $this->core(); $this->prepare_db($input->getOption('database')); $action = $input->getArgument('action'); if (empty($action)) { throw new \tf_exception("empty action\n"); } $ids = $input->getArgument('models'); if (empty($ids)) { throw new \tf_exception("empty ID\n"); } if ($ids[0] == '*') { $ids = Helpers\ModelEnumerator::find(); } /* * $action = @$_SERVER['argv'][2] ? : 'render'; if (in_array('--', $_SERVER['argv'])) { } */ $output->writeln('action: ' . $action); /** @var collection_generator */ $generator = \abs_collection::get_generator(); foreach ($ids as $mid) { $_mid = explode('.', trim($mid)); if (count($_mid) == 1) { array_unshift($_mid, 'core'); $container = core::selfie(); } else { $container = core::module($_mid[0]); } if (!$container) { $output->writeln('skip ' . $mid); continue; } $method = 'get_' . $_mid[1] . '_handle'; // allow model with params: get_model_handle | model('model') $obj = \functions::is_callable(array($container, $method)) ? $container->{$method}() : $container->model($_mid[1]); $generator->append_object($obj); } $output->writeln($generator->render_table_structure(), OutputInterface::OUTPUT_RAW); if ($action == 'update') { $generator->update_table_structure(); } if ($action == 'create') { $generator->update_table_structure(true); } }
/** * @param $input * @param $output */ function migrateDeprecated($input, $output) { $root = loader::get_public() . loader::DIR_MODULES . '*/classes'; $finder = new Finder(); $finder->directories()->in($root)->name('*')->depth('== 0'); $generator = \abs_collection::get_generator(); /** @var \SplFileInfo $file */ foreach ($finder as $file) { preg_match('@(?P<module>[\\w_+]*)[\\\\/]classes[\\\\/](?P<model>[\\w_+]*)$@', $file, $matches); if ('core' == $matches['module'] || core::modules()->is_registered($matches['module'])) { $model = $matches['module'] . '.' . $matches['model']; $generator->append_object($this->core()->model($model), $model); $output->writeln('...' . $model); } } $output->writeln($generator->update_table_structure(true)); }
/** * Update item field/s indirect * @param array data * 1) 'param' => $value - indirect * 2) 'param1', 'param2' - directly from item */ function update_fields($data) { if (!is_array($data) && func_num_args() > 0) { $keys = func_get_args(); $data = array(); foreach ($keys as $v) { $data[$v] = $this->get_data($v); } } else { // array('field', ...) if (is_array($data) && isset($data[0])) { $keys = $data; $data = array(); foreach ($keys as $v) { $data[$v] = $this->get_data($v); } } } if ($this->is_dummy) { return; } $this->container->update_item_fields($this->id, $data); }
/** * compare 2 collections * @return bool */ public function compare(abs_collection $subj) { $subj->rewind(); while ($item = $subj->next()) { if (!(($tmp = $this->get_element_by_id($item->id)) && $tmp->get_data() == $item->get_data())) { return false; } } if ($subj->count() != $this->count()) { return false; } // passed return true; }
public function __construct($config) { return parent::__construct($config); }
function __construct($config) { $config['order_sql'] = 'time DESC'; return parent::__construct($config); }
/** * Direct rendering * (editor) * Render collection * and * filter: * pagination * filters * * @deprecated */ function render2edt() { core::lib('tpl_parser')->assign('filter', array('pagination' => $this->pagination, 'filters' => $this->get_filters())); return $this->collection->render2edt(); }
/** * Process upload * Return data for saving * * @param abs_collection $citem * @param array $vf * @param array $fld * @param array $current * @return array|string * @throws collection_exception */ static function process_modify($citem, $vf, $fld, $current) { /** @var tf_uploader $uploader */ $uploader = core::lib('uploader'); // remove file if ($fld == 'remove' && !empty($current['file'])) { core::dprint('[COLLECTION] delete file '); // function format_field_on_remove($vf, &$fld, $current) { $citem->format_field_on_remove($vf, $fld, $current); $fld = ''; return $fld; } if (!is_array($fld)) { core::dprint('Field must be submitted via multipart from enctype="multipart/form-data", add _FILES to submit vars: '); $fld = ''; } else { $error = core::lib('uploader')->get_upload_error(@$fld['error']); if (false !== $error) { core::dprint(array('Upload error : %s', $error), core::E_ERROR); $fld = ''; } } $pinfo = array(); if (!empty($fld['name'])) { $pinfo = isset($fld['name']) ? pathinfo($fld['name']) : false; $pinfo['extension'] = strtolower($pinfo['extension']); } if (!empty($fld) && !empty($fld['size']) && (empty($vf['allow']) || !empty($vf['allow']) && in_array($pinfo['extension'], $vf['allow']))) { $path = loader::get_uploads($vf['storage']); // reuse name, if it here already if (!empty($current['file'])) { // unlink? $citem->format_field_on_remove($vf, $fld, $current); } // $naming = isset($vf['unique']) ? (md5(microtime(true)) . '.' . $pinfo['extension']) : false; $naming = functions::url_hash() . '.' . $pinfo['extension']; // dd($naming, $path); if (!empty($vf['spacing'])) { $path .= '/' . substr($naming, 0, $vf['spacing']); } if (!is_dir($path) && !@mkdir($path, 0777, 1)) { throw new collection_exception('Upload error. Cant create directory: ' . $path); } $file = $uploader->upload_file($fld, $path, $naming, array('force_override' => true)); // check for bad image $exists = false; if (!$file || !($exists = file_exists($file)) || !getimagesize($file)) { if ($exists) { unlink($file); } throw new collection_exception('Upload error. invalid file'); } // fix bad \\ $fld['file'] = str_replace(array('\\\\', '\\'), '/', $file); // override type with extension $fld['type'] = $pinfo['extension']; if (!empty($vf['original'])) { copy($fld['file'], preg_replace('@\\.([^\\.]+)$@', '.orig.$1', $fld['file'])); } // make max_width if (!empty($vf['max_width']) || !empty($vf['max_height'])) { core::lib('images')->resample_image_bigger($fld['file'], $fld['file'], @$vf['max_width'], @$vf['max_height']); } // {{{thumbnail}}} // ------------------------------------------------ if (!empty($vf['thumbnail'])) { $t_props = $vf['thumbnail']; $t_file = preg_replace('@\\.([^\\.]+)$@', '.thumb.$1', $fld['file']); $t_height = false; $t_filter = false; if (is_array($t_props)) { if (isset($t_props['width'])) { //fullpros $t_height = @intval($t_props['height']); $t_width = @intval($t_props['width']); $t_filter = @$t_props['filter']; } elseif (isset($t_props['format'])) { // see below, for b.c. } else { //(x,y) $t_height = $t_props[1]; $t_width = $t_props[0]; } } else { $t_width = (int) $t_props; } if (isset($t_props['format'])) { // with Wideimage self::runWideImage($fld['file'], $t_file, $t_props['format']); } else { // resample_image($src, $dst, $new_width, $new_height = false) if ($t_width > 0) { core::lib('images')->resample_image($fld['file'], $t_file, $t_width, $t_height); } else { // just copy copy($fld['file'], $t_file); } } // filter for thumbnail if (isset($t_filter['id'])) { core::lib('images')->image_filter($t_file, $t_file, $t_filter['id'], @$t_filter['params']); } } // {{{/thumbnail}}} // make width if (!empty($vf['width']) && !empty($vf['height'])) { core::lib('images')->resample_image($fld['file'], $fld['file'], $vf['width'], $vf['height']); } if (isset($vf['format'])) { // with Wideimage self::runWideImage($fld['file'], $fld['file'], $vf['format']); } // filter if (isset($vf['filter'])) { core::lib('images')->image_filter($fld['file'], $fld['file'], $vf['filter']['id'], @$vf['filter']['params']); } if (!empty($vf['watermark'])) { $wm_file = loader::get_public($vf['watermark']['file']); core::lib('images')->watermark($fld['file'], $fld['file'], $wm_file, @$vf['watermark']['options']); } unset($fld['error']); unset($fld['tmp_name']); // relative to app-path? // what if on another server } else { $fld = $current; } return $fld; }
/** * Insert/update * needs: uid, uip */ function modify($data, $id = false) { $data['skey'] = $this->_session_key; return parent::modify($data, $id); }
/** * construct */ function __construct($config) { parent::__construct($config); }