Ejemplo n.º 1
0
 public function getName()
 {
     if (null === $this->name && $this->column) {
         $this->name = $this->column->getName();
     }
     return $this->name;
 }
Ejemplo n.º 2
0
 /**
  * get custom field data
  *
  * @internal
  * @param string $infoType
  * @param string $productId
  * @return array
  */
 private function getCustomFieldData($infoType, $productId)
 {
     $data = array();
     $fields = FieldConfig::model()->findAllByAttributes(array('product_id' => $productId, 'is_dropped' => false, 'type' => ucfirst($infoType)));
     foreach ($fields as $field) {
         switch ($field->field_type) {
             case FieldConfig::FIELD_TYPE_SINGLESELECT:
             case FieldConfig::FIELD_TYPE_SINGLEUSER:
                 $data[] = array('title' => Yii::t('Report', '{type} per {group}', array('{type}' => ucfirst($infoType), '{group}' => $field->field_label)), 'type' => Report::TYPE_BAR, 'group' => $field->field_name, 'infoType' => $infoType);
                 break;
             case FieldConfig::FIELD_TYPE_DATE:
                 $data[] = array('title' => Yii::t('Report', '{type} {group} per day', array('{type}' => ucfirst($infoType), '{group}' => $field->field_label)), 'type' => Report::TYPE_COLUMN, 'where' => $field->field_name . ' IS NOT NULL', 'group' => 'DATE_FORMAT(' . $field->field_name . ', "%Y-%m-%d")', 'order' => Report::GROUP_LABEL, 'asc' => false, 'limit' => 90, 'showOther' => false, 'showTable' => false, 'reverse' => true, 'infoType' => $infoType);
                 $data[] = array('title' => Yii::t('Report', '{type} {group} per week', array('{type}' => ucfirst($infoType), '{group}' => $field->field_label)), 'type' => Report::TYPE_COLUMN, 'where' => $field->field_name . ' IS NOT NULL', 'group' => 'DATE_FORMAT(DATE_SUB(' . $field->field_name . ', INTERVAL (if(DATE_FORMAT(' . $field->field_name . ', "%w") = 0,7,DATE_FORMAT(' . $field->field_name . ', "%w")))-1 DAY), "%Y-%m-%d")', 'order' => Report::GROUP_LABEL, 'asc' => true, 'limit' => 0, 'showTable' => false, 'infoType' => $infoType);
                 $data[] = array('title' => Yii::t('Report', '{type} {group} per month', array('{type}' => ucfirst($infoType), '{group}' => $field->field_label)), 'type' => Report::TYPE_COLUMN, 'where' => $field->field_name . ' IS NOT NULL', 'group' => 'DATE_FORMAT(' . $field->field_name . ', "%Y-%m")', 'order' => Report::GROUP_LABEL, 'asc' => true, 'limit' => 0, 'showTable' => false, 'infoType' => $infoType);
                 break;
             default:
                 break;
         }
     }
     return $data;
 }
Ejemplo n.º 3
0
 /**
  * Returns value of specified column from row.
  *
  * @param FieldConfig|string $field
  * @return mixed
  */
 public function getCellValue($field)
 {
     $fieldName = $field instanceof FieldConfig ? $field->getName() : $field;
     return $this->extractCellValue($fieldName);
 }
Ejemplo n.º 4
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct('ID', 'Id');
 }
Ejemplo n.º 5
0
 /**
  * This function render the single field
  * @global type $post
  * @param type $field
  * @param type $add2form_content
  * @return type
  */
 public function renderField($field, $add2form_content = false)
 {
     global $post;
     //echo "<br>{$field['name']}";
     if (defined('WPTOOLSET_FORMS_ABSPATH') && function_exists('wptoolset_form_field')) {
         require_once WPTOOLSET_FORMS_ABSPATH . '/api.php';
         require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.fieldconfig.php';
         require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.types.php';
         require_once WPTOOLSET_FORMS_ABSPATH . '/classes/class.cred.php';
         $id = $this->form_id;
         $field['id'] = $id;
         if ($field['type'] == 'messages') {
             $this->isForm = true;
             return;
         }
         if ($this->form_type == 'edit' && $field['name'] == 'user_login') {
             $field['attr']['readonly'] = "readonly";
             $field['attr']['style'] = "background-color:#ddd;";
             $field['attr']['onclick'] = "blur();";
         }
         if ($field['type'] == 'credfile' || $field['type'] == 'credaudio' || $field['type'] == 'credvideo' || $field['type'] == 'credimage' || $field['type'] == 'file') {
             $this->isUploadForm = true;
             //$field['type'] = 'credfile';
         }
         /* $validation = array(
            'validation' => array(
            'required' => array(
            'args' => array($field['value'], true),
            'message' => 'Required'),
            'maxlength' => array(
            'args' => array($field['value'], 12),
            'message' => 'maxlength of 12 exceeded'
            ),
            'rangelength' => array(
            'args' => array($field['value'], 3, 25),
            'message' => 'input range from 3 to 25'
            ),
            )); */
         //#############################################################################################################################################################
         //Client-side validation is not using the custom messages provided in CRED forms for CRED custom fields
         //https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/187800735/comments
         $this->fixCredCustomFieldMessages($field);
         //#############################################################################################################################################################
         $mytype = $this->transType($field['type']);
         $fieldConfig = new FieldConfig();
         $fieldConfig->setDefaultValue($field['type'], $field);
         $fieldConfig->setOptions($field['name'], $field['type'], $field['value'], $field['attr']);
         $fieldConfig->setId($this->form_properties['name'] . "_" . $field['name']);
         $fieldConfig->setName($field['name']);
         $this->cleanAttr($field['attr']);
         $fieldConfig->setAttr($field['attr']);
         $_curr_value = "";
         //#############################################################################################################################################################
         //Fix https://icanlocalize.basecamphq.com/projects/7393061-toolset/todo_items/192427784/comments#300129108
         //losting filled data if using hook validate system
         if (isset($this->controls[$field['name']]) && !empty($this->controls[$field['name']])) {
             $_curr_value = $this->controls[$field['name']];
         } else {
             if (isset($field['value']) && !empty($field['value'])) {
                 $_curr_value = $field['value'];
             }
         }
         //#############################################################################################################################################################
         if (!$this->is_submit_success && ($mytype != 'credfile' && $mytype != 'credaudio' && $mytype != 'credvideo' && $mytype != 'credimage')) {
             $_curr_value = isset($this->controls[$field['name']]) ? $this->controls[$field['name']] : $field['value'];
         } else {
             if (isset($field['attr']['preset_value']) && !empty($field['attr']['preset_value'])) {
                 $_curr_value = $field['attr']['preset_value'];
             }
         }
         $fieldConfig->setValue($_curr_value);
         $fieldConfig->setDescription(!empty($field['description']) ? $field['description'] : "");
         $fieldConfig->setTitle($field['title']);
         $fieldConfig->setType($mytype);
         if (isset($field['data']) && isset($field['data']['repetitive'])) {
             $fieldConfig->setRepetitive((bool) $field['data']['repetitive']);
         }
         if (isset($field['attr']) && isset($field['attr']['type'])) {
             $fieldConfig->setDisplay($field['attr']['type']);
         }
         $config = $fieldConfig->createConfig();
         // Modified by Srdjan
         // Validation and conditional filtering
         if (isset($field['plugin_type']) && $field['plugin_type'] == 'types') {
             // This is not set in DB
             $field['meta_key'] = WPToolset_Types::getMetakey($field);
             $config['validation'] = WPToolset_Types::filterValidation($field);
             if ($post) {
                 $config['conditional'] = WPToolset_Types::filterConditional($field, $post->ID);
             }
         } else {
             $config['validation'] = WPToolset_Cred::filterValidation($field);
         }
         // Modified by Srdjan END
         $_values = array();
         if (isset($field['data']['repetitive']) && $field['data']['repetitive'] == 1) {
             //$_values = $field['value'];
             $_values = $_curr_value;
         } else {
             //$_values = array($field['value']);
             $_values = array($_curr_value);
         }
         // Added by Srdjan
         /*
          * Use $_validation_errors
          * set in $this::validate()
          */
         if (isset($this->_validation_errors['fields'][$config['id']])) {
             $config['validation_error'] = $this->_validation_errors['fields'][$config['id']];
         }
         if ($this->form_type == 'edit' && $mytype == 'checkbox') {
             unset($config['default_value']);
         }
         // Added by Srdjan END
         $html = wptoolset_form_field($this->form_id, $config, $_values);
         if ($add2form_content) {
             $this->_form_content .= $html;
         } else {
             return $html;
         }
         /*
          <input id="cred_form_853_1__cred_cred_wpnonce" type="hidden" user_defined="" value="d9f46d7082" name="_cred_cred_wpnonce">
          <input id="cred_form_853_1__cred_cred_prefix_form_id" type="hidden" user_defined="" value="853" name="_cred_cred_prefix_form_id">
          <input id="cred_form_853_1__cred_cred_prefix_form_count" type="hidden" user_defined="" value="1" name="_cred_cred_prefix_form_count">
          <input id="cred_form_853_1_name_cred_form_853_1" type="hidden" user_defined="" value="cred_form_853_1" name="name_cred_form_853_1">
         */
     }
 }
Ejemplo n.º 6
0
 private static function checkSingleField($fieldInfo, $sourceFieldArr)
 {
     $checkResultStr = '';
     $sourceMatchedInfo = array();
     foreach ($sourceFieldArr as $souceFieldInfo) {
         if ($souceFieldInfo['field_name'] == $fieldInfo['field_name']) {
             $sourceMatchedInfo = $souceFieldInfo;
             break;
         }
     }
     if (empty($sourceMatchedInfo)) {
         $checkResultStr = "[{$fieldInfo['field_name']}]" . Yii::t('Common', 'is not existed') . "\n";
     } else {
         $compareAttributeArr = array('field_type', 'edit_in_result', 'validate_rule');
         foreach ($compareAttributeArr as $attribute) {
             if (trim($sourceMatchedInfo[$attribute]) != trim($fieldInfo[$attribute])) {
                 $checkResultStr .= '[' . $fieldInfo['field_name'] . '][' . FieldConfig::model()->getAttributeLabel($attribute) . '] ' . Yii::t('Common', 'is different') . "\n";
             }
         }
         if (0 < count(array_diff(CommonService::splitStringToArray(',', $sourceMatchedInfo['field_value']), CommonService::splitStringToArray(',', $fieldInfo['field_value'])))) {
             $checkResultStr .= '[' . $fieldInfo['field_name'] . '][' . FieldConfig::model()->getAttributeLabel('field_value') . '] ' . Yii::t('Common', 'is different') . "\n";
         }
         if (FieldConfig::VALIDATION_RULE_MATCH == $fieldInfo['validate_rule']) {
             if ($fieldInfo['match_expression'] != $sourceMatchedInfo['match_expression']) {
                 $checkResultStr .= '[' . $fieldInfo['field_name'] . '][' . FieldConfig::model()->getAttributeLabel('match_expression') . '] ' . Yii::t('Common', 'is different') . "\n";
             }
         }
     }
     return $checkResultStr;
 }