function add() { $ok = True; // Check name $name = filter_var($this->param('name'), FILTER_SANITIZE_STRING); if (empty($name)) { $ok = False; jMessage::add('Please give a name', 'error'); } if ($ok) { $dao = jDao::get('lizmap~geobookmark'); $record = jDao::createRecord('lizmap~geobookmark'); $record->name = $name; $params = array(); foreach ($this->whiteParams as $param) { $val = filter_var($this->param($param), FILTER_SANITIZE_STRING); $params[$param] = $val; } $record->map = $params['repository'] . ':' . $params['project']; $record->params = json_encode($params); $record->login = jAuth::getUserSession()->login; // Save the new bookmark $id = Null; try { $id = $dao->insert($record); } catch (Exception $e) { jLog::log('Error while inserting the bookmark'); jLog::log($e->getMessage()); jMessage::add('Error while inserting the bookmark', 'error'); } } return $this->getGeoBookmarks($params['repository'], $params['project']); }
/** * */ function save() { $rep = $this->getResponse('json'); $group_id = $this->param('group_id', '', true); $feature_id = $this->param('feature_id'); //insert if (!empty($group_id) && !empty($feature_id)) { // instanciation de la factory $tb = jDao::get("group_feature"); // creation d'un record correspondant au dao foo $record = jDao::createRecord("group_feature"); // on remplit le record $record->group_id = $group_id; $record->feature_id = $feature_id; //$groupfeature->icone = $this->saveIcon($icone,$group_id); // on le sauvegarde dans la base try { $tb->insert($record); $this->success = true; $this->msg = 'fonctionnalité ajoutée'; } catch (Exception $e) { $this->msg = 'fonctionnalité non ajoutée'; $this->success = false; } } $rep->data = array('success' => $this->success, 'msg' => $this->msg); return $rep; }
public function createUserObject($login, $password) { $user = jDao::createRecord($this->_params['dao'], $this->_params['profile']); $user->login = $login; $user->password = $this->cryptPassword($password); return $user; }
/** * */ function save() { $rep = $this->getResponse('json'); $group_id = $this->intParam('group_id', null, true); $user_id = $this->intParam('user_id', null, true); //insert if (!empty($user_id) && !empty($group_id)) { // instanciation de la factory $tb = jDao::get("user_group"); // creation d'un record correspondant au dao foo $record = jDao::createRecord("user_group"); // on remplit le record $record->group_id = $group_id; $record->user_id = $user_id; //$group->icone = $this->saveIcon($icone,$title); try { $tb->insert($record); $this->success = true; $this->msg = "groupe ajouté "; } catch (Exception $exc) { $this->success = false; $this->msg = 'groupe non ajouté'; } } $rep->data = array('success' => $this->success, 'msg' => $this->msg); return $rep; }
function testEvents() { global $TEST_DAO_EVENTS; $TEST_DAO_EVENTS = array(); $this->emptyTable('product_test'); $dao = jDao::get('products_events'); $prod1 = jDao::createRecord('products_events'); $prod1->name = 'assiette'; $prod1->price = 3.87; $prod2 = jDao::createRecord('products_events'); $prod2->name = 'assiette'; $prod2->price = 3.87; //$prod2 = clone $prod1; $res = $dao->insert($prod2); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoInsertBefore'])); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoInsertAfter'])); $this->assertEqual($TEST_DAO_EVENTS['onDaoInsertBefore']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoInsertBefore']['record'], $prod1); $this->assertEqual($TEST_DAO_EVENTS['onDaoInsertAfter']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoInsertAfter']['record'], $prod2); $prod2->name = 'nouvelle assiette'; $prod = $dao->update($prod2); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoUpdateBefore'])); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoUpdateAfter'])); $this->assertEqual($TEST_DAO_EVENTS['onDaoUpdateBefore']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoUpdateBefore']['record'], $prod2); $this->assertEqual($TEST_DAO_EVENTS['onDaoUpdateAfter']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoUpdateAfter']['record'], $prod2); $dao->delete(0); // unexistant id $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoDeleteBefore'])); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoDeleteAfter'])); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteBefore']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteBefore']['keys'], array('id' => 0)); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteAfter']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteAfter']['keys'], array('id' => 0)); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteAfter']['result'], 0); $dao->delete($prod2->id); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoDeleteBefore'])); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoDeleteAfter'])); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteBefore']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteBefore']['keys'], array('id' => $prod2->id)); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteAfter']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteAfter']['keys'], array('id' => $prod2->id)); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteAfter']['result'], 1); $conditions = jDao::createConditions(); $conditions->addCondition('id', '=', $prod2->id); $dao->deleteBy($conditions); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoDeleteByBefore'])); $this->assertTrue(isset($TEST_DAO_EVENTS['onDaoDeleteByAfter'])); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteByBefore']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteByBefore']['criterias'], $conditions); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteByAfter']['dao'], 'jelix_tests~products_events'); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteByAfter']['result'], 0); $this->assertEqual($TEST_DAO_EVENTS['onDaoDeleteByAfter']['criterias'], $conditions); }
function createsave() { $news = jDao::createRecord('medsite~news'); $news->sujet = $this->param('sujet'); $news->texte = $this->param('texte'); $news->news_date = $this->param('date'); $dao = jDao::get('medsite~news'); $dao->insert($news); $rep = $this->getResponse('redirect'); $rep->action = 'medsite~default:index'; return $rep; }
/** * */ function save() { $rep = $this->getResponse('json'); $id = $this->intParam('id', 0, true); $title = $this->param('title', '', true); $code = $this->param('code', '', true); $description = $this->param('description'); if ($id) { //update if (!empty($title)) { // instanciation de la factory $this->msg = 'rolee non modifié'; // instanciation de la factory $tb = jDao::get("role"); // creation d'un record correspondant au dao foo $record = $tb->get($id); // on remplit le record $record->title = $title; $record->code = $code; $record->description = $description; if (isset($_FILES['icone'])) { $record->icone = $this->saveIcon($_FILES['icone'], $title); } // on le sauvegarde dans la base $this->success = $tb->update($record); if ($this->success) { $this->msg = "rolee modifié"; } } } else { //insert if (!empty($title)) { $this->msg = 'rolee non ajouté'; // instanciation de la factory $tb = jDao::get("role"); // creation d'un record correspondant au dao foo $record = jDao::createRecord("role"); // on remplit le record $record->title = $title; $record->code = $code; $record->description = $description; //$role->icone = $this->saveIcon($icone,$title); // on le sauvegarde dans la base $this->success = $tb->insert($record); if ($this->success) { $this->msg = "rolee ajouté "; } } } $rep->data = array('success' => $this->success, 'msg' => $this->msg); return $rep; }
function savecreate() { $form = jForms::get('files'); $form->initFromRequest(); $rep = $this->getResponse('redirect'); $form->saveAllFiles("files/"); $dao = jDao::get('files'); $record = jDao::createRecord('files'); $record->name = $form->getData('name'); $record->url = "http://www.helenekling.com/" . $this->testDir . $this->uploadsDirectory . "/" . $form->getData('file'); $dao->insert($record); $rep->action = 'files:index'; jForms::destroy($this->form); return $rep; }
/** * Subscribe to a thread * @param integer $id of the THREAD! to subscribe * @return boolean */ public static function subscribe($id) { $dao = jDao::get(self::$daoSub); if (jAuth::isConnected()) { $id_user = jAuth::getUserSession()->id; if (!$dao->get($id, $id_user)) { $record = jDao::createRecord(self::$daoSub); $record->id_post = $id; // thread ID $record->id_user = $id_user; $dao->insert($record); return true; } } return false; }
function testdao() { $dao = jDao::get('testnews'); if ($id = $this->param('newid')) { $dao = jDao::get('config'); $rec = jDao::createRecord('config'); $rec->ckey = $id; $rec->cvalue = $this->param('newvalue', ''); $dao->insert($rec); } $rep = $this->getResponse('html'); $rep->title = 'This is a DAO Test'; $rep->bodyTpl = 'testapp~main'; $rep->body->assign('person', 'Laurent'); $rep->body->assignZone('MAIN', 'test'); return $rep; }
/** * manages the content of the search_words table * for one post, we update all the words in search_words table * @return void */ function searchEngineUpdate() { if ($this->id == '' or $this->dataSource == '') { return; } // 1) remove all the words of the current datasource in the table of the search engine $dao = jDao::get('hfnusearch~searchwords'); $dao->deleteByIdDataSource($this->id, $this->dataSource); // 2) add all the words of the current post foreach ($this->getWords() as $word => $weight) { $record = jDao::createRecord('hfnusearch~searchwords'); $record->id = $this->id; $record->words = $word; $record->weight = $weight; $record->datasource = $this->dataSource; $dao->insert($record); } }
public function saveData($champs, $rows) { $s = false; $ir = array_search('ID Patient', $rows[0]); $reception_id = $rows[1][$ir]; // foreach ($champs as $c) { $valeur = ''; $index = array_search($c->importation, $rows[0]); if ($index) { $valeur = $rows[1][$index]; if (strpos($c->importation, "10^(-1)")) { $valeur = (double) $valeur; $valeur = $valeur * 0.1; } } else { $valeur = 0; } // instanciation de la factory $tb = jDao::get("radiologie~resexamen"); // creation d'un record correspondant au dao $record = jDao::createRecord("radiologie~resexamen"); // on remplit le record $user = jAuth::getUserSession(); $record->user_id = $user->id; $record->champ_id = $c->champ_id; $record->examen_id = $reception_id; $record->acte_id = $c->acte_id; $record->valeur = $valeur; $record->datecreation = date('Y-d-m H:i:s'); $record->datemodification = date('Y-d-m H:i:s'); // on le sauvegarde dans la base try { //jLog::dump($record); $tb->insert($record); $s = true; } catch (Exception $e) { //jLog::dump($e->getTraceAsString()); $s = false; } } return $s; }
/** * this function save which message from which forum has been read by which user * @param record $post record of the current read post */ public function insertReadPost($post, $datePost) { if ($post->thread_id > 0 and $post->id_forum > 0 and jAuth::isConnected()) { $dao = jDao::get('havefnubb~read_posts'); $id_user = jAuth::getUserSession()->id; $exist = $dao->get($id_user, $post->id_forum, $post->thread_id); if ($exist === false) { $rec = jDao::createRecord('havefnubb~read_posts'); $rec->id_forum = $post->id_forum; $rec->thread_id = $post->thread_id; $rec->id_user = $id_user; $rec->date_read = $datePost; $dao->insert($rec); } else { $exist->date_read = $datePost; $dao->update($exist); } } }
function prepareToSave() { $tpl = new jTpl(); $rep = $this->getResponse('html'); if ($this->param('id') === null) { $form = jForms::fill('NewsLetter~news'); $dao = jDao::get('NewsLetter~newsLetter'); $r = jDao::createRecord('NewsLetter~newsLetter'); $r->date_create = date("Y-m-d"); $r->text = $form->getData('text'); $dao->insert($r); } else { $id = $this->param('id'); $dao = jDao::get('NewsLetter~newsLetter'); $r = $dao->get($this->param('id')); } $actions = array(); $emails_dao = jDao::get('emails'); $conds = jDao::createConditions(); $count = $emails_dao->countBy($conds); $email_rate = 2000; for ($i = 0; $i <= $count; $i += $email_rate) { $action = array(); $action['inf'] = $i; $action['sup'] = $i + $email_rate; $action['url'] = 'send'; $action['id'] = $r->id; $actions[] = $action; } $tpl->assign('actions', $actions); $tpl->assign('id', $r->id); $emailSrv = new EmailService(); if ($emailSrv->nbEmailsToSend($r->id) == 0) { $emailSrv->resetLogs($r->id); } $tpl->assign('n_emails', $emailSrv->nbEmailsToSend($r->id)); $tpl->assign('n_emails_sent', $emailSrv->nbEmailsSent($r->id)); $tpl->assign('servers', $emailSrv->getServers()); $tpl->assign('maxMailPerMin', $emailSrv->maxMailPerMin()); $tpl->assign('maxMailPerDay', $emailSrv->maxMailPerDay()); $rep->body->assign('MAIN', $tpl->fetch('prepare_sending')); return $rep; }
/** * save the Rate to a given source and ID * @param integer $id_source the id to link to the source * @param string $source the linked source * @param integer $rate the rate * @return boolean */ function saveRatesBySource($id_source, $source, $rate) { $dao = jDao::get('hfnurates~rates'); $id_user = jAuth::isConnected() ? 0 : jAuth::getUserSession()->id; $rec = $dao->getByIdSourceSourceRate($id_user, $id_source, $source); if ($rec == false) { $record = jDao::createRecord('hfnurates~rates'); $record->id_source = $id_source; $record->id_user = $id_user; $record->source = $source; $record->level = $rate; $record->ip = $_SERVER['REMOTE_ADDR']; $dao->insert($record); } else { $rec->level = $rate; $dao->update($rec); } jZone::clear("hfnurates~rates"); return true; }
/** * */ function read() { $rep = $this->getResponse('json'); $app = $this->param('app', null, true); $tb = jDao::get("param"); $conditions = jDao::createConditions(); if (!empty($app)) { $conditions->addCondition('app', '=', $app); $t = $tb->countBy($conditions); if ($t == 0) { $record = jDao::createRecord("param"); $record->app = $app; $record->params = null; $record->user_id = jAuth::getUserSession()->id; $tb->insert($record); } } $record = $tb->findBy($conditions)->fetch(); $record->params = (object) json_decode($record->params); $rep->data = $record; return $rep; }
function savecreate() { $rep = $this->getResponse('redirect'); $rep->action = 'hfnuadmin~ranks:index'; if ($this->param('validate') == jLocale::get('hfnuadmin~rank.saveBt')) { $dao = jDao::get('havefnubb~ranks'); $form = jForms::fill('hfnuadmin~ranks'); if (!$form) { jMessage::add(jLocale::get('hfnuadmin~rank.invalid.datas'), 'error'); return $rep; } if (!$form->check()) { jMessage::add(jLocale::get('hfnuadmin~rank.invalid.datas'), 'error'); return $rep; } $record = jDao::createRecord('havefnubb~ranks'); $record->rank_name = $form->getData('rank_name'); $record->rank_limit = $form->getData('rank_limit'); $dao->insert($record); jForms::destroy('hfnuadmin~ranks'); jMessage::add(jLocale::get('hfnuadmin~rank.rank.added'), 'ok'); } return $rep; }
/** * Save the data for the services section. * @return Redirect to the index. */ function saveAccount() { // Get lizmap services $services = lizmap::getServices(); $rep = $this->getResponse('redirect'); $rep->action = 'view~default:index'; // Redirect if option not active if (!$services->allowUserAccountRequests) { return $rep; } // Redirect if already a logged user if (jAuth::isConnected()) { jMessage::add(jLocale::get("view~user.already.logged")); return $rep; } // Get the form $form = jForms::get('view~lizmap_user'); // token $token = $this->param('__JFORMS_TOKEN__'); if (!$token) { $rep->action = "view~user:createAccount"; return $rep; } // If the form is not defined, redirection if (!$form) { $rep->action = "view~user:createAccount"; return $rep; } // Set the other form data from the request data $form->initFromRequest(); // Check the form $ok = true; if (!$form->check()) { $ok = false; } // Check the honey pot. Redirect if filled (means robot) $honey = $form->getData('name'); if ($honey and !empty($honey)) { $rep->action = "view~user:createAccount"; return $rep; } if (!$ok) { // Errors : redirection to the display action $rep->action = 'view~user:editAccount'; return $rep; } // Save the data $evresp = array(); if (!jEvent::notify('jauthdbAdminCheckCreateForm', array('form' => $form))->inResponse('check', false, $evresp)) { // Sanitize some fields $sanitize = array('login', 'firstname', 'lastname', 'organization', 'phonenumber', 'street', 'postcode', 'city', 'country', 'comment'); foreach ($sanitize as $field) { $form->setData($field, filter_var($form->getData($field), FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES)); } // Add user to database via jAuth methods try { $props = jDao::createRecord('jauthdb~jelixuser', 'jauth')->getProperties(); $user = jAuth::createUserObject($form->getData('login'), $form->getData('password')); $form->setData('password', $user->password); $form->prepareObjectFromControls($user, $props); jAuth::saveNewUser($user); jMessage::add(jLocale::get("view~user.form.message.saved")); $ok = true; $rep->action = "view~user:validateAccount"; } catch (exception $e) { $ok = false; jMessage::add(jLocale::get("view~user.form.message.not.saved")); $rep->action = "view~user:editAccount"; } // Send email to the administrator if ($ok) { try { $this->sendEmailToAdmin($user); } catch (Exception $e) { jLog::log('error while sending email to admin: ' . $e->getMessage()); } } } return $rep; }
/** * set a specific data in the cache * @param string $key key used for storing data * @param mixed $var data to store * @param int $ttl data time expiration. -1 means no change * @return boolean false if failure */ public function set($key, $var, $ttl = 0) { try { $var = serialize($var); if ($this->base64encoding) { $var = base64_encode($var); } } catch (Exception $e) { throw new jException('jelix~cache.error.serialize.data', array($this->profil_name, $e->getMessage())); } $dao = jDao::get($this->_dao, $this->_dbprofile); $n = 0; switch ($ttl) { case -1: $date = -1; $n = $dao->updateData($key, $var); break; case 0: $date = null; $n = $dao->updateFullData($key, $var, $date); break; default: if ($ttl <= 2592000) { $ttl += time(); } $date = date("Y-m-d H:i:s", $ttl); $n = $dao->updateFullData($key, $var, $date); break; } if ($n == 0) { $cache = jDao::createRecord($this->_dao, $this->_dbprofile); $cache->key = $key; $cache->data = $var; $cache->date = $date; return !($dao->insert($cache) ? false : true); } return true; }
/** * create a new group * @param string $name its name * @return int the id of the new group */ public static function createGroup($name) { $p = jAcl2Db::getProfile(); $group = jDao::createRecord('jelix~jacl2group', $p); $group->name = $name; $group->grouptype = 0; jDao::get('jelix~jacl2group', $p)->insert($group); return $group->id_aclgrp; }
/** * create a new group * @param string $name its name * @return int the id of the new group */ public static function createGroup($name) { $group = jDao::createRecord('jacldb~jaclgroup', 'jacl_profile'); $group->name = $name; $group->grouptype = 0; $daogroup = jDao::get('jacldb~jaclgroup', 'jacl_profile'); $daogroup->insert($group); return $group->id_aclgrp; }
function __construct($selector, $method, $label, $key, $profile = '', $criteria = null, $criteriaFrom = null, $labelSeparator = '') { $this->selector = $selector; $this->profile = $profile; $this->method = $method; $this->labelProperty = preg_split('/[\\s,]+/', $label); $this->labelSeparator = $labelSeparator; if ($criteria !== null) { $this->criteria = preg_split('/[\\s,]+/', $criteria); } if ($criteriaFrom !== null) { $this->criteriaFrom = preg_split('/[\\s,]+/', $criteriaFrom); } if ($key == '') { $rec = jDao::createRecord($this->selector, $this->profile); $pfields = $rec->getPrimaryKeyNames(); $key = $pfields[0]; } $this->keyProperty = $key; }
/** * create a new subject * @param string $subject the key of the subject * @param string $label_key the key of a locale which represents the label of the subject */ public static function addSubject($subject, $label_key) { // ajoute un sujet dans la table jacl_subject $p = jAcl2Db::getProfile(); $subj = jDao::createRecord('jelix~jacl2subject', $p); $subj->id_aclsbj = $subject; $subj->label_key = $label_key; jDao::get('jelix~jacl2subject', $p)->insert($subj); jAcl2::clearCache(); }
/** * save data of a form in a new record */ function savecreate() { $form = jForms::get($this->form); $form->initFromRequest(); $rep = $this->getResponse('redirect'); if ($form == null) { $rep->action = 'default:index'; return $rep; } $evresp = array(); if ($form->check() && !jEvent::notify('jauthdbAdminCheckCreateForm', array('form' => $form))->inResponse('check', false, $evresp)) { $props = jDao::createRecord($this->dao, $this->dbProfile)->getProperties(); $user = jAuth::createUserObject($form->getData('login'), $form->getData('password')); $form->setData('password', $user->password); $form->prepareObjectFromControls($user, $props); $form->saveAllFiles($this->uploadsDirectory); jAuth::saveNewUser($user); jForms::destroy($this->form); jMessage::add(jLocale::get('crud.message.create.ok', $user->login), 'notice'); $rep->action = 'default:view'; $rep->params['id'] = $user->login; return $rep; } else { $rep->action = 'default:create'; return $rep; } }
/** * */ function save() { $rep = $this->getResponse('json'); if (isset($_FILES['candidats'])) { $this->success = true; //get files $file_name = 'liste_candidats_' . uniqid(); //$csv = new SplFileObject($this->saveFile($_FILES['candidats'],$file_name), 'r'); $csv = new SplFileObject($_FILES['candidats']['tmp_name'], 'r'); $csv->setFlags(SplFileObject::READ_CSV); $csv->setCsvControl(';'); $rows = array(); $i = 0; foreach ($csv as $ligne) { $rows[$i] = $ligne; $i++; } // get header ( colonnes) : fields $indexMatricule = array_search('matricule', $rows[0]); jLog::dump($indexMatricule); $indexDdn = array_search('ddn', $rows[0]); $indexLn = array_search('ln', $rows[0]); $indexConcour = array_search('concour', $rows[0]); $indexCodebarre = array_search('codebarre', $rows[0]); $indexNom = array_search('nom', $rows[0]); $indexPrenom = array_search('prenom', $rows[0]); $indexDatevisite = array_search('datevisite', $rows[0]); // instanciation de la factory $tb = jDao::get("candidat"); $cnx = jDb::getConnection(); $i = 0; set_time_limit(60 * 60); foreach ($csv as $ligne) { if ($i > 0) { try { $cnx->beginTransaction(); //i start la transaction $record = jDao::createRecord("candidat"); // on remplit le record $record->matricule = $ligne[$indexMatricule]; $record->ddn = $ligne[$indexDdn]; $record->ln = $ligne[$indexLn]; $record->concour = $ligne[$indexConcour]; $record->codedarre = $ligne[$indexCodebarre]; $record->nom = $ligne[$indexNom]; $record->prenom = $ligne[$indexPrenom]; $record->datevisite = $ligne[$indexDatevisite]; // on le sauvegarde dans la base $tb->insert($record); $cnx->commit(); } catch (Exception $e) { $cnx->rollback(); $this->msg = "Des doublons ont été detectés dans le fichier source et ignorés lors de l'operation"; } } $i++; } } $rep->data = array('success' => $this->success, 'msg' => $this->msg); return $rep; }
/** * subscribe to one forum * @param int $id_forum id of the forum to subscribe */ public function subscribe($id_forum) { if (jAuth::isConnected()) { //check if this forum is already subscribed if (!jDao::get('havefnubb~forum_sub')->get(jAuth::getUserSession()->id, $id_forum)) { $dao = jDao::get('havefnubb~forum_sub'); $rec = jDao::createRecord('havefnubb~forum_sub'); $rec->id_forum = $id_forum; $rec->id_user = jAuth::getUserSession()->id; $dao->insert($rec); } } }
/** * this function permits to split the thread to another thread * @param integer $id_post id post to split * @param integer $thread_id thread of the current id post * @param integer $new_thread_id parent id to attach to * @return boolean */ public function splitToThread($id_post, $thread_id, $new_thread_id) { if ($id_post == 0 or $thread_id == 0 or $new_thread_id == 0) { return false; } $dao = jDao::get('havefnubb~posts'); $datas = $dao->findAllFromCurrentIdPostWithThreadId($thread_id, $id_post); $i = 0; foreach ($datas as $data) { $i++; $record = jDao::createRecord('havefnubb~posts'); $record = $data; $record->id_post = null; //to create a new record ! $record->id_forum = $data->id_forum; // the id forum of the same forum $record->thread_id = $new_thread_id; // the id of the parent id on which we link the thread $dao->insert($record); } $dao->deleteAllFromCurrentIdPostWithThreadId($thread_id, $id_post); // delete the old records //Thread Update process : $daoThreads = jDao::get('havefnubb~threads_alone'); // 1) add to the "target" Thread all the infos $threadRec = $daoThreads->get($new_thread_id); $threadRec->nb_replies += $i; $threadRec->id_last_msg = $dao->getLastCreatedPostByThreadId($new_thread_id)->id_post; $id_first_msg = $threadRec->id_first_msg; $daoThreads->update($threadRec); // 2) remove from the "source" Thread all the infos $threadRec = $daoThreads->get($thread_id); if ($threadRec->nb_replies > 0) { $threadRec->nb_replies -= $i; } if ($dao->getLastCreatedPostByThreadId($thread_id) === false) { $daoThreads->delete($thread_id); } else { $threadRec->id_last_msg = $dao->getLastCreatedPostByThreadId($thread_id)->id_post; $daoThreads->update($threadRec); } //return the id of the first msg of the thread // where we have to go to after we moved all the data // of the old post return $id_first_msg; }
/** * to answer to jcommunity_save_account event * @param object $event the given event to answer to */ function onjcommunity_save_account($event) { $login = $event->getParam('login'); $form = $event->getParam('form'); $user = $event->getParam('record'); $to_insert = $event->getParam('to_insert'); if ($to_insert) { return; } // we need an existing user $fields = jDao::get('havefnubb~member_custom_fields'); $id = $user->id; $record = jDao::createRecord('havefnubb~member_custom_fields'); $record->id = $id; $imlist = array('im:xfire', 'im:icq', 'im:yim', 'im:hotmail', 'im:aol', 'im:gtalk', 'im:jabber'); foreach ($imlist as $im) { $imrec = $fields->get($id, $im); $data = $form->getData($im); if ($imrec) { if ($data != $imrec->data) { if ($data == '') { $fields->delete($id, $im); } else { $imrec->data = $data; $fields->update($imrec); } } } else { if ($data != '') { $record->type = $im; $record->data = $data; $fields->insert($record); } } } }
/** * save data of a control using a dao. * * The control must be a container like checkboxes or listbox with multiple attribute. * If the form contain a new record (no formId), you should call saveToDao before * in order to get a new id (the primary key of the new record), or you should get a new id * by an other way. then you must pass this primary key in the third argument. * If the form has already a formId, then it will be used as a primary key, unless * you give one in the third argument. * * The Dao should map to an "association table" : its primary key should be * the primary key stored in the formId + the field which will contain one of * the values of the control. If this order is not the same as defined into the dao, * you should provide the list of property names which corresponds to the primary key * in this order : properties for the formId, followed by the property which contains * the value. * All existing records which have the formid in their keys are deleted * before to insert new values. * * @param string $controlName the name of the control * @param string $daoSelector the selector of a dao file * @param mixed $primaryKey the primary key if the form have no id. (optional) * @param mixed $primaryKeyNames list of field corresponding to primary keys (optional) * @param string $dbProfile the jDb profile to use with the dao * @see jDao */ public function saveControlToDao($controlName, $daoSelector, $primaryKey = null, $primaryKeyNames = null, $dbProfile = '') { if (!$this->controls[$controlName]->isContainer()) { throw new jExceptionForms('jelix~formserr.control.not.container', array($controlName, $this->sel)); } $values = $this->container->data[$controlName]; if (!is_array($values) && $values != '') { throw new jExceptionForms('jelix~formserr.value.not.array', array($controlName, $this->sel)); } if (!$this->container->formId && !$primaryKey) { throw new jExceptionForms('jelix~formserr.formid.undefined.for.dao', array($controlName, $this->sel)); } if ($primaryKey === null) { $primaryKey = $this->container->formId; } if (!is_array($primaryKey)) { $primaryKey = array($primaryKey); } $dao = jDao::create($daoSelector, $dbProfile); $daorec = jDao::createRecord($daoSelector, $dbProfile); $conditions = jDao::createConditions(); if ($primaryKeyNames) { $pkNamelist = $primaryKeyNames; } else { $pkNamelist = $dao->getPrimaryKeyNames(); } foreach ($primaryKey as $k => $pk) { $conditions->addCondition($pkNamelist[$k], '=', $pk); $daorec->{$pkNamelist[$k]} = $pk; } $dao->deleteBy($conditions); if (is_array($values)) { $valuefield = $pkNamelist[$k + 1]; foreach ($values as $value) { $daorec->{$valuefield} = $value; $dao->insert($daorec); } } }
protected function createTag($tag_name) { $factory_tags = jDao::get($this->dao_tags); $newTag = jDao::createRecord($this->dao_tags); $newTag->tag_name = $tag_name; $newTag->nbuse = 1; $factory_tags->insert($newTag); return $newTag->getPk(); }