public function save($form) { // Load the parameters. $params = JComponentHelper::getParams('com_joaktree'); if ($params->get('siteedit', 1)) { $canDo = JoaktreeHelper::getActions(false); } if (is_object($canDo) && ($canDo->get('core.create') || $canDo->get('core.edit'))) { $prefix = 'Table'; $config = array(); $table = JTable::getInstance('joaktree_sources', $prefix, $config); // Bind the form fields to the table if (empty($form['id'])) { // retreive ID and double check that it is not used $continue = true; $i = 0; while ($continue) { $tmpId = JoaktreeHelper::generateJTId(); $i++; if ($this->check($tmpId)) { $form['id'] = $tmpId; $continue = false; break; } if ($i > 100) { $continue = false; return false; } } $status = 'new'; $crud = 'C'; } else { $status = 'changed'; $crud = 'U'; } $table->id = $form['id']; $table->app_id = $form['app_id']; $table->title = htmlspecialchars($form['title'], ENT_QUOTES, 'UTF-8'); $table->author = htmlspecialchars($form['author'], ENT_QUOTES, 'UTF-8'); $table->publication = htmlspecialchars($form['publication'], ENT_QUOTES, 'UTF-8'); $table->information = htmlspecialchars($form['information'], ENT_QUOTES, 'UTF-8'); // repo id $tmp = explode('!', $form['app_repo_id']); if (count($tmp) == 2) { $table->repo_id = $tmp[1]; } else { $table->repo_id = null; } // Make sure the data is valid if (!$table->check()) { return false; } // Store the table to the database if (!$table->store(true)) { $this->setError($this->_db->getErrorMsg()); return false; } // log $log = JTable::getInstance('joaktree_logs', $prefix, $config); $log->app_id = $form['app_id']; $log->object_id = $form['id']; $log->object = 'sour'; $log->log($crud); //return $ret = new stdClass(); $ret->object = 'source'; $ret->app_id = $form['app_id']; $ret->object_id = $form['id']; $ret->status = $status; $statusObj = $this->get('returnObject'); $ret->action = $statusObj->action; $return = base64_encode(json_encode($ret)); } else { $return = false; } return $return; }
private function checkFamilyId($appId, $pid1, $pid2, $familyId) { $query = $this->_db->getQuery(true); $query->select(' jrn.family_id '); $query->from(' #__joaktree_relations jrn '); $query->where(' jrn.app_id = ' . $appId . ' '); $query->where(' jrn.family_id = ' . $this->_db->quote($familyId) . ' '); $query->where(' jrn.type = ' . $this->_db->quote('partner') . ' '); $query->where(' jrn.person_id_1 IN (' . $this->_db->quote($pid1) . ', ' . $this->_db->quote($pid2) . ') '); $query->where(' jrn.person_id_2 NOT IN (' . $this->_db->quote($pid1) . ', ' . $this->_db->quote($pid2) . ') '); $this->_db->setQuery($query); $result = $this->_db->loadResult(); if ($result) { // retreive ID and double check that it is not used $continue = true; $i = 0; while ($continue) { $tmpId = JoaktreeHelper::generateJTId(); $i++; if ($this->check($tmpId, 'family')) { $familyId = $tmpId; $continue = false; break; } if ($i > 100) { $continue = false; return false; } } } return $familyId; }