/**
  * Return repository which was first added and last commit info
  *
  * @param Project $project
  * @return array
  */
 function findByPortalProject($project)
 {
     $repository = ProjectObjects::find(array('conditions' => array('project_id = ? AND type = ? AND state >= ?', $project->getId(), 'Repository', STATE_VISIBLE), 'order' => 'created_on ASC', 'one' => true));
     if (instance_of($repository, 'Repository')) {
         $repository->last_commit = $repository->getLastCommit();
     }
     // if
     return $repository;
 }
 /**
  * Return TimeRecords by parent
  *
  * @param ProjectObject $parent
  * @param array $billable_status
  * @param integer $min_state
  * @param integer $min_visibility
  * @return array
  */
 function findByParent($parent, $billable_status = null, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     if (is_foreachable($billable_status)) {
         $conditions = array('parent_id = ? AND type = ? AND state >= ? AND visibility >= ? and integer_field_2 IN (?)', $parent->getId(), 'TimeRecord', $min_state, $min_visibility, $billable_status);
     } else {
         $conditions = array('parent_id = ? AND type = ? AND state >= ? AND visibility >= ?', $parent->getId(), 'TimeRecord', $min_state, $min_visibility);
     }
     // if
     return ProjectObjects::find(array('conditions' => $conditions, 'order' => 'date_field_1 DESC, id DESC'));
 }
 /**
  * Find trashed project objects
  *
  * @param User $user
  * @return null
  */
 function findTrashed($user)
 {
     $type_filter = ProjectUsers::getVisibleTypesFilter($user, array(PROJECT_STATUS_ACTIVE, PROJECT_STATUS_PAUSED, PROJECT_STATUS_CANCELED, PROJECT_STATUS_COMPLETED));
     if ($type_filter) {
         return ProjectObjects::find(array('conditions' => array($type_filter . ' AND state = ? AND visibility >= ?', STATE_DELETED, $user->getVisibility()), 'order' => 'updated_on'));
     } else {
         return null;
     }
 }
 /**
  * Return all milestones for a given portal project
  *
  * @param Portal $portal
  * @param Project $project
  * @return array
  */
 function findByPortalProject($portal, $project)
 {
     if ($portal->getProjectPermissionValue('milestone') >= PROJECT_PERMISSION_ACCESS) {
         return ProjectObjects::find(array('conditions' => array('project_id = ? AND type = ? AND state >= ? AND visibility >= ?', $project->getId(), 'Milestone', STATE_VISIBLE, VISIBILITY_NORMAL), 'order' => 'name'));
     }
     // if
     return null;
 }
 /**
  * Serve iCal data
  *
  * @param void
  * @return null
  */
 function ical()
 {
     if ($this->active_project->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $filter = ProjectUsers::getVisibleTypesFilterByProject($this->logged_user, $this->active_project, get_completable_project_object_types());
     if ($filter) {
         $objects = ProjectObjects::find(array('conditions' => array($filter . ' AND completed_on IS NULL AND state >= ? AND visibility >= ?', STATE_VISIBLE, $this->logged_user->getVisibility()), 'order' => 'priority DESC'));
         render_icalendar($this->active_project->getName() . ' ' . lang('calendar'), $objects);
         die;
     } else {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
 }
 /**
  * Export discussions
  *
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $module_objects = Discussions::findByProject($this->active_project, STATE_VISIBLE, $object_visibility);
     $module_categories = Categories::findByModuleSection($this->active_project, $this->active_module, $this->active_module);
     $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index');
     $output_builder->smarty->assign('categories', $module_categories);
     $output_builder->smarty->assign('objects', $module_objects);
     $output_builder->outputToFile('index');
     // export files by categories
     if (is_foreachable($module_categories)) {
         foreach ($module_categories as $module_category) {
             if (instance_of($module_category, 'Category')) {
                 $objects = ProjectObjects::find(array('conditions' => array('parent_id = ? AND project_id = ? AND type = ? AND state >= ? AND visibility >= ?', $module_category->getId(), $this->active_project->getId(), 'Discussion', STATE_VISIBLE, $object_visibility), 'order' => 'boolean_field_1, datetime_field_1 DESC'));
                 $output_builder->smarty->assign(array('current_category' => $module_category, 'objects' => $objects));
                 $output_builder->outputToFile('category_' . $module_category->getId());
             }
             // if
         }
         // foreach
     }
     // if
     // export discussions
     if (is_foreachable($module_objects)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'object');
         foreach ($module_objects as $module_object) {
             if (instance_of($module_object, 'Discussion')) {
                 $comments = $module_object->getComments($object_visibility);
                 $output_builder->smarty->assign(array('object' => $module_object));
                 $output_builder->smarty->assign('comments', $comments);
                 $output_builder->outputToFile('discussion_' . $module_object->getId());
                 $output_builder->outputObjectsAttachments($comments);
                 $output_builder->outputAttachments($module_object->getAttachments());
             }
             // if
         }
         // foreach
     }
     // if
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 /**
  * Export project pages
  *
  * @param void
  * @return null
  */
 function export()
 {
     $object_visibility = array_var($_GET, 'visibility', VISIBILITY_NORMAL);
     $exportable_modules = explode(',', array_var($_GET, 'modules', null));
     if (!is_foreachable($exportable_modules)) {
         $exportable_modules = null;
     }
     // if
     require_once PROJECT_EXPORTER_MODULE_PATH . '/models/ProjectExporterOutputBuilder.class.php';
     $output_builder = new ProjectExporterOutputBuilder($this->active_project, $this->smarty, $this->active_module, $exportable_modules);
     if (!$output_builder->createOutputFolder()) {
         $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
     }
     // if
     $output_builder->createAttachmentsFolder();
     $module_categories = Categories::findByModuleSection($this->active_project, PAGES_MODULE, 'pages');
     $output_builder->smarty->assign(array('categories' => $module_categories, 'visibility' => $object_visibility));
     $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'index');
     $output_builder->outputToFile('index');
     if (is_foreachable($module_categories)) {
         foreach ($module_categories as $module_category) {
             $output_builder->smarty->assign('current_category', $module_category);
             $output_builder->smarty->assign('objects', Pages::findByCategory($module_category, STATE_VISIBLE, $object_visibility));
             $output_builder->outputToFile('category_' . $module_category->getId());
         }
         // foreach
     }
     // if
     $pages = ProjectObjects::find(array("conditions" => array("project_id = ? AND module = ? AND type = ?", $this->active_project->getId(), 'pages', 'Page')));
     $page_ids = array();
     if (is_foreachable($pages)) {
         $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'object');
         foreach ($pages as $page) {
             if (instance_of($page, 'Page')) {
                 $page_ids[] = $page->getId();
                 $parent = $page->getParent();
                 $comments = $page->getComments($object_visibility);
                 $output_builder->smarty->assign(array('page' => $page, 'subpages' => $page->getSubpages($object_visibility), 'parent' => $parent, 'comments' => $comments));
                 if (instance_of($parent, 'Page')) {
                     $output_builder->smarty->assign('parent_url', './page_' . $parent->getId() . '.html');
                 } else {
                     if (instance_of($parent, 'Category')) {
                         $output_builder->smarty->assign('parent_url', './category_' . $parent->getId() . '.html');
                     }
                 }
                 // if
                 $output_builder->outputToFile('page_' . $page->getId());
                 $output_builder->outputObjectsAttachments($comments);
                 $output_builder->outputAttachments($page->getAttachments());
             }
             // if
         }
         // foreach
         $revisions = PageVersions::findByPageIds($page_ids);
         if (is_foreachable($revisions)) {
             $output_builder->setFileTemplate($this->active_module, $this->controller_name, 'revision');
             foreach ($revisions as $revision) {
                 $output_builder->smarty->assign('revision', $revision);
                 $output_builder->outputToFile('revision_' . $revision->getPageId() . '_' . $revision->getVersion());
             }
             // foreach
         }
         // if
     }
     // if
     $this->serveData($output_builder->execution_log, 'execution_log', null, FORMAT_JSON);
 }
 /**
  * Render global iCalendar feed
  *
  * @param void
  * @return null
  */
 function ical()
 {
     $filter = ProjectUsers::getVisibleTypesFilter($this->logged_user, array(PROJECT_STATUS_ACTIVE), get_completable_project_object_types());
     if ($filter) {
         $objects = ProjectObjects::find(array('conditions' => array($filter . ' AND completed_on IS NULL AND state >= ? AND visibility >= ?', STATE_VISIBLE, $this->logged_user->getVisibility()), 'order' => 'priority DESC'));
         render_icalendar(lang('Global Calendar'), $objects, true);
         die;
     } elseif ($this->request->get('subscribe')) {
         flash_error(lang('You are not able to download .ics file because you are not participating in any of the active projects at the moment'));
         $this->redirectTo('ical_subscribe');
     } else {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
 }
 /**
  * Return categories for module section (ex. attachments of resources module)
  *
  * @param Project $project
  * @param string $module
  * @param string $controller
  * @return array
  */
 function findByModuleSection($project, $module, $controller)
 {
     return ProjectObjects::find(array('conditions' => array('type = ? AND project_id = ? AND module = ? AND state >= ? AND varchar_field_1 = ?', 'Category', $project->getId(), $module, STATE_VISIBLE, $controller), 'order' => 'name'));
 }
 /**
  * Return only completed tasks that belong to a specific object
  *
  * @param ProjectObject $object
  * @param integer $limit
  * @param integer $min_state
  * @return array
  */
 function findCompletedByObject($object, $limit = NULL, $min_state = STATE_VISIBLE)
 {
     $conditions = array('conditions' => array('parent_id = ? AND type = ? AND state >= ? AND completed_on IS NOT NULL', $object->getId(), 'Task', $min_state), 'order' => 'completed_on DESC');
     if ($limit !== null) {
         $conditions['limit'] = $limit;
     }
     // if
     return ProjectObjects::find($conditions);
 }
 function findOpenByMilestone($milestone, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     return ProjectObjects::find(array('conditions' => array('milestone_id = ? AND type = ? AND state >= ? AND visibility >= ? AND completed_on IS NULL', $milestone->getId(), 'Ticket', $min_state, $min_visibility), 'order' => 'name'));
 }
 /**
  * Return files by category
  *
  * @param Category $category
  * @param integer $min_state
  * @param integer $min_visibility
  * @return array
  */
 function findByCategory($category, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     return ProjectObjects::find(array('conditions' => array('parent_id = ? AND type = ? AND state >= ? AND visibility >= ?', $category->getId(), 'Discussion', $min_state, $min_visibility), 'order' => 'boolean_field_1 DESC, datetime_field_1 DESC'));
 }
 /**
  * Return completed checklists by project
  *
  * @param Project $project
  * @param integer $min_state
  * @param integer $min_visibility
  * @return array
  */
 function findCompletedByProject($project, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     return ProjectObjects::find(array('conditions' => array('project_id = ? AND type = ? AND state >= ? AND visibility >= ? AND completed_on IS NOT NULL', $project->getId(), 'Checklist', $min_state, $min_visibility), 'order' => 'ISNULL(position) ASC, position, created_on'));
 }
 function findByCategories($categories, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     $categories_string = '';
     $project_id = 0;
     foreach ($categories as $category) {
         if (empty($project_id)) {
             $project_id = $category->getProjectId();
         }
         $categories_string .= $category->getId() . ', ';
     }
     if (!empty($categories_string)) {
         $categories_string = substr($categories_string, 0, -2);
         if ($project_id == TASK_LIST_PROJECT_ID) {
             $listing_new = array();
             $listing = ProjectObjects::find(array('conditions' => array('parent_id in (?) AND type = ? AND state >= ? AND visibility >= ? and completed_on is null', $categories_string, 'Page', $min_state, $min_visibility), 'order' => 'name'));
             $link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
             mysql_select_db(DB_NAME);
             foreach ($listing as $entry) {
                 $temp_name = $entry->getName();
                 if (strpos($temp_name, '-') !== false) {
                     $temp_name = trim(substr($temp_name, 0, strpos($temp_name, '-')));
                     @(list($first_name, $last_name, ) = explode(' ', $temp_name));
                     $query = mysql_query("select * from healingcrystals_users where first_name='" . mysql_real_escape_string($first_name) . "' and last_name='" . mysql_real_escape_string($last_name) . "'");
                     if (mysql_num_rows($query)) {
                         $listing_new[] = $entry;
                     }
                 }
             }
             mysql_close($link);
             return $listing_new;
         } else {
             return ProjectObjects::find(array('conditions' => array('parent_id in (?) AND type = ? AND state >= ? AND visibility >= ? and completed_on is null', $categories_string, 'Page', $min_state, $min_visibility), 'order' => 'name'));
         }
     } else {
         return array();
     }
 }
 /**
  * Return last comment for a given object
  *
  * @param ProjectObject $object
  * @param integer $min_state
  * @param integer $min_visiblity
  * @return Comment
  */
 function findLastCommentByObject($object, $min_state = STATE_VISIBLE, $min_visiblity = VISIBILITY_NORMAL)
 {
     return ProjectObjects::find(array('conditions' => array("type = 'Comment' AND parent_id = ? AND state >= ? AND visibility >= ?", $object->getId(), $min_state, $min_visiblity), 'order' => 'created_on DESC', 'limit' => 1, 'offset' => 0, 'one' => true));
 }
 /**
  * Return Files by a given milestone
  *
  * @param Milestone $milestone
  * @param integer $min_state
  * @param integer $min_visibility
  * @return array
  */
 function findByMilestone($milestone, $min_state = STATE_VISIBLE, $min_visibility = VISIBILITY_NORMAL)
 {
     return ProjectObjects::find(array('conditions' => array('milestone_id = ? AND type = ? AND state >= ? AND visibility >= ?', $milestone->getId(), 'File', $min_state, $min_visibility), 'order' => 'created_on, name'));
 }