diff --git a/lib/classes/ACL.class.php b/lib/classes/ACL.class.php index 3d7a383906..3f303fd792 100644 --- a/lib/classes/ACL.class.php +++ b/lib/classes/ACL.class.php @@ -1510,34 +1510,48 @@ class ACL implements cache_cacheableInterface } /** - * get array of base_id's on which the user is 'order master' + * Returns an array of collections on which the user is 'order master' * * @return array */ - public function get_order_master_bids() + public function get_order_master_collections() { - $sql = 'SELECT base_id FROM basusr WHERE order_master=\'1\' AND usr_id= :id '; + $sql = 'SELECT base_id FROM basusr WHERE order_master="1" AND usr_id= :usr_id '; $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':id' => $this->user->get_id())); - $row = $stmt->fetchAll(PDO::FETCH_COLUMN); + $stmt->execute(array(':usr_id' => $this->user->get_id())); + $rs = $stmt->fetchAll(\PDO::FETCH_ASSOC); $stmt->closeCursor(); - foreach($row as $k=>$v) { - $row[$k] = (int)$v; + + $collections = array(); + + foreach($rs as $row) { + $collections[] = \collection::get_from_base_id($row['base_id']); } - return $row; + + return $collections; } /** - * set the user as "order_master" on a collection + * Sets the user as "order_master" on a collection * - * @param int $bid + * @param \collection $collection The collection to apply + * @param Boolean $bool Wheter the user is order master or not + * + * @return ACL */ - public function set_order_master($bid, $flag) + public function set_order_master(\collection $collection, $bool) { - $sql = 'UPDATE basusr SET order_master= :flag WHERE usr_id= :id AND base_id= :bid'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $r = $stmt->execute(array(':flag' => $flag, ':id' => $this->user->get_id(), 'bid' => $bid)); - $stmt->closeCursor(); - } + $sql = 'UPDATE basusr SET order_master = :master + WHERE usr_id = :usr_id AND base_id = :base_id'; + $stmt = $this->appbox->get_connection()->prepare($sql); + $stmt->execute(array( + ':master' => $bool ? 1 : 0, + ':usr_id' => $this->user->get_id(), + ':base_id' => $collection->get_base_id() + )); + $stmt->closeCursor(); + + return $this; + } } diff --git a/tests/ACLTest.php b/tests/ACLTest.php index c241359ba8..868e8002ff 100644 --- a/tests/ACLTest.php +++ b/tests/ACLTest.php @@ -246,22 +246,20 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract } /** - * @covers \ACL::get_order_master_bids - * @covers \ACL::set_order_master_bids + * @covers \ACL::get_order_master_collections + * @covers \ACL::set_order_master */ - - public function testOrder_master_bids() + public function testGetSetOrder_master() { - $appbox = appbox::get_instance(\bootstrap::getCore()); + $appbox = \appbox::get_instance(\bootstrap::getCore()); $acl = self::$user->ACL(); foreach ($appbox->get_databoxes() as $databox) { foreach ($databox->get_collections() as $collection) { - $base_id = $collection->get_base_id(); - $acl->set_order_master($base_id, false); + $acl->set_order_master($collection, false); } } - $this->assertEquals(0, count($acl->get_order_master_bids())); + $this->assertEquals(0, count($acl->get_order_master_collections())); $tbas = array(); foreach ($appbox->get_databoxes() as $databox) { @@ -270,15 +268,16 @@ class ACLTest extends PhraseanetPHPUnitAuthenticatedAbstract if(!$acl->has_access_to_base($bid)) { $acl->give_access_to_base(array($bid)); } - $acl->set_order_master($bid, true); + $acl->set_order_master($collection, true); $tbas[] = $bid; } } - $tbas = array_diff($tbas, $acl->get_order_master_bids()); + $tbas = array_diff($tbas, array_map(function (\collection $collection) { + return $collection->get_base_id(); + }, $acl->get_order_master_collections())); $this->assertEquals(0, count($tbas)); } - public function testIs_restricted_download() { $this->testSet_quotas_on_base();