Skip to content

Commit

Permalink
merging with vnenkpet/test
Browse files Browse the repository at this point in the history
  • Loading branch information
noumo committed May 25, 2015
1 parent f2575d9 commit 180b365
Show file tree
Hide file tree
Showing 22 changed files with 1,063 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.idea

vendor
Thumbs.db
9 changes: 9 additions & 0 deletions behaviors/CacheFlush.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,14 @@
use Yii;
use yii\db\ActiveRecord;

/**
* CacheFlush behavior
* @package yii\easyii\behaviors
* @inheritdoc
*/
class CacheFlush extends \yii\base\Behavior
{
/** @var string */
public $key;

public function attach($owner)
Expand All @@ -24,6 +30,9 @@ public function events()
];
}

/**
* Flush cache
*/
public function flush()
{
if($this->key) {
Expand Down
16 changes: 7 additions & 9 deletions behaviors/SortableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,27 @@ public function move($id, $direction, $condition = [])
{
$modelClass = $this->model;
$success = '';
if(($model = $modelClass::findOne($id))){
if($direction === 'up'){
if (($model = $modelClass::findOne($id))) {
if ($direction === 'up') {
$eq = '>';
$orderDir = 'ASC';
} else {
$eq = '<';
$orderDir = 'DESC';
}

$query = $modelClass::find()->orderBy('order_num '.$orderDir)->limit(1);
$query = $modelClass::find()->orderBy('order_num ' . $orderDir)->limit(1);

$where = [$eq, 'order_num', $model->order_num];
if(count($condition)){
if (count($condition)) {
$where = ['and', $where];
foreach($condition as $key => $value){
foreach ($condition as $key => $value) {
$where[] = [$key => $value];
}
}
$modelSwap = $query->where($where)->one();

if(!empty($modelSwap))
{
if (!empty($modelSwap)) {
$newOrderNum = $modelSwap->order_num;

$modelSwap->order_num = $model->order_num;
Expand All @@ -43,8 +42,7 @@ public function move($id, $direction, $condition = [])

$success = ['swap_id' => $modelSwap->primaryKey];
}
}
else{
} else {
$this->owner->error = Yii::t('easyii', 'Not found');
}

Expand Down
4 changes: 4 additions & 0 deletions behaviors/SortableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

use yii\db\ActiveRecord;

/**
* Sortable behavior. Enables model to be sorted manually by admin
* @package yii\easyii\behaviors
*/
class SortableModel extends \yii\base\Behavior
{
public function events()
Expand Down
4 changes: 4 additions & 0 deletions behaviors/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

use Yii;

/**
* Status behavior. Adds statuses to models
* @package yii\easyii\behaviors
*/
class StatusController extends \yii\base\Behavior
{
public $model;
Expand Down
6 changes: 6 additions & 0 deletions components/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@

use Yii;

/**
* Base API component. Used by all modules
* @package yii\easyii\components
*/
class API extends \yii\base\Object
{
/** @var array */
static $classes;
/** @var string module name */
public $module;

public function init()
Expand Down
4 changes: 4 additions & 0 deletions components/ActiveQuery.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php
namespace yii\easyii\components;

/**
* Base active query class for models
* @package yii\easyii\components
*/
class ActiveQuery extends \yii\db\ActiveQuery
{
/**
Expand Down
3 changes: 2 additions & 1 deletion components/ActiveQueryNS.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

class ActiveQueryNS extends ActiveQuery
{
public function behaviors() {
public function behaviors()
{
return [
NestedSetsQueryBehavior::className(),
];
Expand Down
9 changes: 9 additions & 0 deletions components/ActiveRecord.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
<?php
namespace yii\easyii\components;

/**
* Base active record class for easyii models
* @package yii\easyii\components
*/
class ActiveRecord extends \yii\db\ActiveRecord
{
/** @var string */
public static $SLUG_PATTERN = '/^[0-9a-z-]{0,128}$/';

/**
* Get active query
* @return ActiveQuery
*/
public static function find()
{
return new ActiveQuery(get_called_class());
Expand Down
7 changes: 6 additions & 1 deletion components/ApiObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@
use Yii;
use yii\easyii\helpers\Image;

/**
* Class ApiObject
* @package yii\easyii\components
*/
class ApiObject extends \yii\base\Object
{
/** @var \yii\base\Model */
public $model;

/**
* Generates ApiObject, attaching all settable properties to the child object
* @param \stdClass $model yii\base\Model object
* @param \yii\base\Model $model
*/
public function __construct($model){
$this->model = $model;
Expand Down
79 changes: 79 additions & 0 deletions components/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,26 @@
use yii\web\UploadedFile;
use yii\easyii\helpers\Image;

/**
* Category controller component
* @package yii\easyii\components
*/
class CategoryController extends Controller
{
/** @var string */
public $categoryClass;

/** @var string */
public $moduleName;

/** @var string */
public $viewRoute = '/items';

/**
* Categories list
*
* @return string
*/
public function actionIndex()
{
$class = $this->categoryClass;
Expand All @@ -21,6 +35,13 @@ public function actionIndex()
]);
}

/**
* Create form
*
* @param null $parent
* @return array|string|\yii\web\Response
* @throws \yii\web\HttpException
*/
public function actionCreate($parent = null)
{
$class = $this->categoryClass;
Expand Down Expand Up @@ -70,6 +91,13 @@ public function actionCreate($parent = null)
}
}

/**
* Edit form
*
* @param $id
* @return array|string|\yii\web\Response
* @throws \yii\web\HttpException
*/
public function actionEdit($id)
{
$class = $this->categoryClass;
Expand Down Expand Up @@ -108,6 +136,12 @@ public function actionEdit($id)
}
}

/**
* Remove category image
*
* @param $id
* @return \yii\web\Response
*/
public function actionClearImage($id)
{
$class = $this->categoryClass;
Expand All @@ -127,6 +161,12 @@ public function actionClearImage($id)
return $this->back();
}

/**
* Delete the category by ID
*
* @param $id
* @return mixed
*/
public function actionDelete($id)
{
$class = $this->categoryClass;
Expand All @@ -142,28 +182,60 @@ public function actionDelete($id)
return $this->formatResponse(Yii::t('easyii', 'Category deleted'));
}

/**
* Move category one level up up
*
* @param $id
* @return \yii\web\Response
*/
public function actionUp($id)
{
return $this->move($id, 'up');
}

/**
* Move category one level down
*
* @param $id
* @return \yii\web\Response
*/
public function actionDown($id)
{
return $this->move($id, 'down');
}

/**
* Activate category action
*
* @param $id
* @return mixed
*/
public function actionOn($id)
{
$class = $this->categoryClass;
return $this->changeStatus($id, $class::STATUS_ON);
}

/**
* Activate category action
*
* @param $id
* @return mixed
*/
public function actionOff($id)
{
$class = $this->categoryClass;
return $this->changeStatus($id, $class::STATUS_OFF);
}

/**
* Move category up/down
*
* @param $id
* @param $direction
* @return \yii\web\Response
* @throws \Exception
*/
private function move($id, $direction)
{
$modelClass = $this->categoryClass;
Expand Down Expand Up @@ -211,6 +283,13 @@ private function move($id, $direction)
return $this->back();
}

/**
* Change category status
*
* @param $id
* @param $status
* @return mixed
*/
public function changeStatus($id, $status)
{
$modelClass = $this->categoryClass;
Expand Down
8 changes: 8 additions & 0 deletions components/CategoryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
use yii\easyii\behaviors\SeoBehavior;
use creocoder\nestedsets\NestedSetsBehavior;

/**
* Base CategoryModel. Shared by categories
* @package yii\easyii\components
* @inheritdoc
*/
class CategoryModel extends \yii\easyii\components\ActiveRecord
{
const STATUS_OFF = 0;
Expand Down Expand Up @@ -76,6 +81,9 @@ public function afterDelete()
}
}

/**
* @return ActiveQueryNS
*/
public static function find()
{
return new ActiveQueryNS(get_called_class());
Expand Down
4 changes: 4 additions & 0 deletions components/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
use yii\easyii\models;
use yii\helpers\Url;

/**
* Base easyii controller component
* @package yii\easyii\components
*/
class Controller extends \yii\web\Controller
{
public $enableCsrfValidation = false;
Expand Down
Loading

0 comments on commit 180b365

Please sign in to comment.