function updateEditMilestones($datestamp)
 {
     $dbr = wfGetDB(DB_SLAVE);
     echo "Updating the editing milestones for " . $datestamp . "\n";
     $timestamp = $datestamp . "000000";
     $dateUnix = wfTimestamp(TS_UNIX, $timestamp);
     $tomorrowUnix = strtotime("+1 day", $dateUnix);
     $tomorrowTimestamp = wfTimestamp(TS_MW, $tomorrowUnix);
     $tomorrowDatestamp = substr($tomorrowTimestamp, 0, 8);
     echo "starting " . $timestamp . " " . $tomorrowTimestamp . "\n";
     $res = $dbr->select('recentchanges', array('rc_user', 'rc_comment'), array('rc_namespace' => 0, "rc_timestamp >= '{$timestamp}'", "rc_timestamp < '{$tomorrowTimestamp}'", 'rc_user != 0'), __METHOD__);
     $users = array();
     $usersArray = array();
     foreach ($res as $object) {
         $userArray[] = $object;
     }
     foreach ($userArray as $user) {
         if ($users[$user->rc_user] == null) {
             if (stripos($user->rc_comment, "Reverted edits by") !== false) {
                 continue;
             }
             $users[$user->rc_user] = $user;
         }
     }
     echo "Found " . count($users) . " users who edited\n";
     foreach ($users as $user) {
         Milestones::updateUserStat('edit', $user, $datestamp);
         $userObj = User::newFromId($user->rc_user);
     }
 }
/**
 * with_successive_milestones helper
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_with_successive_milestones($params, &$smarty)
{
    static $counter = 1;
    $name = array_var($params, 'name');
    if (empty($name)) {
        return new InvalidParamError('name', $name, '$name value is required', true);
    }
    // if
    $milestone = array_var($params, 'milestone');
    if (!instance_of($milestone, 'Milestone')) {
        return new InvalidParamError('milestone', $milestone, '$milestone value is expected to be an instance of Milestone class', true);
    }
    // if
    $id = array_var($params, 'id');
    if (empty($id)) {
        $id = 'with_successive_milestones_' . $counter;
        $counter++;
    }
    // if
    $value = array_var($params, 'value');
    $action = array_var($value, 'action', 'dont_move');
    $milestones = array_var($value, 'milestones');
    if (!is_array($milestones)) {
        $milestones = array();
    }
    // if
    $logged_user = $smarty->get_template_vars('logged_user');
    $successive_milestones = Milestones::findSuccessiveByMilestone($milestone, STATE_VISIBLE, $logged_user->getVisibility());
    if (!is_foreachable($successive_milestones)) {
        return '<p class="details">' . lang('This milestone does not have any successive milestones') . '</p>';
    }
    // if
    $result = "<div class=\"with_successive_milestones\">\n<div class=\"options\">\n";
    $options = array('dont_move' => lang("Don't change anything"), 'move_all' => lang('Adjust all successive milestone by the same number of days'), 'move_selected' => lang('Adjust only selected successive milestones by the same number of days'));
    foreach ($options as $k => $v) {
        $radio = radio_field($name . '[action]', $k == $action, array('value' => $k, 'id' => $id . '_' . $k));
        $label = label_tag($v, $id . '_' . $k, false, array('class' => 'inline'), '');
        $result .= '<span class="block">' . $radio . ' ' . $label . "</span>\n";
    }
    // if
    $result .= "</div>\n<div class=\"successive_milestones\">";
    foreach ($successive_milestones as $successive_milestone) {
        $input_attributes = array('name' => $name . '[milestones][]', 'id' => $id . '_milestones_' . $successive_milestone->getId(), 'type' => 'checkbox', 'value' => $successive_milestone->getId(), 'class' => 'auto');
        if (in_array($successive_milestone->getId(), $milestones)) {
            $input_attributes['checked'] = true;
        }
        // if
        $input = open_html_tag('input', $input_attributes, true);
        $label = label_tag($successive_milestone->getName(), $id . '_milestones_' . $successive_milestone->getId(), false, array('class' => 'inline'), '');
        $result .= '<span class="block">' . $input . ' ' . $label . "</span>\n";
    }
    // foreach
    $result .= "</div>\n</div>\n";
    return $result;
}
 /**
  * List of tickets
  *
  */
 function index()
 {
     $this->addBreadcrumb(lang('List'));
     if ($this->active_category->isLoaded()) {
         $tickets = Milestones::groupByMilestone(Tickets::findOpenByCategory($this->active_category, STATE_VISIBLE, $this->logged_user->getVisibility()), STATE_VISIBLE, $this->logged_user->getVisibility());
     } else {
         $tickets = Milestones::groupByMilestone(Tickets::findOpenByProject($this->active_project, STATE_VISIBLE, $this->logged_user->getVisibility()), STATE_VISIBLE, $this->logged_user->getVisibility());
     }
     // if
     $this->smarty->assign(array('categories' => Categories::findByModuleSection($this->active_project, TICKETS_MODULE, 'tickets'), 'tickets' => $tickets, 'pagination_url' => assemble_url('mobile_access_view_tickets', array('project_id' => $this->active_project->getId())), 'page_back_url' => assemble_url('mobile_access_view_project', array('project_id' => $this->active_project->getId()))));
 }
 public function actionMilestonesPending()
 {
     $Milestones = Milestones::model()->MilestoneWithPendingTasks();
     foreach ($Milestones as $milestone) {
         $Tasks = Tasks::model()->findTaskByMilestone($milestone->milestone_id);
         $str = CBaseController::renderInternal(Yii::app()->params['templatesPath'] . '/milestones/overdueMilestones.php', array('user' => $milestone->Users->completeName, 'tasks' => $Tasks, 'applicationName' => Yii::app()->name, 'applicationUrl' => "http://localhost/celestic/" . Yii::app()->request->baseUrl), true);
         $subject = Yii::t('email', 'overdueMilestone');
         Yii::import('application.extensions.phpMailer.yiiPhpMailer');
         $mailer = new yiiPhpMailer();
         $mailer->pushMail($subject, $str, array('name' => $milestone->Users->CompleteName, 'email' => $milestone->Users->user_email), Emails::PRIORITY_NORMAL);
     }
 }
