Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
julienV committed Jun 20, 2015
2 parents c81342e + f0cf93c commit b523d15
Show file tree
Hide file tree
Showing 15 changed files with 412 additions and 18 deletions.
50 changes: 50 additions & 0 deletions component/admin/controllers/projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,54 @@
*/
class TracksControllerProjects extends RControllerAdmin
{
/**
* Deep Copy projects
*
* @return void
*/
public function copy()
{
// Check for request forgeries
JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));

// Get items to publish from the request.
$cid = JFactory::getApplication()->input->get('cid', array(), 'array');

if (empty($cid))
{
JLog::add(JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), JLog::WARNING, 'jerror');
}
else
{
// Get the model.
$model = $this->getModel();

// Make sure the item ids are integers
JArrayHelper::toInteger($cid);

// Copy the items.
try
{
if ($model->copy($cid))
{
$this->setMessage(JText::plural('COM_TRACKS_PROJECTS_N_ITEMS_COPIED', count($cid)));
}
else
{
$this->setMessage($model->getError(), 'error');
}
}
catch (Exception $e)
{
$this->setMessage($e->getMessage(), 'error');
}
}

$extension = $this->input->get('extension');
$extensionURL = ($extension) ? '&extension=' . $extension : '';

// Set redirect
$this->setRedirect($this->getRedirectToListRoute($extensionURL));

}
}
1 change: 1 addition & 0 deletions component/admin/language/en-GB/en-GB.com_tracks.ini
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ COM_TRACKS_XML_PROJECT_PARAMS_RANKINGVIEW_SHOW_AVERAGE="Show average"
COM_TRACKS_XML_PROJECT_PARAMS_RANKINGVIEW_SHOW_AVERAGE_DESC="Show average finish position"
COM_TRACKS_XML_PROJECT_PARAMS_RANKINGVIEW_SHOW_STARTS="Show starts"
COM_TRACKS_XML_PROJECT_PARAMS_RANKINGVIEW_SHOW_STARTS_DESC="Show number of starts to ranking events (i.i: the one that award points)"
COM_TRACKS_PROJECT_COPY_OF_S="Copy of %s"

; models/round.xml
COM_TRACKS_FIELD_COUNTRY_LABEL="Country"
Expand Down
2 changes: 1 addition & 1 deletion component/admin/layouts/form/field/projectround.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

// Build the script
$script = array();
$script[] = ' function jSelectProjectround_' . $data['id'] . '(id, title, object) {';
$script[] = ' function jSelectProjectround_' . $data['id'] . '(id, title) {';
$script[] = ' document.id("' . $data['id'] . '_id").value = id;';
$script[] = ' document.id("' . $data['id'] . '_name").value = title;';
$script[] = ' SqueezeBox.close();';
Expand Down
27 changes: 27 additions & 0 deletions component/admin/models/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,31 @@ public function getItem($pk = null)

return $item;
}

/**
* 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();
}
}
}
47 changes: 47 additions & 0 deletions component/admin/models/project.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,52 @@
*/
class TracksModelProject extends RModelAdmin
{
/**
* 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);
}
}

/**
* Copy project rounds from one project to the other
*
* @param int $source source project id
* @param int $destination destination project id
*
* @return void
*/
protected function copyProjectRounds($source, $destination)
{
$query = $this->_db->getQuery(true)
->select('id')
->from('#__tracks_projects_rounds')
->where('project_id = ' . $source);

$this->_db->setQuery($query);
$projectRoundIds = $this->_db->loadColumn();

if ($projectRoundIds)
{
$model = RModel::getAdminInstance('Projectround');
$model->copy($projectRoundIds, $destination);
}
}
}
54 changes: 54 additions & 0 deletions component/admin/models/projectround.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,58 @@ public function validate($form, $data, $group = null)

return parent::validate($form, $data, $group);
}

