Exemplo n.º 1
0
 /**
  * Counts the project's issues assigned to the given user
  *
  * @param  int  $user_id
  * @return int
  */
 public function count_assigned_issues($user_id = null)
 {
     if (is_null($user_id)) {
         $user_id = \Auth::user()->id;
     }
     return \Project\Issue::where('project_id', '=', $this->id)->where('assigned_to', '=', $user_id)->where('status', '=', 1)->count();
 }
Exemplo n.º 2
0
 public function post_closeIssue()
 {
     $input = Input::all();
     $project = new Project\Issue();
     $project::load_issue($input['id']);
     \Project\Issue::update_status_project($input, $project::current());
     echo '1';
     die;
 }
Exemplo n.º 3
0
 /**
  * Delete a comment and its attachments
  *
  * @param int    $comment
  * @return bool
  */
 public static function delete_comment($comment)
 {
     \User\Activity::where('action_id', '=', $comment)->delete();
     $comment = static::find($comment);
     if (!$comment) {
         return false;
     }
     $issue = \Project\Issue::find($comment->issue_id);
     /* Delete attachments and files */
     $path = \Config::get('application.upload_path') . $issue->project_id;
     foreach ($comment->attachments()->get() as $row) {
         Attachment::delete_file($path . '/' . $row->upload_token, $row->filename);
         $row->delete();
     }
     $comment->delete();
     return true;
 }
Exemplo n.º 4
0
 /**
  * Display issues for a project
  * /project/(:num)
  *
  * @return View
  */
 public function get_issues()
 {
     Asset::add('tag-it-js', '/app/assets/js/tag-it.min.js', array('jquery', 'jquery-ui'));
     Asset::add('tag-it-css-base', '/app/assets/css/jquery.tagit.css');
     Asset::add('tag-it-css-zendesk', '/app/assets/css/tagit.ui-zendesk.css');
     /* Get what to sort by */
     $sort_by = Input::get('sort_by', '');
     if (substr($sort_by, 0, strlen('tag:')) == 'tag:') {
         $sort_by_clause = DB::raw("\n\t\t\t\tMIN(CASE WHEN tags.tag LIKE " . DB::connection('mysql')->pdo->quote(substr($sort_by, strlen('tag:')) . ':%') . " THEN 1 ELSE 2 END), \n\t\t\t\tIF(NOT ISNULL(tags.tag), 1, 2), \n\t\t\t\ttags.tag\n\t\t\t");
     } else {
         $sort_by = 'updated';
         $sort_by_clause = 'projects_issues.updated_at';
     }
     /* Get what order to use for sorting */
     $default_sort_order = $sort_by == 'updated' ? 'desc' : 'asc';
     $sort_order = Input::get('sort_order', $default_sort_order);
     $sort_order = in_array($sort_order, array('asc', 'desc')) ? $sort_order : $default_sort_order;
     /* Get which user's issues to show */
     $assigned_to = Input::get('assigned_to', '');
     /* Get which tags to show */
     $tags = Input::get('tags', '');
     /* Build query for issues */
     $issues = \Project\Issue::with('tags');
     if ($tags || $sort_by != 'updated') {
         $issues = $issues->join('projects_issues_tags', 'projects_issues_tags.issue_id', '=', 'projects_issues.id')->join('tags', 'tags.id', '=', 'projects_issues_tags.tag_id');
     }
     $issues = $issues->where('project_id', '=', Project::current()->id);
     if ($assigned_to) {
         $issues = $issues->where('assigned_to', '=', $assigned_to);
     }
     if ($tags) {
         $tags_collection = explode(',', $tags);
         $tags_amount = count($tags_collection);
         /*
         			foreach (explode(',', $tags) as $tag)
         			{
         				if (substr($tag, -2) == ':*')
         				{
         					$tags_collection[] = substr($tag, 0, strlen($tag) - 2) . ':%';
         					//$issues = $issues->where('tags.tag', 'LIKE', $tag);
         				}
         				else
         				{
         					$tags_collection[] =$tag;
         					//$issues = $issues->where('tags.tag', '=', $tag);
         				}
         			}
         */
         $issues = $issues->where_in('tags.tag', $tags_collection);
         //->get();
     }
     $issues = $issues->group_by('projects_issues.id')->order_by($sort_by_clause, $sort_order);
     if ($tags && $tags_amount > 1) {
         // L3
         $issues = $issues->having(DB::raw('COUNT(DISTINCT `tags`.`tag`)'), '=', $tags_amount);
         // L4 $issues = $issues->havingRaw("COUNT(DISTINCT `tags`.`tag`) = ".$tags_amount);
     }
     $issues = $issues->get(array('projects_issues.*'));
     /* Get which tab to highlight */
     if ($assigned_to == Auth::user()->id) {
         $active = 'assigned';
     } else {
         if (Input::get('tags', '') == 'status:closed') {
             $active = 'closed';
         } else {
             $active = 'open';
         }
     }
     /* Get sort options */
     $tags = \Tag::order_by('tag', 'ASC')->get();
     $sort_options = array('updated' => 'updated');
     foreach ($tags as $tag) {
         $colon_pos = strpos($tag->tag, ':');
         if ($colon_pos !== false) {
             $tag = substr($tag->tag, 0, $colon_pos);
         } else {
             $tag = $tag->tag;
         }
         $sort_options["tag:{$tag}"] = $tag;
     }
     /* Get assigned users */
     $assigned_users = array('' => '');
     foreach (Project::current()->users as $user) {
         $assigned_users[$user->id] = $user->firstname . ' ' . $user->lastname;
     }
     /* Build layout */
     return $this->layout->nest('content', 'project.index', array('page' => View::make('project/index/issues', array('sort_options' => $sort_options, 'sort_order' => $sort_order, 'assigned_users' => $assigned_users, 'issues' => $issues)), 'active' => $active, 'open_count' => Project::current()->count_open_issues(), 'closed_count' => Project::current()->count_closed_issues(), 'assigned_count' => Project::current()->count_assigned_issues()));
 }