phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] [19021] Add 2 methods : get_locations_by_apps, get_na


From: Caeies
Subject: [Phpgroupware-cvs] [19021] Add 2 methods : get_locations_by_apps, get_name ( perhaps not the best named method).
Date: Wed, 07 Jan 2009 18:08:19 +0000

Revision: 19021
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=19021
Author:   Caeies
Date:     2009-01-07 18:08:18 +0000 (Wed, 07 Jan 2009)

Log Message:
-----------
Add 2 methods : get_locations_by_apps, get_name (perhaps not the best named 
method). Fix the verify method ...

Modified Paths:
--------------
    core/trunk/phpgwapi/inc/class.locations.inc.php

Modified: core/trunk/phpgwapi/inc/class.locations.inc.php
===================================================================
--- core/trunk/phpgwapi/inc/class.locations.inc.php     2009-01-07 18:02:47 UTC 
(rev 19020)
+++ core/trunk/phpgwapi/inc/class.locations.inc.php     2009-01-07 18:08:18 UTC 
(rev 19021)
@@ -192,8 +192,29 @@
                        }
                        return 0;
                }
-               
+
                /**
+                * Get the app / location of an ID -> this is not id2name since 
where's not returning only the name ...
+                *
+                * @param int $location_id the location id
+                *
+                * @return array 'app_id' => contains the id of the application 
for the location - 'name' => contains the name of the location
+                */
+               public function get_name($location_id)
+               {
+                       $location_id = (int)$location_id;
+                       $ret = array();
+                       $sql = "SELECT app_id, name from phpgw_locations WHERE 
location_id = ${location_id}";
+                       $this->_db->query($sql, __LINE__, __FILE__);
+                       if( $this->_db->next_record() )
+                       {
+                               $ret['app_id'] = (int)$this->_db->f('app_id');
+                               $ret['name'] = $this->_db->f('name');
+                       }
+                       return $ret;
+               }
+
+               /**
                 * Get the subs for a location/application accociation
                 *
                 * @param string $appname  the name of the application for the 
location
@@ -232,6 +253,8 @@
 
                /**
                * This does something - ask sigurd he wrote the code
+               * XXX Caeies JAN09 : I guess this is more or less a broken 
design. It should be better do to this work when installing the application
+               * So a developper could explicitly ask for an acl management 
... my 2c€. Anyway, I fixed it.
                *
                * @param something $apps     a paramater
                * @param string?   $location something - ask sigurd
@@ -246,10 +269,15 @@
                        {
                                $apps = array();
                        }
-
                        foreach ( $apps as $appname => $values )
                        {
                                $appname = $this->_db->db_addslashes($appname);
+                               $app_id = 
$GLOBALS['phpgw']->applications->name2id($appname);
+                               //If the application is not installed, skip it
+                               if($app_id == 0)
+                               {
+                                       continue;
+                               }
                                $sql = 'SELECT phpgw_applications.app_name'
                                        . ' FROM phpgw_applications'
                                        . " {$this->_join} phpgw_locations ON 
phpgw_applications.app_id = phpgw_locations.app_id"
@@ -261,8 +289,6 @@
                                if ( !$this->_db->next_record() )
                                {
                                        $top = (int) $values['top_grant'];
-                                       $app_id = 
$GLOBALS['phpgw']->applications->name2id($appname);
-
                                        $sql = 'INSERT INTO phpgw_locations 
(app_id, name, descr, allow_grant)'
                                                . " VALUES ({$app_id}, 
'{$location}', 'Top', {$top})";
 
@@ -270,4 +296,32 @@
                                }
                        }
                }
+
+               /**
+               * Ask sigurd for what is should be used ...
+               */
+               public function get_locations_by_apps($appname, 
$allow_c_attrib, $grant)
+               {
+                       $location = array();
+                       $app_id = 
$GLOBALS['phpgw']->applications->name2id($appname);
+                       
+                       $filter = " WHERE app_id = ${app_id} ";
+                       
+                       if($allow_c_attrib)
+                       {
+                               $filter .= ' AND allow_c_attrib = 1';
+                       }
+
+                       if($grant)
+                       {
+                               $filter .= ' AND allow_grant = 1';
+                       }
+                       $this->_db->query("SELECT location_id, descr FROM 
phpgw_locations $filter ORDER BY location_id");
+                       
+                       while ($this->_db->next_record())
+                       {
+                               $location[$this->_db->f('location_id')] = 
$this->_db->f('descr', true);
+                       }
+                       return $location;
+               }
        }






reply via email to

[Prev in Thread] Current Thread [Next in Thread]