Skip to content

Commit

Permalink
Updating controllers
Browse files Browse the repository at this point in the history
  • Loading branch information
vespakoen committed Jul 6, 2012
1 parent 98b7e2b commit 84202b6
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 113 deletions.
15 changes: 9 additions & 6 deletions controllers/account.php
Expand Up @@ -3,8 +3,8 @@
use Laravel\Messages;

use Layla\API;
use Layla\Module;
use Layla\Module\Form;
use Layla\Artifact;
use Layla\Artifact\Form;

use Admin\Forms\Account\EditForm;

Expand Down Expand Up @@ -54,12 +54,13 @@ public function get_read_multiple()
// Paginate the Accounts
$accounts = Paginator::make($accounts->get('results'), $accounts->get('total'), $this->per_page);

$this->layout->content = Module::page('account.read_multiple', $accounts);
$this->layout->content = Artifact::page('account.read_multiple')
->with('accounts', $accounts);
}

public function get_create()
{
$this->layout->content = Module::page('account.create');
$this->layout->content = Artifact::page('account.create');
}

public function post_create()
Expand Down Expand Up @@ -91,7 +92,8 @@ public function get_update($id = null, $sub = null, $sub_id = null)
//var_dump($id, $sub, $sub_id); die;
$account = API::get(array('account', $id), array('version' => $sub_id));

$this->layout->content = Module::page('account.update', $account);
$this->layout->content = Artifact::page('account.update')
->with('account', $account);
}

public function put_update($id = null)
Expand Down Expand Up @@ -121,7 +123,8 @@ public function put_update($id = null)

public function get_delete($id = null)
{
$this->layout->content = Module::page('account.delete', $id);
$this->layout->content = Artifact::page('account.delete')
->with('id', $id);
}

public function delete_delete($id = null)
Expand Down
73 changes: 3 additions & 70 deletions controllers/media.php
Expand Up @@ -3,7 +3,7 @@
use Laravel\Messages;

use Layla\API;
use Layla\Module;
use Layla\Artifact;

class Admin_Media_Controller extends Admin_Base_Controller
{
Expand Down Expand Up @@ -50,75 +50,8 @@ public function get_read_multiple()
// Paginate the modules
$modules = Paginator::make($modules->get('results'), $modules->get('total'), $this->per_page);

$this->layout->content = Module::page('media.read_multiple', $modules);
}

public function get_module($id = null)
{
// Set API options
$options = array(
'offset' => (Input::get('page', 1) - 1) * $this->per_page,
'limit' => $this->per_page,
'sort_by' => Input::get('sort_by', 'name'),
'order' => Input::get('order', 'ASC'),
'filter' => array(
'module_id' => $id
)
);

// Add search to API options
if(Input::has('q'))
{
$options['search'] = array(
'string' => Input::get('q'),
'columns' => array(
'name',
'email'
)
);
}

// Get the Accounts
$mediagroups = API::get(array('media', $id, 'groups'), $options);

// Paginate the mediagroups
$mediagroups = Paginator::make($mediagroups->get('results'), $mediagroups->get('total'), $this->per_page);

$this->layout->content = Module::page('media.groups', $mediagroups, $id);
}

public function get_group($module_id, $id = null)
{
// Set API options
$options = array(
'offset' => (Input::get('page', 1) - 1) * $this->per_page,
'limit' => $this->per_page,
'sort_by' => Input::get('sort_by', 'name'),
'order' => Input::get('order', 'ASC'),
'filter' => array(
'group_id' => $id
)
);

// Add search to API options
if(Input::has('q'))
{
$options['search'] = array(
'string' => Input::get('q'),
'columns' => array(
'name',
'email'
)
);
}

// Get the Accounts
$assets = API::get(array('media', $module_id, 'group', $id, 'assets'), $options);

// Paginate the assets
$assets = Paginator::make($assets->get('results'), $assets->get('total'), $this->per_page);

$this->layout->content = Module::page('media.assets', $assets, $module_id, $id);
$this->layout->content = Artifact::page('media.read_multiple')
->with('modules', $modules);
}

}
6 changes: 4 additions & 2 deletions controllers/media/group.php
Expand Up @@ -3,7 +3,7 @@
use Laravel\Messages;

use Layla\API;
use Layla\Module;
use Layla\Artifact;

class Admin_Media_Group_Controller extends Admin_Base_Controller
{
Expand Down Expand Up @@ -48,7 +48,9 @@ public function get_read_multiple($id = null)
// Paginate the mediagroups
$mediagroups = Paginator::make($mediagroups->get('results'), $mediagroups->get('total'), $this->per_page);

$this->layout->content = Module::page('media.group.read_multiple', $mediagroups, $id);
$this->layout->content = Artifact::page('media.group.read_multiple')
->with('mediagroups', $mediagroups)
->with('module_id', $id);
}

}
7 changes: 5 additions & 2 deletions controllers/media/group/asset.php
Expand Up @@ -3,7 +3,7 @@
use Laravel\Messages;

use Layla\API;
use Layla\Module;
use Layla\Artifact;

class Admin_Media_Group_Asset_Controller extends Admin_Base_Controller
{
Expand Down Expand Up @@ -51,7 +51,10 @@ public function get_read_multiple($module_id, $id = null)
// Paginate the assets
$assets = Paginator::make($assets->get('results'), $assets->get('total'), $this->per_page);

$this->layout->content = Module::page('media.group.asset.read_multiple', $assets, $module_id, $id);
$this->layout->content = Artifact::page('media.group.asset.read_multiple')
->with('assets', $assets)
->with('module_id', $module_id)
->with('mediagroup_id', $id);
}

}
14 changes: 7 additions & 7 deletions controllers/module.php
Expand Up @@ -3,8 +3,8 @@
use Laravel\Messages;

