diff --git a/README.md b/README.md index a3d3ee5..864d022 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/_build/build.transport.php b/_build/build.transport.php index 1650bb8..087009b 100644 --- a/_build/build.transport.php +++ b/_build/build.transport.php @@ -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 @@ -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(); @@ -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'; diff --git a/_build/data/events/tvsorter.php b/_build/data/events/tvsorter.php new file mode 100644 index 0000000..fcff28b --- /dev/null +++ b/_build/data/events/tvsorter.php @@ -0,0 +1,23 @@ +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; diff --git a/_build/data/transport.plugins.php b/_build/data/transport.plugins.php new file mode 100644 index 0000000..d978aa8 --- /dev/null +++ b/_build/data/transport.plugins.php @@ -0,0 +1,29 @@ +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; diff --git a/_build/includes/helper.php b/_build/includes/helper.php new file mode 100644 index 0000000..c6c7da6 --- /dev/null +++ b/_build/includes/helper.php @@ -0,0 +1,99 @@ +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('', '', $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; + } + +} diff --git a/core/components/tvsorter/docs/changelog.txt b/core/components/tvsorter/docs/changelog.txt index c9b82d1..af51639 100644 --- a/core/components/tvsorter/docs/changelog.txt +++ b/core/components/tvsorter/docs/changelog.txt @@ -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 \ No newline at end of file diff --git a/manager/components/tvsorter/js/home/tvs.grid.js b/manager/components/tvsorter/js/home/tvs.grid.js index f073508..8a390a7 100644 --- a/manager/components/tvsorter/js/home/tvs.grid.js +++ b/manager/components/tvsorter/js/home/tvs.grid.js @@ -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']