Esempio n. 1
0
 /**
  * Method to update the access level of topics and replies
  * associated with the given context
  *
  * @param     string     $context    The context name
  * @param     integer    $id         The context id
  * @param     integer    $access     The access level
  *
  * @return    void
  */
 protected function updateAccess($context, $id, $access)
 {
     jimport('projectfork.library');
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $allowed = PFAccessHelper::getAccessTree($access);
     $fields = array('com_pfprojects.project' => 'project_id', 'com_pfforum.topic' => 'topic_id');
     // Update replies
     $query->update('#__pf_replies')->set('access = ' . (int) $access)->where($fields[$context] . ' = ' . (int) $id);
     if (count($allowed) == 1) {
         $query->where('access <> ' . (int) $allowed[0]);
     } elseif (count($allowed) > 1) {
         $query->where('access NOT IN( ' . implode(', ', $allowed) . ')');
     }
     $db->setQuery($query);
     $db->execute();
     if ($context == 'com_pfforum.topic') {
         return;
     }
     // Update topics
     $query->clear();
     $query->update('#__pf_topics')->set('access = ' . (int) $access)->where($fields[$context] . ' = ' . (int) $id);
     if (count($allowed) == 1) {
         $query->where('access <> ' . (int) $allowed[0]);
     } elseif (count($allowed) > 1) {
         $query->where('access NOT IN( ' . implode(', ', $allowed) . ')');
     }
     $db->setQuery($query);
     $db->execute();
 }
 /**
  * Method to update the access level of all milestones
  * associated with the given project
  *
  * @param     integer    $project    The project
  * @param     integer    $access     The access level
  *
  * @return    void
  */
 protected function updateAccess($project, $access)
 {
     jimport('projectfork.library');
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $allowed = PFAccessHelper::getAccessTree($access);
     $query->update('#__pf_milestones')->set('access = ' . (int) $access)->where('project_id = ' . (int) $project);
     if (count($allowed) == 1) {
         $query->where('access <> ' . (int) $allowed[0]);
     } elseif (count($allowed) > 1) {
         $query->where('access NOT IN( ' . implode(', ', $allowed) . ')');
     }
     $db->setQuery($query);
     $db->execute();
 }
Esempio n. 3
0
 /**
  * Method to update the access level of topics and replies
  * associated with the given context
  *
  * @param     string     $context    The context name
  * @param     integer    $id         The context id
  * @param     integer    $access     The access level
  *
  * @return    void
  */
 protected function updateAccess($context, $id, $access)
 {
     jimport('projectfork.library');
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $allowed = PFAccessHelper::getAccessTree($access);
     if ($context == 'com_pfrepo.directory') {
         $query->select('lft, rgt')->from('#__pf_repo_dirs')->where('id = ' . (int) $id);
         $db->setQuery($query);
         $dir = $db->loadObject();
         if (empty($dir)) {
             return;
         }
         // Get sub dirs
         $query->clear()->select('id')->from('#__pf_repo_dirs')->where('lft > ' . (int) $dir->lft)->where('rgt < ' . (int) $dir->rgt);
         $db->setQuery($query);
         $dirs = (array) $db->loadColumn();
         $dirs[] = (int) $id;
         // Update sub-dirs
         $query->clear();
         $query->update('#__pf_repo_dirs')->set('access = ' . (int) $access)->where('lft > ' . (int) $dir->lft)->where('rgt < ' . (int) $dir->rgt);
         if (count($allowed) == 1) {
             $query->where('access <> ' . (int) $allowed[0]);
         } elseif (count($allowed) > 1) {
             $query->where('access NOT IN(' . implode(', ', $allowed) . ')');
         }
         $db->setQuery($query);
         $db->execute();
         // Update notes and files
         foreach ($dirs as $pk) {
             // Update notes
             $query->clear();
             $query->update('#__pf_repo_notes')->set('access = ' . (int) $access)->where('dir_id = ' . (int) $pk);
             if (count($allowed) == 1) {
                 $query->where('access <> ' . (int) $allowed[0]);
             } elseif (count($allowed) > 1) {
                 $query->where('access NOT IN(' . implode(', ', $allowed) . ')');
             }
             $db->setQuery($query);
             $db->execute();
             // Update files
             $query->clear();
             $query->update('#__pf_repo_files')->set('access = ' . (int) $access)->where('dir_id = ' . (int) $pk);
             if (count($allowed) == 1) {
                 $query->where('access <> ' . (int) $allowed[0]);
             } elseif (count($allowed) > 1) {
                 $query->where('access NOT IN(' . implode(', ', $allowed) . ')');
             }
             $db->setQuery($query);
             $db->execute();
         }
     } else {
         // Update dirs
         $query->clear();
         $query->update('#__pf_repo_dirs')->set('access = ' . (int) $access)->where('project_id = ' . (int) $id);
         if (count($allowed) == 1) {
             $query->where('access <> ' . (int) $allowed[0]);
         } elseif (count($allowed) > 1) {
             $query->where('access NOT IN(' . implode(', ', $allowed) . ')');
         }
         $db->setQuery($query);
         $db->execute();
         // Update notes
         $query->clear();
         $query->update('#__pf_repo_notes')->set('access = ' . (int) $access)->where('project_id = ' . (int) $id);
         if (count($allowed) == 1) {
             $query->where('access <> ' . (int) $allowed[0]);
         } elseif (count($allowed) > 1) {
             $query->where('access NOT IN(' . implode(', ', $allowed) . ')');
         }
         $db->setQuery($query);
         $db->execute();
         // Update files
         $query->clear();
         $query->update('#__pf_repo_files')->set('access = ' . (int) $access)->where('project_id = ' . (int) $id);
         if (count($allowed) == 1) {
             $query->where('access <> ' . (int) $allowed[0]);
         } elseif (count($allowed) > 1) {
             $query->where('access NOT IN(' . implode(', ', $allowed) . ')');
         }
         $db->setQuery($query);
         $db->execute();
     }
 }