function smarty_function_object_project_selection($params, &$smarty)
{
    $object = array_var($params, 'object');
    if (!instance_of($object, 'ProjectObject')) {
        return new InvalidParamError('object', $object, '$object is not valid instance of ProjectObject class', true);
    }
    $user = array_var($params, 'user');
    $select = '';
    //$active_milestones = Milestones::findByProject($object->getProject(), $user);
    $active_milestones = Milestones::findActiveByProject_custom($object->getProject());
    $select = '<select onchange="modify_project_association(this);">';
    $select .= '<option value="">-- Select Project --</option>';
    foreach ($active_milestones as $active_milestone) {
        $select .= '<option value="' . $active_milestone->getId() . '" ' . ($object->getMilestoneId() == $active_milestone->getId() ? ' selected ' : '') . ' >' . $active_milestone->getName() . '</option>';
    }
    $select .= '</select>';
    return $select;
}
示例#6
0
 public function indexAction()
 {
     //get session info
     $auth = $this->session->get('auth');
     $userID = $auth['userID'];
     $username = $auth['username'];
     //get other user information from db
     $user = Users::findFirstByUserID($userID);
     if ($user) {
         //user found, get rest of info
         $this->view->setVar("firstname", $user->firstname);
         $this->view->setVar("lastname", $user->lastname);
         $this->view->setVar("email", $user->email);
         $this->view->setVar("location", $user->location);
         $this->view->setVar("username", $user->username);
         $goals = Goals::findAllBySeekerID($userID);
         $this->view->setVar("goals", $goals);
         $gifts = Gifts::findAllByMotivatorID($userID);
         $goalIDs = array();
         $exists = false;
         if ($gifts) {
             foreach ($gifts as $gift) {
                 $milestone = Milestones::findFirstByMilestoneID($gift->milestoneID);
                 if ($milestone) {
                     for ($i = 0; i < array_count_values($goalIDs) && $exists == false; $i++) {
                         if ($goalIDs[$i] == $milestone->goalID) {
                             $exists = true;
                         }
                     }
                     if ($exists == false) {
                         array_push($goalIDs, $milestone->goalID);
                     }
                 }
             }
         }
     } else {
         //error, go to login
         $this->flashSession->error("Error: Unable to access user information");
         $this->response->redirect("index");
         $this->view->disable();
     }
 }
 /**
  * Get all projects events (milestones)
  * By default project_id is selected
  * @return model list milestones
  */
 public function getCalendarEvents()
 {
     if (Yii::app()->user->getState('project_selected') != null) {
         $projects = Yii::app()->user->getState('project_selected');
     } else {
         $WorkingProjects = Projects::model()->findMyProjects(Yii::app()->user->id);
         $projectList = array();
         foreach ($WorkingProjects as $project) {
             array_push($projectList, $project->project_id);
         }
         $projects = implode(",", $projectList);
     }
     // Finding all projects milestones
     $Milestones = Milestones::model()->findAll(array('condition' => 't.project_id IN (:project_id)', 'params' => array('project_id' => $projects)));
     // Creating event format required by fullcalendar component
     $arrayOfEvents = array();
     foreach ($Milestones as $milestone) {
         array_push($arrayOfEvents, array('title' => $milestone->milestone_title, 'start' => CHtml::encode(Yii::app()->dateFormatter->format('yyyy-MM-dd', $milestone->milestone_duedate)), 'end' => CHtml::encode(Yii::app()->dateFormatter->format('yyyy-MM-dd', $milestone->milestone_duedate)), 'description' => $milestone->milestone_description, 'className' => 'holiday'));
     }
     return $arrayOfEvents;
 }
示例#8
0
 public function run()
 {
     $controller = $this->controller;
     $milestones = Milestones::checkForDeadlines();
     $projects = Project::checkForDeadlines();
     if (count($milestones) != 0) {
         $s = '<div style="padding: 5px;background-color: #ffcccc; border: 3px solid red;margin-bottom: 10px;">';
         $s .= ' <b>Deadline is comming up for:</b><br /> ';
         foreach ($milestones as $row) {
             $p = array();
             $i = 0;
             foreach ($row as $key => $value) {
                 $p[$i] = $value;
                 $i++;
             }
             $s .= 'Projekt: <a href ="project/' . $p[0] . '">' . $p[1] . '</a> Milestone: <a href="milestones/view/id/' . $p[2] . '">' . $p[3] . '</a> (' . $p[4] . ')<br />';
         }
         $s .= '</div>';
         Yii::app()->user->setFlash('deadline-milestone', $s);
     }
     if (count($projects) != 0) {
         $s = '<div style="padding: 5px;background-color: #ffcccc; border: 3px solid red;margin-bottom: 10px;">';
         $s .= ' <b>Deadline is comming up for:</b><br /> ';
         foreach ($projects as $row) {
             $p = array();
             $i = 0;
             foreach ($row as $key => $value) {
                 $p[$i] = $value;
                 $i++;
             }
             $s .= 'Projekt: <a href ="project/' . $p[0] . '">' . $p[1] . '</a> ends on: ' . $p[2] . '<br />';
         }
         $s .= '</div>';
         Yii::app()->user->setFlash('deadline-project', $s);
     }
     $dataProvider = new CActiveDataProvider('Project');
     $controller->render('project/list', array('dataProvider' => $dataProvider));
 }
示例#9
0
 /**
  * Given the current number milestone, it returns the next one for the goal
  */
 public static function findNextMilestoneInGoal($curr)
 {
     return Milestones::findFirst(array("goalID = :goalID: AND number = :number:", "bind" => array('goalID' => $goalID, 'number' => $curr++)));
 }
 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());
 }
 /**
  * Lists all models.
  */
 public function actionIndex()
 {
     if (Yii::app()->user->checkAccess('indexTasks')) {
         $view = Yii::app()->user->getState('view') != null ? Yii::app()->user->getState('view') : 'list';
         if (isset($_GET['view']) && !empty($_GET['view'])) {
             if ($_GET['view'] == 'grid') {
                 $view = 'grid';
             } elseif ($_GET['view'] == 'kanban') {
                 $view = 'kanban';
             } else {
                 $view = 'list';
             }
         }
         Yii::app()->user->setState('view', $view);
         $model = new TasksSearchForm();
         //$model->search();
         //$model->unsetAttributes();  // clear any default values
         $Milestones = Milestones::model()->with('Projects.Company.Cusers')->together()->findAll(array('condition' => 'Cusers.user_id = :user_id AND t.project_id = :project_id', 'params' => array(':user_id' => Yii::app()->user->id, ':project_id' => Yii::app()->user->getState('project_selected'))));
         $Cases = Cases::model()->with('Projects.Company.Cusers')->together()->findAll(array('condition' => 'Cusers.user_id = :user_id AND t.project_id = :project_id', 'params' => array(':user_id' => Yii::app()->user->id, ':project_id' => Yii::app()->user->getState('project_selected'))));
         if (isset($_GET['TasksSearchForm'])) {
             $model->attributes = $_GET['TasksSearchForm'];
         }
         if ($view == 'kanban') {
             $this->layout = 'column1';
         }
         $this->render('index', array('model' => $model, 'status' => Status::model()->findAllOrdered(), 'types' => TaskTypes::model()->findAll(), 'stages' => TaskStages::model()->findAll(), 'milestones' => $Milestones, 'cases' => $Cases, 'users' => Projects::model()->findAllUsersByProject(Yii::app()->user->getState('project_selected'))));
     } else {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     }
 }
