diff --git a/lib/Alchemy/Phrasea/Command/CreateCollection.php b/lib/Alchemy/Phrasea/Command/CreateCollection.php index e69e59a406..d1319d9dbb 100644 --- a/lib/Alchemy/Phrasea/Command/CreateCollection.php +++ b/lib/Alchemy/Phrasea/Command/CreateCollection.php @@ -46,7 +46,7 @@ class CreateCollection extends Command if ($new_collection && $input->getOption('base_id_rights')) { - $query = new \User_Query($this->container); + $query = $this->container['phraseanet.user-query']; $total = $query->on_base_ids([$input->getOption('base_id_rights')])->get_total(); $n = 0; diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php index b785a6f196..1e937d8c7e 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Collection.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Collection.php @@ -136,7 +136,7 @@ class Collection implements ControllerProviderInterface $admins = []; if ($app['acl']->get($app['authentication']->getUser())->has_right_on_base($bas_id, 'manage')) { - $query = new \User_Query($app); + $query = $app['phraseanet.user-query']; $admins = $query->on_base_ids([$bas_id]) ->who_have_right(['order_master']) ->execute() @@ -198,7 +198,7 @@ class Collection implements ControllerProviderInterface $conn->beginTransaction(); try { - $userQuery = new \User_Query($app); + $userQuery = $app['phraseanet.user-query']; $result = $userQuery->on_base_ids([$bas_id]) ->who_have_right(['order_master']) diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Databox.php b/lib/Alchemy/Phrasea/Controller/Admin/Databox.php index d9eec78329..ba023ed57c 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Databox.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Databox.php @@ -400,7 +400,7 @@ class Databox implements ControllerProviderInterface $othCollSel = (int) $request->request->get("othcollsel") ?: null; if (null !== $othCollSel) { - $query = new \User_Query($app); + $query = $app['phraseanet.user-query']; $n = 0; while ($n < $query->on_base_ids([$othCollSel])->get_total()) { @@ -798,7 +798,7 @@ class Databox implements ControllerProviderInterface if (($request->request->get('ccusrothercoll') === "on") && (null !== $othcollsel = $request->request->get('othcollsel'))) { - $query = new \User_Query($app); + $query = $app['phraseanet.user-query']; $total = $query->on_base_ids([$othcollsel])->get_total(); $n = 0; while ($n < $total) { diff --git a/lib/Alchemy/Phrasea/Controller/Admin/Users.php b/lib/Alchemy/Phrasea/Controller/Admin/Users.php index 4617600974..fd5fc8a565 100644 --- a/lib/Alchemy/Phrasea/Controller/Admin/Users.php +++ b/lib/Alchemy/Phrasea/Controller/Admin/Users.php @@ -215,8 +215,7 @@ class Users implements ControllerProviderInterface $controllers->get('/typeahead/search/', function (Application $app) { $request = $app['request']; - $user_query = new \User_Query($app); - + $user_query = $app['phraseanet.user-query']; $like_value = $request->query->get('term'); $rights = $request->query->get('filter_rights') ? : []; $have_right = $request->query->get('have_right') ? : []; @@ -279,7 +278,7 @@ class Users implements ControllerProviderInterface $controllers->post('/export/csv/', function (Application $app) { $request = $app['request']; - $user_query = new \User_Query($app); + $user_query = $app['phraseanet.user-query']; $like_value = $request->request->get('like_value'); $like_field = $request->request->get('like_field'); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Order.php b/lib/Alchemy/Phrasea/Controller/Prod/Order.php index ec024072c7..27dafc0a25 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Order.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Order.php @@ -101,8 +101,6 @@ class Order implements ControllerProviderInterface $order->setDeadline((null !== $deadLine = $request->request->get('deadline')) ? new \DateTime($deadLine) : $deadLine); $order->setOrderUsage($request->request->get('use', '')); foreach ($records as $key => $record) { - $query = new \User_Query($app); - if ($collectionHasOrderAdmins->containsKey($record->get_base_id())) { if (!$collectionHasOrderAdmins->get($record->get_base_id())) { $records->remove($key); @@ -110,7 +108,7 @@ class Order implements ControllerProviderInterface } if (!isset($hasOneAdmin[$record->get_base_id()])) { - $query = new \User_Query($app); + $query = $app['phraseanet.user-query']; $hasOneAdmin[$record->get_base_id()] = (Boolean) count($query->on_base_ids([$record->get_base_id()]) ->who_have_right(['order_master']) ->execute()->get_results()); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Push.php b/lib/Alchemy/Phrasea/Controller/Prod/Push.php index 4add54bbcc..d27add32cb 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Push.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Push.php @@ -447,7 +447,7 @@ class Push implements ControllerProviderInterface $request = $app['request']; - $query = new \User_Query($app); + $query = new $app['phraseanet.user-query']; $query->on_bases_where_i_am($app['acl']->get($app['authentication']->getUser()), ['canpush']); @@ -558,7 +558,7 @@ class Push implements ControllerProviderInterface $controllers->get('/search-user/', function (Application $app) use ($userFormatter, $listFormatter) { $request = $app['request']; - $query = new \User_Query($app); + $query = $app['phraseanet.user-query']; $query->on_bases_where_i_am($app['acl']->get($app['authentication']->getUser()), ['canpush']); @@ -598,7 +598,7 @@ class Push implements ControllerProviderInterface $list = $repository->findUserListByUserAndId($app['authentication']->getUser(), $list_id); - $query = new \User_Query($app); + $query = $app['phraseanet.user-query']; $query->on_bases_where_i_am($app['acl']->get($app['authentication']->getUser()), ['canpush']); diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/FeedEntrySubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/FeedEntrySubscriber.php index 5a9a491237..f0ac35a9ee 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/FeedEntrySubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/FeedEntrySubscriber.php @@ -36,7 +36,7 @@ class FeedEntrySubscriber extends AbstractNotificationSubscriber $datas = json_encode($params); - $Query = new \User_Query($this->app); + $Query = $this->app['phraseanet.user-query']; $Query->include_phantoms(true) ->include_invite(false) diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/LazaretSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/LazaretSubscriber.php index d769475c32..a4fd9c513c 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/LazaretSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/LazaretSubscriber.php @@ -35,8 +35,7 @@ class LazaretSubscriber extends AbstractNotificationSubscriber $this->notifyUser($user, json_encode($params)); } else { //No lazaretSession user, fil is uploaded via automated tasks etc .. - $query = new \User_Query($this->app); - + $query = $this->app['phraseanet.user-query']; $users = $query ->on_base_ids([$lazaretFile->getBaseId()]) ->who_have_right(['canaddrecord']) diff --git a/lib/Alchemy/Phrasea/Core/Event/Subscriber/OrderSubscriber.php b/lib/Alchemy/Phrasea/Core/Event/Subscriber/OrderSubscriber.php index e28b207a9c..169f6dba34 100644 --- a/lib/Alchemy/Phrasea/Core/Event/Subscriber/OrderSubscriber.php +++ b/lib/Alchemy/Phrasea/Core/Event/Subscriber/OrderSubscriber.php @@ -34,7 +34,7 @@ class OrderSubscriber extends AbstractNotificationSubscriber return $element->getBaseId(); }, iterator_to_array($event->getOrder()->getElements()))); - $query = new \User_Query($this->app); + $query = $this->app['phraseanet.user-query']; $users = $query->on_base_ids($base_ids) ->who_have_right(['order_master']) ->execute()->get_results(); diff --git a/lib/Alchemy/Phrasea/Core/Provider/PhraseanetServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/PhraseanetServiceProvider.php index 9392a13afd..5239d8ce1e 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/PhraseanetServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/PhraseanetServiceProvider.php @@ -61,6 +61,10 @@ class PhraseanetServiceProvider implements ServiceProviderInterface $app['phraseanet.metadata-setter'] = $app->share(function (SilexApplication $app) { return new PhraseanetMetadataSetter(); }); + + $app['phraseanet.user-query'] = function (SilexApplication $app) { + return new \User_Query($app); + }; } public function boot(SilexApplication $app) diff --git a/lib/Alchemy/Phrasea/Helper/User/Edit.php b/lib/Alchemy/Phrasea/Helper/User/Edit.php index 8990473b87..d7732d5790 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Edit.php +++ b/lib/Alchemy/Phrasea/Helper/User/Edit.php @@ -164,7 +164,7 @@ class Edit extends \Alchemy\Phrasea\Helper\Helper } } - $query = new \User_Query($this->app); + $query = $this->app['phraseanet.user-query']; $templates = $query ->only_templates(true) ->execute()->get_results(); diff --git a/lib/Alchemy/Phrasea/Helper/User/Manage.php b/lib/Alchemy/Phrasea/Helper/User/Manage.php index 45916432b4..b4ed5729c5 100644 --- a/lib/Alchemy/Phrasea/Helper/User/Manage.php +++ b/lib/Alchemy/Phrasea/Helper/User/Manage.php @@ -57,7 +57,7 @@ class Manage extends Helper , 'offset_start' => 0 ]; - $query = new \User_Query($this->app); + $query = $this->app['phraseanet.user-query']; if (is_array($this->query_parms['base_id'])) $query->on_base_ids($this->query_parms['base_id']); @@ -95,7 +95,7 @@ class Manage extends Helper , 'offset_start' => $offset_start ]; - $query = new \User_Query($this->app); + $query = $this->app['phraseanet.user-query']; if (is_array($this->query_parms['base_id'])) $query->on_base_ids($this->query_parms['base_id']); @@ -124,7 +124,7 @@ class Manage extends Helper $this->query_parms[$k] = false; } - $query = new \User_Query($this->app); + $query = $this->app['phraseanet.user-query']; $templates = $query ->only_templates(true) ->execute()->get_results(); diff --git a/lib/Alchemy/Phrasea/Utilities/Countries.php b/lib/Alchemy/Phrasea/Utilities/Countries.php new file mode 100644 index 0000000000..af40fb6dbd --- /dev/null +++ b/lib/Alchemy/Phrasea/Utilities/Countries.php @@ -0,0 +1,518 @@ + 'AFGHANISTAN', + 'AX' => 'ÅLAND ISLANDS', + 'AL' => 'ALBANIA', + 'DZ' => 'ALGERIA', + 'AS' => 'AMERICAN SAMOA', + 'AD' => 'ANDORRA', + 'AO' => 'ANGOLA', + 'AI' => 'ANGUILLA', + 'AQ' => 'ANTARCTICA', + 'AG' => 'ANTIGUA AND BARBUDA', + 'AR' => 'ARGENTINA', + 'AM' => 'ARMENIA', + 'AW' => 'ARUBA', + 'AU' => 'AUSTRALIA', + 'AT' => 'AUSTRIA', + 'AZ' => 'AZERBAIJAN', + 'BS' => 'BAHAMAS', + 'BH' => 'BAHRAIN', + 'BD' => 'BANGLADESH', + 'BB' => 'BARBADOS', + 'BY' => 'BELARUS', + 'BE' => 'BELGIUM', + 'BZ' => 'BELIZE', + 'BJ' => 'BENIN', + 'BM' => 'BERMUDA', + 'BT' => 'BHUTAN', + 'BO' => 'BOLIVIA', + 'BA' => 'BOSNIA AND HERZEGOVINA', + 'BW' => 'BOTSWANA', + 'BV' => 'BOUVET ISLAND', + 'BR' => 'BRAZIL', + 'IO' => 'BRITISH INDIAN OCEAN TERRITORY', + 'BN' => 'BRUNEI DARUSSALAM', + 'BG' => 'BULGARIA', + 'BF' => 'BURKINA FASO', + 'BI' => 'BURUNDI', + 'KH' => 'CAMBODIA', + 'CM' => 'CAMEROON', + 'CA' => 'CANADA', + 'CV' => 'CAPE VERDE', + 'KY' => 'CAYMAN ISLANDS', + 'CF' => 'CENTRAL AFRICAN REPUBLIC', + 'TD' => 'CHAD', + 'CL' => 'CHILE', + 'CN' => 'CHINA', + 'CX' => 'CHRISTMAS ISLAND', + 'CC' => 'COCOS (KEELING) ISLANDS', + 'CO' => 'COLOMBIA', + 'KM' => 'COMOROS', + 'CG' => 'CONGO', + 'CD' => 'CONGO, THE DEMOCRATIC REPUBLIC OF THE', + 'CK' => 'COOK ISLANDS', + 'CR' => 'COSTA RICA', + 'CI' => 'CÔTE D\'IVOIRE', + 'HR' => 'CROATIA', + 'CU' => 'CUBA', + 'CY' => 'CYPRUS', + 'CZ' => 'CZECH REPUBLIC', + 'DK' => 'DENMARK', + 'DJ' => 'DJIBOUTI', + 'DM' => 'DOMINICA', + 'DO' => 'DOMINICAN REPUBLIC', + 'EC' => 'ECUADOR', + 'EG' => 'EGYPT', + 'SV' => 'EL SALVADOR', + 'GQ' => 'EQUATORIAL GUINEA', + 'ER' => 'ERITREA', + 'EE' => 'ESTONIA', + 'ET' => 'ETHIOPIA', + 'FK' => 'FALKLAND ISLANDS (MALVINAS)', + 'FO' => 'FAROE ISLANDS', + 'FJ' => 'FIJI', + 'FI' => 'FINLAND', + 'FR' => 'FRANCE', + 'GF' => 'FRENCH GUIANA', + 'PF' => 'FRENCH POLYNESIA', + 'TF' => 'FRENCH SOUTHERN TERRITORIES', + 'GA' => 'GABON', + 'GM' => 'GAMBIA', + 'GE' => 'GEORGIA', + 'DE' => 'GERMANY', + 'GH' => 'GHANA', + 'GI' => 'GIBRALTAR', + 'GR' => 'GREECE', + 'GL' => 'GREENLAND', + 'GD' => 'GRENADA', + 'GP' => 'GUADELOUPE', + 'GU' => 'GUAM', + 'GT' => 'GUATEMALA', + 'GG' => 'GUERNSEY', + 'GN' => 'GUINEA', + 'GW' => 'GUINEA-BISSAU', + 'GY' => 'GUYANA', + 'HT' => 'HAITI', + 'HM' => 'HEARD ISLAND AND MCDONALD ISLANDS', + 'VA' => 'HOLY SEE (VATICAN CITY STATE)', + 'HN' => 'HONDURAS', + 'HK' => 'HONG KONG', + 'HU' => 'HUNGARY', + 'IS' => 'ICELAND', + 'IN' => 'INDIA', + 'ID' => 'INDONESIA', + 'IR' => 'IRAN, ISLAMIC REPUBLIC OF', + 'IQ' => 'IRAQ', + 'IE' => 'IRELAND', + 'IM' => 'ISLE OF MAN', + 'IL' => 'ISRAEL', + 'IT' => 'ITALY', + 'JM' => 'JAMAICA', + 'JP' => 'JAPAN', + 'JE' => 'JERSEY', + 'JO' => 'JORDAN', + 'KZ' => 'KAZAKHSTAN', + 'KE' => 'KENYA', + 'KI' => 'KIRIBATI', + 'KP' => 'KOREA, DEMOCRATIC PEOPLE\'S REPUBLIC OF', + 'KR' => 'KOREA, REPUBLIC OF', + 'KW' => 'KUWAIT', + 'KG' => 'KYRGYZSTAN', + 'LA' => 'LAO PEOPLE\'S DEMOCRATIC REPUBLIC', + 'LV' => 'LATVIA', + 'LB' => 'LEBANON', + 'LS' => 'LESOTHO', + 'LR' => 'LIBERIA', + 'LY' => 'LIBYAN ARAB JAMAHIRIYA', + 'LI' => 'LIECHTENSTEIN', + 'LT' => 'LITHUANIA', + 'LU' => 'LUXEMBOURG', + 'MO' => 'MACAO', + 'MK' => 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF', + 'MG' => 'MADAGASCAR', + 'MW' => 'MALAWI', + 'MY' => 'MALAYSIA', + 'MV' => 'MALDIVES', + 'ML' => 'MALI', + 'MT' => 'MALTA', + 'MH' => 'MARSHALL ISLANDS', + 'MQ' => 'MARTINIQUE', + 'MR' => 'MAURITANIA', + 'MU' => 'MAURITIUS', + 'YT' => 'MAYOTTE', + 'MX' => 'MEXICO', + 'FM' => 'MICRONESIA, FEDERATED STATES OF', + 'MD' => 'MOLDOVA, REPUBLIC OF', + 'MC' => 'MONACO', + 'MN' => 'MONGOLIA', + 'ME' => 'MONTENEGRO', + 'MS' => 'MONTSERRAT', + 'MA' => 'MOROCCO', + 'MZ' => 'MOZAMBIQUE', + 'MM' => 'MYANMAR', + 'NA' => 'NAMIBIA', + 'NR' => 'NAURU', + 'NP' => 'NEPAL', + 'NL' => 'NETHERLANDS', + 'AN' => 'NETHERLANDS ANTILLES', + 'NC' => 'NEW CALEDONIA', + 'NZ' => 'NEW ZEALAND', + 'NI' => 'NICARAGUA', + 'NE' => 'NIGER', + 'NG' => 'NIGERIA', + 'NU' => 'NIUE', + 'NF' => 'NORFOLK ISLAND', + 'MP' => 'NORTHERN MARIANA ISLANDS', + 'NO' => 'NORWAY', + 'OM' => 'OMAN', + 'PK' => 'PAKISTAN', + 'PW' => 'PALAU', + 'PS' => 'PALESTINIAN TERRITORY, OCCUPIED', + 'PA' => 'PANAMA', + 'PG' => 'PAPUA NEW GUINEA', + 'PY' => 'PARAGUAY', + 'PE' => 'PERU', + 'PH' => 'PHILIPPINES', + 'PN' => 'PITCAIRN', + 'PL' => 'POLAND', + 'PT' => 'PORTUGAL', + 'PR' => 'PUERTO RICO', + 'QA' => 'QATAR', + 'RE' => 'REUNION', + 'RO' => 'ROMANIA', + 'RU' => 'RUSSIAN FEDERATION', + 'RW' => 'RWANDA', + 'BL' => 'SAINT BARTHÉLEMY', + 'SH' => 'SAINT HELENA', + 'KN' => 'SAINT KITTS AND NEVIS', + 'LC' => 'SAINT LUCIA', + 'MF' => 'SAINT MARTIN', + 'PM' => 'SAINT PIERRE AND MIQUELON', + 'VC' => 'SAINT VINCENT AND THE GRENADINES', + 'WS' => 'SAMOA', + 'SM' => 'SAN MARINO', + 'ST' => 'SAO TOME AND PRINCIPE', + 'SA' => 'SAUDI ARABIA', + 'SN' => 'SENEGAL', + 'RS' => 'SERBIA', + 'SC' => 'SEYCHELLES', + 'SL' => 'SIERRA LEONE', + 'SG' => 'SINGAPORE', + 'SK' => 'SLOVAKIA', + 'SI' => 'SLOVENIA', + 'SB' => 'SOLOMON ISLANDS', + 'SO' => 'SOMALIA', + 'ZA' => 'SOUTH AFRICA', + 'GS' => 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS', + 'ES' => 'SPAIN', + 'LK' => 'SRI LANKA', + 'SD' => 'SUDAN', + 'SR' => 'SURINAME', + 'SJ' => 'SVALBARD AND JAN MAYEN', + 'SZ' => 'SWAZILAND', + 'SE' => 'SWEDEN', + 'CH' => 'SWITZERLAND', + 'SY' => 'SYRIAN ARAB REPUBLIC', + 'TW' => 'TAIWAN, PROVINCE OF CHINA', + 'TJ' => 'TAJIKISTAN', + 'TZ' => 'TANZANIA, UNITED REPUBLIC OF', + 'TH' => 'THAILAND', + 'TL' => 'TIMOR-LESTE', + 'TG' => 'TOGO', + 'TK' => 'TOKELAU', + 'TO' => 'TONGA', + 'TT' => 'TRINIDAD AND TOBAGO', + 'TN' => 'TUNISIA', + 'TR' => 'TURKEY', + 'TM' => 'TURKMENISTAN', + 'TC' => 'TURKS AND CAICOS ISLANDS', + 'TV' => 'TUVALU', + 'UG' => 'UGANDA', + 'UA' => 'UKRAINE', + 'AE' => 'UNITED ARAB EMIRATES', + 'GB' => 'UNITED KINGDOM', + 'US' => 'UNITED STATES', + 'UM' => 'UNITED STATES MINOR OUTLYING ISLANDS', + 'UY' => 'URUGUAY', + 'UZ' => 'UZBEKISTAN', + 'VU' => 'VANUATU', + 'VE' => 'VENEZUELA', + 'VN' => 'VIET NAM', + 'VG' => 'VIRGIN ISLANDS, BRITISH', + 'VI' => 'VIRGIN ISLANDS, U.S.', + 'WF' => 'WALLIS AND FUTUNA', + 'EH' => 'WESTERN SAHARA', + 'YE' => 'YEMEN', + 'ZM' => 'ZAMBIA', + 'ZW' => 'ZIMBABWE', + ]; + + $countries['us'] = $countries['en']; + + $countries['fr'] = [ + 'AF' => 'AFGHANISTAN', + 'ZA' => 'AFRIQUE DU SUD', + 'AX' => 'ÅLAND, ÎLES', + 'AL' => 'ALBANIE', + 'DZ' => 'ALGÉRIE', + 'DE' => 'ALLEMAGNE', + 'AD' => 'ANDORRE', + 'AO' => 'ANGOLA', + 'AI' => 'ANGUILLA', + 'AQ' => 'ANTARCTIQUE', + 'AG' => 'ANTIGUA-ET-BARBUDA', + 'AN' => 'ANTILLES NÉERLANDAISES', + 'SA' => 'ARABIE SAOUDITE', + 'AR' => 'ARGENTINE', + 'AM' => 'ARMÉNIE', + 'AW' => 'ARUBA', + 'AU' => 'AUSTRALIE', + 'AT' => 'AUTRICHE', + 'AZ' => 'AZERBAÏDJAN', + 'BS' => 'BAHAMAS', + 'BH' => 'BAHREÏN', + 'BD' => 'BANGLADESH', + 'BB' => 'BARBADE', + 'BY' => 'BÉLARUS', + 'BE' => 'BELGIQUE', + 'BZ' => 'BELIZE', + 'BJ' => 'BÉNIN', + 'BM' => 'BERMUDES', + 'BT' => 'BHOUTAN', + 'BO' => 'BOLIVIE', + 'BA' => 'BOSNIE-HERZÉGOVINE', + 'BW' => 'BOTSWANA', + 'BV' => 'BOUVET, ÎLE', + 'BR' => 'BRÉSIL', + 'BN' => 'BRUNÉI DARUSSALAM', + 'BG' => 'BULGARIE', + 'BF' => 'BURKINA FASO', + 'BI' => 'BURUNDI', + 'KY' => 'CAÏMANES, ÎLES', + 'KH' => 'CAMBODGE', + 'CM' => 'CAMEROUN', + 'CA' => 'CANADA', + 'CV' => 'CAP-VERT', + 'CF' => 'CENTRAFRICAINE, RÉPUBLIQUE', + 'CL' => 'CHILI', + 'CN' => 'CHINE', + 'CX' => 'CHRISTMAS, ÎLE', + 'CY' => 'CHYPRE', + 'CC' => 'COCOS (KEELING), ÎLES', + 'CO' => 'COLOMBIE', + 'KM' => 'COMORES', + 'CG' => 'CONGO', + 'CD' => 'CONGO, LA RÉPUBLIQUE DÉMOCRATIQUE DU', + 'CK' => 'COOK, ÎLES', + 'KR' => 'CORÉE, RÉPUBLIQUE DE', + 'KP' => 'CORÉE, RÉPUBLIQUE POPULAIRE DÉMOCRATIQUE DE', + 'CR' => 'COSTA RICA', + 'CI' => 'CÔTE D\'IVOIRE', + 'HR' => 'CROATIE', + 'CU' => 'CUBA', + 'DK' => 'DANEMARK', + 'DJ' => 'DJIBOUTI', + 'DO' => 'DOMINICAINE, RÉPUBLIQUE', + 'DM' => 'DOMINIQUE', + 'EG' => 'ÉGYPTE', + 'SV' => 'EL SALVADOR', + 'AE' => 'ÉMIRATS ARABES UNIS', + 'EC' => 'ÉQUATEUR', + 'ER' => 'ÉRYTHRÉE', + 'ES' => 'ESPAGNE', + 'EE' => 'ESTONIE', + 'US' => 'ÉTATS-UNIS', + 'ET' => 'ÉTHIOPIE', + 'FK' => 'FALKLAND, ÎLES (MALVINAS)', + 'FO' => 'FÉROÉ, ÎLES', + 'FJ' => 'FIDJI', + 'FI' => 'FINLANDE', + 'FR' => 'FRANCE', + 'GA' => 'GABON', + 'GM' => 'GAMBIE', + 'GE' => 'GÉORGIE', + 'GS' => 'GÉORGIE DU SUD ET LES ÎLES SANDWICH DU SUD', + 'GH' => 'GHANA', + 'GI' => 'GIBRALTAR', + 'GR' => 'GRÈCE', + 'GD' => 'GRENADE', + 'GL' => 'GROENLAND', + 'GP' => 'GUADELOUPE', + 'GU' => 'GUAM', + 'GT' => 'GUATEMALA', + 'GG' => 'GUERNESEY', + 'GN' => 'GUINÉE', + 'GW' => 'GUINÉE-BISSAU', + 'GQ' => 'GUINÉE ÉQUATORIALE', + 'GY' => 'GUYANA', + 'GF' => 'GUYANE FRANÇAISE', + 'HT' => 'HAÏTI', + 'HM' => 'HEARD, ÎLE ET MCDONALD, ÎLES', + 'HN' => 'HONDURAS', + 'HK' => 'HONG-KONG', + 'HU' => 'HONGRIE', + 'IM' => 'ÎLE DE MAN', + 'UM' => 'ÎLES MINEURES ÉLOIGNÉES DES ÉTATS-UNIS', + 'VG' => 'ÎLES VIERGES BRITANNIQUES', + 'VI' => 'ÎLES VIERGES DES ÉTATS-UNIS', + 'IN' => 'INDE', + 'ID' => 'INDONÉSIE', + 'IR' => 'IRAN, RÉPUBLIQUE ISLAMIQUE D\'', + 'IQ' => 'IRAQ', + 'IE' => 'IRLANDE', + 'IS' => 'ISLANDE', + 'IL' => 'ISRAËL', + 'IT' => 'ITALIE', + 'JM' => 'JAMAÏQUE', + 'JP' => 'JAPON', + 'JE' => 'JERSEY', + 'JO' => 'JORDANIE', + 'KZ' => 'KAZAKHSTAN', + 'KE' => 'KENYA', + 'KG' => 'KIRGHIZISTAN', + 'KI' => 'KIRIBATI', + 'KW' => 'KOWEÏT', + 'LA' => 'LAO, RÉPUBLIQUE DÉMOCRATIQUE POPULAIRE', + 'LS' => 'LESOTHO', + 'LV' => 'LETTONIE', + 'LB' => 'LIBAN', + 'LR' => 'LIBÉRIA', + 'LY' => 'LIBYENNE, JAMAHIRIYA ARABE', + 'LI' => 'LIECHTENSTEIN', + 'LT' => 'LITUANIE', + 'LU' => 'LUXEMBOURG', + 'MO' => 'MACAO', + 'MK' => 'MACÉDOINE, L\'EX-RÉPUBLIQUE YOUGOSLAVE DE', + 'MG' => 'MADAGASCAR', + 'MY' => 'MALAISIE', + 'MW' => 'MALAWI', + 'MV' => 'MALDIVES', + 'ML' => 'MALI', + 'MT' => 'MALTE', + 'MP' => 'MARIANNES DU NORD, ÎLES', + 'MA' => 'MAROC', + 'MH' => 'MARSHALL, ÎLES', + 'MQ' => 'MARTINIQUE', + 'MU' => 'MAURICE', + 'MR' => 'MAURITANIE', + 'YT' => 'MAYOTTE', + 'MX' => 'MEXIQUE', + 'FM' => 'MICRONÉSIE, ÉTATS FÉDÉRÉS DE', + 'MD' => 'MOLDOVA, RÉPUBLIQUE DE', + 'MC' => 'MONACO', + 'MN' => 'MONGOLIE', + 'ME' => 'MONTÉNÉGRO', + 'MS' => 'MONTSERRAT', + 'MZ' => 'MOZAMBIQUE', + 'MM' => 'MYANMAR', + 'NA' => 'NAMIBIE', + 'NR' => 'NAURU', + 'NP' => 'NÉPAL', + 'NI' => 'NICARAGUA', + 'NE' => 'NIGER', + 'NG' => 'NIGÉRIA', + 'NU' => 'NIUÉ', + 'NF' => 'NORFOLK, ÎLE', + 'NO' => 'NORVÈGE', + 'NC' => 'NOUVELLE-CALÉDONIE', + 'NZ' => 'NOUVELLE-ZÉLANDE', + 'IO' => 'OCÉAN INDIEN, TERRITOIRE BRITANNIQUE DE L\'', + 'OM' => 'OMAN', + 'UG' => 'OUGANDA', + 'UZ' => 'OUZBÉKISTAN', + 'PK' => 'PAKISTAN', + 'PW' => 'PALAOS', + 'PS' => 'PALESTINIEN OCCUPÉ, TERRITOIRE', + 'PA' => 'PANAMA', + 'PG' => 'PAPOUASIE-NOUVELLE-GUINÉE', + 'PY' => 'PARAGUAY', + 'NL' => 'PAYS-BAS', + 'PE' => 'PÉROU', + 'PH' => 'PHILIPPINES', + 'PN' => 'PITCAIRN', + 'PL' => 'POLOGNE', + 'PF' => 'POLYNÉSIE FRANÇAISE', + 'PR' => 'PORTO RICO', + 'PT' => 'PORTUGAL', + 'QA' => 'QATAR', + 'RE' => 'RÉUNION', + 'RO' => 'ROUMANIE', + 'GB' => 'ROYAUME-UNI', + 'RU' => 'RUSSIE, FÉDÉRATION DE', + 'RW' => 'RWANDA', + 'EH' => 'SAHARA OCCIDENTAL', + 'BL' => 'SAINT-BARTHÉLEMY', + 'SH' => 'SAINTE-HÉLÈNE', + 'LC' => 'SAINTE-LUCIE', + 'KN' => 'SAINT-KITTS-ET-NEVIS', + 'SM' => 'SAINT-MARIN', + 'MF' => 'SAINT-MARTIN', + 'PM' => 'SAINT-PIERRE-ET-MIQUELON', + 'VA' => 'SAINT-SIÈGE (ÉTAT DE LA CITÉ DU VATICAN)', + 'VC' => 'SAINT-VINCENT-ET-LES GRENADINES', + 'SB' => 'SALOMON, ÎLES', + 'WS' => 'SAMOA', + 'AS' => 'SAMOA AMÉRICAINES', + 'ST' => 'SAO TOMÉ-ET-PRINCIPE', + 'SN' => 'SÉNÉGAL', + 'RS' => 'SERBIE', + 'SC' => 'SEYCHELLES', + 'SL' => 'SIERRA LEONE', + 'SG' => 'SINGAPOUR', + 'SK' => 'SLOVAQUIE', + 'SI' => 'SLOVÉNIE', + 'SO' => 'SOMALIE', + 'SD' => 'SOUDAN', + 'LK' => 'SRI LANKA', + 'SE' => 'SUÈDE', + 'CH' => 'SUISSE', + 'SR' => 'SURINAME', + 'SJ' => 'SVALBARD ET ÎLE JAN MAYEN', + 'SZ' => 'SWAZILAND', + 'SY' => 'SYRIENNE, RÉPUBLIQUE ARABE', + 'TJ' => 'TADJIKISTAN', + 'TW' => 'TAÏWAN, PROVINCE DE CHINE', + 'TZ' => 'TANZANIE, RÉPUBLIQUE-UNIE DE', + 'TD' => 'TCHAD', + 'CZ' => 'TCHÈQUE, RÉPUBLIQUE', + 'TF' => 'TERRES AUSTRALES FRANÇAISES', + 'TH' => 'THAÏLANDE', + 'TL' => 'TIMOR-LESTE', + 'TG' => 'TOGO', + 'TK' => 'TOKELAU', + 'TO' => 'TONGA', + 'TT' => 'TRINITÉ-ET-TOBAGO', + 'TN' => 'TUNISIE', + 'TM' => 'TURKMÉNISTAN', + 'TC' => 'TURKS ET CAÏQUES, ÎLES', + 'TR' => 'TURQUIE', + 'TV' => 'TUVALU', + 'UA' => 'UKRAINE', + 'UY' => 'URUGUAY', + 'VU' => 'VANUATU', + 'VE' => 'VENEZUELA', + 'VN' => 'VIET NAM', + 'WF' => 'WALLIS ET FUTUNA', + 'YE' => 'YÉMEN', + 'ZM' => 'ZAMBIE', + 'ZW' => 'ZIMBABWE' + ]; + + if (!isset($countries[$lng])) { + $lng = 'us'; + } + foreach ($countries[$lng] as $k => $country) { + $countries[$lng][$k] = mb_strtolower($country); + } + + return $countries[$lng]; + } +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Vocabulary/ControlProvider/UserProvider.php b/lib/Alchemy/Phrasea/Vocabulary/ControlProvider/UserProvider.php index 17db8c19a7..31bf8bc1c5 100644 --- a/lib/Alchemy/Phrasea/Vocabulary/ControlProvider/UserProvider.php +++ b/lib/Alchemy/Phrasea/Vocabulary/ControlProvider/UserProvider.php @@ -52,7 +52,7 @@ class UserProvider implements ControlProviderInterface */ public function find($query, User $for_user,\databox $on_databox = null) { - $user_query = new \User_Query($this->app); + $user_query = $this->app['phraseanet.user-query']; $users = $user_query ->like(\User_Query::LIKE_EMAIL, $query) diff --git a/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php b/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php index 4ace803674..1b13f552ba 100644 --- a/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php +++ b/lib/Alchemy/Phrasea/Webhook/Processor/FeedEntryProcessor.php @@ -22,7 +22,7 @@ class FeedEntryProcessor extends AbstractProcessor implements ProcessorInterface $feed = $entry->getFeed(); - $query = new \User_Query($this->app); + $query = $this->app['phraseanet.user-query']; $query->include_phantoms(true) ->include_invite(false) diff --git a/lib/classes/User/Query.php b/lib/classes/User/Query.php index 34a427aadb..a7953a9322 100644 --- a/lib/classes/User/Query.php +++ b/lib/classes/User/Query.php @@ -12,147 +12,12 @@ use Alchemy\Phrasea\Application; use Alchemy\Phrasea\Model\Entities\User; use Doctrine\Common\Collections\ArrayCollection; +use Alchemy\Phrasea\Utilities\Countries; class User_Query implements User_QueryInterface { - /** - * - * @var Application - */ - protected $app; - - /** - * - * @var Array - */ - protected $results = []; - - /** - * - * @var Array - */ - protected $sort = []; - - /** - * - * @var Array - */ - protected $like_field = []; - - /** - * - * @var Array - */ - protected $have_rights; - - /** - * - * @var Array - */ - protected $have_not_rights; - - /** - * - * @var string - */ - protected $like_match = 'OR'; - - /** - * - * @var string - */ - protected $get_inactives = ''; - - /** - * - * @var int - */ - protected $total = 0; - - /** - * - * @var Array - */ - protected $active_bases = []; - - /** - * - * @var Array - */ - protected $active_sbas = []; - - /** - * - * @var boolean - */ - protected $bases_restrictions = false; - - /** - * - * @var boolean - */ - protected $sbas_restrictions = false; - - /** - * - * @var boolean - */ - protected $include_templates = false; - - /** - * - * @var boolean - */ - protected $only_templates = false; - - /** - * - * @var boolean - */ - protected $email_not_null = false; - - /** - * - * @var Array - */ - protected $base_ids = []; - - /** - * - * @var Array - */ - protected $sbas_ids = []; - - /** - * - * @var int - */ - protected $page; - - /** - * - * @var int - */ - protected $offset_start; - protected $last_model; - - /** - * - * @var int - */ - protected $results_quantity; - protected $include_phantoms = true; - protected $include_special_users = false; - protected $include_invite = false; - protected $activities; - protected $templates; - protected $companies; - protected $countries; - protected $positions; - protected $in_ids; - - const ORD_ASC = 'asc'; - const ORD_DESC = 'desc'; + const ORD_ASC = 'ASC'; + const ORD_DESC = 'DESC'; const SORT_FIRSTNAME = 'first_name'; const SORT_LASTNAME = 'last_name'; const SORT_COMPANY = 'company'; @@ -172,28 +37,49 @@ class User_Query implements User_QueryInterface const LIKE_MATCH_AND = 'AND'; const LIKE_MATCH_OR = 'OR'; - /** - * - * @return User_Query - */ + protected $app; + protected $results = []; + protected $sort = []; + protected $like_field = []; + protected $have_rights = null; + protected $have_not_rights = null; + protected $like_match = 'OR'; + protected $get_inactives = ''; + protected $total = 0; + protected $active_bases = []; + protected $active_sbas = []; + protected $bases_restrictions = false; + protected $sbas_restrictions = false; + protected $include_templates = false; + protected $only_templates = false; + protected $email_not_null = false; + protected $base_ids = []; + protected $sbas_ids = []; + protected $page = null; + protected $offset_start = null; + protected $last_model = null; + protected $results_quantity = null; + protected $include_phantoms = true; + protected $include_special_users = false; + protected $include_invite = false; + protected $activities = null; + protected $templates = null; + protected $companies = null; + protected $countries = null; + protected $positions = null; + protected $in_ids = null; + protected $sql_params = null; + public function __construct(Application $app) { $this->app = $app; - - foreach ($app['phraseanet.appbox']->get_databoxes() as $databox) { - $this->active_sbas[] = $databox->get_sbas_id(); - foreach ($databox->get_collections() as $collection) { - $this->active_bases[] = $collection->get_base_id(); - } - } - - return $this; + $this->setActiveBases(); } - protected $sql_params; /** + * Return query results * - * @return \Doctrine\Common\Collections\ArrayCollection + * @return array */ public function get_results() { @@ -201,21 +87,720 @@ class User_Query implements User_QueryInterface } /** + * Restrict users to the provided ones * - * @return string + * @param array $usr_ids + * + * @return $this */ + public function in(array $usr_ids) + { + $this->in_ids = array_unique(array_filter(array_map('intval', $usr_ids))); + + return $this; + } + + /** + * Restrict user with the provided last model + * + * @param User|string|null $login + * + * @return $this + */ + public function last_model_is($login = null) + { + $this->last_model = $login instanceof User ? $login->getLogin() : $login; + + return $this; + } + + /** + * Include users with no rights in any base + * + * @param bool $boolean + * + * @return $this + */ + public function include_phantoms($boolean = true) + { + $this->include_phantoms = !!$boolean; + + return $this; + } + + /** + * Include user such as 'guest' and 'autoregister' + * + * @param bool $boolean + * + * @return $this + */ + public function include_special_users($boolean = false) + { + $this->include_special_users = !!$boolean; + + return $this; + } + + /** + * Include guest user + * + * @param bool $boolean + * + * @return $this + */ + public function include_invite($boolean = false) + { + $this->include_invite = !!$boolean; + + return $this; + } + + /** + * Include user with provided rights + * + * @param array $rights + * + * @return $this + */ + public function who_have_right(array $rights) + { + $this->have_rights = $rights; + + return $this; + } + + /** + * Include users who are in reality templates + * + * @param $boolean + * + * @return $this + */ + public function include_templates($boolean) + { + $this->include_templates = !!$boolean; + + return $this; + } + + /** + * Restrict to templates + * + * @param $boolean + * + * @return $this + */ + public function only_templates($boolean) + { + $this->only_templates = !!$boolean; + + return $this; + } + + /** + * Restrict to user with an email + * + * @param $boolean + * + * @return $this + */ + public function email_not_null($boolean) + { + $this->email_not_null = !!$boolean; + + return $this; + } + + /** + * Restrict to users who have provided rights + * + * @param array $rights + * + * @return $this + */ + public function who_have_not_right(array $rights) + { + $this->have_not_rights = $rights; + + return $this; + } + + /** + * Execute query + * + * @return $this + */ + public function execute() + { + $conn = $this->app['phraseanet.appbox']->get_connection(); + $sql = 'SELECT DISTINCT Users.id ' . $this->generate_sql_constraints(); + + if ('' !== $sorter = $this->generate_sort_constraint()) { + $sql .= ' ORDER BY ' . $sorter; + } + + if (is_int($this->offset_start) && is_int($this->results_quantity)) { + $sql .= sprintf( + ' LIMIT %d, %d' + , $this->offset_start + , $this->results_quantity + ); + } + + $stmt = $conn->prepare($sql); + $stmt->execute($this->sql_params); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $users = new ArrayCollection(); + + foreach ($rs as $row) { + $users[] = $this->app['repo.users']->find($row['id']); + } + + $this->results = $users; + + return $this; + } + + /** + * Get total of fetched users + * + * @return int + */ + public function get_total() + { + if ($this->total) { + return $this->total; + } + + $conn = $this->app['phraseanet.appbox']->get_connection(); + + $sql_count = 'SELECT COUNT(DISTINCT Users.id) as total ' . $this->generate_sql_constraints(); + + $stmt = $conn->prepare($sql_count); + $stmt->execute($this->sql_params); + $row = $stmt->fetch(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $this->total = $row['total']; + + $this->page = 1; + if ($this->total > 0 && is_int($this->offset_start) && is_int($this->results_quantity)) { + $this->page = floor($this->offset_start / $this->results_quantity) + 1; + $this->total_page = floor($this->total / $this->results_quantity) + 1; + } + + return $this->total; + } + + /** + * Get current page + * + * @return null|int + */ + public function get_page() + { + $this->get_total(); + + return $this->page; + } + + /** + * Get total page + * + * @return null|int + */ + public function get_total_page() + { + $this->get_total(); + + return $this->total_page; + } + + /** + * Restrict users on collection with provided rights + * + * @param ACL $ACL + * @param array $rights + * + * @return $this + */ + public function on_bases_where_i_am(ACL $ACL, Array $rights) + { + $this->bases_restrictions = true; + $collections = array_keys($ACL->get_granted_base($rights)); + + if (count($this->base_ids) > 0) { + $this->base_ids = array_intersect($this->base_ids, $collections); + } else { + $this->base_ids = $collections; + } + + $this->total = $this->page = $this->total_page = null; + + return $this; + } + + /** + * Restrict users on database with provided rights + * + * @param ACL $ACL + * @param array $rights + * + * @return $this + */ + public function on_sbas_where_i_am(ACL $ACL, Array $rights) + { + $this->sbas_restrictions = true; + $databoxes = array_keys($ACL->get_granted_sbas($rights)); + + if (count($this->sbas_ids) > 0) + $this->sbas_ids = array_intersect($this->sbas_ids, $databoxes); + else + $this->sbas_ids = $databoxes; + + $this->total = $this->page = $this->total_page = null; + + return $this; + } + + /** + * Restrict to provided limits + * + * @param $offset_start + * @param $results_quantity + * + * @return $this + */ + public function limit($offset_start, $results_quantity) + { + $this->offset_start = (int) $offset_start; + $this->results_quantity = (int) $results_quantity; + + return $this; + } + + /** + * Restrict on provided field with provided value + * + * @param $like_field + * @param $like_value + * + * @return $this + */ + public function like($like_field, $like_value) + { + $this->like_field[trim($like_field)] = trim($like_value); + $this->total = $this->page = $this->total_page = null; + + return $this; + } + + /** + * Restrict on match + * + * @param $like_match + * + * @return $this + */ + public function like_match($like_match) + { + switch ($like_match) { + case self::LIKE_MATCH_AND: + case self::LIKE_MATCH_OR: + $this->like_match = $like_match; + break; + default: + break; + } + $this->total = $this->page = $this->total_page = null; + + return $this; + } + + /** + * Restrict on collections + * + * @param array $base_ids + * + * @return $this + */ + public function on_base_ids(array $base_ids = null) + { + if (! $base_ids) { + return $this; + } + + $this->bases_restrictions = true; + + $this->include_phantoms(false); + + if (count($this->base_ids) > 0) { + $this->base_ids = array_intersect($this->base_ids, $base_ids); + } else { + $this->base_ids = $base_ids; + } + + $this->total = $this->page = $this->total_page = null; + + return $this; + } + + /** + * Restrict on databoxes + * + * @param array $sbas_ids + * + * @return $this + */ + public function on_sbas_ids(Array $sbas_ids = null) + { + if (! $sbas_ids) { + return $this; + } + + $this->sbas_restrictions = true; + + $this->include_phantoms(false); + + if (count($this->sbas_ids) > 0) { + $this->sbas_ids = array_intersect($this->sbas_ids, $sbas_ids); + } else { + $this->sbas_ids = $sbas_ids; + } + + $this->total = $this->page = $this->total_page = null; + + return $this; + } + + /** + * Sort by + * + * @param $sort + * @param string $ord + * + * @return $this + */ + public function sort_by($sort, $ord = self::ORD_ASC) + { + $this->sort[$sort] = $ord; + + return $this; + } + + /** + * Restrict users with provided activities + * + * @param array $req_activities + * + * @return $this + */ + public function haveActivities(array $req_activities) + { + $activities = new ArrayCollection(); + + foreach ($req_activities as $activity) { + if ($activity = trim($activity) === '') { + continue; + } + + if ($activities->contains($activity)) { + continue; + } + + $activities->add($activity); + } + + if (!$activities->isEmpty()) { + $this->activities = $activities; + } + + return $this; + } + + /** + * Restrict users with provided jobs + * + * @param array $req_positions + * + * @return $this + */ + public function havePositions(array $req_positions) + { + $positions = new ArrayCollection(); + + foreach ($req_positions as $position) { + if ($position = trim($position) === '') { + continue; + } + if ($positions->contains($position)) { + continue; + } + + $positions->add($position); + } + + if (!$positions->isEmpty()) { + $this->positions = $positions; + } + + return $this; + } + + /** + * Restrict users by countries + * + * @param array $req_countries + * + * @return $this + */ + public function inCountries(array $req_countries) + { + $countries = new ArrayCollection(); + + foreach ($req_countries as $country) { + if ($country = trim($country) === '') { + continue; + } + if ($countries->contains($country)) { + continue; + } + + $countries->add($country); + } + + if (!$countries->isEmpty()) { + $this->countries = $countries; + } + + return $this; + } + + /** + * Restrict users by companies + * + * @param array $req_companies + * + * @return $this + */ + public function inCompanies(array $req_companies) + { + $companies = new ArrayCollection(); + + foreach ($req_companies as $company) { + if ($company = trim($company) === '') { + continue; + } + if ($companies->contains($company)) { + continue; + } + $companies->add($company); + } + + if (!$companies->isEmpty()) { + $this->companies = $companies; + } + + return $this; + } + + /** + * Restrict users with given templates + * + * @param array $req_templates + * + * @return $this + */ + public function haveTemplate(array $req_templates) + { + $templates = new ArrayCollection(); + + foreach ($req_templates as $template) { + if ($template = trim($template) === '') { + continue; + } + if ($templates->contains($template)) { + continue; + } + $templates->add($template); + } + + if (!$templates->isEmpty()) { + $this->templates = $templates; + } + + return $this; + } + + /** + * Retrieve inactive use + * (inactive users do not have the "access" right) + * + * @param bool $boolean + * + * @return $this + */ + public function get_inactives($boolean = true) + { + $this->get_inactives = !!$boolean; + + return $this; + } + + /** + * Get users activities + * + * @return array + */ + public function getRelatedActivities() + { + $conn = $this->app['phraseanet.appbox']->get_connection(); + + $sql = 'SELECT DISTINCT Users.activity ' . $this->generate_sql_constraints(). ' ORDER BY Users.activity'; + + $stmt = $conn->prepare($sql); + $stmt->execute($this->sql_params); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $activities = []; + foreach ($rs as $row) { + if (trim($row['activity']) === '') { + continue; + } + $activities[] = $row['activite']; + } + + return $activities; + } + + /** + * Get users jobs + * + * @return array + */ + public function getRelatedPositions() + { + $conn = $this->app['phraseanet.appbox']->get_connection(); + + $sql = 'SELECT DISTINCT Users.job ' . $this->generate_sql_constraints() . ' ORDER BY Users.job'; + + $stmt = $conn->prepare($sql); + $stmt->execute($this->sql_params); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $jobs = []; + foreach ($rs as $row) { + if (trim($row['job']) === '') { + continue; + } + $jobs[] = $row['job']; + } + + return $jobs; + } + + /** + * Get user countries + * + * @return array + */ + public function getRelatedCountries() + { + $conn = $this->app['phraseanet.appbox']->get_connection(); + + $sql = 'SELECT DISTINCT Users.country ' . $this->generate_sql_constraints() . ' ORDER BY Users.country'; + + $stmt = $conn->prepare($sql); + $stmt->execute($this->sql_params); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $countries = []; + $listCountry = Countries::getCountries($this->app['locale']); + foreach ($rs as $row) { + if (trim($row['country']) === '') { + continue; + } + + if (isset($listCountry[$row['country']])) { + $countries[$row['country']] = $listCountry[$row['country']]; + } + } + + return $countries; + } + + /** + * Get users companies + * + * @return array + */ + public function getRelatedCompanies() + { + $conn = $this->app['phraseanet.appbox']->get_connection(); + + $sql = 'SELECT DISTINCT Users.company ' . $this->generate_sql_constraints() . ' ORDER BY Users.company'; + + $stmt = $conn->prepare($sql); + $stmt->execute($this->sql_params); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $companies = []; + foreach ($rs as $row) { + if (trim($row['company']) === '') { + continue; + } + $companies[] = $row['company']; + } + + return $companies; + } + + /** + * Get users templates + * + * @return array + */ + public function getRelatedTemplates() + { + $conn = $this->app['phraseanet.appbox']->get_connection(); + + $sql = 'SELECT DISTINCT Users.last_model ' . $this->generate_sql_constraints() . ' ORDER BY Users.last_model'; + + $stmt = $conn->prepare($sql); + $stmt->execute($this->sql_params); + $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $lastModel = []; + foreach ($rs as $row) { + if (trim($row['last_model']) === '') { + continue; + } + + $lastModel[] = $row['last_model']; + } + + return $lastModel; + } + protected function generate_sql_constraints() { $this->sql_params = []; $sql = ' - FROM Users LEFT JOIN basusr ON (Users.id = basusr.usr_id) - LEFT JOIN sbasusr ON (Users.id = sbasusr.usr_id) - WHERE 1 '; + FROM Users LEFT JOIN basusr ON (Users.id = basusr.usr_id) + LEFT JOIN sbasusr ON (Users.id = sbasusr.usr_id) + WHERE 1 '; if (! $this->include_special_users) { - $sql .= ' AND Users.login != "autoregister" - AND Users.login != "invite" '; + $sql .= ' AND Users.login != "autoregister" AND Users.login != "invite" '; } $sql .= ' AND Users.deleted="0" '; @@ -262,27 +847,25 @@ class User_Query implements User_QueryInterface } if (count($this->base_ids) == 0) { - if ($this->bases_restrictions) + if ($this->bases_restrictions) { throw new Exception('No base available for you, not enough rights'); + } } else { $extra = $this->include_phantoms ? ' OR base_id IS NULL ' : ''; $not_base_id = array_diff($this->active_bases, $this->base_ids); if (count($not_base_id) > 0 && count($not_base_id) < count($this->base_ids)) { - $sql .= sprintf(' AND ((base_id != %s ) ' . $extra . ')' - , implode(' AND base_id != ', $not_base_id) - ); + $sql .= sprintf(' AND ((base_id != %s ) ' . $extra . ')', implode(' AND base_id != ', $not_base_id)); } else { - $sql .= sprintf(' AND (base_id = %s ' . $extra . ') ' - , implode(' OR base_id = ', $this->base_ids) - ); + $sql .= sprintf(' AND (base_id = %s ' . $extra . ') ', implode(' OR base_id = ', $this->base_ids)); } } if (count($this->sbas_ids) == 0) { - if ($this->sbas_restrictions) + if ($this->sbas_restrictions) { throw new Exception('No base available for you, not enough rights'); + } } else { $extra = $this->include_phantoms ? ' OR sbas_id IS NULL ' : ''; @@ -324,14 +907,13 @@ class User_Query implements User_QueryInterface foreach ($this->like_field as $like_field => $like_value) { switch ($like_field) { case self::LIKE_NAME: - $qrys = []; + $queries = []; foreach (explode(' ', $like_value) as $like_val) { if (trim($like_val) === '') continue; - $qrys[] = sprintf( - ' (Users.`%s` LIKE "%s%%" COLLATE utf8_unicode_ci - OR Users.`%s` LIKE "%s%%" COLLATE utf8_unicode_ci) ' + $queries[] = sprintf( + ' (Users.`%s` LIKE "%s%%" COLLATE utf8_unicode_ci OR Users.`%s` LIKE "%s%%" COLLATE utf8_unicode_ci) ' , self::LIKE_FIRSTNAME , str_replace(['"', '%'], ['\"', '\%'], $like_val) , self::LIKE_LASTNAME @@ -339,9 +921,9 @@ class User_Query implements User_QueryInterface ); } - if (count($qrys) > 0) - $sql_like[] = ' (' . implode(' AND ', $qrys) . ') '; - + if (count($queries) > 0) { + $sql_like[] = ' (' . implode(' AND ', $queries) . ') '; + } break; case self::LIKE_FIRSTNAME: case self::LIKE_LASTNAME: @@ -360,8 +942,9 @@ class User_Query implements User_QueryInterface } } - if (count($sql_like) > 0) + if (count($sql_like) > 0) { $sql .= sprintf(' AND (%s) ', implode($this->like_match, $sql_like)); + } return $sql; } @@ -374,629 +957,18 @@ class User_Query implements User_QueryInterface foreach ($fields as $field) { $constraints[':' . $fieldName . $n ++] = $field; } - $sql = ' AND (' . $fieldName . ' = ' - . implode(' OR ' . $fieldName . ' = ', array_keys($constraints)) . ') '; + $sql = ' AND (' . $fieldName . ' = ' . implode(' OR ' . $fieldName . ' = ', array_keys($constraints)) . ') '; $this->sql_params = array_merge($this->sql_params, $constraints); return $sql; } - public function in(array $usr_ids) - { - $tmp_usr_ids = []; - - foreach ($usr_ids as $usr_id) { - $tmp_usr_ids[] = (int) $usr_id; - } - - $this->in_ids = array_unique($tmp_usr_ids); - - return $this; - } - - public function last_model_is($login = null) - { - $this->last_model = $login instanceof User ? $login->getLogin() : $login; - - return $this; - } - - public function include_phantoms($boolean = true) - { - $this->include_phantoms = ! ! $boolean; - - return $this; - } - - public function include_special_users($boolean = false) - { - $this->include_special_users = ! ! $boolean; - - return $this; - } - - public function include_invite($boolean = false) - { - $this->include_invite = ! ! $boolean; - - return $this; - } - - /** - * - * @param array $rights - * @return User_Query - */ - public function who_have_right(Array $rights) - { - $this->have_rights = $rights; - - return $this; - } - - /** - * - * @param boolean $boolean - * @return User_Query - */ - public function include_templates($boolean) - { - $this->include_templates = ! ! $boolean; - - return $this; - } - - /** - * - * @param boolean $boolean - * @return User_Query - */ - public function only_templates($boolean) - { - $this->only_templates = ! ! $boolean; - - return $this; - } - - /** - * - * @param boolean $boolean - * @return User_Query - */ - public function email_not_null($boolean) - { - $this->email_not_null = ! ! $boolean; - - return $this; - } - - /** - * - * @param array $rights - * @return User_Query - */ - public function who_have_not_right(Array $rights) - { - $this->have_not_rights = $rights; - - return $this; - } - - /** - * - * @return User_Query - */ - public function execute() - { - $conn = $this->app['phraseanet.appbox']->get_connection(); - $sql = 'SELECT DISTINCT Users.id ' . $this->generate_sql_constraints(); - - if ('' !== $sorter = $this->generate_sort_constraint()) { - $sql .= ' ORDER BY ' . $sorter; - } - - if (is_int($this->offset_start) && is_int($this->results_quantity)) { - $sql .= sprintf( - ' LIMIT %d, %d' - , $this->offset_start - , $this->results_quantity - ); - } - - $stmt = $conn->prepare($sql); - $stmt->execute($this->sql_params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $users = new ArrayCollection(); - - foreach ($rs as $row) { - $users[] = $this->app['repo.users']->find($row['id']); - } - - $this->results = $users; - - return $this; - } - - /** - * - * @return int - */ - public function get_total() - { - if ($this->total) { - return $this->total; - } - - $conn = $this->app['phraseanet.appbox']->get_connection(); - - $sql_count = 'SELECT COUNT(DISTINCT Users.id) as total ' - . $this->generate_sql_constraints(); - - $stmt = $conn->prepare($sql_count); - $stmt->execute($this->sql_params); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $this->total = $row['total']; - - $this->page = 1; - if ($this->total > 0 && is_int($this->offset_start) && is_int($this->results_quantity)) { - $this->page = floor($this->offset_start / $this->results_quantity) + 1; - $this->total_page = floor($this->total / $this->results_quantity) + 1; - } - - return $this->total; - } - - /** - * - * @return int - */ - public function get_page() - { - $this->get_total(); - - return $this->page; - } - - /** - * - * @return int - */ - public function get_total_page() - { - $this->get_total(); - - return $this->total_page; - } - - /** - * - * @param ACL $ACL User's ACLs - * @param array $rights An array of base rights you need - * @return User_Query - */ - public function on_bases_where_i_am(ACL $ACL, Array $rights) - { - $this->bases_restrictions = true; - $baslist = array_keys($ACL->get_granted_base($rights)); - - if (count($this->base_ids) > 0) - $this->base_ids = array_intersect($this->base_ids, $baslist); - else - $this->base_ids = $baslist; - - $this->total = $this->page = $this->total_page = null; - - return $this; - } - - /** - * - * @param ACL $ACL - * @param array $rights An array of sbas rights you need - * @return User_Query - */ - public function on_sbas_where_i_am(ACL $ACL, Array $rights) - { - $this->sbas_restrictions = true; - $sbaslist = array_keys($ACL->get_granted_sbas($rights)); - - if (count($this->sbas_ids) > 0) - $this->sbas_ids = array_intersect($this->sbas_ids, $sbaslist); - else - $this->sbas_ids = $sbaslist; - - $this->total = $this->page = $this->total_page = null; - - return $this; - } - - /** - * - * @param int $offset_start - * @param int $results_quantity - * @return User_Query - */ - public function limit($offset_start, $results_quantity) - { - $this->offset_start = (int) $offset_start; - $this->results_quantity = (int) $results_quantity; - - return $this; - } - - /** - * Query width a like field - * like fields are defined as constants of the object - * - * @param const $like_field - * @param string $like_value - * @return User_Query - */ - public function like($like_field, $like_value) - { - $this->like_field[trim($like_field)] = trim($like_value); - $this->total = $this->page = $this->total_page = null; - - return $this; - } - - /** - * Choose whether multiple like will be treated as AND or OR - * - * @param type $like_match - * @return User_Query - */ - public function like_match($like_match) - { - switch ($like_match) { - case self::LIKE_MATCH_AND: - case self::LIKE_MATCH_OR: - $this->like_match = $like_match; - break; - default: - break; - } - $this->total = $this->page = $this->total_page = null; - - return $this; - } - - /** - * Restrict User search on base_ids - * - * @param array $base_ids - * @return User_Query - */ - public function on_base_ids(Array $base_ids = null) - { - if (! $base_ids) { - return $this; - } - - $this->bases_restrictions = true; - - $this->include_phantoms(false); - - if (count($this->base_ids) > 0) - $this->base_ids = array_intersect($this->base_ids, $base_ids); - else - $this->base_ids = $base_ids; - - $this->total = $this->page = $this->total_page = null; - - return $this; - } - - /** - * - * @param array $sbas_ids - * @return User_Query - */ - public function on_sbas_ids(Array $sbas_ids = null) - { - if (! $sbas_ids) { - return $this; - } - - $this->sbas_restrictions = true; - - $this->include_phantoms(false); - - if (count($this->sbas_ids) > 0) - $this->sbas_ids = array_intersect($this->sbas_ids, $sbas_ids); - else - $this->sbas_ids = $sbas_ids; - - $this->total = $this->page = $this->total_page = null; - - return $this; - } - - /** - * Sort results. Sort field and sort order are defined as constants - * of this object - * - * @param const $sort - * @param const $ord - * @return User_Query - */ - public function sort_by($sort, $ord = 'asc') - { - $this->sort[$sort] = $ord; - - return $this; - } - - public function haveActivities(array $req_activities) - { - $Activities = new \Doctrine\Common\Collections\ArrayCollection(); - - foreach ($req_activities as $activity) { - $activity = trim($activity); - - if ($activity === '') - continue; - - if ($Activities->contains($activity)) - continue; - - $Activities->add($activity); - } - - if ( ! $Activities->isEmpty()) { - $this->activities = $Activities; - } - - return $this; - } - - public function havePositions(array $req_positions) - { - $Positions = new \Doctrine\Common\Collections\ArrayCollection(); - - foreach ($req_positions as $Position) { - $Position = trim($Position); - - if ($Position === '') - continue; - - if ($Positions->contains($Position)) - continue; - - $Positions->add($Position); - } - - if ( ! $Positions->isEmpty()) { - $this->positions = $Positions; - } - - return $this; - } - - public function inCountries(array $req_countries) - { - $Countries = new \Doctrine\Common\Collections\ArrayCollection(); - - foreach ($req_countries as $Country) { - $Country = trim($Country); - - if ($Country === '') - continue; - - if ($Countries->contains($Country)) - continue; - - $Countries->add($Country); - } - - if ( ! $Countries->isEmpty()) { - $this->countries = $Countries; - } - - return $this; - } - - public function inCompanies(array $req_companies) - { - $Companies = new \Doctrine\Common\Collections\ArrayCollection(); - - foreach ($req_companies as $Company) { - $Company = trim($Company); - - if ($Company === '') - continue; - - if ($Companies->contains($Company)) - continue; - - $Companies->add($Company); - } - - if ( ! $Companies->isEmpty()) { - $this->companies = $Companies; - } - - return $this; - } - - public function haveTemplate(array $req_templates) - { - $Templates = new \Doctrine\Common\Collections\ArrayCollection(); - - foreach ($req_templates as $Template) { - $Template = trim($Template); - - if ($Template === '') - continue; - - if ($Templates->contains($Template)) - continue; - - $Templates->add($Template); - } - - if ( ! $Templates->isEmpty()) { - $this->templates = $Templates; - } - - return $this; - } - - /** - * Wheter or not retrieve inactive users - * (inactive users do not have the "access" right) - * - * @param boolean $boolean - * @return User_Query - */ - public function get_inactives($boolean = true) - { - $this->get_inactives = ! ! $boolean; - - return $this; - } - - public function getRelatedActivities() - { - $conn = $this->app['phraseanet.appbox']->get_connection(); - - $sql = 'SELECT DISTINCT Users.activity ' . $this->generate_sql_constraints(); - - $sql .= ' ORDER BY Users.activity'; - - $stmt = $conn->prepare($sql); - $stmt->execute($this->sql_params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $activities = []; - - foreach ($rs as $row) { - if (trim($row['activity']) === '') - continue; - - $activities[] = $row['activite']; - } - - return $activities; - } - - public function getRelatedPositions() - { - $conn = $this->app['phraseanet.appbox']->get_connection(); - - $sql = 'SELECT DISTINCT Users.job ' . $this->generate_sql_constraints(); - - $sql .= ' ORDER BY Users.job'; - - $stmt = $conn->prepare($sql); - $stmt->execute($this->sql_params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $fonction = []; - - foreach ($rs as $row) { - if (trim($row['job']) === '') - continue; - - $fonction[] = $row['job']; - } - - return $fonction; - } - - public function getRelatedCountries() - { - require_once __DIR__ . '/../../classes/deprecated/countries.php'; - - $conn = $this->app['phraseanet.appbox']->get_connection(); - - $sql = 'SELECT DISTINCT Users.country ' . $this->generate_sql_constraints(); - - $sql .= ' ORDER BY Users.country'; - - $stmt = $conn->prepare($sql); - $stmt->execute($this->sql_params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $pays = []; - - $ctry = \getCountries($this->app['locale']); - - foreach ($rs as $row) { - if (trim($row['country']) === '') - continue; - - if (isset($ctry[$row['country']])) - $pays[$row['country']] = $ctry[$row['country']]; - } - - return $pays; - } - - public function getRelatedCompanies() - { - $conn = $this->app['phraseanet.appbox']->get_connection(); - - $sql = 'SELECT DISTINCT Users.company ' . $this->generate_sql_constraints(); - - $sql .= ' ORDER BY Users.company'; - - $stmt = $conn->prepare($sql); - $stmt->execute($this->sql_params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $societe = []; - - foreach ($rs as $row) { - if (trim($row['company']) === '') - continue; - - $societe[] = $row['company']; - } - - return $societe; - } - - public function getRelatedTemplates() - { - $conn = $this->app['phraseanet.appbox']->get_connection(); - - $sql = 'SELECT DISTINCT Users.last_model ' . $this->generate_sql_constraints(); - - $sql .= ' ORDER BY Users.last_model'; - - $stmt = $conn->prepare($sql); - $stmt->execute($this->sql_params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $lastModel = []; - - foreach ($rs as $row) { - if (trim($row['last_model']) === '') - continue; - - $lastModel[] = $row['last_model']; - } - - return $lastModel; - } - private function generate_sort_constraint() { $sorter = []; foreach ($this->sort as $sort => $ord) { - $k = count($sorter); switch ($sort) { @@ -1017,7 +989,7 @@ class User_Query implements User_QueryInterface break; } - if ( ! isset($sorter[$k])) + if (!isset($sorter[$k])) continue; switch ($ord) { @@ -1033,4 +1005,14 @@ class User_Query implements User_QueryInterface return implode(', ', $sorter); } + + private function setActiveBases() + { + foreach ($this->app['phraseanet.appbox']->get_databoxes() as $databox) { + $this->active_sbas[] = $databox->get_sbas_id(); + foreach ($databox->get_collections() as $collection) { + $this->active_bases[] = $collection->get_base_id(); + } + } + } } diff --git a/lib/classes/User/QueryInterface.php b/lib/classes/User/QueryInterface.php index 455b52645b..e2e93acf52 100644 --- a/lib/classes/User/QueryInterface.php +++ b/lib/classes/User/QueryInterface.php @@ -13,7 +13,6 @@ use Alchemy\Phrasea\Application; interface User_QueryInterface { - public function __construct(Application $app); public function get_results(); diff --git a/lib/classes/collection.php b/lib/classes/collection.php index 0671c3c417..c1ed5a2f0b 100644 --- a/lib/classes/collection.php +++ b/lib/classes/collection.php @@ -515,7 +515,7 @@ class collection implements cache_cacheableInterface { $params = [':base_id' => $this->get_base_id()]; - $query = new User_Query($app); + $query = $app['phraseanet.user-query']; $total = $query->on_base_ids([$this->get_base_id()]) ->include_phantoms(false) ->include_special_users(true) diff --git a/lib/classes/databox.php b/lib/classes/databox.php index 8aaf05b1c4..0aa1687e8c 100644 --- a/lib/classes/databox.php +++ b/lib/classes/databox.php @@ -458,7 +458,7 @@ class databox extends base $collection->unmount_collection($this->app); } - $query = new User_Query($this->app); + $query = $this->app['phraseanet.user-query']; $total = $query->on_sbas_ids([$this->id]) ->include_phantoms(false) ->include_special_users(true) diff --git a/lib/classes/deprecated/countries.php b/lib/classes/deprecated/countries.php deleted file mode 100644 index 16e8ded15b..0000000000 --- a/lib/classes/deprecated/countries.php +++ /dev/null @@ -1,519 +0,0 @@ - 'AFGHANISTAN', - 'AX' => 'ÅLAND ISLANDS', - 'AL' => 'ALBANIA', - 'DZ' => 'ALGERIA', - 'AS' => 'AMERICAN SAMOA', - 'AD' => 'ANDORRA', - 'AO' => 'ANGOLA', - 'AI' => 'ANGUILLA', - 'AQ' => 'ANTARCTICA', - 'AG' => 'ANTIGUA AND BARBUDA', - 'AR' => 'ARGENTINA', - 'AM' => 'ARMENIA', - 'AW' => 'ARUBA', - 'AU' => 'AUSTRALIA', - 'AT' => 'AUSTRIA', - 'AZ' => 'AZERBAIJAN', - 'BS' => 'BAHAMAS', - 'BH' => 'BAHRAIN', - 'BD' => 'BANGLADESH', - 'BB' => 'BARBADOS', - 'BY' => 'BELARUS', - 'BE' => 'BELGIUM', - 'BZ' => 'BELIZE', - 'BJ' => 'BENIN', - 'BM' => 'BERMUDA', - 'BT' => 'BHUTAN', - 'BO' => 'BOLIVIA', - 'BA' => 'BOSNIA AND HERZEGOVINA', - 'BW' => 'BOTSWANA', - 'BV' => 'BOUVET ISLAND', - 'BR' => 'BRAZIL', - 'IO' => 'BRITISH INDIAN OCEAN TERRITORY', - 'BN' => 'BRUNEI DARUSSALAM', - 'BG' => 'BULGARIA', - 'BF' => 'BURKINA FASO', - 'BI' => 'BURUNDI', - 'KH' => 'CAMBODIA', - 'CM' => 'CAMEROON', - 'CA' => 'CANADA', - 'CV' => 'CAPE VERDE', - 'KY' => 'CAYMAN ISLANDS', - 'CF' => 'CENTRAL AFRICAN REPUBLIC', - 'TD' => 'CHAD', - 'CL' => 'CHILE', - 'CN' => 'CHINA', - 'CX' => 'CHRISTMAS ISLAND', - 'CC' => 'COCOS (KEELING) ISLANDS', - 'CO' => 'COLOMBIA', - 'KM' => 'COMOROS', - 'CG' => 'CONGO', - 'CD' => 'CONGO, THE DEMOCRATIC REPUBLIC OF THE', - 'CK' => 'COOK ISLANDS', - 'CR' => 'COSTA RICA', - 'CI' => 'CÔTE D\'IVOIRE', - 'HR' => 'CROATIA', - 'CU' => 'CUBA', - 'CY' => 'CYPRUS', - 'CZ' => 'CZECH REPUBLIC', - 'DK' => 'DENMARK', - 'DJ' => 'DJIBOUTI', - 'DM' => 'DOMINICA', - 'DO' => 'DOMINICAN REPUBLIC', - 'EC' => 'ECUADOR', - 'EG' => 'EGYPT', - 'SV' => 'EL SALVADOR', - 'GQ' => 'EQUATORIAL GUINEA', - 'ER' => 'ERITREA', - 'EE' => 'ESTONIA', - 'ET' => 'ETHIOPIA', - 'FK' => 'FALKLAND ISLANDS (MALVINAS)', - 'FO' => 'FAROE ISLANDS', - 'FJ' => 'FIJI', - 'FI' => 'FINLAND', - 'FR' => 'FRANCE', - 'GF' => 'FRENCH GUIANA', - 'PF' => 'FRENCH POLYNESIA', - 'TF' => 'FRENCH SOUTHERN TERRITORIES', - 'GA' => 'GABON', - 'GM' => 'GAMBIA', - 'GE' => 'GEORGIA', - 'DE' => 'GERMANY', - 'GH' => 'GHANA', - 'GI' => 'GIBRALTAR', - 'GR' => 'GREECE', - 'GL' => 'GREENLAND', - 'GD' => 'GRENADA', - 'GP' => 'GUADELOUPE', - 'GU' => 'GUAM', - 'GT' => 'GUATEMALA', - 'GG' => 'GUERNSEY', - 'GN' => 'GUINEA', - 'GW' => 'GUINEA-BISSAU', - 'GY' => 'GUYANA', - 'HT' => 'HAITI', - 'HM' => 'HEARD ISLAND AND MCDONALD ISLANDS', - 'VA' => 'HOLY SEE (VATICAN CITY STATE)', - 'HN' => 'HONDURAS', - 'HK' => 'HONG KONG', - 'HU' => 'HUNGARY', - 'IS' => 'ICELAND', - 'IN' => 'INDIA', - 'ID' => 'INDONESIA', - 'IR' => 'IRAN, ISLAMIC REPUBLIC OF', - 'IQ' => 'IRAQ', - 'IE' => 'IRELAND', - 'IM' => 'ISLE OF MAN', - 'IL' => 'ISRAEL', - 'IT' => 'ITALY', - 'JM' => 'JAMAICA', - 'JP' => 'JAPAN', - 'JE' => 'JERSEY', - 'JO' => 'JORDAN', - 'KZ' => 'KAZAKHSTAN', - 'KE' => 'KENYA', - 'KI' => 'KIRIBATI', - 'KP' => 'KOREA, DEMOCRATIC PEOPLE\'S REPUBLIC OF', - 'KR' => 'KOREA, REPUBLIC OF', - 'KW' => 'KUWAIT', - 'KG' => 'KYRGYZSTAN', - 'LA' => 'LAO PEOPLE\'S DEMOCRATIC REPUBLIC', - 'LV' => 'LATVIA', - 'LB' => 'LEBANON', - 'LS' => 'LESOTHO', - 'LR' => 'LIBERIA', - 'LY' => 'LIBYAN ARAB JAMAHIRIYA', - 'LI' => 'LIECHTENSTEIN', - 'LT' => 'LITHUANIA', - 'LU' => 'LUXEMBOURG', - 'MO' => 'MACAO', - 'MK' => 'MACEDONIA, THE FORMER YUGOSLAV REPUBLIC OF', - 'MG' => 'MADAGASCAR', - 'MW' => 'MALAWI', - 'MY' => 'MALAYSIA', - 'MV' => 'MALDIVES', - 'ML' => 'MALI', - 'MT' => 'MALTA', - 'MH' => 'MARSHALL ISLANDS', - 'MQ' => 'MARTINIQUE', - 'MR' => 'MAURITANIA', - 'MU' => 'MAURITIUS', - 'YT' => 'MAYOTTE', - 'MX' => 'MEXICO', - 'FM' => 'MICRONESIA, FEDERATED STATES OF', - 'MD' => 'MOLDOVA, REPUBLIC OF', - 'MC' => 'MONACO', - 'MN' => 'MONGOLIA', - 'ME' => 'MONTENEGRO', - 'MS' => 'MONTSERRAT', - 'MA' => 'MOROCCO', - 'MZ' => 'MOZAMBIQUE', - 'MM' => 'MYANMAR', - 'NA' => 'NAMIBIA', - 'NR' => 'NAURU', - 'NP' => 'NEPAL', - 'NL' => 'NETHERLANDS', - 'AN' => 'NETHERLANDS ANTILLES', - 'NC' => 'NEW CALEDONIA', - 'NZ' => 'NEW ZEALAND', - 'NI' => 'NICARAGUA', - 'NE' => 'NIGER', - 'NG' => 'NIGERIA', - 'NU' => 'NIUE', - 'NF' => 'NORFOLK ISLAND', - 'MP' => 'NORTHERN MARIANA ISLANDS', - 'NO' => 'NORWAY', - 'OM' => 'OMAN', - 'PK' => 'PAKISTAN', - 'PW' => 'PALAU', - 'PS' => 'PALESTINIAN TERRITORY, OCCUPIED', - 'PA' => 'PANAMA', - 'PG' => 'PAPUA NEW GUINEA', - 'PY' => 'PARAGUAY', - 'PE' => 'PERU', - 'PH' => 'PHILIPPINES', - 'PN' => 'PITCAIRN', - 'PL' => 'POLAND', - 'PT' => 'PORTUGAL', - 'PR' => 'PUERTO RICO', - 'QA' => 'QATAR', - 'RE' => 'REUNION', - 'RO' => 'ROMANIA', - 'RU' => 'RUSSIAN FEDERATION', - 'RW' => 'RWANDA', - 'BL' => 'SAINT BARTHÉLEMY', - 'SH' => 'SAINT HELENA', - 'KN' => 'SAINT KITTS AND NEVIS', - 'LC' => 'SAINT LUCIA', - 'MF' => 'SAINT MARTIN', - 'PM' => 'SAINT PIERRE AND MIQUELON', - 'VC' => 'SAINT VINCENT AND THE GRENADINES', - 'WS' => 'SAMOA', - 'SM' => 'SAN MARINO', - 'ST' => 'SAO TOME AND PRINCIPE', - 'SA' => 'SAUDI ARABIA', - 'SN' => 'SENEGAL', - 'RS' => 'SERBIA', - 'SC' => 'SEYCHELLES', - 'SL' => 'SIERRA LEONE', - 'SG' => 'SINGAPORE', - 'SK' => 'SLOVAKIA', - 'SI' => 'SLOVENIA', - 'SB' => 'SOLOMON ISLANDS', - 'SO' => 'SOMALIA', - 'ZA' => 'SOUTH AFRICA', - 'GS' => 'SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS', - 'ES' => 'SPAIN', - 'LK' => 'SRI LANKA', - 'SD' => 'SUDAN', - 'SR' => 'SURINAME', - 'SJ' => 'SVALBARD AND JAN MAYEN', - 'SZ' => 'SWAZILAND', - 'SE' => 'SWEDEN', - 'CH' => 'SWITZERLAND', - 'SY' => 'SYRIAN ARAB REPUBLIC', - 'TW' => 'TAIWAN, PROVINCE OF CHINA', - 'TJ' => 'TAJIKISTAN', - 'TZ' => 'TANZANIA, UNITED REPUBLIC OF', - 'TH' => 'THAILAND', - 'TL' => 'TIMOR-LESTE', - 'TG' => 'TOGO', - 'TK' => 'TOKELAU', - 'TO' => 'TONGA', - 'TT' => 'TRINIDAD AND TOBAGO', - 'TN' => 'TUNISIA', - 'TR' => 'TURKEY', - 'TM' => 'TURKMENISTAN', - 'TC' => 'TURKS AND CAICOS ISLANDS', - 'TV' => 'TUVALU', - 'UG' => 'UGANDA', - 'UA' => 'UKRAINE', - 'AE' => 'UNITED ARAB EMIRATES', - 'GB' => 'UNITED KINGDOM', - 'US' => 'UNITED STATES', - 'UM' => 'UNITED STATES MINOR OUTLYING ISLANDS', - 'UY' => 'URUGUAY', - 'UZ' => 'UZBEKISTAN', - 'VU' => 'VANUATU', - 'VE' => 'VENEZUELA', - 'VN' => 'VIET NAM', - 'VG' => 'VIRGIN ISLANDS, BRITISH', - 'VI' => 'VIRGIN ISLANDS, U.S.', - 'WF' => 'WALLIS AND FUTUNA', - 'EH' => 'WESTERN SAHARA', - 'YE' => 'YEMEN', - 'ZM' => 'ZAMBIA', - 'ZW' => 'ZIMBABWE', - ]; - - $countries['us'] = $countries['en']; - - $countries['fr'] = [ - 'AF' => 'AFGHANISTAN', - 'ZA' => 'AFRIQUE DU SUD', - 'AX' => 'ÅLAND, ÎLES', - 'AL' => 'ALBANIE', - 'DZ' => 'ALGÉRIE', - 'DE' => 'ALLEMAGNE', - 'AD' => 'ANDORRE', - 'AO' => 'ANGOLA', - 'AI' => 'ANGUILLA', - 'AQ' => 'ANTARCTIQUE', - 'AG' => 'ANTIGUA-ET-BARBUDA', - 'AN' => 'ANTILLES NÉERLANDAISES', - 'SA' => 'ARABIE SAOUDITE', - 'AR' => 'ARGENTINE', - 'AM' => 'ARMÉNIE', - 'AW' => 'ARUBA', - 'AU' => 'AUSTRALIE', - 'AT' => 'AUTRICHE', - 'AZ' => 'AZERBAÏDJAN', - 'BS' => 'BAHAMAS', - 'BH' => 'BAHREÏN', - 'BD' => 'BANGLADESH', - 'BB' => 'BARBADE', - 'BY' => 'BÉLARUS', - 'BE' => 'BELGIQUE', - 'BZ' => 'BELIZE', - 'BJ' => 'BÉNIN', - 'BM' => 'BERMUDES', - 'BT' => 'BHOUTAN', - 'BO' => 'BOLIVIE', - 'BA' => 'BOSNIE-HERZÉGOVINE', - 'BW' => 'BOTSWANA', - 'BV' => 'BOUVET, ÎLE', - 'BR' => 'BRÉSIL', - 'BN' => 'BRUNÉI DARUSSALAM', - 'BG' => 'BULGARIE', - 'BF' => 'BURKINA FASO', - 'BI' => 'BURUNDI', - 'KY' => 'CAÏMANES, ÎLES', - 'KH' => 'CAMBODGE', - 'CM' => 'CAMEROUN', - 'CA' => 'CANADA', - 'CV' => 'CAP-VERT', - 'CF' => 'CENTRAFRICAINE, RÉPUBLIQUE', - 'CL' => 'CHILI', - 'CN' => 'CHINE', - 'CX' => 'CHRISTMAS, ÎLE', - 'CY' => 'CHYPRE', - 'CC' => 'COCOS (KEELING), ÎLES', - 'CO' => 'COLOMBIE', - 'KM' => 'COMORES', - 'CG' => 'CONGO', - 'CD' => 'CONGO, LA RÉPUBLIQUE DÉMOCRATIQUE DU', - 'CK' => 'COOK, ÎLES', - 'KR' => 'CORÉE, RÉPUBLIQUE DE', - 'KP' => 'CORÉE, RÉPUBLIQUE POPULAIRE DÉMOCRATIQUE DE', - 'CR' => 'COSTA RICA', - 'CI' => 'CÔTE D\'IVOIRE', - 'HR' => 'CROATIE', - 'CU' => 'CUBA', - 'DK' => 'DANEMARK', - 'DJ' => 'DJIBOUTI', - 'DO' => 'DOMINICAINE, RÉPUBLIQUE', - 'DM' => 'DOMINIQUE', - 'EG' => 'ÉGYPTE', - 'SV' => 'EL SALVADOR', - 'AE' => 'ÉMIRATS ARABES UNIS', - 'EC' => 'ÉQUATEUR', - 'ER' => 'ÉRYTHRÉE', - 'ES' => 'ESPAGNE', - 'EE' => 'ESTONIE', - 'US' => 'ÉTATS-UNIS', - 'ET' => 'ÉTHIOPIE', - 'FK' => 'FALKLAND, ÎLES (MALVINAS)', - 'FO' => 'FÉROÉ, ÎLES', - 'FJ' => 'FIDJI', - 'FI' => 'FINLANDE', - 'FR' => 'FRANCE', - 'GA' => 'GABON', - 'GM' => 'GAMBIE', - 'GE' => 'GÉORGIE', - 'GS' => 'GÉORGIE DU SUD ET LES ÎLES SANDWICH DU SUD', - 'GH' => 'GHANA', - 'GI' => 'GIBRALTAR', - 'GR' => 'GRÈCE', - 'GD' => 'GRENADE', - 'GL' => 'GROENLAND', - 'GP' => 'GUADELOUPE', - 'GU' => 'GUAM', - 'GT' => 'GUATEMALA', - 'GG' => 'GUERNESEY', - 'GN' => 'GUINÉE', - 'GW' => 'GUINÉE-BISSAU', - 'GQ' => 'GUINÉE ÉQUATORIALE', - 'GY' => 'GUYANA', - 'GF' => 'GUYANE FRANÇAISE', - 'HT' => 'HAÏTI', - 'HM' => 'HEARD, ÎLE ET MCDONALD, ÎLES', - 'HN' => 'HONDURAS', - 'HK' => 'HONG-KONG', - 'HU' => 'HONGRIE', - 'IM' => 'ÎLE DE MAN', - 'UM' => 'ÎLES MINEURES ÉLOIGNÉES DES ÉTATS-UNIS', - 'VG' => 'ÎLES VIERGES BRITANNIQUES', - 'VI' => 'ÎLES VIERGES DES ÉTATS-UNIS', - 'IN' => 'INDE', - 'ID' => 'INDONÉSIE', - 'IR' => 'IRAN, RÉPUBLIQUE ISLAMIQUE D\'', - 'IQ' => 'IRAQ', - 'IE' => 'IRLANDE', - 'IS' => 'ISLANDE', - 'IL' => 'ISRAËL', - 'IT' => 'ITALIE', - 'JM' => 'JAMAÏQUE', - 'JP' => 'JAPON', - 'JE' => 'JERSEY', - 'JO' => 'JORDANIE', - 'KZ' => 'KAZAKHSTAN', - 'KE' => 'KENYA', - 'KG' => 'KIRGHIZISTAN', - 'KI' => 'KIRIBATI', - 'KW' => 'KOWEÏT', - 'LA' => 'LAO, RÉPUBLIQUE DÉMOCRATIQUE POPULAIRE', - 'LS' => 'LESOTHO', - 'LV' => 'LETTONIE', - 'LB' => 'LIBAN', - 'LR' => 'LIBÉRIA', - 'LY' => 'LIBYENNE, JAMAHIRIYA ARABE', - 'LI' => 'LIECHTENSTEIN', - 'LT' => 'LITUANIE', - 'LU' => 'LUXEMBOURG', - 'MO' => 'MACAO', - 'MK' => 'MACÉDOINE, L\'EX-RÉPUBLIQUE YOUGOSLAVE DE', - 'MG' => 'MADAGASCAR', - 'MY' => 'MALAISIE', - 'MW' => 'MALAWI', - 'MV' => 'MALDIVES', - 'ML' => 'MALI', - 'MT' => 'MALTE', - 'MP' => 'MARIANNES DU NORD, ÎLES', - 'MA' => 'MAROC', - 'MH' => 'MARSHALL, ÎLES', - 'MQ' => 'MARTINIQUE', - 'MU' => 'MAURICE', - 'MR' => 'MAURITANIE', - 'YT' => 'MAYOTTE', - 'MX' => 'MEXIQUE', - 'FM' => 'MICRONÉSIE, ÉTATS FÉDÉRÉS DE', - 'MD' => 'MOLDOVA, RÉPUBLIQUE DE', - 'MC' => 'MONACO', - 'MN' => 'MONGOLIE', - 'ME' => 'MONTÉNÉGRO', - 'MS' => 'MONTSERRAT', - 'MZ' => 'MOZAMBIQUE', - 'MM' => 'MYANMAR', - 'NA' => 'NAMIBIE', - 'NR' => 'NAURU', - 'NP' => 'NÉPAL', - 'NI' => 'NICARAGUA', - 'NE' => 'NIGER', - 'NG' => 'NIGÉRIA', - 'NU' => 'NIUÉ', - 'NF' => 'NORFOLK, ÎLE', - 'NO' => 'NORVÈGE', - 'NC' => 'NOUVELLE-CALÉDONIE', - 'NZ' => 'NOUVELLE-ZÉLANDE', - 'IO' => 'OCÉAN INDIEN, TERRITOIRE BRITANNIQUE DE L\'', - 'OM' => 'OMAN', - 'UG' => 'OUGANDA', - 'UZ' => 'OUZBÉKISTAN', - 'PK' => 'PAKISTAN', - 'PW' => 'PALAOS', - 'PS' => 'PALESTINIEN OCCUPÉ, TERRITOIRE', - 'PA' => 'PANAMA', - 'PG' => 'PAPOUASIE-NOUVELLE-GUINÉE', - 'PY' => 'PARAGUAY', - 'NL' => 'PAYS-BAS', - 'PE' => 'PÉROU', - 'PH' => 'PHILIPPINES', - 'PN' => 'PITCAIRN', - 'PL' => 'POLOGNE', - 'PF' => 'POLYNÉSIE FRANÇAISE', - 'PR' => 'PORTO RICO', - 'PT' => 'PORTUGAL', - 'QA' => 'QATAR', - 'RE' => 'RÉUNION', - 'RO' => 'ROUMANIE', - 'GB' => 'ROYAUME-UNI', - 'RU' => 'RUSSIE, FÉDÉRATION DE', - 'RW' => 'RWANDA', - 'EH' => 'SAHARA OCCIDENTAL', - 'BL' => 'SAINT-BARTHÉLEMY', - 'SH' => 'SAINTE-HÉLÈNE', - 'LC' => 'SAINTE-LUCIE', - 'KN' => 'SAINT-KITTS-ET-NEVIS', - 'SM' => 'SAINT-MARIN', - 'MF' => 'SAINT-MARTIN', - 'PM' => 'SAINT-PIERRE-ET-MIQUELON', - 'VA' => 'SAINT-SIÈGE (ÉTAT DE LA CITÉ DU VATICAN)', - 'VC' => 'SAINT-VINCENT-ET-LES GRENADINES', - 'SB' => 'SALOMON, ÎLES', - 'WS' => 'SAMOA', - 'AS' => 'SAMOA AMÉRICAINES', - 'ST' => 'SAO TOMÉ-ET-PRINCIPE', - 'SN' => 'SÉNÉGAL', - 'RS' => 'SERBIE', - 'SC' => 'SEYCHELLES', - 'SL' => 'SIERRA LEONE', - 'SG' => 'SINGAPOUR', - 'SK' => 'SLOVAQUIE', - 'SI' => 'SLOVÉNIE', - 'SO' => 'SOMALIE', - 'SD' => 'SOUDAN', - 'LK' => 'SRI LANKA', - 'SE' => 'SUÈDE', - 'CH' => 'SUISSE', - 'SR' => 'SURINAME', - 'SJ' => 'SVALBARD ET ÎLE JAN MAYEN', - 'SZ' => 'SWAZILAND', - 'SY' => 'SYRIENNE, RÉPUBLIQUE ARABE', - 'TJ' => 'TADJIKISTAN', - 'TW' => 'TAÏWAN, PROVINCE DE CHINE', - 'TZ' => 'TANZANIE, RÉPUBLIQUE-UNIE DE', - 'TD' => 'TCHAD', - 'CZ' => 'TCHÈQUE, RÉPUBLIQUE', - 'TF' => 'TERRES AUSTRALES FRANÇAISES', - 'TH' => 'THAÏLANDE', - 'TL' => 'TIMOR-LESTE', - 'TG' => 'TOGO', - 'TK' => 'TOKELAU', - 'TO' => 'TONGA', - 'TT' => 'TRINITÉ-ET-TOBAGO', - 'TN' => 'TUNISIE', - 'TM' => 'TURKMÉNISTAN', - 'TC' => 'TURKS ET CAÏQUES, ÎLES', - 'TR' => 'TURQUIE', - 'TV' => 'TUVALU', - 'UA' => 'UKRAINE', - 'UY' => 'URUGUAY', - 'VU' => 'VANUATU', - 'VE' => 'VENEZUELA', - 'VN' => 'VIET NAM', - 'WF' => 'WALLIS ET FUTUNA', - 'YE' => 'YÉMEN', - 'ZM' => 'ZAMBIE', - 'ZW' => 'ZIMBABWE' - ]; - if ( ! isset($countries[$lng])) - $lng = 'us'; - foreach ($countries[$lng] as $k => $country) - $countries[$lng][$k] = mb_strtolower($country); - - return $countries[$lng]; -} diff --git a/lib/classes/record/exportElement.php b/lib/classes/record/exportElement.php index d4d8e8903b..eee4b434dd 100644 --- a/lib/classes/record/exportElement.php +++ b/lib/classes/record/exportElement.php @@ -116,7 +116,7 @@ class record_exportElement extends record_adapter $go_dl['preview'] = true; } - $query = new User_Query($this->app); + $query = $this->app['phraseanet.user-query']; $masters = $query->on_base_ids([$this->base_id]) ->who_have_right(['order_master']) diff --git a/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php b/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php index a773dbe8db..1f96950351 100644 --- a/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php +++ b/tests/Alchemy/Tests/Phrasea/Controller/Prod/OrderTest.php @@ -3,6 +3,7 @@ namespace Alchemy\Tests\Phrasea\Controller\Prod; use Alchemy\Phrasea\Core\PhraseaEvents; +use Doctrine\Common\Collections\ArrayCollection; use Symfony\Component\EventDispatcher\Event; use Alchemy\Phrasea\Model\Entities\Order; use Alchemy\Phrasea\Model\Entities\OrderElement; @@ -22,6 +23,12 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase */ public function testCreateOrder() { + self::$DI['app']['phraseanet.user-query'] = $this->getMockBuilder('\User_Query')->disableOriginalConstructor()->getMock(); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('get_results')->will($this->returnValue(new ArrayCollection([self::$DI['user_alt2']]))); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('on_base_ids')->will($this->returnSelf()); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('who_have_right')->will($this->returnSelf()); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('execute')->will($this->returnSelf()); + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') ->disableOriginalConstructor() ->getMock(); @@ -47,6 +54,13 @@ class OrderTest extends \PhraseanetAuthenticatedWebTestCase */ public function testCreateOrderJson() { + self::$DI['app']['phraseanet.user-query'] = $this->getMockBuilder('\User_Query')->disableOriginalConstructor()->getMock(); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('get_results')->will($this->returnValue(new ArrayCollection([self::$DI['user_alt2']]))); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('on_base_ids')->will($this->returnSelf()); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('who_have_right')->will($this->returnSelf()); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('execute')->will($this->returnSelf()); + + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') ->disableOriginalConstructor() ->getMock(); diff --git a/tests/classes/record/adapterTest.php b/tests/classes/record/adapterTest.php index 382583fb9c..d389975ec2 100644 --- a/tests/classes/record/adapterTest.php +++ b/tests/classes/record/adapterTest.php @@ -3,6 +3,7 @@ use Rhumsaa\Uuid\Uuid; use Alchemy\Phrasea\Core\PhraseaEvents; use Symfony\Component\EventDispatcher\Event; +use Doctrine\Common\Collections\ArrayCollection; class record_adapterTest extends \PhraseanetAuthenticatedTestCase { @@ -67,6 +68,12 @@ class record_adapterTest extends \PhraseanetAuthenticatedTestCase self::$DI['app']['acl'] = $aclProvider; + self::$DI['app']['phraseanet.user-query'] = $this->getMockBuilder('\User_Query')->disableOriginalConstructor()->getMock(); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('get_results')->will($this->returnValue(new ArrayCollection([self::$DI['user_alt2']]))); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('on_base_ids')->will($this->returnSelf()); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('who_have_right')->will($this->returnSelf()); + self::$DI['app']['phraseanet.user-query']->expects($this->any())->method('execute')->will($this->returnSelf()); + self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\Phrasea\Notification\Deliverer') ->disableOriginalConstructor() ->getMock();