Skip to content

Commit

Permalink
Dev code clean up and moving components to a namespace.
Browse files Browse the repository at this point in the history
  • Loading branch information
SamMousa committed Sep 24, 2015
1 parent a7475a0 commit 03368b8
Show file tree
Hide file tree
Showing 92 changed files with 811 additions and 786 deletions.
75 changes: 52 additions & 23 deletions protected/components/AuthManager.php
@@ -1,91 +1,120 @@
<?php

class AuthManager implements IAuthManager {
namespace ls\components;

use IAuthManager;
use SettingGlobal;

class AuthManager implements IAuthManager
{
/**
* @var IAuthManager
*/
public $authorizationPlugin;
public function init() {

public function init()
{
$id = SettingGlobal::get('authorizationPlugin', 'ls_core_plugins_PermissionDb');
$this->authorizationPlugin = App()->pluginManager->getPlugin($id);
$this->authorizationPlugin = App()->pluginManager->getPlugin($id);
}
public function addItemChild($itemName, $childName) {

public function addItemChild($itemName, $childName)
{
return $this->authorizationPlugin->addItemChild($itemName, $childName);
}

public function assign($itemName, $userId, $bizRule = null, $data = null) {
public function assign($itemName, $userId, $bizRule = null, $data = null)
{
return $this->authorizationPlugin->assign($itemName, $userId, $bizRule, $data);
}

public function checkAccess($itemName, $userId, $params = array()) {
public function checkAccess($itemName, $userId, $params = array())
{
return $this->authorizationPlugin->checkAccess($itemName, $userId, $params);
}

public function clearAll() {
public function clearAll()
{
return $this->authorizationPlugin->clearAll();
}

public function clearAuthAssignments() {
public function clearAuthAssignments()
{
return $this->authorizationPlugin->clearAuthAssignments();
}

public function createAuthItem($name, $type, $description = '', $bizRule = null, $data = null) {
public function createAuthItem($name, $type, $description = '', $bizRule = null, $data = null)
{
return $this->authorizationPlugin->createAuthItem($name, $type, $description, $bizRule, $data);
}

public function executeBizRule($bizRule, $params, $data) {
public function executeBizRule($bizRule, $params, $data)
{
return $this->authorizationPlugin->executeBizRule($bizRule, $params, $data);
}

public function getAuthAssignment($itemName, $userId) {
public function getAuthAssignment($itemName, $userId)
{
return $this->authorizationPlugin->getAuthAssignment($itemName, $userId);
}

public function getAuthAssignments($userId) {
public function getAuthAssignments($userId)
{
return $this->authorizationPlugin->getAuthAssignments($userId);
}

public function getAuthItem($name) {
public function getAuthItem($name)
{
return $this->authorizationPlugin->getAuthItem($name);
}

public function getAuthItems($type = null, $userId = null) {
public function getAuthItems($type = null, $userId = null)
{
return $this->authorizationPlugin->getAuthItems($type, $userId);
}

public function getItemChildren($itemName) {
public function getItemChildren($itemName)
{
return $this->authorizationPlugin->getItemChildren($itemName);
}

public function hasItemChild($itemName, $childName) {
public function hasItemChild($itemName, $childName)
{
return $this->authorizationPlugin->hasItemChild($itemName, $childName);
}

public function isAssigned($itemName, $userId) {
public function isAssigned($itemName, $userId)
{
return $this->authorizationPlugin->isAssigned($itemName, $userId);
}

public function removeAuthItem($name) {
public function removeAuthItem($name)
{
return $this->authorizationPlugin->removeAuthItem($name);
}

public function removeItemChild($itemName, $childName) {
public function removeItemChild($itemName, $childName)
{
return $this->authorizationPlugin->removeItemChild($itemName, $childName);
}

public function revoke($itemName, $userId) {
public function revoke($itemName, $userId)
{
return $this->authorizationPlugin->revoke($itemName, $userId);
}

public function save() {
public function save()
{
return $this->authorizationPlugin->save();
}

public function saveAuthAssignment($assignment) {
public function saveAuthAssignment($assignment)
{
return $this->authorizationPlugin->saveAuthAssignment($assignment);
}

public function saveAuthItem($item, $oldName = null) {
public function saveAuthItem($item, $oldName = null)
{
return $this->authorizationPlugin->saveAuthItem($item);
}

Expand Down
36 changes: 22 additions & 14 deletions protected/components/Batch.php
@@ -1,35 +1,38 @@
<?php
/**
* Created by PhpStorm.
* User: sam
* Date: 5/29/15
* Time: 5:46 PM
*/
namespace ls\components;

class Batch {
use Closure;

class Batch
{

/**
* @var Closure
*/
protected $callback;

protected $defaultCategory;
public $batchSize;
public $commitCount = 0;
protected $data = [];

public function __construct(Closure $callback, $batchSize = 5000, $defaultCategory = 'default') {
public function __construct(\Closure $callback, $batchSize = 5000, $defaultCategory = 'default')
{
$this->callback = $callback;
$this->batchSize = $batchSize;
$this->defaultCategory = $defaultCategory;
}


public function add($elements, $category = null) {
public function add($elements, $category = null)
{
if (!empty($elements) && is_scalar(reset($elements))) {
$elements = [$elements];
}
if (!isset($category)) {
$category = $this->defaultCategory;
}
foreach($elements as $element) {
foreach ($elements as $element) {
$this->data[$category][] = ($element instanceof \CActiveRecord) ? $element->attributes : $element;


Expand All @@ -41,19 +44,24 @@ public function add($elements, $category = null) {
}
}

public function commitCategory($category) {
public function commitCategory($category)
{

$callback = $this->callback;
$callback($this->data[$category], $category);
$this->commitCount++;
unset($this->data[$category]);
}
public function commit() {
foreach($this->data as $key => $items) {

public function commit()
{
foreach ($this->data as $key => $items) {
$this->commitCategory($key);
}
}
public function __destruct() {

public function __destruct()
{
$this->commit();
}
}
14 changes: 10 additions & 4 deletions protected/components/DeferredValue.php
@@ -1,17 +1,23 @@
<?php
namespace ls\components;

/**
* This class wraps a Closure and returns the closures' result when serialized to string.
* Class DeferredValue
* Class ls\components\DeferredValue
*/
class DeferredValue {
class DeferredValue
{
private $closure;
public function __construct(\Closure $closure) {

public function __construct(\Closure $closure)
{
$this->closure = $closure;
}

public function __toString() {
public function __toString()
{
$result = call_user_func($this->closure);

return "" . $result;
}
}
27 changes: 19 additions & 8 deletions protected/components/LocalizedFormatter.php
@@ -1,26 +1,37 @@
<?php
class LocalizedFormatter extends CLocalizedFormatter {

public function formatSurveyStatus($value) {
namespace ls\components;

use CLocalizedFormatter;
use TbHtml;

class LocalizedFormatter extends CLocalizedFormatter
{

public function formatSurveyStatus($value)
{
switch ($value) {
case 'active':
$icon = TbHtml::ICON_PLAY;
break;
case 'inactive':
case 'inactive':
$icon = TbHtml::ICON_STOP;
break;
case 'expired':
$icon = TbHtml::ICON_PAUSE;
break;

}

return TbHtml::icon($icon);
}

public function formatBooleanIcon($value) {
public function formatBooleanIcon($value)
{
return TbHtml::icon($value ? TbHtml::ICON_CHECK : TbHtml::ICON_UNCHECKED);
}
public function formatPercentage($factor) {

public function formatPercentage($factor)
{
return number_format($factor * 100, 1) . '%';
}
/**
Expand All @@ -36,5 +47,5 @@ public function formatPercentage($factor) {
// }
// return parent::formatEmail($encoded);
// }

}

0 comments on commit 03368b8

Please sign in to comment.