示例#12
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Milestones::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 /**
  * Group objects by milestone
  * 
  * This function will group any group of object by milestone
  *
  * @param array $objects
  * @param integer $min_state
  * @param integer $min_visibility
  * @return array
  */
 function groupByMilestone($objects, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     $result = array();
     if (is_foreachable($objects)) {
         $milestone_ids = objects_array_extract($objects, 'getMilestoneId');
         if (is_foreachable($milestone_ids)) {
             $milestones = Milestones::findByIds($milestone_ids, $min_state, $min_visibility);
             if (is_foreachable($milestones)) {
                 foreach ($milestones as $milestone) {
                     $result[$milestone->getId()] = array('milestone' => $milestone, 'objects' => array());
                 }
                 // foreach
             }
             // if
         }
         // if
         // For unknown milestone objects
         $result[0] = array('milestone' => null, 'objects' => array());
         foreach ($objects as $object) {
             if (isset($result[$object->getMilestoneId()])) {
                 $result[$object->getMilestoneId()]['objects'][] = $object;
             } else {
                 $result[0]['objects'][] = $object;
             }
             // if
         }
         // foreach
     }
     // if
     return $result;
 }
 function add()
 {
     if ($this->request->isAsyncCall() || $this->request->isMobileDevice() || $this->request->isApiCall() && $this->request->isSubmitted()) {
         if (Milestones::canAdd($this->logged_user, $this->active_project)) {
             $milestone_data = $this->request->post('milestone');
             $this->smarty->assign('milestone_data', $milestone_data);
             if ($this->request->isSubmitted()) {
                 try {
                     DB::beginWork('Creating milestone @ ' . __CLASS__);
                     $this->active_milestone = new RemediaMilestone();
                     $this->active_milestone->setAttributes($milestone_data);
                     $start_on = $this->active_milestone->getStartOn();
                     if ($start_on instanceof DateValue) {
                         if (Globalization::isWeekend($start_on) || Globalization::isDayOff($start_on)) {
                             throw new Error(lang('Start date needs to be set on working day'));
                         }
                         //if
                     }
                     //if
                     $due_on = $this->active_milestone->getDueOn();
                     if ($due_on instanceof DateValue) {
                         if (Globalization::isWeekend($due_on) || Globalization::isDayOff($due_on)) {
                             throw new Error(lang('Due date needs to be set on working day'));
                         }
                         //if
                     }
                     //if
                     $this->active_milestone->setProjectId($this->active_project->getId());
                     $this->active_milestone->setCreatedBy($this->logged_user);
                     $this->active_milestone->setState(STATE_VISIBLE);
                     $this->active_milestone->setVisibility(VISIBILITY_NORMAL);
                     $this->active_milestone->save();
                     /* INIZIO frosso hack */
                     if (AngieApplication::isModuleLoaded('tracking') && TrackingObjects::canAdd($this->logged_user, $this->active_project)) {
                         $estimate_value = isset($milestone_data['estimate_value']) && $milestone_data['estimate_value'] ? (double) $milestone_data['estimate_value'] : null;
                         $estimate_job_type = isset($milestone_data['estimate_job_type_id']) && $milestone_data['estimate_job_type_id'] ? JobTypes::findById($milestone_data['estimate_job_type_id']) : null;
                         $estimate_comment = isset($milestone_data['estimate_comment']) ? $milestone_data['estimate_comment'] : null;
                         if ($estimate_value > 0 && $estimate_job_type instanceof JobType) {
                             $this->active_milestone->tracking()->setEstimate($estimate_value, $estimate_job_type, $estimate_comment, $this->logged_user);
                         } else {
                             if ($this->active_milestone->tracking()->getEstimate() instanceof Estimate) {
                                 $this->active_milestone->tracking()->setEstimate($estimate_value, $estimate_job_type, $estimate_comment, $this->logged_user);
                             }
                             // if
                         }
                         // if
                     }
                     // if
                     /* FINE frosso hack */
                     $this->active_milestone->subscriptions()->set(array_unique(array_merge((array) $this->logged_user->getId(), (array) $this->active_project->getLeaderId(), (array) array_var($milestone_data, 'subscribers', array()))), false);
                     DB::commit('Milestone created @ ' . __CLASS__);
                     $this->logged_user->notifier()->notifySubscribers($this->active_milestone, 'system/new_milestone');
                     if ($this->request->isPageCall()) {
                         $this->flash->success('Milestone ":name" has been created', array('name' => $this->active_milestone->getName()));
                         $this->response->redirectToUrl($this->active_milestone->getViewUrl());
                     } else {
                         $this->response->respondWithData($this->active_milestone, array('as' => 'milestone', 'detailed' => true));
                     }
                     // if
                 } catch (Exception $e) {
                     DB::rollback('Failed to create milestone @ ' . __CLASS__);
                     if ($this->request->isPageCall()) {
                         $this->smarty->assign('errors', $e);
                     } else {
                         $this->response->exception($e);
                     }
                     // if
                 }
                 // try
             }
             // if
         } else {
             $this->response->forbidden();
         }
         // if
     } else {
         $this->response->badRequest();
     }
     // if
 }
 function mass_update()
 {
     if ($this->request->isSubmitted()) {
         $action = $this->request->post('with_selected');
         if (trim($action) == '') {
             flash_error('Please select what you want to do with selected milestones');
             $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
         }
         // if
         $milestone_ids = $this->request->post('milestones');
         $milestones = Milestones::findByIds($milestone_ids, STATE_VISIBLE, $this->logged_user->getVisibility());
         $updated = 0;
         if (is_foreachable($milestones)) {
             // Complete selected milestones
             if ($action == 'complete') {
                 $message = lang(':count milestones completed');
                 //BOF:mod 20110617
                 //BOF:mod 20120917 (reversed by shawn)
                 /*
                 //EOF:mod 20120917
                             		$warning = '';
                             		foreach($milestones as $milestone) {
                 			if($milestone->isOpen() && $milestone->canChangeCompleteStatus($this->logged_user)) {
                               				$responsible_assignee = $milestone->getResponsibleAssignee();
                               				$created_by_id = $milestone->getCreatedById();
                               				$project_leader = $this->active_project->getLeaderId();
                               				if ( (!is_null($responsible_assignee) && $responsible_assignee->getId()==$this->logged_user->getId()) 
                 						|| $created_by_id==$this->logged_user->getId() 
                 						|| $project_leader==$this->logged_user->getId() 
                 						|| $this->logged_user->isAdministrator() ){
                 					$warning .= '';
                 				} else {
                 					$warning .= '"' . $milestone->getName() . '", ';
                 				}
                 			}
                 		}
                 		if (!empty($warning)){
                                                         $temp = new User(!empty($created_by_id) ? $created_by_id : $project_leader);
                                                         $warning = 'Project ' . substr($warning, 0, -2) . ' cannot be closed at this time. Please send message to ' . $temp->getName() . ' to close this ticket.';
                                                         unset($temp);
                 		          		flash_error($warning, null, true);
                 		          		$this->redirectToReferer($this->smarty->get_template_vars('milestones_url'));
                 		} else {
                 //BOF:mod 20120917 (reversed by shawn)
                 */
                 //EOF:mod 20120917
                 //EOF:mod 20110617
                 foreach ($milestones as $milestone) {
                     if ($milestone->isOpen() && $milestone->canChangeCompleteStatus($this->logged_user)) {
                         $complete = $milestone->complete($this->logged_user);
                         if ($complete && !is_error($complete)) {
                             $updated++;
                         }
                         // if
                     }
                     // if
                 }
                 // foreach
                 $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
                 //BOF:mod 20110617
                 //BOF:mod 20120917 (reversed by shawn)
                 /*
                 //EOF:mod 20120917
                 		}
                 //BOF:mod 20120917 (reversed by shawn)
                 */
                 //EOF:mod 20120917
                 //EOF:mod 20110617
                 // Open selected milestones
             } elseif ($action == 'open') {
                 $message = lang(':count milestones opened');
                 foreach ($milestones as $milestone) {
                     if ($milestone->isCompleted() && $milestone->canChangeCompleteStatus($this->logged_user)) {
                         $open = $milestone->open($this->logged_user);
                         if ($open && !is_error($open)) {
                             $updated++;
                         }
                         // if
                     }
                     // if
                 }
                 // foreach
                 $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
                 // Mark object as starred
             } elseif ($action == 'star') {
                 $message = lang(':count milestones starred');
                 foreach ($milestones as $milestone) {
                     $star = $milestone->star($this->logged_user);
                     if ($star && !is_error($star)) {
                         $updated++;
                     }
                     // if
                 }
                 // foreach
                 $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
                 // Unstar objects
             } elseif ($action == 'unstar') {
                 $message = lang(':count milestones unstarred');
                 foreach ($milestones as $milestone) {
                     $unstar = $milestone->unstar($this->logged_user);
                     if ($unstar && !is_error($unstar)) {
                         $updated++;
                     }
                     // if
                 }
                 // foreach
                 $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
                 // Move selected objects to Trash
             } elseif ($action == 'trash') {
                 $message = lang(':count milestones moved to Trash');
                 foreach ($milestones as $milestone) {
                     if ($milestone->canDelete($this->logged_user)) {
                         $delete = $milestone->moveToTrash();
                         if ($delete && !is_error($delete)) {
                             $updated++;
                         }
                         // if
                     }
                     // if
                 }
                 // foreach
                 $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
                 // Set a selected priority
             } elseif (str_starts_with($action, 'set_priority')) {
                 $priority = (int) substr($action, 13);
                 $message = lang(':count milestones updated');
                 foreach ($milestones as $milestone) {
                     if ($milestone->canEdit($this->logged_user)) {
                         $milestone->setPriority($priority);
                         $save = $milestone->save();
                         if ($save && !is_error($save)) {
                             $updated++;
                         }
                         // if
                     }
                     // if
                 }
                 // foreach
                 $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
                 // Set visibility
             } elseif (str_starts_with($action, 'set_visibility')) {
                 $visibility = (int) substr($action, 15);
                 $message = lang(':count milestones updated');
                 foreach ($milestones as $milestone) {
                     if ($milestone->canEdit($this->logged_user)) {
                         $milestone->setVisibility($visibility);
                         $save = $milestone->save();
                         if ($save && !is_error($save)) {
                             $updated++;
                         }
                         // if
                     }
                     // if
                 }
                 // foreach
                 $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
                 // Move selected milestones to selected category
             } elseif (str_starts_with($action, 'move_to_category')) {
                 if ($action == 'move_to_category') {
                     $category_id = null;
                 } else {
                     $category_id = (int) substr($action, 17);
                 }
                 // if
                 //$category = $category_id ? Categories::findById($category_id) : null;
                 $message = lang(':count milestones updated');
                 foreach ($milestones as $milestone) {
                     if ($milestone->canEdit($this->logged_user)) {
                         $milestone->setCategoryId($category_id);
                         $save = $milestone->save();
                         if ($save && !is_error($save)) {
                             $updated++;
                         }
                         // if
                     }
                     // if
                 }
                 // foreach
                 $this->redirectToReferer($this->smarty->get_template_vars('milestoness_url'));
             } else {
                 $this->httpError(HTTP_ERR_BAD_REQUEST);
             }
             // if
         } else {
             flash_error('Please select milestones that you would like to update');
             $this->redirectToReferer($this->smarty->get_template_vars('milestones_url'));
         }
         // if
     } else {
         $this->httpError(HTTP_ERR_BAD_REQUEST);
     }
 }
