/php/webservices/content_object/create.class.php
PHP | 193 lines | 166 code | 27 blank | 0 comment | 10 complexity | 1efe7ffff4f4465943b4bc4a81036b0d MD5 | raw file
- <?php
-
- namespace repository;
-
- use common\libraries\Translation;
- use common\libraries\CreateObjectWebserviceHandler;
- use common\libraries\DataClass;
- use common\libraries\EqualityCondition;
- use repository\content_object\assessment_multiple_choice_question\AssessmentMultipleChoiceQuestion;
- use repository\content_object\assessment_multiple_choice_question\AssessmentMultipleChoiceQuestionOption;
- use repository\content_object\assessment_matching_question\AssessmentMatchingQuestion;
- use repository\content_object\assessment_matching_question\AssessmentMatchingQuestionOption;
- use repository\content_object\assessment_match_numeric_question\AssessmentMatchNumericQuestion;
- use repository\content_object\assessment_match_numeric_question\AssessmentMatchNumericQuestionOption;
- use repository\content_object\assessment_match_text_question\AssessmentMatchTextQuestion;
- use repository\content_object\assessment_match_text_question\AssessmentMatchTextQuestionOption;
- use repository\content_object\assessment_matrix_question\AssessmentMatrixQuestion;
- use repository\content_object\assessment_matrix_question\AssessmentMatrixQuestionOption;
- use repository\content_object\assessment_select_question\AssessmentSelectQuestion;
- use repository\content_object\assessment_select_question\AssessmentSelectQuestionOption;
- use repository\content_object\document\Document;
-
- class ContentObjectCreateWebserviceHandler extends CreateObjectWebserviceHandler
- {
-
- function get_object()
- {
- $data = $this->get_data();
- $type = $data[self :: PROPERTIES][DataClass :: PROPERTIES_DEFAULT][ContentObject :: PROPERTY_TYPE];
-
- $content_object = ContentObject :: factory($type);
- if ($content_object instanceof ContentObject)
- {
- return $content_object;
- }
-
- return false;
- }
-
- function get_object_translation()
- {
- return Translation :: get('ContentObject');
- }
-
- function is_allowed_to_create_object($object)
- {
- if ($this->get_user()->is_platform_admin() || $object->get_parent_id() == 0)
- {
- return true;
- }
- $condition = new EqualityCondition(RepositoryCategory :: PROPERTY_ID, $object->get_parent_id());
- $category = RepositoryDataManager :: get_instance()->retrieve_categories($condition)->next_result();
- if ($category)
- {
- return ($category->get_user_id() == $this->get_user_id());
- }
- return false;
- }
-
- function manipulate_data($object, $extra = null)
- {
- $object->set_owner_id($this->get_user_id());
-
- if (! empty($extra) || $_FILES['file']['size'] > 0)
- {
- switch ($object->get_type())
- {
- case AssessmentMatchingQuestion :: get_type_name() :
- $object = $this->process_assessment_matching_question($object, $extra);
- break;
-
- case AssessmentMatchNumericQuestion :: get_type_name() :
- $object = $this->process_assessment_match_numeric_question($object, $extra);
- break;
-
- case AssessmentMatchTextQuestion :: get_type_name() :
- $object = $this->process_assessment_match_text_question($object, $extra);
- break;
-
- case AssessmentMultipleChoiceQuestion :: get_type_name() :
- $object = $this->process_assessment_multiple_choice_question($object, $extra);
- break;
-
- case AssessmentMatrixQuestion :: get_type_name() :
- $object = $this->process_assessment_matrix_question($object, $extra);
- break;
-
- case AssessmentSelectQuestion :: get_type_name() :
- $object = $this->process_assessment_select_question($object, $extra);
- break;
-
- case Document :: get_type_name() :
- $object = $this->process_document($object, $extra);
- break;
-
- default :
- return false;
- }
- }
-
- return $object;
- }
-
- private function process_assessment_multiple_choice_question($object, $extra)
- {
- $options = array();
- foreach ($extra[AssessmentMultipleChoiceQuestion :: PROPERTY_OPTIONS] as $option_array)
- {
- $option = new AssessmentMultipleChoiceQuestionOption($option_array[AssessmentMultipleChoiceQuestionOption :: PROPERTY_VALUE], $option_array[AssessmentMultipleChoiceQuestionOption :: PROPERTY_CORRECT], $option_array[AssessmentMultipleChoiceQuestionOption :: PROPERTY_SCORE], $option_array[AssessmentMultipleChoiceQuestionOption :: PROPERTY_FEEDBACK]);
- $options[] = $option;
- }
- $object->set_options($options);
- return $object;
- }
-
- private function process_assessment_matching_question($object, $extra)
- {
- $options = array();
- foreach ($extra[AssessmentMatchingQuestion :: PROPERTY_OPTIONS] as $option_array)
- {
- $option = new AssessmentMatchingQuestionOption($option_array[AssessmentMatchingQuestionOption :: PROPERTY_VALUE], $option_array[AssessmentMatchingQuestionOption :: PROPERTY_MATCH], $option_array[AssessmentMatchingQuestionOption :: PROPERTY_SCORE], $option_array[AssessmentMatchingQuestionOption :: PROPERTY_FEEDBACK]);
- $options[] = $option;
- }
- $object->set_options($options);
- $object->set_matches($extra[AssessmentMatchingQuestion :: PROPERTY_MATCHES]);
- return $object;
- }
-
- private function process_assessment_match_numeric_question($object, $extra)
- {
- $options = array();
- foreach ($extra[AssessmentMatchNumericQuestion :: PROPERTY_OPTIONS] as $option_array)
- {
- $option = new AssessmentMatchNumericQuestionOption($option_array[AssessmentMatchNumericQuestionOption :: PROPERTY_VALUE], $option_array[AssessmentMatchNumericQuestionOption :: PROPERTY_TOLERANCE], $option_array[AssessmentMatchNumericQuestionOption :: PROPERTY_SCORE], $option_array[AssessmentMatchNumericQuestionOption :: PROPERTY_FEEDBACK]);
- $options[] = $option;
- }
- $object->set_options($options);
- return $object;
- }
-
- private function process_assessment_match_text_question($object, $extra)
- {
- $options = array();
- foreach ($extra[AssessmentMatchTextQuestion :: PROPERTY_OPTIONS] as $option_array)
- {
- $option = new AssessmentMatchTextQuestionOption($option_array[AssessmentMatchTextQuestionOption :: PROPERTY_VALUE], $option_array[AssessmentMatchTextQuestionOption :: PROPERTY_SCORE], $option_array[AssessmentMatchTextQuestionOption :: PROPERTY_FEEDBACK]);
- $options[] = $option;
- }
- $object->set_options($options);
- return $object;
- }
-
- private function process_assessment_matrix_question($object, $extra)
- {
- $options = array();
- foreach ($extra[AssessmentMatrixQuestion :: PROPERTY_OPTIONS] as $option_array)
- {
- $option = new AssessmentMatrixQuestionOption($option_array[AssessmentMatrixQuestionOption :: PROPERTY_VALUE], $option_array[AssessmentMatrixQuestionOption :: PROPERTY_MATCHES], $option_array[AssessmentMatrixQuestionOption :: PROPERTY_SCORE], $option_array[AssessmentMatrixQuestionOption :: PROPERTY_FEEDBACK]);
- $options[] = $option;
- }
- $object->set_options($options);
- $object->set_matches($extra[AssessmentMatrixQuestion :: PROPERTY_MATCHES]);
- return $object;
- }
-
- private function process_assessment_select_question($object, $extra)
- {
- $options = array();
- foreach ($extra[AssessmentSelectQuestion :: PROPERTY_OPTIONS] as $option_array)
- {
- $option = new AssessmentSelectQuestionOption($option_array[AssessmentSelectQuestionOption :: PROPERTY_VALUE], $option_array[AssessmentSelectQuestionOption :: PROPERTY_CORRECT], $option_array[AssessmentSelectQuestionOption :: PROPERTY_SCORE], $option_array[AssessmentSelectQuestionOption :: PROPERTY_FEEDBACK]);
- $options[] = $option;
- }
- $object->set_options($options);
- return $object;
- }
-
- private function process_document($object, $extra)
- {
- if ($extra['file'])
- {
- $object->set_in_memory_file(base64_decode($extra['file']));
- }
- else
- {
- $object->set_temporary_file_path($_FILES['file']['tmp_name']);
- }
- return $object;
- }
-
- }
-
- ?>