コード例 #1
0
 function lookup($var, $tid = 0)
 {
     $id = is_numeric($var) ? $var : self::getIdByFileHash($var, $tid);
     return $id && is_numeric($id) && ($attach = new Attachment($id, $tid)) && $attach->getId() == $id ? $attach : null;
 }
コード例 #2
0
ファイル: Connection.php プロジェクト: stingmu/youtrack
 /**
  * Deletes an attachment
  *
  * @param Issue $issue
  * @param Attachment $attachment
  * @return bool
  * @throws Exception
  * @throws NotAuthorizedException
  * @throws NotFoundException
  * @throws \Exception
  */
 public function deleteAttachment(Issue $issue, Attachment $attachment)
 {
     $issueId = $issue->getId();
     $attachmentId = $attachment->getId();
     $result = $this->request('DELETE', '/issue/' . rawurlencode($issueId) . '/attachment/' . rawurlencode($attachmentId));
     $response = $result['response'];
     if ($response['http_code'] == 200) {
         return true;
     }
     return false;
 }
コード例 #3
0
 function move_to()
 {
     $gettype = $_GET['gettype'];
     $team_id = $_GET['team_id'];
     $project_id = $_GET['project_id'];
     $ticket_id = $_GET['ticket_id'];
     $move_to_object_id = $_GET['move_to_object_id'];
     if (!empty($gettype)) {
         $this->smarty->assign('gettype', $gettype);
         switch ($gettype) {
             case 'projects':
                 $projects = array();
                 if (!empty($team_id)) {
                     $project_obj = new Project($team_id);
                     //$projects = Milestones::findByProject($project_obj, $this->logged_user);
                     $projects = Milestones::findActiveByProject($project_obj, STATE_VISIBLE, VISIBILITY_NORMAL, 'name', '', '-1');
                 }
                 $this->smarty->assign('projects', $projects);
                 break;
             case 'tickets':
                 $tickets = array();
                 if (!empty($project_id)) {
                     $milestone_obj = new Milestone($project_id);
                     //$tickets = Tickets::findByMilestone($milestone_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                     $tickets = Tickets::findOpenByMilestone($milestone_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                 }
                 $this->smarty->assign('tickets', $tickets);
                 break;
             case 'pages':
                 $pages_with_milestone = array();
                 $pages_with_project = array();
                 if (!empty($team_id)) {
                     $project_obj = new Project($team_id);
                     //$pages_with_project = Pages::findByProjectWithoutMilestoneAssociation($project_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                     $pages_with_project = Pages::findUnarchivedByProjectWithoutMilestoneAssociation($project_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                 } elseif (!empty($project_id)) {
                     if (!empty($project_id)) {
                         $milestone_obj = new Milestone($project_id);
                         $team_id = $milestone_obj->getProjectId();
                         //$pages_with_milestone = Pages::findByMilestone($milestone_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                         $pages_with_milestone = Pages::findUnarchivedByMilestone($milestone_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                         $project_obj = new Project($team_id);
                         //$pages_with_project = Pages::findByProjectWithoutMilestoneAssociation($project_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                         $pages_with_project = Pages::findUnarchivedByProjectWithoutMilestoneAssociation($project_obj, STATE_VISIBLE, $this->logged_user->getVisibility());
                     }
                 }
                 $this->smarty->assign('pages_with_milestone', $pages_with_milestone);
                 $this->smarty->assign('pages_with_project', $pages_with_project);
                 break;
             case 'action':
                 $move_to_object = new ProjectObject($move_to_object_id);
                 $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
                 mysql_select_db(DB_NAME);
                 mysql_query("update healingcrystals_attachments set parent_id='" . $move_to_object->getId() . "', parent_type='" . $move_to_object->getType() . "' where id='" . $this->active_attachment->getId() . "'");
                 mysql_close($link);
                 $type = $move_to_object->getType();
                 $obj = new $type($move_to_object_id);
                 $link = 'Attachment Moved: <a href="' . $obj->getViewUrl() . '">Click to View</a>';
                 $this->smarty->assign('link', $link);
                 break;
         }
     } else {
         $teams = Projects::findNamesByUser($this->logged_user);
         $this->smarty->assign('teams', $teams);
     }
     $parent = $this->active_attachment->getParent();
     $this->smarty->assign('cur_project_id', $parent->getProjectId());
     $this->smarty->assign('cur_attachment_id', $this->active_attachment->getId());
 }
コード例 #4
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Attachment $value A Attachment object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Attachment $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
コード例 #5
0
 /**
  * Provides logic for image picker dialog
  * 
  * @param void
  * @return null
  */
 function image_picker()
 {
     $project_id = $this->request->get('project_id');
     if ($project_id) {
         $this->active_project = Projects::findById($project_id);
     }
     // if
     if (!instance_of($this->active_project, 'Project')) {
         $this->active_project = new Project();
     }
     // if
     $image_picker_url = assemble_url('image_picker', array('project_id' => $this->active_project->getId()));
     $this->smarty->assign(array('image_picker_url' => $image_picker_url, 'disable_upload' => (bool) $this->request->get('disable_upload')));
     if ($this->request->isSubmitted()) {
         $action = $this->request->post('widget_action');
         switch ($action) {
             case 'upload':
                 // check if any file is uploaded
                 $uploaded_file = array_var($_FILES, 'image', null);
                 if (!is_array($uploaded_file)) {
                     $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('You did not uploaded any file'), true, true);
                 }
                 // if
                 // we are setting base attributes
                 $attachment = new Attachment();
                 $attachment->setName($uploaded_file['name']);
                 $attachment->setMimeType($uploaded_file['type']);
                 $attachment->setSize($uploaded_file['size']);
                 $attachment->setAttachmentType(ATTACHMENT_TYPE_ATTACHMENT);
                 $attachment->setCreatedBy($this->logged_user);
                 $attachment->setCreatedOn(new DateTimeValue());
                 // check if uploaded file is image
                 if (!$attachment->isImage()) {
                     $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Uploaded file is not image'), true, true);
                 }
                 // if
                 $destination_file = get_available_uploads_filename();
                 if (!move_uploaded_file($uploaded_file['tmp_name'], $destination_file)) {
                     $this->httpError(HTTP_ERR_OPERATION_FAILED, lang('Could not copy uploaded image to work folder'), true, true);
                 }
                 // if
                 if (FIX_UPLOAD_PERMISSION !== false) {
                     @chmod($destination_file, FIX_UPLOAD_PERMISSION);
                 }
                 // if
                 $attachment->setLocation(basename($destination_file));
                 $save = $attachment->save();
                 if (!$save || is_error($save)) {
                     @unlink($destination_file);
                     $this->httpError(HTTP_ERR_OPERATION_FAILED, $save->getMessage(), true, true);
                 }
                 // if
                 echo "<img attachment_id='" . $attachment->getId() . "' src='" . $attachment->getViewUrl($this->active_project->getId()) . "' />";
                 die;
                 break;
             default:
                 break;
         }
         // switch
     }
     // if
 }