/**
 * Render select milestone control
 * 
 * Params:
 * 
 * - project - Project instance that need to be used
 * - active_only - Return only active milestones, true by default
 *
 * @param array $params
 * @param Smarty $smarty
 * @return string
 */
function smarty_function_select_milestone($params, &$smarty)
{
    $project = array_var($params, 'project');
    if (!instance_of($project, 'Project')) {
        return new InvalidParamError('project', $project, '$project value is expected to be an instance of Project class', true);
    }
    // if
    unset($params['project']);
    $active_only = false;
    if (isset($params['active_only'])) {
        $active_only = (bool) $params['active_only'];
        unset($params['active_only']);
    }
    // if
    $value = null;
    if (isset($params['value'])) {
        $value = $params['value'];
        unset($params['value']);
    }
    // if
    $optional = true;
    if (isset($params['optional'])) {
        $optional = (bool) $params['optional'];
        unset($params['optional']);
    }
    // if
    $options = array();
    if ($optional) {
        $options[] = option_tag(lang('-- None --'), '');
        $options[] = option_tag('', '');
    }
    // if
    $logged_user = $smarty->get_template_vars('logged_user');
    $milestones = $active_only ? Milestones::findActiveByProject($project, STATE_VISIBLE, $logged_user->getVisibility()) : Milestones::findByProject($project, $logged_user);
    //BOF:mod 20130126
    $entries_exist = false;
    //EOF:mod 20130126
    if (is_foreachable($milestones)) {
        $completed_options = array();
        foreach ($milestones as $milestone) {
            if ($milestone->isCompleted()) {
                $option_attributes = $milestone->getId() == $value ? array('selected' => true) : null;
                $completed_options[] = option_tag($milestone->getName(), $milestone->getId(), $option_attributes);
            } else {
                //BOF:mod 20130126
                $entries_exist = true;
                //EOF:mod 20130126
                $option_attributes = $milestone->getId() == $value ? array('selected' => true) : null;
                $options[] = option_tag($milestone->getName(), $milestone->getId(), $option_attributes);
            }
            // if
        }
        // foreach
        if (is_foreachable($completed_options)) {
            $options[] = option_tag('', '');
            $options[] = option_group_tag(lang('Completed'), $completed_options);
        }
        // if
    }
    // if
    //BOF:mod 20130126
    if (!$entries_exist) {
        unset($params['class']);
    }
    //EOF:mod 20130126
    return select_box($options, $params);
}
 /**
  * Copy project items into a destination project
  *
  * @param Project $to
  * @return null
  */
 function copyItems(&$to)
 {
     // Prepare time diff
     $source_starts_on = $this->getStartsOn();
     if (!instance_of($source_starts_on, 'DateValue')) {
         $source_starts_on = $this->getCreatedOn();
     }
     // if
     $target_starts_on = $to->getStartsOn();
     if (!instance_of($target_starts_on, 'DateValue')) {
         $target_starts_on = $to->getCreatedOn();
     }
     // if
     $diff = $target_starts_on->getTimestamp() - $source_starts_on->getTimestamp();
     // Migrate project users
     $project_users = ProjectUsers::findByProject($this);
     if (is_foreachable($project_users)) {
         foreach ($project_users as $project_user) {
             if ($to->getLeaderId() != $project_user->getUserId()) {
                 $user = $project_user->getUser();
                 if (instance_of($user, 'User')) {
                     $to->addUser($user, $project_user->getRole(), $project_user->getPermissions());
                 }
                 // if
             }
             // if
         }
         // foreach
     }
     // if
     // We need to move milestones in order to get milestones map
     $milestones_map = null;
     $milestones = Milestones::findAllByProject($this, VISIBILITY_PRIVATE);
     if (is_foreachable($milestones)) {
         $milestones_map = array();
         foreach ($milestones as $milestone) {
             $copied_milestone = $milestone->copyToProject($to);
             if (instance_of($copied_milestone, 'Milestone')) {
                 $copied_milestone->advance($diff, true);
                 $milestones_map[$milestone->getId()] = $copied_milestone;
             }
             // if
         }
         // foreach
     }
     // if
     // Now move categories
     $categories_map = null;
     $categories = Categories::findByProject($this);
     if (is_foreachable($categories)) {
         foreach ($categories as $category) {
             $copied_category = $category->copyToProject($to, null, null, false);
             if (instance_of($copied_category, 'Category')) {
                 $categories_map[$category->getId()] = $copied_category;
             }
             // if
         }
         // foreach
     }
     // if
     // Let the modules to their thing
     event_trigger('on_copy_project_items', array(&$this, &$to, $milestones_map, $categories_map));
     // Now, lets update due dates
     $completable_types = get_completable_project_object_types();
     if (is_foreachable($completable_types)) {
         foreach ($completable_types as $k => $type) {
             if (strtolower($type) == 'milestone') {
                 unset($completable_types[$k]);
             }
             // if
         }
         // foreach
         if (count($completable_types) > 0) {
             $rows = db_execute_all('SELECT id, due_on FROM ' . TABLE_PREFIX . 'project_objects WHERE project_id = ? AND type IN (?) AND due_on IS NOT NULL', $to->getId(), $completable_types);
             if (is_foreachable($rows)) {
                 foreach ($rows as $row) {
                     $id = (int) $row['id'];
                     $new_date = date(DATE_MYSQL, strtotime($row['due_on']) + $diff);
                     db_execute('UPDATE ' . TABLE_PREFIX . 'project_objects SET due_on = ? WHERE id = ?', $new_date, $id);
                     cache_remove("acx_project_objects_id_{$id}");
                 }
                 // foreach
             }
             // if
         }
         // if
     }
     // if
     // Refresh tasks count, just in case...
     $to->refreshTasksCount();
 }
 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);
 }
 /**
  * Get milestoned overdue
  * By default project_id is selected
  * @return model milestones
  */
 public function getOverdue()
 {
     return Milestones::model()->findOverdue(Yii::app()->user->getState('project_selected'));
 }
