-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First implementation of a dashboard for the JQAdm interface
- Loading branch information
Showing
20 changed files
with
1,789 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
|
||
/** | ||
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 | ||
* @copyright Aimeos (aimeos.org), 2016 | ||
* @package Admin | ||
* @subpackage JQAdm | ||
*/ | ||
|
||
|
||
namespace Aimeos\Admin\JQAdm\Dashboard; | ||
|
||
|
||
/** | ||
* Factory for dashboard JQAdm client | ||
* | ||
* @package Admin | ||
* @subpackage JQAdm | ||
*/ | ||
class Factory | ||
extends \Aimeos\Admin\JQAdm\Common\Factory\Base | ||
implements \Aimeos\Admin\JQAdm\Common\Factory\Iface | ||
{ | ||
/** | ||
* Creates a dashboard client object | ||
* | ||
* @param \Aimeos\MShop\Context\Item\Iface $context Shop context instance with necessary objects | ||
* @param array $templatePaths List of file system paths where the templates are stored | ||
* @param string|null $name Admin name (default: "Standard") | ||
* @return \Aimeos\Admin\JQAdm\Iface Filter part implementing \Aimeos\Admin\JQAdm\Iface | ||
* @throws \Aimeos\Admin\JQAdm\Exception If requested client implementation couldn't be found or initialisation fails | ||
*/ | ||
public static function createClient( \Aimeos\MShop\Context\Item\Iface $context, array $templatePaths, $name = null ) | ||
{ | ||
/** admin/jqadm/dashboard/name | ||
* Class name of the used account favorite client implementation | ||
* | ||
* Each default admin client can be replace by an alternative imlementation. | ||
* To use this implementation, you have to set the last part of the class | ||
* name as configuration value so the client factory knows which class it | ||
* has to instantiate. | ||
* | ||
* For example, if the name of the default class is | ||
* | ||
* \Aimeos\Admin\JQAdm\Dashboard\Standard | ||
* | ||
* and you want to replace it with your own version named | ||
* | ||
* \Aimeos\Admin\JQAdm\Dashboard\Myfavorite | ||
* | ||
* then you have to set the this configuration option: | ||
* | ||
* admin/jqadm/dashboard/name = Myfavorite | ||
* | ||
* The value is the last part of your own class name and it's case sensitive, | ||
* so take care that the configuration value is exactly named like the last | ||
* part of the class name. | ||
* | ||
* The allowed characters of the class name are A-Z, a-z and 0-9. No other | ||
* characters are possible! You should always start the last part of the class | ||
* name with an upper case character and continue only with lower case characters | ||
* or numbers. Avoid chamel case names like "MyFavorite"! | ||
* | ||
* @param string Last part of the class name | ||
* @since 2016.01 | ||
* @category Developer | ||
*/ | ||
if( $name === null ) { | ||
$name = $context->getConfig()->get( 'admin/jqadm/dashboard/name', 'Standard' ); | ||
} | ||
|
||
if( ctype_alnum( $name ) === false ) | ||
{ | ||
$classname = is_string( $name ) ? '\\Aimeos\\Admin\\JQAdm\\Dashboard\\' . $name : '<not a string>'; | ||
throw new \Aimeos\Admin\JQAdm\Exception( sprintf( 'Invalid characters in class name "%1$s"', $classname ) ); | ||
} | ||
|
||
$iface = '\\Aimeos\\Admin\\JQAdm\\Iface'; | ||
$classname = '\\Aimeos\\Admin\\JQAdm\\Dashboard\\' . $name; | ||
|
||
$client = self::createClientBase( $context, $classname, $iface, $templatePaths ); | ||
|
||
return self::addClientDecorators( $context, $client, $templatePaths, 'dashboard' ); | ||
} | ||
|
||
} |
276 changes: 276 additions & 0 deletions
276
admin/jqadm/src/Admin/JQAdm/Dashboard/Order/Latest/Standard.php
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,276 @@ | ||
<?php | ||
|
||
/** | ||
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 | ||
* @copyright Aimeos (aimeos.org), 2016 | ||
* @package Admin | ||
* @subpackage JQAdm | ||
*/ | ||
|
||
|
||
namespace Aimeos\Admin\JQAdm\Dashboard\Order\Latest; | ||
|
||
|
||
/** | ||
* Default implementation of dashboard latest order JQAdm client. | ||
* | ||
* @package Admin | ||
* @subpackage JQAdm | ||
*/ | ||
class Standard | ||
extends \Aimeos\Admin\JQAdm\Common\Admin\Factory\Base | ||
implements \Aimeos\Admin\JQAdm\Common\Admin\Factory\Iface | ||
{ | ||
/** admin/jqadm/dashboard/order/latest/standard/subparts | ||
* List of JQAdm sub-clients rendered within the dashboard latest section | ||
* | ||
* The output of the frontend is composed of the code generated by the JQAdm | ||
* clients. Each JQAdm client can consist of serveral (or none) sub-clients | ||
* that are responsible for rendering certain sub-parts of the output. The | ||
* sub-clients can contain JQAdm clients themselves and therefore a | ||
* hierarchical tree of JQAdm clients is composed. Each JQAdm client creates | ||
* the output that is placed inside the container of its parent. | ||
* | ||
* At first, always the JQAdm code generated by the parent is printed, then | ||
* the JQAdm code of its sub-clients. The order of the JQAdm sub-clients | ||
* determines the order of the output of these sub-clients inside the parent | ||
* container. If the configured list of clients is | ||
* | ||
* array( "subclient1", "subclient2" ) | ||
* | ||
* you can easily change the order of the output by reordering the subparts: | ||
* | ||
* admin/jqadm/<clients>/subparts = array( "subclient1", "subclient2" ) | ||
* | ||
* You can also remove one or more parts if they shouldn't be rendered: | ||
* | ||
* admin/jqadm/<clients>/subparts = array( "subclient1" ) | ||
* | ||
* As the clients only generates structural JQAdm, the layout defined via CSS | ||
* should support adding, removing or reordering content by a fluid like | ||
* design. | ||
* | ||
* @param array List of sub-client names | ||
* @since 2016.01 | ||
* @category Developer | ||
*/ | ||
private $subPartPath = 'admin/jqadm/dashboard/order/latest/standard/subparts'; | ||
private $subPartNames = array(); | ||
|
||
|
||
/** | ||
* Copies a resource | ||
* | ||
* @return string|null admin output to display or null for redirecting to the list | ||
*/ | ||
public function copy() | ||
{ | ||
throw new \Aimeos\Admin\JQAdm\Exception( 'The resource can not be copied' ); | ||
} | ||
|
||
|
||
/** | ||
* Creates a new resource | ||
* | ||
* @return string|null admin output to display or null for redirecting to the list | ||
*/ | ||
public function create() | ||
{ | ||
throw new \Aimeos\Admin\JQAdm\Exception( 'New resources can not be created' ); | ||
} | ||
|
||
|
||
/** | ||
* Deletes a resource | ||
* | ||
* @return string|null admin output to display or null for redirecting to the list | ||
*/ | ||
public function delete() | ||
{ | ||
throw new \Aimeos\Admin\JQAdm\Exception( 'The resource can not be deleted' ); | ||
} | ||
|
||
|
||
/** | ||
* Returns a single resource | ||
* | ||
* @return string|null admin output to display or null for redirecting to the list | ||
*/ | ||
public function get() | ||
{ | ||
throw new \Aimeos\Admin\JQAdm\Exception( 'The resource can not be retrieved' ); | ||
} | ||
|
||
|
||
/** | ||
* Saves the data | ||
* | ||
* @return string|null admin output to display or null for redirecting to the list | ||
*/ | ||
public function save() | ||
{ | ||
throw new \Aimeos\Admin\JQAdm\Exception( 'The resource can not be modified' ); | ||
} | ||
|
||
|
||
/** | ||
* Returns a list of resource according to the conditions | ||
* | ||
* @return string admin output to display | ||
*/ | ||
public function search() | ||
{ | ||
$view = $this->getView(); | ||
|
||
try | ||
{ | ||
$this->addOrders( $view ); | ||
$view->orderlatestBody = ''; | ||
|
||
foreach( $this->getSubClients() as $client ) { | ||
$view->orderlatestBody .= $client->search(); | ||
} | ||
} | ||
catch( \Aimeos\MShop\Exception $e ) | ||
{ | ||
$error = array( 'order-latest' => $this->getContext()->getI18n()->dt( 'mshop', $e->getMessage() ) ); | ||
$view->errors = $view->get( 'errors', array() ) + $error; | ||
} | ||
catch( \Exception $e ) | ||
{ | ||
$error = array( 'order-latest' => $e->getMessage() ); | ||
$view->errors = $view->get( 'errors', array() ) + $error; | ||
} | ||
|
||
$tplconf = 'admin/jqadm/dashboard/order/latest/template-item'; | ||
$default = 'dashboard/item-order-latest-default.php'; | ||
|
||
return $view->render( $view->config( $tplconf, $default ) ); | ||
} | ||
|
||
|
||
/** | ||
* Returns the sub-client given by its name. | ||
* | ||
* @param string $type Name of the client type | ||
* @param string|null $name Name of the sub-client (Default if null) | ||
* @return \Aimeos\Admin\JQAdm\Iface Sub-client object | ||
*/ | ||
public function getSubClient( $type, $name = null ) | ||
{ | ||
/** admin/jqadm/dashboard/order/latest/decorators/excludes | ||
* Excludes decorators added by the "common" option from the dashboard JQAdm client | ||
* | ||
* Decorators extend the functionality of a class by adding new aspects | ||
* (e.g. log what is currently done), executing the methods of the underlying | ||
* class only in certain conditions (e.g. only for logged in users) or | ||
* modify what is returned to the caller. | ||
* | ||
* This option allows you to remove a decorator added via | ||
* "admin/jqadm/common/decorators/default" before they are wrapped | ||
* around the JQAdm client. | ||
* | ||
* admin/jqadm/dashboard/order/latest/decorators/excludes = array( 'decorator1' ) | ||
* | ||
* This would remove the decorator named "decorator1" from the list of | ||
* common decorators ("\Aimeos\Admin\JQAdm\Common\Decorator\*") added via | ||
* "admin/jqadm/common/decorators/default" to the JQAdm client. | ||
* | ||
* @param array List of decorator names | ||
* @since 2016.01 | ||
* @category Developer | ||
* @see admin/jqadm/common/decorators/default | ||
* @see admin/jqadm/dashboard/order/latest/decorators/global | ||
* @see admin/jqadm/dashboard/order/latest/decorators/local | ||
*/ | ||
|
||
/** admin/jqadm/dashboard/order/latest/decorators/global | ||
* Adds a list of globally available decorators only to the dashboard JQAdm client | ||
* | ||
* Decorators extend the functionality of a class by adding new aspects | ||
* (e.g. log what is currently done), executing the methods of the underlying | ||
* class only in certain conditions (e.g. only for logged in users) or | ||
* modify what is returned to the caller. | ||
* | ||
* This option allows you to wrap global decorators | ||
* ("\Aimeos\Admin\JQAdm\Common\Decorator\*") around the JQAdm client. | ||
* | ||
* admin/jqadm/dashboard/order/latest/decorators/global = array( 'decorator1' ) | ||
* | ||
* This would add the decorator named "decorator1" defined by | ||
* "\Aimeos\Admin\JQAdm\Common\Decorator\Decorator1" only to the JQAdm client. | ||
* | ||
* @param array List of decorator names | ||
* @since 2016.01 | ||
* @category Developer | ||
* @see admin/jqadm/common/decorators/default | ||
* @see admin/jqadm/dashboard/order/latest/decorators/excludes | ||
* @see admin/jqadm/dashboard/order/latest/decorators/local | ||
*/ | ||
|
||
/** admin/jqadm/dashboard/order/latest/decorators/local | ||
* Adds a list of local decorators only to the dashboard JQAdm client | ||
* | ||
* Decorators extend the functionality of a class by adding new aspects | ||
* (e.g. log what is currently done), executing the methods of the underlying | ||
* class only in certain conditions (e.g. only for logged in users) or | ||
* modify what is returned to the caller. | ||
* | ||
* This option allows you to wrap local decorators | ||
* ("\Aimeos\Admin\JQAdm\Dashboard\Decorator\*") around the JQAdm client. | ||
* | ||
* admin/jqadm/dashboard/order/latest/decorators/local = array( 'decorator2' ) | ||
* | ||
* This would add the decorator named "decorator2" defined by | ||
* "\Aimeos\Admin\JQAdm\Dashboard\Decorator\Decorator2" only to the JQAdm client. | ||
* | ||
* @param array List of decorator names | ||
* @since 2016.01 | ||
* @category Developer | ||
* @see admin/jqadm/common/decorators/default | ||
* @see admin/jqadm/dashboard/order/latest/decorators/excludes | ||
* @see admin/jqadm/dashboard/order/latest/decorators/global | ||
*/ | ||
return $this->createSubClient( 'dashboard/order/latest/' . $type, $name ); | ||
} | ||
|
||
|
||
/** | ||
* Adds the latest orders to the view object | ||
* | ||
* @param \Aimeos\MW\View\Iface $view View object to add the parameters to | ||
*/ | ||
protected function addOrders( \Aimeos\MW\View\Iface $view ) | ||
{ | ||
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order/base' ); | ||
|
||
$search = $manager->createSearch(); | ||
$search->setSortations( array( $search->sort( '-', 'order.base.ctime' ) ) ); | ||
$search->setSlice( 0, 10 ); | ||
|
||
$orders = $manager->searchItems( $search ); | ||
|
||
|
||
$manager = \Aimeos\MShop\Factory::createManager( $this->getContext(), 'order' ); | ||
|
||
$search = $manager->createSearch(); | ||
$search->setConditions( $search->compare( '==', 'order.baseid', array_keys( $orders ) ) ); | ||
|
||
$items = $manager->searchItems( $search ); | ||
|
||
|
||
$view->orderlatestOrders = $orders; | ||
$view->orderlatestItems = $items; | ||
} | ||
|
||
|
||
/** | ||
* Returns the list of sub-client names configured for the client. | ||
* | ||
* @return array List of JQAdm client names | ||
*/ | ||
protected function getSubClientNames() | ||
{ | ||
return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); | ||
} | ||
} |
Oops, something went wrong.