1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35:
36:
37: Yii::import('application.components.x2flow.X2FlowItem');
38: Yii::import('application.components.x2flow.actions.*');
39: Yii::import('application.components.x2flow.triggers.*');
40:
41: 42: 43:
44: class StudioController extends x2base {
45:
46: public $modelClass = 'X2Flow';
47:
48:
49: public function filters() {
50: return array(
51: 'setPortlets',
52:
53: );
54: }
55:
56:
57: public function behaviors(){
58: return array_merge (parent::behaviors () ,
59: array(
60: 'ImportExportBehavior' => array('class' => 'ImportExportBehavior'),
61: )
62: );
63: }
64:
65:
66: public function actions() {
67: if(file_exists(Yii::app()->getBasePath().'/components/FlowDesignerAction.php')) {
68: return array(
69: 'flowDesigner'=>array(
70: 'class'=>'FlowDesignerAction'
71: ),
72: );
73: }
74: return array();
75: }
76:
77:
78: public function actionFlowIndex() {
79: $this->render('flowIndex');
80: }
81:
82: public function actionTriggerLogs($pageSize=null) {
83: $triggerLogsDataProvider = new CActiveDataProvider('TriggerLog', array(
84: 'criteria' => array(
85: 'order' => 'triggeredAt DESC'
86: ),
87: 'pagination'=>array(
88: 'pageSize' => !empty($pageSize) ?
89: $pageSize :
90: Profile::getResultsPerPage()
91: ),
92: ));
93: $viewParams['triggerLogsDataProvider'] = $triggerLogsDataProvider;
94: $this->render('triggerLogs', array (
95: 'triggerLogsDataProvider' => $triggerLogsDataProvider
96: )
97: );
98: }
99:
100: public function actionDeleteFlow($id) {
101: $model = $this->loadModel($id);
102: $model->delete();
103: $this->redirect(array('flowIndex'));
104: }
105:
106: public function actionGetParams($name,$type) {
107: if($type === 'action') {
108: $paramRules = X2FlowAction::getParamRules($name);
109: } elseif($type === 'trigger') {
110: $paramRules = X2FlowTrigger::getParamRules($name);
111: } elseif($type === 'condition') {
112:
113: $paramRules = X2FlowTrigger::getGenericCondition($name);
114: } else {
115: $paramRules = false;
116: }
117:
118: if($paramRules !== false) {
119: if($type === 'condition') {
120: if(isset($paramRules['options']))
121: $paramRules['options'] = AuxLib::dropdownForJson($paramRules['options']);
122: } else {
123:
124: foreach($paramRules['options'] as &$option) {
125: if(isset($option['options']))
126: $option['options'] = AuxLib::dropdownForJson($option['options']);
127: }
128:
129: if (isset ($paramRules['suboptions'])) {
130: foreach($paramRules['suboptions'] as &$subOption) {
131: if(isset($subOption['options']))
132: $subOption['options'] = AuxLib::dropdownForJson(
133: $subOption['options']);
134: }
135: }
136: }
137: }
138: echo CJSON::encode($paramRules);
139: }
140:
141:
142: public function actionGetFields($model) {
143: if(!class_exists($model)) {
144: echo 'false';
145: return;
146: }
147: $fieldModels = X2Model::model($model)->getFields();
148: $fields = array();
149:
150: foreach($fieldModels as &$field) {
151: if($field->isVirtual)
152: continue;
153: $data = array(
154: 'name' => $field->fieldName,
155: 'label' => $field->attributeLabel,
156: 'type' => $field->type,
157: );
158:
159: if($field->required)
160: $data['required'] = 1;
161: if($field->readOnly)
162: $data['readOnly'] = 1;
163: if($field->type === 'assignment' || $field->type === 'optionalAssignment' ) {
164: $data['options'] = AuxLib::dropdownForJson(
165: X2Model::getAssignmentOptions(true, true));
166: if ($field->type === 'assignment')
167: $data['multiple'] = $field->linkType === 'multiple' ? 1 : 0;
168: } elseif($field->type === 'dropdown') {
169: $data['linkType'] = $field->linkType;
170: $dropdown = Dropdowns::model ()->findByPk ($field->linkType);
171: if (!$dropdown) continue;
172: $data['options'] = AuxLib::dropdownForJson(Dropdowns::getItems($field->linkType));
173: $data['multiple'] = $dropdown->multi ? 1 : 0;
174: }
175:
176: if($field->type === 'link') {
177: $staticLinkModel = X2Model::model($field->linkType);
178: if(array_key_exists('X2LinkableBehavior', $staticLinkModel->behaviors())) {
179: $data['linkType'] = $field->linkType;
180: $data['linkSource'] = Yii::app()->controller->createUrl(
181: $staticLinkModel->autoCompleteSource);
182: }
183: }
184:
185:
186: $fields[] = $data;
187: }
188: usort ($fields, function ($a, $b) {
189: return strcmp ($a['label'], $b['label']);
190: });
191: echo CJSON::encode($fields);
192: }
193:
194: public function actionDeleteAllTriggerLogs ($flowId) {
195: if (isset ($flowId)) {
196: $triggerLogs = TriggerLog::model()->findAllByAttributes (array (
197: 'flowId' => $flowId
198: ));
199: foreach ($triggerLogs as $log) {
200: $log->delete ();
201: }
202: echo "success";
203: } else {
204: echo "failure";
205: }
206: }
207:
208: public function actionDeleteAllTriggerLogsForAllFlows () {
209: $triggerLogs = TriggerLog::model()->findAll ();
210: foreach ($triggerLogs as $log) {
211: $log->delete ();
212: }
213: echo "success";
214: }
215:
216: public function actionDeleteTriggerLog ($id) {
217: if (isset ($id)) {
218: $triggerLog = TriggerLog::model()->findByAttributes (array (
219: 'id' => $id
220: ));
221: if (!empty ($triggerLog)) {
222: $triggerLog->delete ();
223: echo "success";
224: return;
225: }
226: }
227: echo "failure";
228: }
229:
230:
231:
232:
233:
234: }
235: