示例#1
0
 /**
  * Gets answer statistics
  *
  * @access public
  * @param int $ID
  * @param int $user
  * @return array
  */
 public static function getAnswerStatistics($ID, $user)
 {
     $answers = array();
     $quiz = ThemexCore::getPostRelations(0, $ID, 'quiz_lesson', true);
     if (!empty($quiz)) {
         $relations = explode(' ; ', ThemexCore::getUserRelations($user, $quiz, 'answers', true) . ' ');
         foreach ($relations as $relation) {
             $answer = array();
             $relation = explode(' , ', $relation);
             if (count($relation) == 3) {
                 $answer['question'] = themex_value($relation, 0);
                 $answer['answer'] = themex_value($relation, 1);
                 $answer['result'] = themex_value($relation, 2);
                 $answers[] = $answer;
             }
         }
     }
     return $answers;
 }
示例#2
0
 /**
  * Gets quiz questions
  *
  * @access public
  * @param int $ID
  * @return array
  */
 public static function getQuestions($ID)
 {
     $selection = absint(ThemexCore::getPostMeta($ID, 'quiz_selection'));
     $questions = themex_filter(ThemexCore::getPostMeta($ID, 'quiz_questions'));
     if (!empty($selection) && $selection < count($questions)) {
         $keys = ThemexCore::getUserRelations(get_current_user_id(), $ID, 'questions', true);
         if (!empty($keys)) {
             $keys = explode(',', $keys);
             $questions = array_intersect_key($questions, array_flip($keys));
         }
         if ($selection != count($questions)) {
             $questions = themex_shuffle($questions);
             $questions = array_slice($questions, 0, $selection);
             $keys = implode(',', array_keys($questions));
             ThemexCore::addUserRelation(get_current_user_id(), $ID, 'questions', $keys);
         }
     }
     return $questions;
 }
 /**
  * Renders option
  *
  * @access public
  * @param array $option
  * @return string
  */
 public static function renderOption($option)
 {
     global $post, $wp_registered_sidebars, $wp_locale;
     $out = '';
     //option wrapper
     if (!isset($option['wrap']) || $option['wrap']) {
         $parent = '';
         if (isset($option['parent'])) {
             $parent = 'data-parent="' . THEMEX_PREFIX . $option['parent']['id'] . '" ';
             $parent .= 'data-value="' . $option['parent']['value'] . '"';
         }
         $out .= '<div class="themex-option themex-' . str_replace('_', '-', $option['type']) . '" ' . $parent . '>';
         if (isset($option['name']) && $option['type'] != 'checkbox') {
             $out .= '<h3 class="themex-option-title">' . $option['name'] . '</h3>';
         }
     }
     //option before
     if (isset($option['before'])) {
         $out .= $option['before'];
     }
     //option description
     if (isset($option['description'])) {
         $out .= '<div class="themex-tooltip"><div class="themex-tooltip-icon"></div><div class="themex-tooltip-text">' . $option['description'] . '</div></div>';
     }
     //option attributes
     $attributes = '';
     if (isset($option['attributes'])) {
         foreach ($option['attributes'] as $name => $value) {
             $attributes .= $name . '="' . $value . '" ';
         }
     }
     //option value
     if (!isset($option['value'])) {
         $option['value'] = '';
         if (isset($option['id'])) {
             $option['value'] = themex_stripslashes(get_option($option['id']));
             if (($option['value'] === false || $option['value'] == '') && isset($option['default'])) {
                 $option['value'] = themex_stripslashes($option['default']);
             }
         } else {
             if (isset($option['default'])) {
                 $option['value'] = themex_stripslashes($option['default']);
             }
         }
     }
     switch ($option['type']) {
         //text field
         case 'text':
             $out .= '<input type="text" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />';
             break;
             //number field
         //number field
         case 'number':
             $out .= '<input type="number" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . abs(intval($option['value'])) . '" ' . $attributes . ' />';
             break;
             //date field
         //date field
         case 'date':
             $out .= '<input type="text" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" class="date-field" ' . $attributes . ' />';
             break;
             //hidden field
         //hidden field
         case 'hidden':
             $out .= '<input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />';
             break;
             //message field
         //message field
         case 'textarea':
             $out .= '<textarea id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . '>' . $option['value'] . '</textarea>';
             break;
             //checkbox
         //checkbox
         case 'checkbox':
             $checked = '';
             if ($option['value'] == 'true') {
                 $checked = 'checked="checked"';
             }
             $out .= '<input type="checkbox" id="' . $option['id'] . '" name="' . $option['id'] . '" value="true" ' . $checked . ' ' . $attributes . ' />';
             if (isset($option['name'])) {
                 $out .= '<label for="' . $option['id'] . '">' . $option['name'] . '</label>';
             }
             break;
             //colorpicker
         //colorpicker
         case 'color':
             $out .= '<input name="' . $option['id'] . '" id="' . $option['id'] . '" type="text" value="' . $option['value'] . '" class="themex-colorpicker" />';
             break;
             //uploader
         //uploader
         case 'uploader':
             $out .= '<input name="' . $option['id'] . '" id="' . $option['id'] . '" type="text" value="' . $option['value'] . '" ' . $attributes . ' />';
             $out .= '<a class="button themex-upload-button">' . __('Browse', 'academy') . '</a>';
             break;
             //multiple uploader
         //multiple uploader
         case 'attachments':
             if (empty($option['value']) || !is_array($option['value'])) {
                 $option['value'] = array('a' . uniqid() => array('title' => '', 'url' => '', 'type' => ''));
             }
             $out .= '<div class="themex-clone-pane"><input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="" />';
             foreach ($option['value'] as $key => $field) {
                 $out .= '<div class="themex-clone-item" id="' . $option['id'] . '_' . $key . '">';
                 $out .= '<a href="#" class="themex-button themex-remove-button themex-trigger" data-element="' . $option['id'] . '_' . $key . '" title="' . __('Remove', 'academy') . '"></a>';
                 $out .= '<a href="#" class="themex-button themex-clone-button themex-trigger" data-element="' . $option['id'] . '_' . $key . '" data-value="' . $key . '" title="' . __('Add', 'academy') . '"></a>';
                 $out .= ThemexInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][title]', 'type' => 'text', 'value' => themex_value($field, 'title'), 'wrap' => false, 'attributes' => array('placeholder' => __('Title', 'academy'))));
                 $out .= ThemexInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][type]', 'type' => 'select', 'value' => themex_value($field, 'type'), 'wrap' => false, 'options' => array('document' => __('Document', 'academy'), 'audio' => __('Audio', 'academy'), 'video' => __('Video', 'academy'))));
                 $out .= ThemexInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][status]', 'type' => 'select', 'value' => themex_value($field, 'status'), 'wrap' => false, 'options' => array('file' => __('File', 'academy'), 'link' => __('Link', 'academy'))));
                 $out .= ThemexInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][url]', 'type' => 'uploader', 'value' => themex_value($field, 'url'), 'attributes' => array('placeholder' => 'URL')));
                 $out .= '</div>';
             }
             $out .= '</div>';
             break;
             //images selector
         //images selector
         case 'select_image':
             foreach ($option['options'] as $name => $src) {
                 $out .= '<image src="' . $src . '" ';
                 if ($name == $option['value']) {
                     $out .= 'class="current"';
                 }
                 $out .= ' data-value="' . $name . '" />';
             }
             $out .= '<input type="hidden" name="' . $option['id'] . '" id="' . $option['id'] . '" value="' . $option['value'] . '" ' . $attributes . ' />';
             break;
             //custom dropdown
         //custom dropdown
         case 'select':
             $out .= '<select id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . '>';
             if (isset($option['options'])) {
                 foreach ($option['options'] as $name => $title) {
                     $selected = '';
                     if ($option['value'] != '' && ($name == $option['value'] || is_array($option['value']) && in_array($name, $option['value']))) {
                         $selected = 'selected="selected"';
                     }
                     $out .= '<option value="' . $name . '" ' . $selected . '>' . $title . '</option>';
                 }
             }
             $out .= '</select>';
             break;
             //fonts dropdown
         //fonts dropdown
         case 'select_font':
             $options = ThemexCore::$components['fonts'];
             asort($options);
             $out .= self::renderOption(array('id' => $option['id'], 'type' => 'select', 'wrap' => false, 'default' => $option['value'], 'options' => $options));
             break;
             //pages dropdown
         //pages dropdown
         case 'select_page':
             $args = array('selected' => $option['value'], 'echo' => 0, 'name' => $option['id'], 'id' => $option['id']);
             $out .= wp_dropdown_pages($args);
             break;
             //posts dropdown
         //posts dropdown
         case 'select_post':
             $atts = array('numberposts' => -1, 'post_type' => $option['post_type'], 'post_status' => array('publish', 'future', 'pending', 'draft'), 'orderby' => 'title', 'order' => 'ASC');
             if (isset($post) && isset($post->ID)) {
                 $atts['exclude'] = array($post->ID);
                 if ($option['post_type'] == 'lesson' && $post->post_type == 'lesson') {
                     $course = ThemexCore::getPostRelations($post->ID, 0, 'lesson_course', true);
                     $atts['include'] = array_diff(ThemexCore::getPostRelations(0, $course, 'lesson_course'), array($post->ID));
                 }
             }
             if ($option['post_type'] != 'product' && !current_user_can('manage_options')) {
                 $atts['author'] = get_current_user_id();
             }
             $items = get_posts($atts);
             $out .= '<select id="' . $option['id'] . '" name="' . $option['id'] . '" ' . $attributes . '>';
             $out .= '<option value="0">' . __('None', 'academy') . '</option>';
             foreach ($items as $item) {
                 $selected = '';
                 if ($item->ID == $option['value']) {
                     $selected = 'selected="selected"';
                 }
                 $out .= '<option value="' . $item->ID . '" ' . $selected . '>' . $item->post_title . '</option>';
             }
             $out .= '</select>';
             break;
             //sidebars dropdown
         //sidebars dropdown
         case 'select_sidebar':
             $sidebars = array();
             foreach ($wp_registered_sidebars as $sidebar) {
                 $sidebars[$sidebar['name']] = $sidebar['name'];
             }
             $out .= self::renderOption(array('id' => $option['id'], 'type' => 'select', 'wrap' => false, 'options' => $sidebars));
             break;
             //categories dropdown
         //categories dropdown
         case 'select_category':
             $args = array('hide_empty' => 0, 'echo' => 0, 'selected' => $option['value'], 'show_option_all' => __('None', 'academy'), 'hierarchical' => 0, 'name' => $option['id'], 'id' => $option['id'], 'depth' => 0, 'tab_index' => 0, 'taxonomy' => $option['taxonomy'], 'hide_if_empty' => false);
             if (isset($option['attributes'])) {
                 $args['class'] = $option['attributes']['class'];
             }
             $out .= wp_dropdown_categories($args);
             break;
             //range slider
         //range slider
         case 'slider':
             $out .= '<div class="themex-slider-controls"></div><div class="themex-slider-value"></div>';
             $out .= '<input type="hidden" class="slider-max" value="' . $option['max_value'] . '" />';
             $out .= '<input type="hidden" class="slider-min" value="' . $option['min_value'] . '" />';
             $out .= '<input type="hidden" class="slider-unit" value="' . $option['unit'] . '" />';
             $out .= '<input type="hidden" class="slider-value" name="' . $option['id'] . '" id="' . $option['id'] . '"  value="' . $option['value'] . '" />';
             break;
             //quiz questions
         //quiz questions
         case 'questions':
             if (empty($option['value']) || !is_array($option['value'])) {
                 $option['value'] = array('q' . uniqid() => array('title' => '', 'type' => ''));
             }
             $out .= '<div class="themex-clone-pane"><input type="hidden" id="' . $option['id'] . '" name="' . $option['id'] . '" value="" />';
             foreach ($option['value'] as $key => $field) {
                 $out .= '<div class="themex-clone-item" id="' . $option['id'] . '_' . $key . '">';
                 $out .= '<a href="#" class="themex-button themex-remove-button themex-trigger" data-element="' . $option['id'] . '_' . $key . '" title="' . __('Remove', 'academy') . '"></a>';
                 $out .= '<a href="#" class="themex-button themex-clone-button themex-trigger" data-value="' . $key . '" title="' . __('Add', 'academy') . '"></a>';
                 $out .= ThemexInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][title]', 'type' => 'text', 'value' => htmlspecialchars(themex_value($field, 'title')), 'wrap' => false, 'attributes' => array('placeholder' => __('Question', 'academy'))));
                 $out .= ThemexInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][type]', 'type' => 'select', 'value' => themex_value($field, 'type'), 'wrap' => false, 'options' => array('single' => __('Single Choice', 'academy'), 'multiple' => __('Multiple Choice', 'academy'), 'string' => __('Short Answer', 'academy'))));
                 if (!isset($field['answers']) || empty($field['answers'])) {
                     $field['answers'] = array('a' . uniqid() => array('title' => ''));
                 }
                 foreach ($field['answers'] as $index => $answer) {
                     $out .= '<div class="themex-clone-item clearfix" id="' . $option['id'] . '_' . $key . '_' . $index . '">';
                     $out .= '<a href="#" class="themex-button themex-remove-button themex-trigger" data-element="' . $option['id'] . '_' . $key . '_' . $index . '" title="' . __('Remove', 'academy') . '"></a>';
                     $out .= '<a href="#" class="themex-button themex-clone-button themex-trigger" data-element="' . $option['id'] . '_' . $key . '_' . $index . '" data-value="' . $index . '" title="' . __('Add', 'academy') . '"></a>';
                     $out .= ThemexInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][answers][' . $index . '][title]', 'type' => 'text', 'value' => htmlspecialchars(themex_value($answer, 'title')), 'wrap' => false, 'attributes' => array('placeholder' => __('Answer', 'academy'))));
                     $out .= ThemexInterface::renderOption(array('id' => $option['id'] . '[' . $key . '][answers][' . $index . '][result]', 'type' => 'checkbox', 'value' => themex_value($answer, 'result'), 'wrap' => false));
                     $out .= '</div>';
                 }
                 $out .= '</div>';
             }
             $out .= '</div>';
             break;
             //users manager
         //users manager
         case 'users':
             $users = ThemexCore::getUserRelations(0, $post->ID, $post->post_type);
             $out .= '<div class="themex-row clearfix">';
             $out .= wp_dropdown_users(array('echo' => false, 'exclude' => $users, 'name' => 'add_user_id', 'id' => 'add_user_id'));
             $out .= '<input type="submit" name="add_user" class="button" value="' . __('Add', 'academy') . '" /></div>';
             if (!empty($users)) {
                 $out .= '<div class="themex-row clearfix">';
                 $out .= wp_dropdown_users(array('echo' => false, 'include' => $users, 'name' => 'remove_user_id', 'id' => 'remove_user_id'));
                 $out .= '<input type="submit" name="remove_user" class="button" value="' . __('Remove', 'academy') . '" /></div>';
             }
             break;
             //module settings
         //module settings
         case 'module':
             $out .= '<div class="' . substr(strtolower(implode('-', preg_split('/(?=[A-Z])/', str_replace(THEMEX_PREFIX, '', $option['id'])))), 1) . '">';
             if (isset($option['slug'])) {
                 $out .= call_user_func(array(str_replace(THEMEX_PREFIX, '', $option['id']), 'renderSettings'), $option['slug']);
             } else {
                 $out .= call_user_func(array(str_replace(THEMEX_PREFIX, '', $option['id']), 'renderSettings'));
             }
             $out .= '</div>';
             break;
     }
     //option after
     if (isset($option['after'])) {
         $out .= $option['after'];
     }
     //wrap option
     if (!isset($option['wrap']) || $option['wrap']) {
         $out .= '</div>';
     }
     return $out;
 }
示例#4
0
 /**
  * Removes user relation
  *
  * @access public
  * @param int $ID
  * @param array $data
  * @return void
  */
 public static function removeRelation($ID, $data)
 {
     $relation = themex_value('relation_id', $data);
     $type = themex_value('relation_type', $data);
     if (in_array($type, array('shop', 'product'))) {
         ThemexCore::removeUserRelation($ID, $relation, $type);
         if ($type == 'shop') {
             $relations = count(ThemexCore::getUserRelations(0, $relation, 'shop'));
             ThemexCore::updatePostMeta($relation, 'admirers', $relations);
         }
     }
     die;
 }