/** * Creates a tracks individual for the user * Method is called after user data is stored in the database * * @param array $user holds the new user data * @param boolean $isnew true if a new user is stored * @param boolean $success true if user was succesfully stored in the database * @param string $msg message * * @return void */ public function onUserAfterSave($user, $isnew, $success, $msg) { $app = JFactory::getApplication(); // Require tracks individual table require_once JPATH_ADMINISTRATOR . '/components/com_tracks/tables/individual.php'; if ($isnew) { $table = RTable::getAdminInstance('Individual', array(), 'com_tracks'); if ($this->params->get('map_name', 0) == 0) { $split = strpos($user['name'], ' '); if ($split && $this->params->get('split_name', 1)) { $table->first_name = substr($user['name'], 0, $split); $table->last_name = substr($user['name'], $split + 1); } else { $table->last_name = $user['name']; } } else { $table->last_name = $user['username']; } switch ($this->params->get('map_nickname', 2)) { case 0: break; case 1: $table->nickname = $user['name']; break; case 2: $table->nickname = $user['username']; break; } $table->user_id = $user['id']; if ($table->check() && $table->store()) { } else { Jerror::raiseWarning(0, JText::_('Error_while_creating_tracks_individual')); } } }
/** * Checks that the object is valid and able to be stored. * * This method checks that the parent_id is non-zero and exists in the database. * Note that the root node (parent_id = 0) cannot be manipulated with this class. * * @return boolean True if all checks pass. */ public function check() { if (empty($this->name)) { $this->setError(JText::_('COM_REDSOURCE_NAME_CANNOT_BE_EMPTY')); } if (!parent::check()) { return false; } // Modification fields are filled inside the model. return !$this->getErrors(); }
/** * Deep copy with rounds and subrounds * * @param array $cid project ids * * @return void */ public function copy($cid) { foreach ($cid as $projectId) { $project = RTable::getAdminInstance('Project'); $project->load($projectId); $newProject = clone $project; $newProject->id = null; $newProject->name = JText::sprintf('COM_TRACKS_PROJECT_COPY_OF_S', $project->name); $newProject->store(); $this->copyProjectRounds($projectId, $newProject->id); } }
/** * Delete project round events * * @param mixed $pk An optional primary key value to delete. If not set the instance property value is used. * * @return boolean True on success. */ protected function deleteProjectroundEvents($pk) { $pks = $this->getPkArray($pk); $pks = implode(', ', RHelperArray::quote($pks)); $query = $this->_db->getQuery(true)->select('id')->from('#__tracks_events')->where('projectround_id IN (' . $pks . ')'); $this->_db->setQuery($query); $eventIds = $this->_db->loadColumn(); $table = RTable::getAdminInstance('Event'); foreach ($eventIds as $id) { $table->delete((int) $id); } return true; }
/** * Copy events from one project round to the other * * @param array $cid ids of events to copy * @param int $destination destination project round id * * @return void */ public function copy($cid, $destination) { if (empty($cid)) { return; } foreach ($cid as $id) { $event = RTable::getAdminInstance('Event'); $event->load($id); $new = clone $event; $new->id = null; $new->projectround_id = $destination; $new->store(); } }
/** * Copy rounds from one project to the other * * @param array $cid ids of rounds to copy * @param int $destination destination project id * * @return void */ public function copy($cid, $destination) { if (empty($cid)) { return; } foreach ($cid as $projectRoundId) { $projectRound = RTable::getAdminInstance('Projectround'); $projectRound->load($projectRoundId); $new = clone $projectRound; $new->id = null; $new->project_id = $destination; $new->store(); $this->copyEvents($projectRoundId, $new->id); } }
/** * Object constructor to set table and key fields. In most cases this will * be overridden by child classes to explicitly set the table and key fields * for a particular database table. * * @param string $table Name of the table to model. * @param mixed $key Name of the primary key field in the table or array of field names that compose the primary key. * @param JDatabaseDriver $db JDatabaseDriver object. * * @since 11.1 */ public function __construct($table, $key, $db) { $this->_tableName = $table; if (is_array($key)) { $this->_tbl_keys = $key; $this->_tbl_key = $key; $this->_tableKey = $key[key($key)]; } else { $this->_tbl_key = $key; $this->_tableKey = $key; } // Set all columns from table as properties $columns = array(); $dbColumns = $db->getTableColumns('#__' . $table, false); if (count($dbColumns) > 0) { foreach ($dbColumns as $columnKey => $columnValue) { $columns[$columnValue->Field] = $columnValue->Default; } $this->setProperties($columns); } parent::__construct($db); }
/** * Method to store a node in the database table. * * @param boolean $updateNulls True to update null values as well. * * @return boolean True on success. */ public function store($updateNulls = false) { if (!parent::store($updateNulls)) { return false; } return true; }
/** * Called before store(). * * @param boolean $updateNulls True to update null values as well. * * @return boolean True on success. */ protected function beforeStore($updateNulls = false) { if ($this->_eventBeforeStore) { // Import the plugin types $this->importPluginTypes(); // Trigger the event $results = RFactory::getDispatcher()->trigger($this->_eventBeforeStore, array($this, $updateNulls)); if (count($results) && in_array(false, $results, true)) { return false; } } // Audit fields optional auto-update (on by default) if ($this->getOption('updateAuditFields', true)) { RTable::updateAuditFields($this); } return true; }
/** * Load the item already loaded in a table * * @param RTable $table Table with the item loaded * * @return TracksEntityBase Self instance for chaining */ public function loadFromTable($table) { $key = $table->getKeyName(); if (!empty($table->{$key})) { // Get the data from the table $data = $table->getProperties(1); // Item is always an object $this->item = JArrayHelper::toObject($data); $this->id = $table->id; $this->table = clone $table; $class = get_called_class(); // Ensure that we cache the item if (!isset(static::$instances[$class][$this->id])) { static::$instances[$class][$this->id] = $this; } } return $this; }
/** * Install Webservice from site * * @param string $client Client * @param string $webservice Webservice Name * @param string $version Webservice version * @param string $path Path to webservice files * @param int $id Path to webservice files * * @return boolean Returns id if Webservice was successfully installed */ public function installWebservice($client = '', $webservice = '', $version = '1.0.0', $path = '', $id = 0) { $webserviceXml = RApiHalHelper::getWebservices($client, $webservice, $version, $path, true); if (!empty($webserviceXml)) { $operations = array(); $scopes = array(); $client = RApiHalHelper::getWebserviceClient($webserviceXml); $version = !empty($webserviceXml->config->version) ? (string) $webserviceXml->config->version : $version; if (!empty($webserviceXml->operations)) { foreach ($webserviceXml->operations as $operation) { foreach ($operation as $key => $method) { if ($key == 'task') { foreach ($method as $taskKey => $task) { $displayName = !empty($task['displayName']) ? (string) $task['displayName'] : $key . ' ' . $taskKey; $scopes[] = array('scope' => strtolower($client . '.' . $webservice . '.' . $key . '.' . $taskKey), 'scopeDisplayName' => ucfirst($displayName)); } } else { $operations[] = strtoupper(str_replace(array('read', 'create', 'update'), array('GET', 'PUT', 'POST'), $key)); $displayName = !empty($method['displayName']) ? (string) $method['displayName'] : $key; $scopes[] = array('scope' => strtolower($client . '.' . $webservice . '.' . $key), 'scopeDisplayName' => ucfirst($displayName)); } } } } RApiHalHelper::$installedWebservices[$client][$webservice][$version] = array('name' => $webservice, 'version' => $version, 'title' => (string) $webserviceXml->name, 'path' => (string) $path, 'xmlFile' => $client . '.' . $webservice . '.' . $version . '.xml', 'xmlHashed' => md5($webserviceXml), 'operations' => json_encode($operations), 'scopes' => json_encode($scopes), 'client' => $client, 'state' => 1, 'id' => $id); /** @var RedcoreTableWebservice $table */ $table = RTable::getInstance('Webservice', 'RedcoreTable'); $table->bind(RApiHalHelper::$installedWebservices[$client][$webservice][$version]); // Check the data. if (!$table->check()) { return false; } if (!$table->store()) { if (empty($id)) { $this->setError(JText::sprintf('COM_REDCORE_WEBSERVICES_WEBSERVICE_NOT_INSTALLED', $table->getError())); } return false; } RApiHalHelper::saveOAuth2Scopes($client, $webservice, $scopes, false); $this->setState($this->getName() . '.id', $table->id); return $table->id; } return false; }