示例#1
0
 /**
 Handles submission creation + Edit
 @param Controller Refrence to the controller object
 
 Handles the submission creation + Edit workflow by looking at the request
 Workflow
 
 1.A sumbission created is in the DRAFT Mode initially. 
 2.Submissions can be published by the user to be made visible to others
 3.Published submissions can only be deleted by the user
 	delete submissions go to the trash
 4.User can delete a submission from trash - thats not displayed to the user 
 	any more
 */
 public function handle_submission_create_edit($controller)
 {
     $errors = null;
     if ($this->status == self::STATUS_PUBLISHED) {
         $controller->show_info_message("You Can't Edit a published Entry");
         return $errors;
     } else {
         if (isset($_REQUEST['draft']) || isset($_REQUEST['publish'])) {
             if (!$this->loaded()) {
                 $errors = $this->create_from_request($_REQUEST);
                 if (!empty($errors)) {
                     $controller->add_activity_result($this->id);
                 }
             } else {
                 $errors = $this->update_info($_REQUEST);
             }
             $locker = new Model_Locker($controller->user);
             if (!empty($errors)) {
                 //if there are errors dont process the content
             } else {
                 if (isset($_REQUEST['text_content'])) {
                     $content = $locker->add_text_content($_REQUEST);
                     $this->add_content($content);
                 } else {
                     if (count($_FILES) > 0) {
                         $contentList = $locker->add_file_content($_FILES, $_REQUEST, $errors);
                         foreach ($contentList as $content) {
                             $this->add_content($content);
                         }
                     }
                 }
             }
             $this->status = self::STATUS_DRAFT;
             $this->modified_at = time();
             try {
                 $this->save();
             } catch (ORM_Validation_Exception $e) {
                 $errors = $e->errors('models');
                 return $errors;
             }
             $controller->show_info_message("Your changes are saved in draft Mode,");
         } else {
             if (isset($_REQUEST['remove'])) {
                 $assoc = ORM::factory('submission_content')->where('submission_id', '=', $this->id)->and_where('content_id', '=', $_REQUEST['remove'])->find();
                 if ($assoc->loaded()) {
                     $assoc->delete();
                 }
             }
         }
     }
     if (isset($_REQUEST['publish'])) {
         if ($this->loaded()) {
             $rule = null;
             if (!empty($this->stimulus_id)) {
                 $rule = ORM::factory('stimulus', $this->stimulus_id);
                 if (!$rule->loaded()) {
                     $rule = null;
                 }
             } else {
                 $rule = ORM::factory('genre', $this->default_genre_id);
                 if (!$rule->loaded()) {
                     $rule = null;
                 }
             }
             if (!empty($rule)) {
                 $content_list = $this->get_content_list();
                 $image_file_count = 0;
                 $video_file_count = 0;
                 $audio_file_count = 0;
                 $total_file_count = 0;
                 foreach ($content_list as $content) {
                     switch ($content->type) {
                         case 'text':
                             $text = $content->text_content;
                             $chars = strip_tags($text);
                             $chars = preg_replace('/ /', ' ', $chars);
                             $words = preg_split('[ ]', $chars);
                             //	echo "word count:".count($words). " chars: ".strlen($chars);
                             if ($rule->text_supported == 140 && strlen($chars) > 140) {
                                 $errors['text_content'] = "The Entry cannot be published as the number of characters  exceeds the limit {$rule->text_supported}";
                             }
                             if ($rule->text_supported == 1000 && count($words) > 100) {
                                 $errors['text_content'] = "The Entry cannot be published as the number of words exceeds the limit 100 words";
                             }
                             break;
                         case 'image':
                             $image_file_count++;
                             $total_file_count++;
                             break;
                         case 'video':
                             $video_file_count++;
                             $total_file_count++;
                             break;
                         case 'audio':
                             $audio_file_count++;
                             $total_file_count++;
                             break;
                     }
                 }
                 if ($rule->image_supported + $rule->video_supported + $rule->audio_supported > 0 && $total_file_count == 0) {
                     $errors['content_file'] = 'Please add file/s before publishing the content';
                 }
             }
             if (empty($errors)) {
                 $this->status = self::STATUS_PUBLISHED;
                 $controller->show_info_message("Your entry is now visible to public");
                 $controller->add_activity_result($this->id);
             }
             $this->save();
         }
     }
     return $errors;
 }
示例#2
0
文件: user.php 项目: kanikaN/qload
 /**
 Edit the user data based on the $_POST and $_FILE variables
 */
 public function edit($data)
 {
     $errors = array();
     $this->first_name = $data['first_name'];
     $this->last_name = $data['last_name'];
     $this->state = $data['state'];
     $this->city = $data['city'];
     $this->myself = @$data['myself'];
     if (isset($_FILES['content_file']) && $_FILES['content_file']['size'][0] > 0) {
         $locker = new Model_Locker($this);
         $list = $locker->add_file_content($_FILES, $_REQUEST, $errors);
         if (count($list) > 0) {
             $this->profile_pic = $list[0]->file_path;
             $this->profile_pic_id = $list[0]->id;
         }
     }
     if (isset($data['profile_pic'])) {
         $this->profile_pic = $data['profile_pic'];
     }
     if ($data['password'] == $data['confirm_password'] && $data['password'] != '') {
         $this->password = md5($data['password']);
         Session::instance()->delete("should_reset_password");
     } else {
         if ($data['password'] != '') {
             $errors['password'] = '******';
             $errors['confirm_password'] = '******';
         }
     }
     try {
         $this->save();
     } catch (ORM_Validation_Exception $e) {
         $e2 = $e->errors('models');
         array_merge($errors, $e2);
     }
     return $errors;
 }