use Layla\API;
use Layla\Module;
use Layla\Module\Form;
use Layla\Artifact;
use Layla\Artifact\Form;

use Admin\Forms\Account\EditForm;

Expand Down Expand Up @@ -54,17 +54,17 @@ public function get_index()
// Paginate the Accounts
$modules = Paginator::make($modules->get('results'), $modules->get('total'), $this->per_page);

$this->layout->content = Module::page('module.index', $modules);
$this->layout->content = Artifact::page('module.index', $modules);
}

public function get_install()
{
$this->layout->content = Module::page('module.install');
$this->layout->content = Artifact::page('module.install');
}

public function get_create()
{
$this->layout->content = Module::page('module.create');
$this->layout->content = Artifact::page('module.create');
}

public function post_add()
Expand Down Expand Up @@ -93,7 +93,7 @@ public function post_add()

public function get_edit($id = null)
{
$this->layout->content = Module::page('module.edit', $id);
$this->layout->content = Artifact::page('module.edit', $id);
}

public function put_edit($id = null)
Expand Down Expand Up @@ -123,7 +123,7 @@ public function put_edit($id = null)

public function get_delete($id = null)
{
$this->layout->content = Module::page('module.delete', $id);
$this->layout->content = Artifact::page('module.delete', $id);
}

public function delete_delete($id = null)
Expand Down
98 changes: 72 additions & 26 deletions controllers/page.php
Expand Up @@ -46,26 +46,20 @@ public function get_read_multiple()
// Paginate the Pages
$pages = Paginator::make($pages->get('results'), $pages->get('total'), $this->per_page);

$this->layout->content = Module::page('page.read_multiple', $pages);
$this->layout->content = Artifact::page('page.read_multiple')
->with('pages', $pages);
}

public function get_create()
{
// Get Languages
$languages = model_array_pluck(API::get(array('language', 'all'))->get('results'), function($language)
{
return $language->name;
}, 'id');

// Get Layouts and put it in a nice array for the dropdown
$layouts = model_array_pluck(API::get(array('layout', 'all'))->get('results'), function($layout)
{
return $layout->name;
}, 'id');

$this->layout->content = View::make('admin::page.create')
->with('languages', $languages)
->with('layouts', $layouts);
$this->layout->content = Artifact::page('page.create')
->with('layouts', $layouts);
}

public function post_create()
Expand All @@ -91,10 +85,50 @@ public function post_create()
return Redirect::to(prefix('admin').'pages');
}

public function get_translate($slug = null, $language_slug = null)
{
if( ! is_null($slug))
{
$response = API::get(array('page', $slug));

if($response->code !== 200)
{
return Event::first($response->code);
}

$page = $response->get();
}

if( ! is_null($language_slug))
{
$response = API::get(array('language', $language_slug));

if($response->code !== 200)
{
return Event::first($response->code);
}

$language = $response->get();
}

// Get Layouts and put it in a nice array for the dropdown
$layouts = model_array_pluck(API::get(array('layouts'))->get('results'), function($layout)
{
return $layout->name;
}, 'id');

$this->layout->content = Artifact::page('page.translate')
->with('id', $page->id)
->with('language', $language)
->with('layouts', $layouts);
}

public function get_update($slug = null)
{
$options = array();

// Get the Page
$response = API::get(array('page', $slug));
$response = API::get(array('page', $slug), $options);

// Handle response codes other than 200 OK
if( ! $response->success)
Expand All @@ -105,19 +139,24 @@ public function get_update($slug = null)
// The response body is the Page
$page = $response->get();

// Get Languages
$languages = model_array_pluck(API::get(array('languages'))->get('results'), function($language)
$response = API::get(array('language', $page->lang->language_id));

if($response->code !== 200)
{
return $language->name;
}, 'id');
return Event::first($response->code);
}

$language = $response->get();

// Get Layouts and put it in a nice array for the dropdown
$layouts = model_array_pluck(API::get(array('layouts'))->get('results'), function($layout)
{
return $layout->name;
}, 'id');

$this->layout->content = Module::page('page.update', $page);
$this->layout->content = Artifact::page('page.update')
->with('language', $language)
->with('page', $page);
}

public function put_update($slug = null)
Expand All @@ -132,35 +171,42 @@ public function put_update($slug = null)
if($response->code == 400)
{
return Redirect::to(prefix('admin').'page/edit/' . $slug)
->with('errors', new Messages($response->get()))
->with_input();
->with('errors', new Messages($response->get()))
->with_input();
}

return Event::first($response->code);
}

// Add success notification
Notification::success('Successfully updated page');
Notification::success('Successfully updated page translation');

return Redirect::to(prefix('admin').'pages');
}

public function get_delete($slug = null)
public function put_translate($id = null, $language_slug = null)
{
// Get the Page
$response = API::get(array('page', $slug));
// Translate the Page
$response = API::put(array('page', $id), Input::all());

// Handle response codes other than 200 OK
if( ! $response->success)
{
// Errors were found on our data! Redirect to form with errors and old input
if($response->code == 400)
{
return Redirect::to(prefix('admin').'page/translate/'.$id.'/'.$language_slug)
->with('errors', new Messages($response->get()))
->with_input();
}

return Event::first($response->code);
}

// The request body is the Page
$page = $response->get();
// Add success notification
Notification::success('Successfully translated page');

$this->layout->content = View::make('admin::page.delete')
->with('page', $page);
return Redirect::to(prefix('admin').'pages');
}

public function delete_delete($slug = null)
Expand Down

0 comments on commit 84202b6

Please sign in to comment.