示例#20
0
 public function viewAction($goalID = -1)
 {
     $goal = Goals::findFirstByGoalID($goalID);
     if ($goal) {
         //check if user owns it
         $auth = $this->session->get('auth');
         $userID = $auth['userID'];
         $owned = false;
         if ($userID == $goal->seekerID) {
             $owned = true;
         }
         //get seeker info
         $seeker = Users::findFirstByUserID($goal->seekerID);
         //grab every milestone for goal
         $milestones = Milestones::findAllByGoalID($goal->goalID);
         //get completed/total number of milestones
         $totalMS = 1;
         $completedMS = 0;
         foreach ($milestones as $ms) {
             if ($ms->number > $totalMS) {
                 $totalMS = $ms->number;
             }
             if ($ms->isComplete == 1) {
                 $completedMS++;
             }
         }
         //pass data
         $this->view->setVar('goal', $goal);
         $this->view->setVar('userID', $userID);
         $this->view->setVar('milestones', $milestones);
         //$this->view->setVar('gifts', $gifts);
         $this->view->setVar('owned', $owned);
         $this->view->setVar('totalMS', $totalMS);
         $this->view->setVar('completedMS', $completedMS);
         $this->view->setVar('seeker', $seeker);
     } else {
         $this->flashSession->error("Error: Invalid Goal");
         $this->response->redirect("index");
         $this->view->disable();
     }
 }
 /**
  * Find successive milestones by a given milestone
  *
  * @param Milestone $milestone
  * @param integer $min_state
  * @param integer $min_visibility
  * @return array
  */
 function findSuccessiveByMilestone($milestone, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     return Milestones::find(array('conditions' => array('project_id = ? AND type = ? AND due_on >= ? AND state >= ? AND visibility >= ? AND id != ?', $milestone->getProjectId(), 'Milestone', $milestone->getDueOn(), $min_state, $min_visibility, $milestone->getId()), 'order' => 'name'));
 }
 /**
  * Return parent milestone
  *
  * @param void
  * @return Milestone
  */
 function &getMilestone()
 {
     if ($this->milestone === false) {
         $this->milestone = $this->getMilestoneId() ? Milestones::findById($this->getMilestoneId()) : null;
     }
     // if
     return $this->milestone;
 }
 public function MilestoneWithPendingTasks()
 {
     $criteria = new CDbCriteria();
     $criteria->select = "Users.*, count(Tasks.task_id) as pending_tasks";
     $criteria->condition = 't.milestone_duedate < NOW() AND Tasks.status_id IN (' . implode(',', array(Status::STATUS_PENDING, Status::STATUS_ACCEPTED, Status::STATUS_TOTEST, Status::STATUS_INPROGRESS)) . ')';
     $criteria->group = 't.milestone_id';
     return Milestones::model()->with('Users', 'Tasks')->together()->findAll($criteria);
 }
 function index()
 {
     parent::index();
     $milestones_t = Milestones::findAllByProject($this->active_project);
     $tasks_t = Tasks::findByProject($this->active_project, $this->logged_user);
     $milestones = array();
     $tasks = array();
     // voglio il task non categorizzato che inizia prima di tutti, quindi setto questo nel futuro
     $first_task_time = new DateValue(time() + time());
     $trovato = false;
     if (is_foreachable($tasks_t)) {
         foreach ($tasks_t as $task) {
             $res = array();
             $res['id'] = $task->getTaskId();
             $res['name'] = $task->getName();
             $task->complete()->describe($this->logged_user, true, true, $completion_description);
             $task_description = $task->describe($this->logged_user, true, true);
             $res['is_completed'] = $completion_description['is_completed'];
             $res['completed_on'] = $completion_description['completed_on'];
             $res['due_on'] = $completion_description['due_on'];
             // non è sempre settato
             $res['milestone_id'] = $task_description['milestone_id'] ? $task_description['milestone_id'] : 0;
             $res['created_on_d'] = $task->getCreatedOn()->getDay();
             $res['created_on_m'] = $task->getCreatedOn()->getMonth() - 1;
             $res['created_on_y'] = $task->getCreatedOn()->getYear();
             // La data di inizio non è sempre presente. Quindi se non c'è, prendo la data di creazione del task.
             // Inoltre questo campo dipende dal modulo TaskPlus
             if (AngieApplication::isModuleLoaded('tasks_plus') && TaskPlus::getStartOn($task)) {
                 $start_on = TaskPlus::getStartOn($task);
             } else {
                 $start_on = $task->getCreatedOn();
             }
             $res['start_on_d'] = $start_on->getDay();
             $res['start_on_m'] = $start_on->getMonth() - 1;
             //javascript merda parte da Gennaio = 0
             $res['start_on_y'] = $start_on->getYear();
             // giorni in più
             $days = 60 * 60 * 24 * 15;
             //15 giorni in più
             if ($completion_description['is_completed']) {
                 $completion_date = $completion_description['completed_on'];
             } else {
                 if ($completion_description['due_on']) {
                     // non è completata ma ha data di fine settata
                     $completion_date = $completion_description['due_on'];
                 } else {
                     if (!$completion_description['due_on']) {
                         // non è completata e non ha data di fine settata
                         $completion_date = $start_on->advance($days, false);
                         // (data_inizio || data_creazione) + 15 giorni
                     }
                 }
             }
             $res['finish_on_d'] = $completion_date->getDay();
             $res['finish_on_m'] = $completion_date->getMonth() - 1;
             //javascript merda parte da Gennaio = 0
             $res['finish_on_y'] = $completion_date->getYear();
             $res['durata'] = $start_on->daysBetween($completion_date) * 8;
             //giorni_differenza * ore_lavorative
             if ($res['is_completed']) {
                 $res['percent_completion'] = 100;
             } else {
                 list($total_subtasks, $open_subtasks) = ProjectProgress::getObjectProgress($task);
                 $completed_subtasks = $total_subtasks - $open_subtasks;
                 if ($open_subtasks) {
                     $res['percent_completion'] = ceil($completed_subtasks / $total_subtasks * 100);
                 } else {
                     $res['percent_completion'] = 0;
                 }
             }
             $tasks[] = $res;
             if ($res['milestone_id'] == 0 && $first_task_time->getTimestamp() > $start_on->getTimestamp()) {
                 $first_task_time = $start_on;
                 $trovato = false;
             }
         }
     }
     if ($trovato) {
         //Aggiungo la milestone per tasks non categorizzati
         $milestones[0]['id'] = 0;
         $milestones[0]['name'] = lang("Uncategorized");
         $milestones[0]['start_on_d'] = $first_task_time->getDay();
         $milestones[0]['start_on_m'] = $first_task_time->getMonth() - 1;
         $milestones[0]['start_on_y'] = $first_task_time->getYear();
         $milestones[0]['durata'] = 1;
     }
     if (is_foreachable($milestones_t)) {
         foreach ($milestones_t as $milestone) {
             $res = array();
             $res['id'] = $milestone->getId();
             $res['name'] = $milestone->getName();
             $res['start_on_d'] = $milestone->getStartOn()->getDay();
             $res['start_on_m'] = $milestone->getStartOn()->getMonth() - 1;
             //javascript merda parte da Gennaio = 0
             $res['start_on_y'] = $milestone->getStartOn()->getYear();
             $res['durata'] = ($milestone->getDueOn()->getTimestamp() - $milestone->getStartOn()->getTimestamp()) / (60 * 60 * 24) * 8;
             //giorni * ore lavorative
             $milestones[] = $res;
         }
     }
     $this->smarty->assign(array('milestones' => $milestones, 'tasks' => $tasks));
 }
