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);
     }
 }
 /**
  * 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;
 }
 /**
  * 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)));
 }
 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);
 }
 /**
  * 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'));
     }
 }
 /**
  * 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'));
 }
Beispiel #7
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;
 }
 /**
  * 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'));
 }
Beispiel #9
0
        echo $type->getLink(CHtml::encode($type->title) . ' <small>(' . Yii::app()->format->number($type->ticketsCount) . ')</small>');
        ?>
                                </li>
                                <?php 
    }
    ?>
							</ul> 
		              </li>
		              <li class="widget-container">
		                  <h3><?php 
    echo Yii::t('global', 'Milestones');
    ?>
</h3>
		                      <ul>
								<?php 
    foreach (Milestones::model()->with(array('ticketsCount'))->findAll() as $milestone) {
        ?>
    							<li>
                                    <?php 
        echo $milestone->getRssLink(CHtml::image(Yii::app()->themeManager->baseUrl . '/images/atom.gif', 'ATOM'), array('class' => 'atom'), 'atom');
        ?>
                                    <?php 
        echo $milestone->getRssLink(CHtml::image(Yii::app()->themeManager->baseUrl . '/images/rss.gif', 'RSS'), array('class' => 'rss'));
        ?>
                                    <?php 
        echo $milestone->getLink(CHtml::encode($milestone->title) . ' <small>(' . Yii::app()->format->number($milestone->ticketsCount) . ')</small>');
        ?>
                                </li>
                                <?php 
    }
    ?>
 /**
  * This method is invoked right before an action is to be executed (after all possible filters.)
  * @param CAction $action the action to be executed.
  * @return boolean whether the action should be executed
  */
 public function beforeAction($action)
 {
     $response = false;
     if (Yii::app()->user->getState('project_selected') != null) {
         if (in_array($action->id, array('view', 'update'))) {
             $response = Milestones::model()->countMilestonesByProject((int) $_GET['id'], Yii::app()->user->getState('project_selected')) > 0 ? true : false;
         } else {
             $response = true;
         }
     } else {
         $response = false;
     }
     if (!$response) {
         throw new CHttpException(403, Yii::t('site', '403_Error'));
     } else {
         return $response;
     }
 }