/**
* 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);
}
}

/**
* Copy project round events from one project round to the other
*
* @param int $source source project round id
* @param int $destination destination project round id
*
* @return void
*/
protected function copyEvents($source, $destination)
{
$query = $this->_db->getQuery(true)
->select('id')
->from('#__tracks_events')
->where('projectround_id = ' . $source);

$this->_db->setQuery($query);
$eventIds = $this->_db->loadColumn();

if ($eventIds)
{
$model = RModel::getAdminInstance('Event');
$model->copy($eventIds, $destination);
}
}
}
28 changes: 14 additions & 14 deletions component/admin/sql/install.mysql.utf8.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_projects` (
`checked_out_time` datetime NOT NULL,
`published` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_competitions` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_competitions` (
`checked_out_time` datetime NOT NULL,
`published` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_seasons` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -34,7 +34,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_seasons` (
`checked_out_time` datetime NOT NULL,
`published` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_teams` (
`id` int(11) NOT NULL auto_increment,
Expand Down Expand Up @@ -62,7 +62,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_teams` (
`checked_out_time` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `club_id` (`club_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_clubs` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -80,7 +80,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_clubs` (
`checked_out` int(11) NOT NULL,
`checked_out_time` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_individuals` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -105,7 +105,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_individuals` (
`checked_out` int(11) NOT NULL,
`checked_out_time` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_rounds` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -120,7 +120,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_rounds` (
`checked_out_time` datetime NOT NULL,
`published` tinyint(1) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_eventtypes` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -133,7 +133,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_eventtypes` (
`checked_out` int(11) NOT NULL,
`checked_out_time` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_projects_rounds` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -150,7 +150,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_projects_rounds` (
PRIMARY KEY (`id`),
KEY `round_id` (`round_id`),
KEY `project_id` (`project_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_events` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -167,7 +167,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_events` (
PRIMARY KEY (`id`),
KEY `projectround_id` (`projectround_id`),
KEY `type` (`type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_participants` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -182,7 +182,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_participants` (
KEY `individual_id` (`individual_id`),
KEY `project_id` (`project_id`),
KEY `team_id` (`team_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_projects_teams` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -195,7 +195,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_projects_teams` (
PRIMARY KEY (`id`),
KEY `team_id` (`team_id`),
KEY `project_id` (`project_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_events_results` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -213,7 +213,7 @@ CREATE TABLE IF NOT EXISTS `#__tracks_events_results` (
KEY `individual_id` (`individual_id`),
KEY `team_id` (`team_id`),
KEY `event_id` (`event_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `#__tracks_project_settings` (
`id` int(11) NOT NULL auto_increment,
Expand All @@ -224,4 +224,4 @@ CREATE TABLE IF NOT EXISTS `#__tracks_project_settings` (
`checked_out_time` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `project_id` (`project_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
14 changes: 14 additions & 0 deletions component/admin/sql/updates/mysql/5.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ALTER TABLE `#__tracks_projects` ENGINE = InnoDB;
ALTER TABLE `#__tracks_competitions` ENGINE = InnoDB;
ALTER TABLE `#__tracks_seasons` ENGINE = InnoDB;
ALTER TABLE `#__tracks_teams` ENGINE = InnoDB;
ALTER TABLE `#__tracks_clubs` ENGINE = InnoDB;
ALTER TABLE `#__tracks_individuals` ENGINE = InnoDB;
ALTER TABLE `#__tracks_rounds` ENGINE = InnoDB;
ALTER TABLE `#__tracks_eventtypes` ENGINE = InnoDB;
ALTER TABLE `#__tracks_projects_rounds` ENGINE = InnoDB;
ALTER TABLE `#__tracks_events` ENGINE = InnoDB;
ALTER TABLE `#__tracks_participants` ENGINE = InnoDB;
ALTER TABLE `#__tracks_projects_teams` ENGINE = InnoDB;
ALTER TABLE `#__tracks_events_results` ENGINE = InnoDB;
ALTER TABLE `#__tracks_project_settings` ENGINE = InnoDB;
Loading

0 comments on commit b523d15

Please sign in to comment.