function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $model_id = $config->get('model_id', 'Data'); $model_id = empty($model_id) ? 'Data' : $model_id; if ($config->get('enabled', 0)) { if ($config->get('ndb_enable', 0)) { \GCore\Libs\Model::generateModel($model_id, array('tablename' => $config->get('ndb_table_name', ''), 'dbo_config' => array('type' => $config->get('ndb_driver', 'mysql'), 'host' => $config->get('ndb_host', 'localhost'), 'name' => $config->get('ndb_database', ''), 'user' => $config->get('ndb_user', ''), 'pass' => $config->get('ndb_password', ''), 'prefix' => $config->get('ndb_prefix', 'jos_')))); } else { if (!$config->get('tablename', '')) { return; } //\GCore\Libs\Model::generateModel($model_id, array('tablename' => $config->get('tablename', ''))); $class_code = ' namespace GCore\\Models; if(!class_exists("\\GCore\\Models\\' . $model_id . '", false)){ class ' . $model_id . ' extends \\GCore\\Libs\\Model { var $tablename = "' . $config->get('tablename', '') . '"; function beforeSave(&$data, &$params, $mode){ if($mode == "create" AND empty($data["uniq_id"])){ $data["uniq_id"] = \\GCore\\Libs\\Str::rand(); } } } } '; eval($class_code); } $model_class = '\\GCore\\Models\\' . $model_id; if (!class_exists($model_class)) { $form->debug[$action_id][self::$title]['Queries'] = "Error creating the model class, please try a different model id."; return; } $data = $form->data; if ((bool) $config->get('save_under_modelid', 0) === true) { $data = $form->data[$model_id]; } $user = \GCore\Libs\Base::getUser(); $conditions = eval('?>' . $config->get('conditions', '')); $initial_queries = $model_class::getInstance()->dbo->log; if ((bool) $config->get('multi_save', 0) === true) { //$data['user_id'] = !empty($data['user_id']) ? $data['user_id'] : $user['id']; $model_class::getInstance()->saveAll($data, array('new' => (bool) $config->get('force_save', 0), 'conditions' => $conditions)); } else { $data['user_id'] = !empty($data['user_id']) ? $data['user_id'] : $user['id']; $model_class::getInstance()->save($data, array('new' => (bool) $config->get('force_save', 0), 'conditions' => $conditions)); } //insert the pkey value to data if ((bool) $config->get('save_under_modelid', 0) === true) { $form->data[$model_id][$model_class::getInstance()->pkey] = $model_class::getInstance()->id; } else { $form->data[$model_class::getInstance()->pkey] = $model_class::getInstance()->id; } $form->debug[$action_id][self::$title]['Queries'] = array_values(array_diff($model_class::getInstance()->dbo->log, $initial_queries)); } }
function beforeSave(&$data, &$params, $mode) { parent::beforeSave($data, $params, $mode); if ($mode == 'update' and empty($data['password']) and array_key_exists('password', $data)) { unset($data['password']); } if (!empty($data['password'])) { $data['password'] = \GCore\Libs\Authenticate::hash_password($data['password']); } if ($mode == 'update' and !empty($data['id']) and (int) $data['id'] == 1) { $user = \GCore\Libs\Base::getUser(); if ($user['id'] != 1) { $session = \GCore\Libs\Base::getSession(); $session->setFlash('error', l_('USERS_CANT_UPDATE_SITE_OWNER')); return false; } } }
function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $mainframe = \JFactory::getApplication(); //set data $user = \GCore\Libs\Base::getUser(); $article_data['created_by'] = $user['id']; $article_data['access'] = $config->get('access', 1); $article_data['created'] = date("Y-m-d H:i:s"); $article_data['catid'] = $config->get('catid', ''); $article_data['sectionid'] = $config->get('sectionid', 0); $article_data['state'] = $config->get('state', 0); $article_data['title'] = $form->data($config->get('title', '')); $article_data['fulltext'] = $form->data($config->get('fulltext', '')); $article_data['introtext'] = strlen($form->data($config->get('introtext', ''))) ? $form->data($config->get('introtext', '')) : ''; //$article_data['created_by_alias'] = $form->data[$config->get('created_by_alias', '')]; $article_data['language'] = '*'; //alias $article_data['alias'] = \JFilterOutput::stringURLSafe($article_data['title']); //$article_data['id'] = null; \GCore\Libs\GModel::generateModel('CFJArticle', array('tablename' => '#__content')); \GCore\Models\CFJArticle::getInstance()->save($article_data); }
function execute(&$form, $action_id) { $config = $form->actions_config[$action_id]; $config = new \GCore\Libs\Parameter($config); $model_id = $config->get('model_id', 'Data'); $model_id = empty($model_id) ? 'Data' : $model_id; if ($config->get('tablename', '')) { \GCore\Libs\Model::generateModel($model_id, array('tablename' => $config->get('tablename', ''))); $model_class = '\\GCore\\Models\\' . $model_id; $data = $form->data; if ((bool) $config->get('save_under_modelid', 0) === true) { $data = $form->data[$model_id]; } $user = \GCore\Libs\Base::getUser(); $data['user_id'] = $user['id']; $initial_queries = $model_class::getInstance()->dbo->log; if ((bool) $config->get('multi_save', 0) === true) { $model_class::getInstance()->saveAll($data); } else { $model_class::getInstance()->save($data); } $form->debug[$action_id][self::$title]['Queries'] = array_values(array_diff($model_class::getInstance()->dbo->log, $initial_queries)); } }