示例#25
0
 /**
  * Find project objects in commit message, make them links and
  * save the relations to database
  *
  * @param string $commit_message
  * @param string $commit_author
  * @param integer $revision
  * @param Repository $repository
  * @param Project $project
  * @return string
  */
 function analyze_message($commit_message, $commit_author, $revision, $repository, $project)
 {
     if (define('PURIFY_HTML') && PURIFY_HTML) {
         $commit_message = purify_html($commit_message);
         // Clean!
     }
     // if
     $pattern = '/((complete[d]*)[\\s]+)?(ticket|milestone|discussion|task)[s]*[\\s]+[#]*\\d+/i';
     if (preg_match_all($pattern, $commit_message, $matches)) {
         $i = 0;
         $search = array();
         $replace = array();
         $matches_unique = array_unique($matches['0']);
         foreach ($matches_unique as $key => $match) {
             $match_data = preg_split('/[\\s,]+/', $match, null, PREG_SPLIT_NO_EMPTY);
             // check if the object got completed by this commit
             $object_completed = false;
             if (strpos(strtolower($match_data['0']), 'complete') !== false) {
                 $object_completed = true;
                 unset($match_data['0']);
                 $match_data = array_values($match_data);
             }
             // if
             $object_class_name = $match_data['0'];
             $module_name = Inflector::pluralize($object_class_name);
             $object_id = trim($match_data['1'], '#');
             $search[$i] = $match;
             if (class_exists($module_name) && class_exists($object_class_name)) {
                 $object = null;
                 switch (strtolower($module_name)) {
                     case 'tickets':
                         $object = Tickets::findByTicketId($project, $object_id);
                         break;
                     case 'discussions':
                         $object = Discussions::findById($object_id);
                         break;
                     case 'milestones':
                         $object = Milestones::findById($object_id);
                         break;
                     case 'tasks':
                         $object = Tasks::findById($object_id);
                         break;
                 }
                 // switch
                 if (instance_of($object, $object_class_name)) {
                     $link_already_created = CommitProjectObjects::count("object_id = '" . $object->getId() . "' AND revision = '{$revision}'") > 0;
                     if (!$link_already_created) {
                         $comit_project_object = new CommitProjectObject();
                         $comit_project_object->setProjectId($object->getProjectId());
                         $comit_project_object->setObjectId($object->getId());
                         $comit_project_object->setObjectType(ucfirst($object_class_name));
                         $comit_project_object->setRepositoryId($repository->getId());
                         $comit_project_object->setRevision($revision);
                         db_begin_work();
                         $save = $comit_project_object->save();
                         if ($save && !is_error($save)) {
                             db_commit();
                         } else {
                             db_rollback();
                         }
                         // if save
                     }
                     // if
                     $replace[$i] = ($object_completed ? 'Completed ' : '') . '<a href="' . $object->getViewUrl() . '">' . $match_data['0'] . ' ' . $match_data['1'] . '</a>';
                     // set the object as completed
                     if ($object_completed && !instance_of($object, 'Discussion')) {
                         $completed_by = $repository->getMappedUser($commit_author);
                         $object->complete($completed_by);
                     }
                     // if
                 } else {
                     $replace[$i] = ($object_completed ? 'Completed ' : '') . '<a href="#" class="project_object_missing" title="' . lang('Project object does not exist in this project') . '">' . $match_data['0'] . ' ' . $match_data['1'] . '</a>';
                 }
                 // if instance_of
                 $i++;
             }
             // if module loaded
         }
         // foreach
         return str_ireplace($search, $replace, htmlspecialchars($commit_message));
         // linkify
     }
     // if preg_match
     return $commit_message;
 }
<?php

