/**
  * Class constructor
  *
  * @param unknown_type $request
  */
 function __construct($request)
 {
     parent::__construct($request);
     if ($this->logged_user->getProjectPermission('repository', $this->active_project) < PROJECT_PERMISSION_ACCESS) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $source_module_url = source_module_url($this->active_project);
     $add_repository_url = source_module_add_repository_url($this->active_project);
     // wireframe
     $this->wireframe->addBreadCrumb(lang('Source'), $source_module_url);
     $this->wireframe->print_button = false;
     $repository_id = $this->request->get('repository_id');
     $this->active_repository = Repositories::findById($repository_id);
     if (instance_of($this->active_repository, 'Repository')) {
         // load repository engine
         if (!$this->active_repository->loadEngine()) {
             flash_error('Failed to load repository engine class');
             $this->redirectToUrl($source_module_url);
         }
         // if
         $this->repository_engine = new RepositoryEngine($this->active_repository);
         $this->active_repository->mapped_users = SourceUsers::findByRepository($this->active_repository);
         if (!$this->repository_engine->executableExists()) {
             $this->wireframe->addPageMessage(lang("Source executable not found. You won't be able to use this module"), 'error');
         }
         // if
         // active commit
         $this->active_revision = intval($this->request->get('r'));
         $this->active_commit = Commits::findByRevision($this->active_revision, $this->active_repository);
         js_assign('update_url', $this->active_repository->getupdateurl());
         js_assign('active_revision', intval($this->request->get('r')));
         if (!$this->active_repository->isNew()) {
             $this->wireframe->addBreadCrumb(clean($this->active_repository->getName()), $this->active_repository->getHistoryUrl());
         }
         // if
     } else {
         $this->active_repository = new Repository();
         $this->active_repository->setRepositoryType(1);
         $this->active_repository->loadEngine();
         $this->repository_engine = new RepositoryEngine($this->active_repository);
     }
     // if
     if (!instance_of($this->active_commit, 'Commit')) {
         $this->active_commit = new Commit();
     }
     // if
     // active file
     $this->active_file = urldecode($this->request->get('path'));
     $path_info = pathinfo($this->active_file);
     $this->active_file_basename = array_var($path_info, 'basename', null);
     // smarty stuff
     $this->smarty->assign(array('project_tab' => SOURCE_MODULE, 'active_repository' => $this->active_repository, 'active_revision' => $this->active_revision, 'active_commit' => $this->active_commit, 'active_file' => $this->active_file, 'active_file_basename' => $this->active_file_basename, 'page_tab' => 'source', 'add_repository_url' => $add_repository_url));
 }
 /**
  * Get all commits related to a project object
  *
  * @param integer $object_id
  * @return array
  */
 function findCommitsByObject($object)
 {
     $parent_object_ids = array();
     $parent_object_ids[] = $object->getId();
     /**
      * Try to find commits related to children objects
      */
     $task_ids = array();
     if (instance_of($object, 'Ticket')) {
         $tasks = db_execute_all("SELECT id FROM " . TABLE_PREFIX . "project_objects WHERE parent_id = " . $object->getid() . " AND `type` = 'Task'");
         if (is_foreachable($tasks)) {
             foreach ($tasks as $task) {
                 $task_ids[] = $task['id'];
             }
             // foreach
         }
         // if
     }
     // if
     $objects_ids = array_merge($parent_object_ids, $task_ids);
     $commit_project_objects = CommitProjectObjects::find(array('conditions' => array("object_id IN(" . implode(',', $objects_ids) . ")"), 'order' => 'repository_id ASC, revision DESC'));
     if (is_foreachable($commit_project_objects)) {
         $commits = array();
         $revisions = array();
         foreach ($commit_project_objects as $commit_project_object) {
             if (!in_array($commit_project_object->getRevision(), $revisions)) {
                 // prevent commits from showing more than once
                 $revisions[] = $commit_project_object->getRevision();
                 $commit = Commits::findByRevision($commit_project_object->getRevision(), Repositories::findById($commit_project_object->getRepositoryId()));
                 if (instance_of($commit, 'Commit')) {
                     $commit->repository = Repositories::findById($commit->getProjectId());
                     $commits[] = $commit;
                 }
                 // if
             }
             // if
         }
         // foreach
         return group_by_date($commits);
     } else {
         return false;
     }
     // if
 }
 /**
  * Constructor
  *
  * @param Request $request
  * @return MobileAccessProjectRepositoriesController extends ApplicationController 
  */
 function __construct($request)
 {
     parent::__construct($request);
     if ($this->logged_user->getProjectPermission('repository', $this->active_project) < PROJECT_PERMISSION_ACCESS) {
         $this->httpError(HTTP_ERR_FORBIDDEN);
     }
     // if
     $this->controller_description_name = lang('Repositories');
     $this->active_project_section = 'repositories';
     $repository_id = $this->request->getId('object_id');
     if ($repository_id) {
         $this->active_repository = Repositories::findById($repository_id);
     }
     // if
     if (!instance_of($this->active_repository, 'Repository')) {
         $this->active_repository = new Repository();
     }
     // if
     $this->smarty->assign(array("active_repository" => $this->active_repository, "active_project_section" => $this->active_project_section));
     $this->addBreadcrumb($this->controller_description_name, assemble_url('mobile_access_view_repositories', array('project_id' => $this->active_project->getId())));
 }
 /**
  * Get CreatedBy information
  *
  * @param Repository $repository
  * @return User
  */
 function getCreatedBy($repository = null)
 {
     if (is_null($repository)) {
         $repository = Repositories::findById($this->getParentId());
         $repository->mapped_users = SourceUsers::findByRepository($repository);
     }
     // if
     if (isset($repository->mapped_users[$this->getCreatedByName()]) && instance_of($repository->mapped_users[$this->getCreatedByName()], 'SourceUser')) {
         $source_user = $repository->mapped_users[$this->getCreatedByName()];
         if (instance_of($source_user->system_user, 'User')) {
             return $source_user->system_user;
         }
         // if
     }
     // if
     return parent::getCreatedBy();
 }