Exemple #1
0
 private function saveAttachment(Model_Attachment $attachment, View_Html $view)
 {
     if (isset($_REQUEST['save'])) {
         $attachment->setData($_POST);
         if (!($errors = $attachment->validate())) {
             if ($_FILES && $_FILES['attach']) {
                 if (!$attachment->uploadFile($_FILES['attach'])) {
                     $errors['attach'] = 'File attachment failed.';
                     return false;
                 }
             }
             $attachment->save();
             $attachment->getRights()->setRights($_POST['rights'], $_POST['owner'], $_POST['group'])->save();
             $view->redir('Admin_Article', 'edit', array('id' => $attachment->article));
             return true;
         }
         $view->errors = $errors;
     }
     return false;
 }
Exemple #2
0
 public function add_file($input_arr)
 {
     $current_time = date("Y-m-d H:i:s");
     //$ticket_id=$input_arr['ticket_id'];
     $name = $input_arr['name'];
     $size = $input_arr['size'];
     $uploader = $input_arr['uploader'];
     $created_at = $current_time;
     $updated_at = $current_time;
     $is_deleted = '0';
     $local_filepath = $input_arr['local_filepath'];
     $attachment = new Model_Attachment();
     $attachment->ticket_id = $ticket_id;
     $attachment->name = $name;
     $attachment->size = $size;
     $attachment->uploader = $uploader;
     $attachment->created_at = $created_at;
     $attachment->updated_at = $updated_at;
     $attachment->is_deleted = $is_deleted;
     $attachment->local_filepath = $local_filepath;
     $attachment->save();
     return $attachment->id;
 }
Exemple #3
0
 private function saveArticle(Model_Article $article, View_Html $view)
 {
     if (isset($_REQUEST['save'])) {
         foreach (array("published", "archived") as $name) {
             $_POST[$name] = Filter_Date::fromString($_POST[$name]);
         }
         if (!isset($_POST['flags'])) {
             $_POST['flags'] = array();
         }
         $article->setData($_POST);
         if (!($errors = $article->validate())) {
             $article->save();
             $article->getRights()->setRights($_POST['rights'], $_POST['owner'], $_POST['group'])->save();
             $article->dropTags();
             $tags = isset($_POST['tag']) ? $_POST['tag'] : (isset($_POST['tags']) ? explode(", ", $_POST['tags']) : null);
             Model_Tag::setAutoCreate();
             if ($tags) {
                 $article->addTags($tags);
             }
             if ($_FILES && $_FILES["attach"]) {
                 $store = $this->getStorage();
                 foreach ($_FILES["attach"]["name"] as $index => $name) {
                     $attachment = new Model_Attachment($store);
                     $file = array('name' => $name, 'tmp_name' => $_FILES['attach']['tmp_name'][$index], 'error' => $_FILES['attach']['error'][$index], 'size' => $_FILES['attach']['size'][$index], 'type' => $_FILES['attach']['type'][$index]);
                     if ($attachment->uploadFile($file)) {
                         $attachment->attachTo($article);
                         $attachment->save();
                     }
                 }
             }
             $view->redir('Admin_Topic', 'default', array('id' => $article->topic));
             return true;
         }
         $view->errors = $errors;
     }
     return false;
 }
Exemple #4
0
 public function attach(Model_Attachment $attachment)
 {
     $attachment->article = $this->getId();
     $attachment->save();
     return $this;
 }