コード例 #1
0
 /**
  * Return manager instance
  *
  * @access protected
  * @param void
  * @return ProjectCompanies 
  */
 function manager()
 {
     if (!$this->manager instanceof ProjectCompanies) {
         $this->manager = ProjectCompanies::instance();
     }
     return $this->manager;
 }
コード例 #2
0
 /**
  * Return all projects that this company is member of
  *
  * @access public
  * @param Company $company
  * @param string $additional_conditions Additional SQL conditions
  * @return array
  */
 static function getProjectsByCompany(Company $company, $additional_conditions = null)
 {
     if ($company->isOwner()) {
         return Projects::getAll();
     }
     $projects_table = Projects::instance()->getTableName(true);
     $project_companies_table = ProjectCompanies::instance()->getTableName(true);
     $projects = array();
     $sql = "SELECT {$projects_table}.* FROM {$projects_table}, {$project_companies_table} WHERE ({$projects_table}.`id` = {$project_companies_table}.`project_id` AND {$project_companies_table}.`company_id` = " . DB::escape($company->getId()) . ')';
     if (trim($additional_conditions) != '') {
         $sql .= " AND ({$additional_conditions})";
     }
     $rows = DB::executeAll($sql);
     if (is_array($rows)) {
         foreach ($rows as $row) {
             $projects[] = Projects::instance()->loadFromRow($row);
         }
         // foreach
     }
     // if
     return count($projects) ? $projects : null;
 }
コード例 #3
0
ファイル: User.class.php プロジェクト: pombredanne/ArcherSys
    /**
    * Returns true if this user can see $company. Members of owener company and
    * coworkers are visible without project check! Also, members of owner company
    * can see all clients without any prior check!
    *
    * @param Company $company
    * @return boolean
    */
    function canSeeCompany(Company $company) {
      if ($this->isMemberOfOwnerCompany()) {
        return true;
      } // if
            
      if ($company->isOwner()) {
        $this->visible_companies[$company->getId()] = true;
        return true;
      } // if

      if (isset($this->visible_companies[$company->getId()])) {
        return $this->visible_companies[$company->getId()];
      } // if

      if ($this->getCompanyId() == $company->getId()) {
        $this->visible_companies[$company->getId()] = true;
        return true;
      } // if
      
      // Lets company projects for company of this user and for $company and 
      // compare if we have projects where both companies work together
      $projects_1 = DB::executeAll("SELECT `project_id` FROM " . ProjectCompanies::instance()->getTableName(true) . " WHERE `company_id` = ?", $this->getCompanyId());
      $projects_2 = DB::executeAll("SELECT `project_id` FROM " . ProjectCompanies::instance()->getTableName(true) . " WHERE `company_id` = ?", $company->getId());
      
      if (!is_array($projects_1) || !is_array($projects_2)) {
        $this->visible_companies[$company->getId()] = false;
        return false;
      } // if
      
      foreach ($projects_1 as $project_id) {
        if (in_array($project_id, $projects_2)) {
          $this->visible_companies[$company->getId()] = true;
          return true;
        } // if
      } // foreach
      
      $this->visible_companies[$company->getId()] = false;
      return false;
    } // canSeeCompany
コード例 #4
0
ファイル: Project.class.php プロジェクト: swenson/projectpier
 /**
  * Clear project level permissions
  *
  * @param void
  * @return null
  */
 function clearPermissions()
 {
     ProjectCompanies::clearByProject($this);
     ProjectUsers::clearByProject($this);
 }
コード例 #5
0
 /**
  * Update company permissions
  *
  * @param void
  * @return null
  */
 function update_permissions()
 {
     if (!logged_user()->isAdministrator(owner_company())) {
         flash_error(lang('no access permissions'));
         $this->redirectTo('dashboard');
     }
     // if
     $company = Companies::findById(get_id());
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         $this->redirectToReferer(get_url('administration'));
     }
     // if
     if ($company->isOwner()) {
         flash_error(lang('error owner company has all permissions'));
         $this->redirectToReferer(get_url('administration'));
     }
     // if
     $projects = Projects::getAll(Projects::ORDER_BY_NAME);
     if (!is_array($projects) || !count($projects)) {
         flash_error(lang('no projects in db'));
         $this->redirectToUrl($company->getViewUrl());
     }
     // if
     tpl_assign('projects', $projects);
     tpl_assign('company', $company);
     if (array_var($_POST, 'submitted') == 'submitted') {
         $counter = 0;
         $logged_user = logged_user();
         // reuse...
         foreach ($projects as $project) {
             if (!$logged_user->isProjectUser($project)) {
                 continue;
             }
             // if
             $new_value = array_var($_POST, 'project_' . $project->getId()) == 'checked';
             $relation = ProjectCompanies::findById(array('project_id' => $project->getId(), 'company_id' => $company->getId()));
             // findById
             $current_value = $relation instanceof ProjectCompany;
             try {
                 if ($current_value != $new_value) {
                     if ($new_value) {
                         $relation = new ProjectCompany();
                         $relation->setProjectId($project->getId());
                         $relation->setCompanyId($company->getId());
                         $relation->save();
                     } else {
                         $relation->delete();
                     }
                     // if
                     $counter++;
                 }
                 // if
             } catch (Exception $e) {
                 die($e->__toString());
             }
             // if
         }
         // foreach
         flash_success(lang('success update company permissions', $counter));
         $this->redirectToUrl($company->getViewUrl());
     }
     // if
 }
