/**
  * Render popup content
  *
  * @param void
  * @return null
  */
 function _render_popup_content()
 {
     if (!instance_of($this->active_object, 'ProjectObject')) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     if (TimeRecord::canAdd($this->logged_user, $this->active_project)) {
         $add_record_url = timetracking_module_add_record_url($this->active_project, array('for' => $this->active_object->getId(), 'for_popup_dialog' => 1));
     } else {
         $add_record_url = false;
     }
     // if
     $object_time = TimeRecords::sumObjectTime($this->active_object);
     $tasks_time = $this->active_object->can_have_tasks ? TimeRecords::sumTasksTime($this->active_object) : 0;
     $this->smarty->assign(array('selected_user' => $this->logged_user, 'selected_date' => new DateValue(time() + get_user_gmt_offset($this->logged_user)), 'selected_billable_status' => BILLABLE_STATUS_BILLABLE, 'object_time' => float_format($object_time, 2), 'tasks_time' => float_format($tasks_time, 2), 'total_time' => float_format($object_time + $tasks_time, 2), 'add_url' => $add_record_url));
     $this->smarty->display(get_template_path('_popup', null, TIMETRACKING_MODULE));
     die;
 }
 function convert_object_to_page()
 {
     $process_mode = $_GET['process'];
     $message = '';
     if (empty($process_mode)) {
         switch ($this->active_object->getType()) {
             case 'Milestone':
                 $message = 'This action will convert the Project: "' . $this->active_object->getName() . '" to Page.';
                 break;
             case 'Ticket':
                 $message = 'This action will convert the Ticket: "' . $this->active_object->getName() . '" to Page.';
                 break;
         }
     } else {
         $error = '';
         $page_id = $this->active_object->convertToPage($this->logged_user, $error);
         if (!empty($page_id)) {
             $this->redirectToUrl(assemble_url('project_page', array('project_id' => $this->active_project->getId(), 'page_id' => $page_id)));
         }
     }
     $this->smarty->assign(array('message' => $message, 'redirect_url' => assemble_url('project_object_convert_to_page', array('project_id' => $this->active_object->getProjectId(), 'object_id' => $this->active_object->getId(), 'process' => '1'))));
 }
 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
 /**
  * Return unsubscribe from object URL
  *
  * @param ProjectObject $object
  * @return string
  */
 function getUnsubscribeUrl($object)
 {
     return assemble_url('project_object_unsubscribe_user', array('project_id' => $object->getProjectId(), 'object_id' => $object->getId(), 'user_id' => $this->getId()));
 }
 /**
  * Returns true if $object is viewed by $user
  *
  * @param ProjectObject $object
  * @param User $user
  * @return boolan
  */
 function isViewed($object, $user)
 {
     return (bool) array_var(db_execute_one("SELECT COUNT(*) AS 'row_count' FROM " . TABLE_PREFIX . 'project_object_views WHERE object_id = ? AND created_by_id = ?', $object->getId(), $user->getId()), 'row_count');
 }
 /**
  * Return number of hours tracked for tasks attached to $object
  *
  * @param ProjectObject $object
  * @return float
  */
 function sumTasksTime($object)
 {
     $rows = db_execute_all('SELECT id FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id = ? AND type = ?', $object->getId(), 'Task');
     if (is_foreachable($rows)) {
         $task_ids = array();
         foreach ($rows as $row) {
             $task_ids[] = (int) $row['id'];
         }
         // foreach
         return (double) array_var(db_execute_one("SELECT SUM(float_field_1) AS 'time_sum' FROM " . TABLE_PREFIX . "project_objects WHERE parent_id IN (?) AND state >= ?", $task_ids, STATE_VISIBLE), 'time_sum');
     } else {
         return 0;
     }
     // if
 }
 function move()
 {
     $new_parent_id = $this->request->post('new_parent_id');
     $new_parent_type = $this->request->post('new_parent_type');
     $new_parent_url = '';
     $move_mode = false;
     if (!empty($new_parent_id) && !empty($new_parent_type)) {
         $move_mode = true;
         $parent_obj = $sql_part = null;
         switch ($new_parent_type) {
             case 'milestone':
                 $parent_obj = new MileStone($new_parent_id);
                 break;
             case 'ticket':
                 $parent_obj = new Ticket($new_parent_id);
                 break;
             case 'page':
                 $parent_obj = new Page($new_parent_id);
                 break;
         }
         if ($parent_obj) {
             $body = $this->active_task->getBody();
             $doc = new DOMDocument();
             if ($doc->loadHTML($body)) {
                 $anc_tags = $doc->getElementsByTagName('a');
                 $new_parent_url = '';
                 foreach ($anc_tags as $anc) {
                     if ($anc->nodeValue == 'View Task in Full') {
                         $href = $anc->getAttribute('href');
                         $fragment = substr($href, strpos($href, '#'));
                         $anc->setAttribute('href', $parent_obj->getViewUrl() . $fragment);
                         break;
                     }
                 }
                 if (!empty($fragment)) {
                     $body_tag = $doc->getElementsByTagName('body');
                     $body = $doc->saveXML($body_tag->item(0)->firstChild);
                     $comment_id = str_replace('#comment', '', $fragment);
                 }
             }
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             $query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t  set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tbody = '" . mysql_real_escape_string($body) . "' \n\t\t\t\t\t\t  where\tid='" . $this->active_task->getId() . "'";
             mysql_query($query, $link);
             if (!empty($comment_id)) {
                 $comment_query = "update \n\t\t\t\t\t\t\thealingcrystals_project_objects \n\t\t\t\t\t\t  set \n\t\t\t\t\t\t\tproject_id='" . $parent_obj->getProjectId() . "', \n\t\t\t\t\t\t\tmilestone_id='" . $parent_obj->getMilestoneId() . "', \n\t\t\t\t\t\t\tparent_id='" . $parent_obj->getId() . "', \n\t\t\t\t\t\t\tparent_type='" . $parent_obj->getType() . "', \n\t\t\t\t\t\t\tposition=null\n\t\t\t\t\t\t  where\tid='" . $comment_id . "'";
                 mysql_query($comment_query, $link);
             }
             mysql_close($link);
             $new_parent_url = $parent_obj->getViewUrl() . '#task' . $this->active_task->getId();
             $cache_id = TABLE_PREFIX . 'project_objects_id_' . $this->active_task->getId();
             $cache_obj = cache_get($cache_id);
             if ($cache_obj) {
                 cache_remove($cache_id);
             }
         }
     } else {
         $listing = array();
         switch ($this->active_task_parent->getType()) {
             case 'Milestone':
                 //$listing = Milestones::findByProject($this->active_project, $this->logged_user);
                 $listing = Milestones::findActiveByProject_custom($this->active_project);
                 break;
             case 'Ticket':
                 $listing = Tickets::findOpenByProjectByNameSort($this->active_project, STATE_VISIBLE, $this->logged_user->getVisibility());
                 break;
             case 'Page':
                 $categories = Categories::findByModuleSection($this->active_project, 'pages', 'pages');
                 $listing = Pages::findByCategories($categories, STATE_VISIBLE, $this->logged_user->getVisibility());
                 /*foreach($categories as $category){
                 			$listing = array_merge($listing, Pages::findByCategory($category, STATE_VISIBLE, $this->logged_user->getVisibility()));
                 		}*/
                 break;
         }
         $this->smarty->assign(array('teams' => Projects::findNamesByUser($this->logged_user), 'listing' => $listing, 'task_parent_id' => $this->active_task_parent->getId()));
     }
     $this->smarty->assign('new_parent_url', $new_parent_url);
     $this->smarty->assign('move_mode', $move_mode);
 }
 /**
  * Write Activity Log
  *
  * @param ProjectObject $object
  * @param User $user
  * @param string $action
  * @param string $comment
  * @return null
  */
 function write($object, $user, $action, $comment = null)
 {
     if (!instance_of($user, 'User') && !instance_of($user, 'AnonymousUser')) {
         $user =& get_logged_user();
         if (!instance_of($user, 'User')) {
             return false;
         }
         // if
     }
     // if
     $activity_log = new ActivityLog();
     $activity_log->setAttributes(array('object_id' => $object->getId(), 'project_id' => $object->getProjectId(), 'action' => $action, 'comment' => $comment));
     $activity_log->setCreatedBy($user);
     return $activity_log->save();
 }
 /**
  * DElete by object
  *
  * @param ProjectObject $object
  * @return boolean
  */
 function deleteByObject($object)
 {
     return Attachments::delete(array('parent_id = ? AND parent_type = ?', $object->getId(), get_class($object)));
 }
 /**
  * Delete subscriptions by parent
  *
  * @param ProjectObject $parent
  * @return boolean
  */
 function deleteByParent($parent)
 {
     cache_remove_by_pattern('user_subscriptions_*');
     return Subscriptions::delete(array('parent_id = ?', $parent->getId()));
 }
 /**
  * Drop records by object
  *
  * @param ProjectObject $object
  * @return boolean
  */
 function deleteByObject($object)
 {
     return db_execute('DELETE FROM ' . TABLE_PREFIX . 'starred_objects WHERE object_id = ?', $object->getId());
 }