require_once 'commandLine.inc';
require_once "{$IP}/extensions/wikihow/Milestones.class.php";
$action = $argv[0];
if ($action == "update") {
    $yesterday = $argv[1];
    if (preg_match('@[^0-9]@', $yesterday)) {
        echo "Must include a date (yyyymmdd) as last parameter\n";
        exit;
    }
    $milestone = new Milestones();
    $milestone->updateEditMilestones($yesterday);
} elseif ($action == "email") {
    $yesterday = $argv[1];
    if (preg_match('@[^0-9]@', $yesterday)) {
        echo "Must include a date (yyyymmdd) as last parameter\n";
        exit;
    }
    $milestone = new Milestones();
    $milestone->sendMilestoneEmails($yesterday);
} else {
    $yesterdayUnix = strtotime('midnight yesterday');
    $yesterday = substr(wfTimestamp(TS_MW, $yesterdayUnix), 0, 8);
    $milestone = new Milestones();
    $milestone->updateEditMilestones($yesterday);
    $milestone->sendMilestoneEmails($yesterday);
}
 /**
  * Creates a new model.
  */
 public function actionCreate()
 {
     // create Comments Object
     $model = new Comments();
     // if Comments form exist
     if (isset($_POST['Comments'])) {
         // set form elements to Comments model attributes
         $model->attributes = $_POST['Comments'];
         $module = Modules::model()->find(array('condition' => 't.module_name = :module_name', 'params' => array(':module_name' => $model->module_id)));
         // set module_id finded to model
         $model->module_id = $module->module_id;
         $project = Yii::app()->user->getState('project_selected');
         $model->project_id = $project;
         // validate and save
         if ($model->save()) {
             // create an instance of file uploaded
             $image = CUploadedFile::getInstancesByName('Comment');
             // if file upload exist
             if (count($image > 0)) {
                 // for each file uploaded
                 for ($i = 0; $i < count($image); $i++) {
                     // create an Document object
                     $modeldocs = new Documents();
                     $modeldocs->image = $image[$i];
                     if (!$modeldocs->image->getError()) {
                         // name is formed by date(day+month+year+hour+minutes+seconds+dayofyear+microtime())
                         $this->tmpFileName = str_replace(" ", "", date('dmYHis-z-') . microtime());
                         // set the extension file uploaded
                         $extension = $modeldocs->image->getExtensionName();
                         // if no error saving file
                         if ($modeldocs->image->saveAs(self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension)) {
                             $modeldocs->project_id = $project;
                             $modeldocs->document_name = substr($modeldocs->image->getName(), 0, 30);
                             $modeldocs->document_description = $model->comment_text;
                             $modeldocs->document_path = self::FOLDERIMAGES . $this->tmpFileName . '.' . $extension;
                             $modeldocs->document_revision = '1';
                             $modeldocs->document_uploadDate = date("Y-m-d");
                             $modeldocs->document_type = $modeldocs->image->getType();
                             $modeldocs->document_baseRevision = date('dmYHis');
                             $modeldocs->user_id = Yii::app()->user->id;
                             $modeldocs->comment_id = $model->primaryKey;
                             // save file uploaded as document
                             if ($modeldocs->save()) {
                                 Yii::app()->user->setFlash('CommentMessageSuccess', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadOk'));
                             } else {
                                 Yii::app()->user->setFlash('CommentMessage', $modeldocs->getErrors());
                             }
                         } else {
                             Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->getName() . " " . Yii::t('comments', 'UploadError'));
                         }
                     } else {
                         Yii::app()->user->setFlash('CommentMessage', $modeldocs->image->error . " " . Yii::t('comments', 'UploadCheckErrors'));
                     }
                 }
             }
             // save log
             $attributes = array('log_date' => date("Y-m-d G:i:s"), 'log_activity' => 'CommentPosted', 'log_resourceid' => $model->comment_resourceid, 'log_type' => Logs::LOG_COMMENTED, 'log_commentid' => $model->primaryKey, 'user_id' => Yii::app()->user->id, 'module_id' => $module->module_name, 'project_id' => $project);
             Logs::model()->saveLog($attributes);
             // find project managers to sent comment via mail
             $recipientsList = array();
             $ProjectManagers = Projects::model()->findManagersByProject($project);
             $managersArray = array();
             foreach ($ProjectManagers as $manager) {
                 $managersArray['email'] = $manager->user_email;
                 $managersArray['name'] = $manager->CompleteName;
                 array_push($recipientsList, $managersArray);
             }
             // find task owners to send comment via mail
             if ($module->module_name == 'tasks') {
                 $collaborators = Projects::model()->findAllUsersByProject($project);
                 $ColaboratorsArray = array();
                 foreach ($collaborators as $colaborator) {
                     $ColaboratorsArray['email'] = $colaborator->user_email;
                     $ColaboratorsArray['name'] = $colaborator->CompleteName;
                     // avoid to repeat email address
                     if (!in_array($ColaboratorsArray, $recipientsList)) {
                         array_push($recipientsList, $ColaboratorsArray);
                     }
                 }
             }
             // finding resource title
             switch ($module->module_name) {
                 case "budgets":
                     $resourceModelTitle = Budgets::model()->findByPk($model->comment_resourceid)->budget_title;
                     break;
                 case "invoices":
                     $resourceModelTitle = Invoices::model()->findByPk($model->comment_resourceid)->invoice_number;
                     break;
                 case "expenses":
                     $resourceModelTitle = Expenses::model()->findByPk($model->comment_resourceid)->expense_name;
                     break;
                 case "documents":
                     $resourceModelTitle = Documents::model()->findByPk($model->comment_resourceid)->document_name;
                     break;
                 case "milestones":
                     $resourceModelTitle = Milestones::model()->findByPk($model->comment_resourceid)->milestone_title;
                     break;
                 case "cases":
                     $resourceModelTitle = Cases::model()->findByPk($model->comment_resourceid)->case_name;
                     break;
                 case "tasks":
                     $resourceModelTitle = Tasks::model()->findByPk($model->comment_resourceid)->task_name;
                     break;
                 default:
                     $resourceModelTitle = "{empty}";
                     break;
             }
             // get project information
             $project = Projects::model()->findByPk($project);
             // prepare template to send via email
             $str = $this->renderPartial('//templates/comments/created', array('model' => $model, 'projectName' => $project->project_name, 'userposted' => Yii::app()->user->CompleteName, 'resourceTitle' => $resourceModelTitle, 'moduleName' => Yii::t('modules', $module->module_name), 'applicationName' => Yii::app()->name, 'applicationUrl' => Yii::app()->createAbsoluteUrl($module->module_name . '/view', array('id' => $model->comment_resourceid))), true);
             Yii::import('application.extensions.phpMailer.yiiPhpMailer');
             $mailer = new yiiPhpMailer();
             $subject = Yii::t('email', 'CommentPosted') . " - " . $project->project_name . " - " . Yii::t('modules', $module->module_name);
             $mailer->pushMail($subject, $str, $recipientsList, Emails::PRIORITY_NORMAL);
         } else {
             Yii::app()->user->setFlash('CommentMessage', Yii::t('comments', 'RequiredComment'));
         }
     }
     $this->redirect(Yii::app()->createUrl($_GET['module'] . '/' . $_GET['action'], array('id' => $_GET['id'], '#' => 'comment-' . $model->primaryKey)));
 }
 /**
  * Add AC object links to commit messages
  *
  * @param string
  * @return string
  **/
 private function analyzeCommitMessage($commit_message)
 {
     $pattern = '/(ticket|milestone|discussion|task)[s]*[\\s]+[#]*(\\d+)/i';
     if (preg_match_all($pattern, $commit_message, $matches)) {
         $i = 0;
         $search = array();
         $replace = array();
         $matches_unique = array_unique($matches['0']);
         foreach ($matches_unique as $key => $match) {
             $match_data = preg_split('/[\\s,]+/', $match, null, PREG_SPLIT_NO_EMPTY);
             $object_class_name = $match_data['0'];
             $module_name = Inflector::pluralize($object_class_name);
             $object_id = trim($match_data['1'], '#');
             $search[$i] = $match;
             if (class_exists($module_name) && class_exists($object_class_name)) {
                 $object = null;
                 switch (strtolower($module_name)) {
                     case 'tickets':
                         $object = Tickets::findByTicketId($this->active_project, $object_id);
                         break;
                     case 'discussions':
                         $object = Discussions::findById($object_id);
                         break;
                     case 'milestones':
                         $object = Milestones::findById($object_id);
                         break;
                     case 'tasks':
                         $object = Tasks::findById($object_id);
                         break;
                 }
                 // switch
                 if (instance_of($object, $object_class_name)) {
                     $replace[$i] = '<a href="' . $object->getViewUrl() . '">' . $match_data['0'] . ' ' . $match_data['1'] . '</a>';
                 } else {
                     $replace[$i] = '<a href="#" class="project_object_missing" title="' . lang('Project object does not exist in this project') . '">' . $match_data['0'] . ' ' . $match_data['1'] . '</a>';
                 }
                 // if instance_of
                 $i++;
             }
             // if module loaded
         }
         // foreach
         return str_ireplace($search, $replace, htmlspecialchars($commit_message));
         // linkify
     }
     // if preg_match
     return $commit_message;
 }
 /**
  * Return associative array of changes that is easy to display
  *
  * @param void
  * @return array
  */
 function getVerboseChanges()
 {
     $result = array();
     if (is_foreachable($this->getChanges())) {
         foreach ($this->getChanges() as $field => $change_data) {
             list($old_value, $new_value) = $change_data;
             $log_fields = array('project_id', 'milestone_id', 'parent_id', 'name', 'body', 'priority', 'due_on');
             switch ($field) {
                 case 'project_id':
                     $old_project = Projects::findById($old_value);
                     $new_project = Projects::findById($new_value);
                     $old_project_name = instance_of($old_project, 'Project') ? $old_project->getName() : lang('unknown project');
                     $new_project_name = instance_of($new_project, 'Project') ? $new_project->getName() : lang('unknown project');
                     $result[] = lang('Moved from <span>:from</span> to <span>:to</span>', array('from' => $old_project_name, 'to' => $new_project_name));
                     break;
                 case 'milestone_id':
                     $old_milestone = Milestones::findById($old_value);
                     $new_milestone = Milestones::findById($new_value);
                     $old_milestone_name = instance_of($old_milestone, 'Milestone') ? $old_milestone->getName() : lang('-- none --');
                     $new_milestone_name = instance_of($new_milestone, 'Milestone') ? $new_milestone->getName() : lang('-- none --');
                     $result[] = lang('Moved from <span>:from</span> to <span>:to</span> milestone', array('from' => $old_milestone_name, 'to' => $new_milestone_name));
                     break;
                 case 'parent_id':
                     $old_parent = ProjectObjects::findById($old_value);
                     $new_parent = ProjectObjects::findById($new_value);
                     $old_parent_name = instance_of($old_parent, 'Category') ? $old_parent->getName() : lang('-- none --');
                     $new_parent_name = instance_of($new_parent, 'Category') ? $new_parent->getName() : lang('-- none --');
                     $result[] = lang('Moved from <span>:from</span> to <span>:to</span> category', array('from' => $old_parent_name, 'to' => $new_parent_name));
                     break;
                 case 'name':
                     $result[] = lang('Summary is changed from <span>:from</span> to <span>:to</span>', array('from' => $old_value, 'to' => $new_value));
                     break;
                 case 'body':
                     $result[] = lang('Long description is changed');
                     break;
                 case 'priority':
                     switch ($old_value) {
                         case PRIORITY_HIGHEST:
                             $old_priority = lang('Highest');
                             break;
                         case PRIORITY_HIGH:
                             $old_priority = lang('High');
                             break;
                         case PRIORITY_NORMAL:
                             $old_priority = lang('Normal');
                             break;
                         case PRIORITY_LOW:
                             $old_priority = lang('Low');
                             break;
                         case PRIORITY_LOWEST:
                             $old_priority = lang('Lowest');
                             break;
                         case PRIORITY_ONGOING:
                             $old_priority = lang('Ongoing');
                             break;
                         case PRIORITY_HOLD:
                             $old_priority = lang('Hold');
                             break;
                     }
                     // switch
                     switch ($new_value) {
                         case PRIORITY_HIGHEST:
                             $new_priority = lang('Highest');
                             break;
                         case PRIORITY_HIGH:
                             $new_priority = lang('High');
                             break;
                         case PRIORITY_NORMAL:
                             $new_priority = lang('Normal');
                             break;
                         case PRIORITY_LOW:
                             $new_priority = lang('Low');
                             break;
                         case PRIORITY_LOWEST:
                             $new_priority = lang('Lowest');
                             break;
                         case PRIORITY_ONGOING:
                             $new_priority = lang('Ongoing');
                             break;
                         case PRIORITY_HOLD:
                             $new_priority = lang('Hold');
                             break;
                     }
                     // switch
                     $result[] = lang('Priority is changed from <span>:from</span> to <span>:to</span>', array('from' => $old_priority, 'to' => $new_priority));
                     break;
                 case 'due_on':
                     require_once SMARTY_PATH . '/plugins/modifier.date.php';
                     $old_due_on = instance_of($old_value, 'DateValue') ? smarty_modifier_date($old_value, 0) : lang('-- none --');
                     $new_due_on = instance_of($new_value, 'DateValue') ? smarty_modifier_date($new_value, 0) : lang('-- none --');
                     $result[] = lang('Due date is changed from <span>:from</span> to <span>:to</span>', array('from' => $old_due_on, 'to' => $new_due_on));
                     break;
                 case 'completed_on':
                     if (instance_of($old_value, 'DateValue') && $new_value === null) {
                         $result[] = lang('Status changed to: Open');
                     } elseif ($old_value === null && instance_of($new_value, 'DateValue')) {
                         $result[] = lang('Status changed to: Completed');
                     }
                     // if
                     break;
                 case 'owner':
                     if ($new_value) {
                         $new_owner = Users::findById($new_value);
                         if (instance_of($new_owner, 'User')) {
                             $result[] = lang(':user is responsible', array('user' => $new_owner->getDisplayName()));
                         } else {
                             $result[] = lang('Owner changed (unknown user or deleted in the meantime)');
                         }
                         // if
                     } else {
                         $result[] = lang('Anyone can pick up and work on this ticket');
                     }
                     // if
                     break;
                 case 'assignees':
                     $old_assignees = array();
                     if (is_foreachable($old_value)) {
                         $old_assignees_users = Users::findByIds($old_value);
                         if (is_foreachable($old_assignees_users)) {
                             foreach ($old_assignees_users as $user) {
                                 $old_assignees[$user->getId()] = $user->getDisplayName();
                             }
                             // foreach
                         }
                         // if
                     }
                     // if
                     $new_assignees = array();
                     if (is_foreachable($new_value)) {
                         $new_assignees_users = Users::findByIds($new_value);
                         if (is_foreachable($new_assignees_users)) {
                             foreach ($new_assignees_users as $user) {
                                 $new_assignees[$user->getId()] = $user->getDisplayName();
                             }
                             // foreach
                         }
                         // if
                     }
                     // if
                     foreach ($new_assignees as $new_assignee_id => $new_assignee) {
                         if (!array_key_exists($new_assignee_id, $old_assignees)) {
                             $result[] = lang(':user has been assigned to this ticket', array('user' => $new_assignee));
                         }
                         // if
                     }
                     // foreach
                     foreach ($old_assignees as $old_assignee_id => $old_assignee) {
                         if (!array_key_exists($old_assignee_id, $new_assignees)) {
                             $result[] = lang(':user has been removed from this ticket', array('user' => $old_assignee));
                         }
                         // if
                     }
                     // foreach
                     break;
             }
             // switch
         }
         // foreach
     }
     // if
     return $result;
 }
 /**
  * Return all milestones next to due
  * By default project_id is selected
  * @return model list of milestones
  */
 public function getActivity()
 {
     return Milestones::model()->findActivity(Yii::app()->user->getState('project_selected'));
 }