Skip to content

Instantly share code, notes, and snippets.

@raoul2000
raoul2000 / SwStatus.php
Last active October 2, 2015 06:53
yii2-workflow - WorkflowDbSource prototype
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "{{%sw_status}}".
*
* @property string $id
<?php
namespace app\models\wizflow;
use Yii;
use yii\base\Model;
use raoul2000\workflow\validation\WorkflowScenario;
/**
* ContactForm is the model behind the contact form.
@raoul2000
raoul2000 / Wizflow - the workflow
Created June 27, 2015 15:47
Defines the wizard steps
<?php
namespace app\models\wizflow;
use raoul2000\workflow\source\file\IWorkflowDefinitionProvider;
class Wizflow implements IWorkflowDefinitionProvider
{
public function getDefinition()
{
class WizflowController extends \yii\web\Controller
{
public function beforeAction($action)
{
if (parent::beforeAction($action)) {
Yii::setAlias('@workflowDefinitionNamespace','app\\models\\wizflow');
Yii::$app->set('workflowSource',[
'class' => '\raoul2000\workflow\source\file\WorkflowFileSource'
]);
@raoul2000
raoul2000 / Wizflow - the Manager
Last active August 29, 2015 14:23
The wizflow manager component is used by the controller to handle wizards steps
namespace app\components;
use Yii;
use raoul2000\workflow\base\Status;
use yii\base\Exception;
use yii\base\InvalidConfigException;
/**
* Implement the Wizard UI design pattern using yii2-workflow.
*/
// the model /////////////////////////////////////////////////////////////////////
class Post extends \yii\db\ActiveRecord
{
/**
* @inheritdoc
*/
public static function tableName()
{
return 'item';
@raoul2000
raoul2000 / gist:9133730
Last active August 29, 2015 13:56
create calendar
<?php
$dayNames = array(
0 => "Sunday",
1 => "Monday",
2 => "Tuesday",
3 => "Wednesday",
4 => "Thursday",
5 => "Friday",
6 => "Saturday"
);
@raoul2000
raoul2000 / gist:9132434
Created February 21, 2014 10:57
pick a random image from a folder
<?php
//This will get an array of all the gif, jpg and png images in a folder
$img_array = glob("/path/to/images/*.{gif,jpg,png}",GLOB_BRACE);
//Pick a random image from the array
$img = array_rand($img_array);
//Display the image on the page
echo '<img alt="'.$img_array[$img].'" src="'.$img_array[$img].'" />';
?>
@raoul2000
raoul2000 / gist:5532118
Created May 7, 2013 12:10
Initializing the simpleWorkflow behavior with 'transitionBeforeSave' set to false, will make all transition being fired AFTER the owner model is actually saved
<?php
class User extends CActiveRecord
{
public function behaviors()
{
return array(
'swBehavior' => array(
'class' => 'application.extensions.simpleWorkflow.SWActiveRecordBehavior',