Пример #12
0
 /**
  * Clear reminders by object
  *
  * @param ProjectObject $object
  * @return boolean
  */
 function deleteByObject($object)
 {
     return Reminders::delete(array('object_id = ?', $object->getId()));
 }
 /**
  * Add new entry to the log
  *
  * @param ProjectObject $object
  * @param User $by
  * @param string $comment
  * @return null
  */
 function log($object, $by = null, $comment = null)
 {
     $this->setType(get_class($this));
     $this->setObjectId($object->getId());
     $this->setProjectId($object->getProjectId());
     if ($by === null) {
         $by = get_logged_user();
     }
     // if
     $this->setCreatedBy($by);
     $this->setCreatedOn(new DateTimeValue());
     if ($comment) {
         $this->setComment($comment);
     }
     // if
     return $this->save();
 }
 /**
  * Delete assignmnets by project object
  *
  * @param ProjectObject $object
  * @return boolean
  */
 function deleteByObject($object)
 {
     cache_remove('object_assignments_' . $object->getId());
     cache_remove('object_assignments_' . $object->getId() . '_rendered');
     return Assignments::delete(array('object_id = ?', $object->getId()));
 }
Пример #15
0
 /**
  * Return number of completed tasks in a given object
  *
  * @param ProjectObject $object
  * @param integer $min_state
  * @return integer
  */
 function countCompletedByObject($object, $min_state = STATE_VISIBLE)
 {
     return ProjectObjects::count(array('parent_id = ? AND type = ? AND state >= ? AND completed_on IS NOT NULL', $object->getId(), 'Task', $min_state));
 }
 /**
  * Update field properties for child objects by parent
  * 
  * $properties is an array where key is setter name and value is new value
  *
  * @param ProjectObject $parent
  * @param array $properties
  * @param array $types
  * @return boolean
  */
 function updatePropertiesByParent($parent, $properties, $types)
 {
     if (is_foreachable($properties) && is_foreachable($types)) {
         $objects = ProjectObjects::findBySQL('SELECT * FROM ' . TABLE_PREFIX . 'project_objects WHERE parent_id = ? AND type IN (?)', array($parent->getId(), $types));
         if (is_foreachable($objects)) {
             db_begin_work();
             foreach ($objects as $object) {
                 foreach ($properties as $setter => $value) {
                     $object->{$setter}($value);
                 }
                 // if
                 $object->save();
             }
             // foreach
             db_commit();
         }
         // if
     }
     // if
     return true;
 }
Пример #17
0
 /**
  * Get project section URL
  *
  * @param ProjectObject $project
  * @return string
  */
 function getProjectCalendarUrl($project)
 {
     return assemble_url('project_calendar', array('project_id' => $project->getId()));
 }
Пример #18
0
 /**
  * Return last comment for a given object
  *
  * @param ProjectObject $object
  * @param integer $min_state
  * @param integer $min_visiblity
  * @return Comment
  */
 function findLastCommentByObject($object, $min_state = STATE_VISIBLE, $min_visiblity = VISIBILITY_NORMAL)
 {
     return ProjectObjects::find(array('conditions' => array("type = 'Comment' AND parent_id = ? AND state >= ? AND visibility >= ?", $object->getId(), $min_state, $min_visiblity), 'order' => 'created_on DESC', 'limit' => 1, 'offset' => 0, 'one' => true));
 }