Skip to content

Commit

Permalink
v0.0.2-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
rtripault committed May 1, 2013
1 parent c861805 commit e53939d
Show file tree
Hide file tree
Showing 7 changed files with 185 additions and 5 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ You can do so on the TV grid (once you have selected a template) by double click
You can also "de-activate" each TV (by clicking on the checkbox), and assign them back. Doing so will automatically
give a 'rank' to each selected TV.

You might need to do so for each newly created TV.

## License

TVSorter is licensed under the MIT license.
Expand Down
29 changes: 28 additions & 1 deletion _build/build.transport.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// define package names
define('PKG_NAME', 'TVSorter');
define('PKG_NAME_LOWER', strtolower(PKG_NAME));
define('PKG_VERSION', '0.0.1');
define('PKG_VERSION', '0.0.2');
define('PKG_RELEASE', 'beta');

// Define build paths
Expand All @@ -32,6 +32,7 @@
// Override with your own defines here (see build.config.sample.php)
require_once $sources['build'] . 'build.config.php';
require_once MODX_CORE_PATH . 'model/modx/modx.class.php';
require_once $sources['build'] . '/includes/helper.php';

// Instantiate modX
$modx = new modX();
Expand All @@ -48,6 +49,32 @@
$builder->createPackage(PKG_NAME_LOWER, PKG_VERSION, PKG_RELEASE);
$builder->registerNamespace(PKG_NAME_LOWER, false, true, '{core_path}components/'. PKG_NAME_LOWER .'/');

// add plugins
$plugins = include $sources['data'].'transport.plugins.php';
if (!is_array($plugins)) {
$modx->log(modX::LOG_LEVEL_FATAL, 'Adding plugins failed.');
}
$attributes = array(
xPDOTransport::UNIQUE_KEY => 'name',
xPDOTransport::PRESERVE_KEYS => false,
xPDOTransport::UPDATE_OBJECT => true,
xPDOTransport::RELATED_OBJECTS => true,
xPDOTransport::RELATED_OBJECT_ATTRIBUTES => array (
'PluginEvents' => array(
xPDOTransport::PRESERVE_KEYS => true,
xPDOTransport::UPDATE_OBJECT => false,
xPDOTransport::UNIQUE_KEY => array('pluginid', 'event'),
),
),
);
foreach ($plugins as $plugin) {
$vehicle = $builder->createVehicle($plugin, $attributes);
$builder->putVehicle($vehicle);
}
$modx->log(modX::LOG_LEVEL_INFO, 'Packaged in '.count($plugins).' plugins.');
flush();
unset($plugins, $plugin, $attributes);

// Load menu
$modx->log(modX::LOG_LEVEL_INFO, 'Packaging in menu...');
$menu = include $sources['data'] . 'transport.menu.php';
Expand Down
23 changes: 23 additions & 0 deletions _build/data/events/tvsorter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/**
* @var modX $modx
*/
$events = array();

$ventName = 'OnTVFormSave';
$events[$ventName] = $modx->newObject('modPluginEvent');
$events[$ventName]->fromArray(array(
'event' => $ventName,
'priority' => 0,
'propertyset' => 0,
), '', true, true);

$ventName = 'OnTVFormDelete';
$events[$ventName] = $modx->newObject('modPluginEvent');
$events[$ventName]->fromArray(array(
'event' => $ventName,
'priority' => 0,
'propertyset' => 0,
), '', true, true);

return $events;
29 changes: 29 additions & 0 deletions _build/data/transport.plugins.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* @var modX $modx
* @var array $sources
*/
$plugins = array();
$idx = 0;

$plugins[$idx] = $modx->newObject('modPlugin');
$plugins[$idx]->fromArray(array(
'id' => $idx + 1,
'name' => 'TV Sorter',
'description' => 'This plugin automatically sets (or fix) the TVs ranks when adding or removing a TV.',
'plugincode' => Helper::getPHPContent($sources['elements'] . 'plugins/tvsorter.php'),
'category' => 0,
), '', true, true);

$events = include $sources['data'].'events/tvsorter.php';
if (is_array($events) && !empty($events)) {
$plugins[$idx]->addMany($events);
$modx->log(xPDO::LOG_LEVEL_INFO, 'Packaged in '.count($events).' Plugin Events for TV Sorter.');
flush();
} else {
$modx->log(xPDO::LOG_LEVEL_ERROR, 'Could not find plugin events for TV Sorter!');
}
unset($events);
$idx += 1;

return $plugins;
99 changes: 99 additions & 0 deletions _build/includes/helper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
<?php

class Helper
{
/** @var \modX $modx An instance of the modX object */
public $modx;
/** @var array $bench An array of running benches */
protected $bench = array();
/** @var array $providers An array of available transport package providers */
protected $providers = array();

/**
* Construct the object
*
* @param modX $modx A modX instance
* @param array $options
*/
public function __construct(modX &$modx, array $options = array())
{
$this->modx =& $modx;
}

/**
* Formats the given file to be used as snippet/plugin content
*
* @param string $filename The path the to snippet file
*
* @return string The PHP content
*/
public static function getPHPContent($filename)
{
$o = file_get_contents($filename);
$o = str_replace('<?php', '', $o);
$o = str_replace('?>', '', $o);
$o = trim($o);

return $o;
}

/**
* Recursively unlink/rmdir the given folder
*
* @param string $dir The folder to empty
*
* @return void
*/
public static function recursiveRmDir($dir)
{
if ($handle = opendir($dir)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
if (is_dir($dir."/".$entry) === true){
self::recursiveRmDir($dir."/".$entry);
} else {
unlink($dir."/".$entry);
}
}
}
closedir($handle);
rmdir($dir);
}
}

/**
* Copy the appropriate license model to the right place
*
* @param array $sources An array of options defined in the build script
* @param string $type The license type
*
* @return void
*/
public static function setLicense($sources, $type)
{
$source = $sources['build'] . 'license/'. strtolower($type) .'.txt';
$destination = $sources['docs'] . 'license.txt';
copy($source, $destination);
}

/**
* Format the given array of modAccessPolicy
*
* @param array $permissions
*
* @return string JSON encoded
*/
public function buildPolicyFormatData(array $permissions)
{
$data = array();
/** @var modAccessPolicy $permission */
foreach ($permissions as $permission) {
$data[$permission->get('name')] = true;
}

$data = json_encode($data);

return $data;
}

}
6 changes: 5 additions & 1 deletion core/components/tvsorter/docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog file for TV Sorter
--------------------------------------------------------------------------------

2013/04/28 : TVSorter 0.0.1-beta
2013/05/01: v0.0.2-beta
==============================================================================
- Added a plugin to manage ranks when a TV is attached/removed from a template

2013/04/28 : v0.0.1-beta
==============================================================================
- First build
2 changes: 1 addition & 1 deletion manager/components/tvsorter/js/home/tvs.grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ MODx.grid.TemplateTV = function(config) {
,width: 120
,fixed: true
});
Ext.applyIf(config,{
Ext.applyIf(config, {
id: 'modx-grid-template-tv'
,url: TVSorter.config.connector_url
,fields: ['id','name','description','tv_rank','access','category_name','category']
Expand Down

0 comments on commit e53939d

Please sign in to comment.