Esempio n. 4
0
 /**
  * Method to update the access level of all albums, designs and revs
  * associated with the given context
  *
  * @param     string     $context    The context name
  * @param     integer    $id         The context id
  * @param     integer    $access     The access level
  *
  * @return    void                   
  */
 protected function updateAccess($context, $id, $access)
 {
     jimport('projectfork.library');
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $allowed = PFAccessHelper::getAccessTree($access);
     $fields = array('com_pfprojects.project' => 'project_id', 'com_pfdesigns.album' => 'album_id', 'com_pfdesigns.design' => 'parent_id');
     // Update albums
     if ($context == 'com_pfprojects.project') {
         // Update tasks
         $query->update('#__pf_design_albums')->set('access = ' . (int) $access)->where($fields[$context] . ' = ' . (int) $id);
         if (count($allowed) == 1) {
             $query->where('access <> ' . (int) $allowed[0]);
         } elseif (count($allowed) > 1) {
             $query->where('access NOT IN( ' . implode(', ', $allowed) . ')');
         }
         $db->setQuery($query);
         $db->execute();
     }
     // Update designs
     if (in_array($context, array('com_pfprojects.project', 'com_pfdesigns.album'))) {
         $query->clear();
         $query->update('#__pf_designs')->set('access = ' . (int) $access)->where($fields[$context] . ' = ' . (int) $id);
         if (count($allowed) == 1) {
             $query->where('access <> ' . (int) $allowed[0]);
         } elseif (count($allowed) > 1) {
             $query->where('access NOT IN( ' . implode(', ', $allowed) . ')');
         }
         $db->setQuery($query);
         $db->execute();
     }
     // Update revisions
     if (in_array($context, array('com_pfprojects.project', 'com_pfdesigns.design'))) {
         $query->clear();
         $query->update('#__pf_design_revisions')->set('access = ' . (int) $access)->where($fields[$context] . ' = ' . (int) $id);
         if (count($allowed) == 1) {
             $query->where('access <> ' . (int) $allowed[0]);
         } elseif (count($allowed) > 1) {
             $query->where('access NOT IN( ' . implode(', ', $allowed) . ')');
         }
         $db->setQuery($query);
         $db->execute();
     } elseif ($context == 'com_pfdesigns.album') {
         $query->clear();
         $query->select('id')->from('#__pf_designs')->where($fields[$context] . ' = ' . (int) $id);
         $db->setQuery($query);
         $designs = (array) $db->loadColumn();
         if (!count($designs)) {
             return;
         }
         $query->clear();
         $query->update('#__pf_design_revisions')->set('access = ' . (int) $access)->where('parent_id IN(' . implode(', ', $designs) . ')');
         if (count($allowed) == 1) {
             $query->where('access <> ' . (int) $allowed[0]);
         } elseif (count($allowed) > 1) {
             $query->where('access NOT IN( ' . implode(', ', $allowed) . ')');
         }
         $db->setQuery($query);
         $db->execute();
     }
 }
Esempio n. 5
0
 /**
  * Method to set the "access" field value of a record
  *
  * @param     mixed    $old    The current value
  * @param     mixed    $new    The new value
  *
  * @return    mixed
  */
 public function setAccessValue($old = null, $new = null)
 {
     $allowed = PFAccessHelper::getAccessTree($new);
     return in_array($old, $allowed) ? $old : $new;
 }