/**
  * Load all Fields for second tab in popup window when creating /editing documenttemplate
  * @param sfWebRequest $request
  * @return <type>
  */
 public function executeLoadAllFields(sfWebRequest $request) {
     $fieldObj = new FieldClass();
     $result = FieldTable::instance()->getAllFields();
     $json_result = $fieldObj->buildField($result, $this->getContext());
     $this->renderText('({"result":'.json_encode($json_result).'})');
     return sfView::NONE;
 }
 public function toDialectString(Dialect $dialect)
 {
     if ($this->field instanceof SelectQuery || $this->field instanceof LogicalObject) {
         return '(' . $dialect->fieldToString($this->field) . ')';
     } else {
         return parent::toDialectString($dialect);
     }
 }
 /**
  * Load the Fields for a filter when a filter is executed
  *
  * @param sfWebRequest $filter,
  * @return array $result, contains the fields, for which will be searched
  */
 public function getFields(sfWebRequest $filter) {
     $result = array();
     $hasElements = true;
     $startAt = 0;
     $a = 0;
     if($filter->hasParameter('field0')) {
         while($hasElements) {
             if($filter->hasParameter('field'.$startAt) == true) {
                 $result[$a]['field'] = $filter->getParameter('field'.$startAt);
                 $result[$a]['operator'] = $filter->getParameter('operator'.$startAt);
                 $result[$a]['value'] = $filter->getParameter('value'.$startAt);
                 $fieldTable = FieldTable::instance()->getFieldById($result[$a]['field'])->toArray();
                 $result[$a]['type'] = $fieldTable[0]['type'];
                 $startAt++;
                 $a++;
             }
             else {
                 $hasElements = false;
             }
         }
     }
     else {
         return -1;
     }
     return $result;
 }
 /**
  *
  * Generates the columns for grid, in workflow overivew, todo and archvie
  *
  * @param array $data, columns
  * @param sfContext $context, context
  * @return array $result
  */
 public function generateUserWorklowView(array $data, sfContext $context) {
     sfLoader::loadHelpers('I18N');
     $a = 0;
     foreach($data as $item) {
         $result[$a]['columntext'] = $item['columntext'];
         $result[$a]['hidden'] = $item['isactive'] == 'true' ? 'false' : 'true';
         $result[$a]['fieldid'] = -1;
         $result[$a]['text'] = $context->getI18N()->__($item['columntext'] ,null,'systemsetting');
         switch($item['columntext']) {
             case 'NAME':
                 $result[$a]['store'] = 'name';
                 $result[$a]['width'] = '140';
                 break;
             case 'STATION':
                 $result[$a]['store'] = 'currentstation';
                 $result[$a]['width'] = '180';
                 break;
             case 'DAYS':
                 $result[$a]['store'] = 'stationrunning';
                 $result[$a]['width'] = '130';
                 break;
             case 'START':
                 $result[$a]['store'] = 'versioncreated_at';
                 $result[$a]['width'] = '120';
                 break;
             case 'SENDER':
                 $result[$a]['store'] = 'sendername';
                 $result[$a]['width'] = '200';
                 break;
             case 'TOTALTIME':
                 $result[$a]['store'] = 'currentlyrunning';
                 $result[$a]['width'] = '80';
                 break;
             case 'MAILINGLIST':
                 $result[$a]['store'] = 'mailinglisttemplate';
                 $result[$a]['width'] = '150';
                 break;
             case 'USERDEFINED1':
                 if($item['field_id'] != '' AND is_numeric($item['field_id']) == true AND $item['isactive'] == 'true') {
                     $fieldName = FieldTable::instance()->getFieldById($item['field_id']);
                     $result[$a]['text'] = $fieldName[0]->getTitle();
                     $result[$a]['store'] = 'userdefined1';
                     $result[$a]['fieldid'] = $item['field_id'];
                     $result[$a]['width'] = '100';
                 }
                 else {
                     $result[$a]['width'] = '100';
                     $result[$a]['store'] = 'userdefined1';
                 }
                 break;
             case 'USERDEFINED2':
                 if($item['field_id'] != '' AND is_numeric($item['field_id']) == true AND $item['isactive'] == 'true') {
                     $fieldName = FieldTable::instance()->getFieldById($item['field_id']);
                     $result[$a]['text'] = $fieldName[0]->getTitle();
                     $result[$a]['store'] = 'userdefined2';
                     $result[$a]['fieldid'] = $item['field_id'];
                     $result[$a]['width'] = '100';
                 }
                 else {
                     $result[$a]['width'] = '100';
                     $result[$a]['store'] = 'userdefined2';
                 }
                 break;
         }
         $a++;
     }
     //unset($result[7]);
     //unset($result[8]);
     return $result;
     
 }
 public function toDialectString(Dialect $dialect)
 {
     if ($this->field instanceof SelectQuery || $this->field instanceof LogicalObject) {
         $result = '(' . $dialect->fieldToString($this->field) . ')';
     } else {
         $result = parent::toDialectString($dialect);
     }
     $result .= $this->direction->decide(' ASC', ' DESC') . $this->nulls->decide(' NULLS FIRST', ' NULLS LAST');
     return $result;
 }
    /**
     * update a field
     * @param sfWebRequest $request
     * @return <type>
     */
    public function executeUpdateField(sfWebRequest $request) {
        $fieldType = FieldTable::instance()->getFieldById($request->getParameter('id'));
        $data = $request->getPostParameters();
        $fieldClass = new FieldClass();
        $data = $fieldClass->prepareSaveData($data); // prepare the data to save, set color and writeprotected flag
        FieldTable::instance()->updateFieldById($request->getParameter('id'), $data);
        switch ($fieldType[0]->getType()) {
            case 'TEXTFIELD':
                FieldTextfieldTable::instance()->updateFieldTextfieldById($request->getParameter('id'), $data);
                break;
            case 'CHECKBOX':
                break;
            case 'NUMBER':
                FieldNumberTable::instance()->updateFieldNumberById($request->getParameter('id'), $data);
                break;
            case 'DATE':
                FieldDateTable::instance()->updateFieldDateById($request->getParameter('id'), $data);
                break;
            case 'TEXTAREA':
                $data['fieldTextarea_content'] = $data['fieldTextarea_contenttype'] == 'plain' ? $data['fieldTextarea_textarea']: $data['fieldTextarea_htmlarea'];
                FieldTextareaTable::instance()->updateFieldTextareaById($request->getParameter('id'), $data);
                break;
            case 'RADIOGROUP':
                $fieldClass->saveRadiogroup($request->getParameter('id'), $data);
                break;
            case 'CHECKBOXGROUP':
                $fieldClass->saveCheckboxgroup($request->getParameter('id'), $data);
                break;
            case 'COMBOBOX':
                $fieldClass->saveCombobox($request->getParameter('id'), $data);
                break;
            case 'FILE':
                FieldFileTable::instance()->updateFieldFileById($request->getParameter('id'), $data);
                break;
        }
		$this->renderText('{success:true}');
        return sfView::NONE;
    }
    /**
     * Get userdefined field
     *
     * @param String  $type, userdefined1, userdefined2
     */
    public function getFields($type, $versionId) {
        $view = $this->user->getAttribute('userWorkflowSettings');
        $result = '';
        foreach($view as $singleView) {
            if($singleView['store'] == $type AND $singleView['fieldid'] > -1) {
                $wfItem = WorkflowVersionTable::instance()->getFieldByWorkflowversionIdAndFieldId($singleView['fieldid'], $versionId)->toArray();
                if(empty($wfItem) == true) {
                    return '';
                }
                else {
                    $slots = WorkflowSlotTable::instance()->getFieldBySlotIdAndFieldId($singleView['fieldid'], $versionId)->toArray();
                    $fields = WorkflowSlotFieldTable::instance()->getWorkflowSlotFieldBySlotIdAndFieldId($slots[0]['id'],$singleView['fieldid'])->toArray();
                    $theType = FieldTable::instance()->getFieldById($fields[0]['field_id'])->toArray();
                    if(!empty($theType)) {
                        switch ($theType[0]['type']) {
                            case 'TEXTFIELD':
                                $value = WorkflowSlotFieldTextfieldTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $result = $value[0]['value'];
                                return $result;
                                break;
                            case 'CHECKBOX':
                                $value = WorkflowSlotFieldCheckboxTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $result = $value[0]['value'] == 1 ? $this->context->getI18N()->__('Yes' ,null,'workflowmanagement') : $this->context->getI18N()->__('No' ,null,'workflowmanagement');
                                return $result;
                                break;
                            case 'NUMBER':
                                $value = WorkflowSlotFieldNumberTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $result = $value[0]['value'];
                                return $result;
                                break;
                            case 'DATE':
                                $value = WorkflowSlotFieldDateTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $result = $value[0]['value'];
                                return $result;
                                break;
                            case 'TEXTAREA':
                                $value = WorkflowSlotFieldTextareaTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $result = $value[0]['value'];
                                return $result;
                                break;
                            case 'RADIOGROUP':
                                $value = WorkflowSlotFieldRadiogroupTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $result = $value[0]['value'] == 1 ? $this->context->getI18N()->__('Yes' ,null,'workflowmanagement') : $this->context->getI18N()->__('No' ,null,'workflowmanagement');
                                return $result;
                                break;
                            case 'CHECKBOXGROUP':
                                $value = WorkflowSlotFieldCheckboxgroupTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $result = $value[0]['value'] == 1 ? $this->context->getI18N()->__('Yes' ,null,'workflowmanagement') : $this->context->getI18N()->__('No' ,null,'workflowmanagement');
                                return $result;
                                break;
                            case 'COMBOBOX':
                                $value = WorkflowSlotFieldComboboxTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $result = $value[0]['value'] == 1 ? $this->context->getI18N()->__('Yes' ,null,'workflowmanagement') : $this->context->getI18N()->__('No' ,null,'workflowmanagement');
                                return $result;
                                break;
                            case 'FILE':
                                $value = WorkflowSlotFieldFileTable::instance()->getAllItemsByWorkflowFieldId($fields[0]['id'])->toArray();
                                $url = (url_for('layout/index',true));
                                $url = str_replace('/layout', '', $url);
                                $result['filepath'] = $url . '/file/showAttachment/workflowid/' . $wfItem[0]['workflowtemplate_id'] . '/versionid/' . $wfItem[0]['id'] . '/attachmentid/' . $value[0]['id'] . '/file/1';
                                $fileUrl = '<a href="'.$result['filepath'].'">'.$value[0]['filename'].'</a>';
                                return $fileUrl;
                                break;

                        }
                    }
                    else {
                        return '';
                    }
                }
            }
        }
    }
 public function toDialectString(Dialect $dialect)
 {
     return parent::toDialectString($dialect) . ($this->alias ? ' AS ' . $dialect->quoteField($this->alias) : null);
 }