Last active
August 29, 2015 14:22
-
-
Save Largo/d7371d4ba8c8846fdc38 to your computer and use it in GitHub Desktop.
No warranties. This is very beta extension for implementing the drag and drop order function in bolt. you need a taxonomy "sortierung" and shouldn't have any other taxonomies, because it might not work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Bolt\Extension\Largo\SortOrder; | |
use Symfony\Component\HttpFoundation\Response; | |
use Bolt; | |
class Extension extends \Bolt\BaseExtension | |
{ | |
/** @var boolean */ | |
private $isAdmin; | |
public function getName() { | |
return "SortOrder"; | |
} | |
function info() { | |
$data = array( | |
'name' =>"Sort Order", | |
'description' => "This extension reacts to the event when you reorder something in a content type.", | |
'author' => "Largo", | |
'link' => "http://bolt.cm", | |
'version' => "1.0", | |
'required_bolt_version' => "2.2", | |
'highest_bolt_version' => "2.2", | |
'type' => "", | |
'first_releasedate' => "2015-06-04", | |
'latest_releasedate' => "2015-06-04", | |
); | |
return $data; | |
} | |
// This checks if a user is a dashboard user | |
public function isAdmin() | |
{ | |
if (is_null($this->isAdmin)) { | |
// check if user has allowed role(s) | |
$user = $this->app['users']->getCurrentUser(); | |
$userid = $user['id']; | |
$this->isAdmin = false; | |
//foreach ($this->config['admin_roles'] as $role) { | |
// if ($this->app['users']->hasRole($userid, 'chief-editor')) { | |
if ($user) { //&& $user->isAllowed('login') | |
$this->isAdmin = true; | |
// break; | |
} | |
// } | |
} | |
return $this->isAdmin; | |
} | |
function initialize() { | |
$this->app->match("/bolt/overview/undefinedcontent/sortcontent/{contenttype}", array($this, 'saveorder')); | |
} | |
public function saveorder($contenttype) { | |
if(!$this->isAdmin()) { | |
echo "bye"; exit; | |
} | |
$items = $this->app['request']->get('item'); | |
$body = "success"; | |
$content = $this->app['storage']->getContent( | |
$contenttype, | |
array('limit' => 10000, 'order' => 'datepublish desc', 'hydrate' => true) | |
); | |
foreach ($content as $entry) { | |
$entry->sortorder = (int) array_search($entry->id, $items); | |
$entry->group['order'] = $entry->sortorder; | |
$entry->setTaxonomy('sortierung', 'nicht_sortiert', 'nicht_sortiert', 0); | |
$this->app['storage']->saveContent($entry); | |
$entry->setTaxonomy('sortierung', 'sortierung', 'Beiträge', (int) array_search($entry->id, $items)); | |
$this->app['storage']->saveContent($entry); | |
} | |
foreach ($content as $entry) { | |
$this->app['db']->executeQuery("UPDATE bolt_taxonomy SET sortorder = '". (int) array_search($entry->id, $items) ."' WHERE bolt_taxonomy.content_id = ". $entry->id .";"); | |
} | |
$headers = array(); | |
return new Response($body, 200, $headers); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My Taxonomy:
sortierung:
slug: sortierung
singular_slug: sortierung
behaves_like: grouping
prefix: "Hier wird die Sortierung gespeichert"
options: { sortierung: 'sortierung', nicht_sortiert : 'nicht sortiert' }
has_sortorder: true