コード例 #6
0
 /**
  * Remove company from project
  *
  * @param void
  * @return null
  */
 function remove_company()
 {
     if (!active_project()->canChangePermissions(logged_user())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $project = Projects::findById(get_id('project_id'));
     if (!$project instanceof Project) {
         flash_error(lang('project dnx'));
         ajx_current("empty");
         return;
     }
     // if
     $company = Companies::findById(get_id('company_id'));
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         ajx_current("empty");
         return;
     }
     // if
     $project_company = ProjectCompanies::findById(array('project_id' => $project->getId(), 'company_id' => $company->getId()));
     if (!$project_company instanceof ProjectCompany) {
         flash_error(lang('company not on project'));
         ajx_current("empty");
         return;
     }
     // if
     try {
         DB::beginWork();
         $project_company->delete();
         $users = ProjectUsers::getCompanyUsersByProject($company, $project);
         if (is_array($users)) {
             foreach ($users as $user) {
                 $project_user = ProjectUsers::findById(array('project_id' => $project->getId(), 'user_id' => $user->getId()));
                 if ($project_user instanceof ProjectUser) {
                     $project_user->delete();
                 }
             }
             // foreach
         }
         // if
         DB::commit();
         flash_success(lang('success remove company from project'));
         ajx_current("reload");
     } catch (Exception $e) {
         DB::rollback();
         flash_error(lang('error remove company from project'));
         ajx_current("empty");
     }
     // try
 }
コード例 #7
0
 /**
  * This function will return paginated result. Result is an array where first element is 
  * array of returned object and second populated pagination object that can be used for 
  * obtaining and rendering pagination data using various helpers.
  * 
  * Items and pagination array vars are indexed with 0 for items and 1 for pagination
  * because you can't use associative indexing with list() construct
  *
  * @access public
  * @param array $arguments Query argumens (@see find()) Limit and offset are ignored!
  * @param integer $items_per_page Number of items per page
  * @param integer $current_page Current page number
  * @return array
  */
 function paginate($arguments = null, $items_per_page = 10, $current_page = 1)
 {
     if (isset($this) && instance_of($this, 'ProjectCompanies')) {
         return parent::paginate($arguments, $items_per_page, $current_page);
     } else {
         return ProjectCompanies::instance()->paginate($arguments, $items_per_page, $current_page);
         //$instance =& ProjectCompanies::instance();
         //return $instance->paginate($arguments, $items_per_page, $current_page);
     }
     // if
 }
コード例 #8
0
 /**
  * Delete this company and all related data
  *
  * @access public
  * @param void
  * @return boolean
  * @throws Error
  */
 function delete()
 {
     if ($this->isOwner()) {
         throw new Error(lang('error delete owner company'));
     }
     // if
     $contacts = $this->getContacts();
     if (is_array($contacts) && count($contacts)) {
         foreach ($contacts as $contact) {
             $contact->delete();
         }
     }
     // if
     ProjectCompanies::clearByCompany($this);
     $this->deleteLogo();
     return parent::delete();
 }
コード例 #9
0
 /**
  * Update company permissions
  *
  * @param void
  * @return null
  */
 function update_permissions()
 {
     if (!logged_user()->isAdministrator(owner_company())) {
         flash_error(lang('no access permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $company = Companies::findById(get_id());
     if (!$company instanceof Company) {
         flash_error(lang('company dnx'));
         ajx_current("empty");
         return;
     }
     // if
     if ($company->isOwner()) {
         flash_error(lang('error owner company has all permissions'));
         ajx_current("empty");
         return;
     }
     // if
     $projects = Projects::getAll(Projects::ORDER_BY_NAME);
     if (!is_array($projects) || !count($projects)) {
         flash_error(lang('no projects in db'));
         ajx_current("empty");
         return;
     }
     // if
     tpl_assign('projects', $projects);
     tpl_assign('company', $company);
     if (array_var($_POST, 'submitted') == 'submitted') {
         $counter = 0;
         $logged_user = logged_user();
         // reuse...
         ProjectCompanies::delete('company_id = ' . $company->getId());
         $wsids = array_var($_POST, 'ws_ids', '');
         $selected = Projects::findByCSVIds($wsids);
         $counter = 0;
         foreach ($selected as $ws) {
             $pc = new ProjectCompany();
             $pc->setCompanyId($company->getId());
             $pc->setProjectId($ws->getId());
             $pc->save();
             $counter++;
         }
         flash_success(lang('success update company permissions', $counter));
         ajx_current("back");
     }
     // if
 }