diff --git a/lib/Alchemy/Phrasea/Application/Lightbox.php b/lib/Alchemy/Phrasea/Application/Lightbox.php index db7dbbfb8e..858a74c5f3 100644 --- a/lib/Alchemy/Phrasea/Application/Lightbox.php +++ b/lib/Alchemy/Phrasea/Application/Lightbox.php @@ -74,7 +74,14 @@ return call_user_func( $twig = new supertwig(); $twig->addFilter(array('nl2br' => 'nl2br')); - $basket_element = basket_element_adapter::getInstance($sselcont_id); + + $em = $app['Core']->getEntityManager(); + + /* @var $repository \Repositories\BasketElementRepository */ + $repository = $em->getRepository('\Entities\BasketElement'); + + $basket_element = $repository->findUserElement($sselcont_id, $app['Core']->getAuthenticatedUser()); + $template = '/lightbox/note_form.twig'; $output = $twig->render($template, array('basket_element' => $basket_element, 'module_name' => '')); @@ -89,13 +96,18 @@ return call_user_func( $browser = Browser::getInstance(); + $em = $app['Core']->getEntityManager(); + + /* @var $repository \Repositories\BasketElementRepository */ + $repository = $em->getRepository('\Entities\BasketElement'); + + $BasketElement = $repository->findUserElement($sselcont_id, $app['Core']->getAuthenticatedUser()); + if ($browser->isMobile()) { - $basket_element = basket_element_adapter::getInstance($sselcont_id); - $output = $twig->render('lightbox/basket_element.twig', array( - 'basket_element' => $basket_element, - 'module_name' => $basket_element->get_record()->get_title() + 'basket_element' => $BasketElement, + 'module_name' => $BasketElement->get_record()->get_title() ) ); @@ -119,17 +131,6 @@ return call_user_func( $usr_id = $appbox->get_session()->get_usr_id(); - $em = $app['Core']->getEntityManager(); - - $repository = $em->getRepository('\Entities\BasketElement'); - /* @var $repository \Repositories\BasketElementRepository */ - - $BasketElement = $repository->findUserElement( - $sselcont_id - , $app['Core']->getAuthenticatedUser() - ); - - $Basket = $BasketElement->getBasket(); $ret = array(); @@ -224,11 +225,6 @@ return call_user_func( , $app['Core']->getAuthenticatedUser() ); - if ($basket->is_valid()) - { - $basket->get_first_element()->load_users_infos(); - } - $twig = new supertwig(); $twig->addFilter(array('nl2br' => 'nl2br')); @@ -241,7 +237,7 @@ return call_user_func( $response = new Response($twig->render($template, array( 'baskets_collection' => $basket_collection, 'basket' => $basket, - 'local_title' => strip_tags($basket->get_name()), + 'local_title' => strip_tags($basket->getName()), 'module' => 'lightbox', 'module_name' => _('admin::monitor: module validation') ) @@ -284,7 +280,7 @@ return call_user_func( $response = new Response($twig->render($template, array( 'baskets_collection' => $basket_collection, 'basket' => $basket, - 'local_title' => strip_tags($basket->get_name()), + 'local_title' => strip_tags($basket->getName()), 'module' => 'lightbox', 'module_name' => _('admin::monitor: module validation') ) @@ -358,36 +354,38 @@ return call_user_func( $app->post('/ajax/SET_NOTE/{sselcont_id}/', function (Silex\Application $app, $sselcont_id) { $output = array('error' => true, 'datas' => _('Erreur lors de l\'enregistrement des donnees')); - try + + $request = $app['request']; + $note = $request->get('note'); + + $em = $app['Core']->getEntityManager(); + + /* @var $repository \Repositories\BasketElementRepository */ + $repository = $em->getRepository('\Entities\BasketElement'); + + $basket_element = $repository->findUserElement($sselcont_id, $app['Core']->getAuthenticatedUser()); + + + $basket_element->getUserValidationDatas($app['Core']->getAuthenticatedUser()) + ->setNote($note); + $twig = new supertwig(); + $twig->addFilter(array('nl2br' => 'nl2br')); + + $browser = Browser::getInstance(); + + if ($browser->isMobile()) { - $request = $app['request']; - $note = $request->get('note'); + $datas = $twig->render('lightbox/sc_note.twig', array('basket_element' => $basket_element)); - $basket_element = basket_element_adapter::getInstance($sselcont_id); - $basket_element->set_note($note); - $twig = new supertwig(); - $twig->addFilter(array('nl2br' => 'nl2br')); - - $browser = Browser::getInstance(); - - if ($browser->isMobile()) - { - $datas = $twig->render('lightbox/sc_note.twig', array('basket_element' => $basket_element)); - - $output = array('error' => false, 'datas' => $datas); - } - else - { - $template = 'lightbox/sc_note.twig'; - - $datas = $twig->render($template, array('basket_element' => $basket_element)); - - $output = array('error' => false, 'datas' => $datas); - } + $output = array('error' => false, 'datas' => $datas); } - catch (Exception $e) + else { - return new Response('Bad Request : ' . $e->getMessage() . $e->getFile() . $e->getLine(), 400); + $template = 'lightbox/sc_note.twig'; + + $datas = $twig->render($template, array('basket_element' => $basket_element)); + + $output = array('error' => false, 'datas' => $datas); } $output = p4string::jsonencode($output); diff --git a/lib/Alchemy/Phrasea/Application/Overview.php b/lib/Alchemy/Phrasea/Application/Overview.php index 33b3202bf9..aa39d2ca6b 100644 --- a/lib/Alchemy/Phrasea/Application/Overview.php +++ b/lib/Alchemy/Phrasea/Application/Overview.php @@ -114,11 +114,18 @@ return call_user_func( if ($watermark) { - if (basket_element_adapter::is_in_validation_session($record, $user)) + + $em = $app['Core']->getEntityManager(); + + $repository = $em->getRepository('\Entities\BasketElement'); + + /* @var $repository \Repositories\BasketElementRepository */ + + if ($repository->findReceivedValidationElementsByRecord($record, $user)->count() > 0) { $watermark = false; } - elseif (basket_element_adapter::has_been_received($record, $user)) + elseif ($repository->findReceivedElementsByRecord($record, $user)->count() > 0) { $watermark = false; } @@ -161,14 +168,20 @@ return call_user_func( if ($watermark) { - if (basket_element_adapter::is_in_validation_session($record, $user)) + + $em = $app['Core']->getEntityManager(); + + $repository = $em->getRepository('\Entities\BasketElement'); + + if ($repository->findReceivedValidationElementsByRecord($record, $user)->count() > 0) { $watermark = false; } - elseif (basket_element_adapter::has_been_received($record, $user)) + elseif ($repository->findReceivedElementsByRecord($record, $user)->count() > 0) { $watermark = false; } + } return $deliver_content($session, $record, $subdef, $watermark, $stamp, $app); diff --git a/lib/Alchemy/Phrasea/Controller/Prod/Root.php b/lib/Alchemy/Phrasea/Controller/Prod/Root.php index 9d95ecad32..8635966190 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/Root.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/Root.php @@ -119,7 +119,6 @@ class Root implements ControllerProviderInterface 'GV_defaultQuery_type' => $registry->get('GV_defaultQuery_type'), 'GV_multiAndReport' => $registry->get('GV_multiAndReport'), 'GV_thesaurus' => $registry->get('GV_thesaurus'), -// 'basket_collection' => new \basketCollection($appbox, $user->get_id(), $srt), 'cgus_agreement' => \databox_cgu::askAgreement(), 'css' => $css, 'feeds' => $feeds, diff --git a/lib/Alchemy/Phrasea/Helper/Record/Helper.php b/lib/Alchemy/Phrasea/Helper/Record/Helper.php index 3616f8592b..a3254b6e67 100644 --- a/lib/Alchemy/Phrasea/Helper/Record/Helper.php +++ b/lib/Alchemy/Phrasea/Helper/Record/Helper.php @@ -106,6 +106,9 @@ class Helper extends \Alchemy\Phrasea\Helper\Helper parent::__construct($core); $this->selection = new \set_selection(); + + $request = $core->getRequest(); + $appbox = \appbox::get_instance(); $usr_id = $appbox->get_session()->get_usr_id(); diff --git a/lib/Doctrine/Repositories/BasketElementRepository.php b/lib/Doctrine/Repositories/BasketElementRepository.php index d52614f9dc..d3346b6b2d 100644 --- a/lib/Doctrine/Repositories/BasketElementRepository.php +++ b/lib/Doctrine/Repositories/BasketElementRepository.php @@ -46,6 +46,52 @@ class BasketElementRepository extends EntityRepository return $query->getResult(); } + /** + * + * @param \record_adapter $record + * @param \User_Adapter $user + * @return \Doctrine\Common\Collections\ArrayCollection + */ + public function findReceivedElementsByRecord(\record_adapter $record, \User_Adapter $user) + { + $dql = 'SELECT e FROM Entities\BasketElement e + JOIN e.basket b + WHERE b.usr_id = :usr_id AND b.pusher_id IS NOT NULL + AND e.record_id = :record_id AND e.sbas_id = :sbas_id'; + + $params = array( + 'sbas_id' => $record->get_sbas_id(), + 'record_id' => $record->get_record_id(), + 'usr_id' => $user->get_id() + ); + + $query = $this->_em->createQuery($dql); + $query->setParameters($params); + + return $query->getResult(); + } + + public function findReceivedValidationElementsByRecord(\record_adapter $record, \User_Adapter $user) + { + $dql = 'SELECT e FROM Entities\BasketElement e + JOIN e.basket b + JOIN b.validation v + JOIN v.participants p + WHERE p.usr_id = :usr_id + AND e.record_id = :record_id AND e.sbas_id = :sbas_id'; + + $params = array( + 'sbas_id' => $record->get_sbas_id(), + 'record_id' => $record->get_record_id(), + 'usr_id' => $user->get_id() + ); + + $query = $this->_em->createQuery($dql); + $query->setParameters($params); + + return $query->getResult(); + } + /** * * @param type $element_id diff --git a/lib/Doctrine/Repositories/BasketRepository.php b/lib/Doctrine/Repositories/BasketRepository.php index 0bc3abb163..6e819836b4 100644 --- a/lib/Doctrine/Repositories/BasketRepository.php +++ b/lib/Doctrine/Repositories/BasketRepository.php @@ -38,6 +38,24 @@ class BasketRepository extends EntityRepository return $query->getResult(); } + + /** + * Returns all unread basket for a given user that are not marked as archived + * + * @param \User_Adapter $user + * @return \Doctrine\Common\Collections\ArrayCollection + */ + public function findUnreadActiveByUser(\User_Adapter $user) + { + $dql = 'SELECT b FROM Entities\Basket b + WHERE b.usr_id = :usr_id + AND b.archived = false AND b.is_read = false'; + + $query = $this->_em->createQuery($dql); + $query->setParameters(array('usr_id' => $user->get_id())); + + return $query->getResult(); + } /** * Returns all baskets that are in validation session not expired and @@ -95,8 +113,7 @@ class BasketRepository extends EntityRepository WHERE e.record_id = :record_id AND e.sbas_id = e.sbas_id'; $params = array( - 'record_id' => $record->get_record_id(), - 'sbas_id' => $record->get_sbas_id() + 'record_id' => $record->get_record_id() ); $query = $this->_em->createQuery($dql); diff --git a/lib/classes/API/V1/adapter.class.php b/lib/classes/API/V1/adapter.class.php index fe09fe2e3e..e9ddcfd36c 100644 --- a/lib/classes/API/V1/adapter.class.php +++ b/lib/classes/API/V1/adapter.class.php @@ -585,16 +585,16 @@ class API_V1_adapter extends API_V1_Abstract */ protected function list_baskets($usr_id) { - $basket_coll = new basketCollection($this->appbox, $usr_id); - + $em = $this->core->getEntityManager(); + $repo = $em->getRepository('\Entities\Basket'); + /* @var $repo \Repositories\BasketRepository */ + + $baskets = $repo->findActiveByUser($this->core->getAuthenticatedUser()); + $ret = array(); - foreach ($basket_coll->get_baskets() as $basktype => $baskets) + foreach ($baskets as $basket) { - if (!in_array($basktype, array('recept', 'baskets'))) - continue; - - foreach ($baskets as $basket) - $ret[$basket->get_ssel_id()] = $this->list_basket($basket); + $ret[$basket->getId()] = $this->list_basket($basket); } return $ret; diff --git a/lib/classes/basket/adapter.class.php b/lib/classes/basket/adapter.class.php deleted file mode 100644 index 28ad40b060..0000000000 --- a/lib/classes/basket/adapter.class.php +++ /dev/null @@ -1,1877 +0,0 @@ -base_id; - } - - /** - * - * @return User_Adapter - */ - public function get_pusher() - { - return $this->pusher; - } - - /** - * - * @return DateTime - */ - public function get_create_date() - { - return $this->created_on; - } - - /** - * - * @return DateTime - */ - public function get_update_date() - { - return $this->updated_on; - } - - /** - * - * @return int - */ - public function get_record_id() - { - return $this->record_id; - } - - /** - * - * @return boolean - */ - public function is_mine() - { - return $this->is_mine; - } - - /** - * - * @return boolean - */ - public function is_grouping() - { - return $this->is_grouping; - } - - /** - * - * @return string - */ - public function get_name() - { - return $this->name; - } - - /** - * - * @return string - */ - public function get_description() - { - return $this->desc; - } - - /** - * - * @return int - */ - public function get_ssel_id() - { - return $this->ssel_id; - } - - /** - * - * @return array - */ - public function get_validating_users() - { - return $this->validating_users; - } - - /** - * - * @return basket_element_adapter - */ - public function get_elements() - { - if (!$this->elements) - $this->load_elements(); - - return $this->elements; - } - - /** - * - * @return int - */ - public function get_sbas_id() - { - return $this->sbas_id; - } - - /** - * - * @return boolean - */ - public function is_valid() - { - return in_array($this->valid, array('valid', 'myvalid')); - } - - /** - * - * @return boolean - */ - public function is_my_valid() - { - return $this->valid == 'myvalid'; - } - - /** - * - * @return boolean - */ - public function is_unread() - { - return $this->noview; - } - - /** - * - * @return basket_element_adapter - */ - public function get_first_element() - { - foreach ($this->get_elements() as $basket_element) - - return $basket_element; - return null; - } - - /** - * - * @return DateTime - */ - public function get_validation_end_date() - { - if (!$this->valid || !$this->validation_end_date) - - return null; - return $this->validation_end_date; - } - - /** - * - * @return boolean - */ - public function is_validation_finished() - { - if (!$this->valid || !$this->validation_end_date) - - return null; - $now = new DateTime(); - - return ($now > $this->validation_end_date); - } - - /** - * - * @return boolean - */ - public function is_confirmed() - { - if (!$this->valid) - - return null; - - return $this->validation_is_confirmed; - } - - public function is_releasable() - { - if (!$this->valid) - - return false; - - if ($this->is_confirmed()) - - return false; - - foreach($this->get_elements() as $element) - { - if($element->get_my_agreement() == '0') - - return false; - } - - return true; - } - - /** - * - * @param const $option - * @return string - */ - public function get_cache_key($option = null) - { - return 'basket_' . $this->usr_id . '_' . $this->ssel_id . ($option ? '_' . $option : ''); - } - - /** - * - * @param $option - * @return - */ - public function get_data_from_cache($option = null) - { - return $this->appbox->get_data_from_cache($this->get_cache_key($option)); - } - - /** - * - * @param $value - * @param $option - * @param $duration - * @return - */ - public function set_data_to_cache($value, $option = null, $duration = 0) - { - return $this->appbox->set_data_to_cache($value, $this->get_cache_key($option), $duration); - } - - /** - * - * @param $option - * @return - */ - public function delete_data_from_cache($option = null) - { - if ($option === self::CACHE_ELEMENTS) - $this->elements = null; - - return $this->appbox->delete_data_from_cache($this->get_cache_key($option)); - } - - /** - * - * @param appbox $appbox - * @param int $ssel_id - * @param int $usr_id - * @return basket_adapter - */ - protected function __construct(appbox &$appbox, $ssel_id, $usr_id) - { - $this->instance_key = 'basket_' . $usr_id . '_' . $ssel_id; - $this->appbox = $appbox; - $this->ssel_id = (int) $ssel_id; - $this->usr_id = $usr_id; - - $this->load(); - - if ($this->valid) - $this->load_validation_users(); - - return $this; - } - - protected function load() - { - - try - { - $datas = $this->get_data_from_cache(); - - $this->sbas_id = $datas['sbas_id']; - $this->record_id = $datas['record_id']; - $this->is_grouping = $datas['is_grouping']; - $this->pusher = $datas['pusher_id'] ? User_Adapter::getInstance($datas['pusher_id'], $this->appbox) : null; - $this->validation_is_confirmed = $datas['validation_is_confirmed']; - $this->validation_end_date = $datas['validation_end_date']; - $this->validation_see_others = $datas['validation_see_others']; - $this->valid = $datas['valid']; - $this->is_mine = $datas['is_mine']; - $this->noview = $datas['noview']; - $this->updated_on = $datas['updated_on']; - $this->created_on = $datas['created_on']; - $this->name = $datas['name']; - $this->desc = $datas['desc']; - - return $this; - } - catch (Exception $e) - { - - } - - $sql = 'SELECT s.pushFrom, n.id as noview, s.usr_id as owner, s.rid - , s.sbas_id, s.temporaryType, s.name, s.descript, s.pushFrom - , s.date, s.updater - , v.id as validate_id, v.can_see_others, v.expires_on, v.confirmed - FROM ssel s - LEFT JOIN validate v - ON (s.ssel_id = v.ssel_id AND v.usr_id = :validate_usr_id) - LEFT JOIN sselnew n - ON (n.usr_id = :receive_usr_id AND n.ssel_id = s.ssel_id) - WHERE s.ssel_id = :ssel_id - AND (s.usr_id = :usr_id OR v.id IS NOT NULL)'; - - $params = array( - ':usr_id' => $this->usr_id, - ':receive_usr_id' => $this->usr_id, - ':validate_usr_id' => $this->usr_id, - ':ssel_id' => $this->ssel_id - ); - - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute($params); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if (!$row) - throw new Exception_Basket_NotFound(); - - $this->name = $row['name']; - $this->desc = $row['descript']; - $this->created_on = new DateTime($row['date']); - $this->updated_on = new DateTime($row['updater']); - $this->usr_id = (int) $row['owner']; - $this->noview = !!$row['noview']; - - $this->is_mine = ($row['owner'] == $this->usr_id); - - if ($row['validate_id'] != null) - { - $this->valid = 'valid'; - if ($this->is_mine) - { - $this->valid = 'myvalid'; - $this->validation_see_others = true; - } - elseif ($row['can_see_others'] == '1') - { - $this->validation_see_others = true; - } - $this->validation_end_date = $row['expires_on'] ? new DateTime($row['expires_on']) : null; - $this->validation_is_confirmed = !!$row['confirmed']; - - $this->load_validation_users(); - } - - - if ((int) $row['pushFrom'] > 0) - { - try - { - $this->pusher = User_Adapter::getInstance($row['pushFrom'], $this->appbox); - } - catch (Exception $e) - { - - } - } - - $this->is_grouping = ($row['temporaryType'] == 1); - if ($this->is_grouping) - { - $this->record_id = $row['rid']; - $this->sbas_id = $row['sbas_id']; - } - - $pusher_id = $this->pusher instanceof User_Adapter ? $this->pusher->get_id() : null; - - $datas = array( - 'sbas_id' => $this->sbas_id - , 'record_id' => $this->record_id - , 'is_grouping' => $this->is_grouping - , 'pusher_id' => $pusher_id - , 'validation_is_confirmed' => $this->validation_is_confirmed - , 'validation_end_date' => $this->validation_end_date - , 'validation_see_others' => $this->validation_see_others - , 'valid' => $this->valid - , 'is_mine' => $this->is_mine - , 'noview' => $this->noview - , 'updated_on' => $this->updated_on - , 'created_on' => $this->created_on - , 'name' => $this->name - , 'desc' => $this->desc - ); - - $this->set_data_to_cache($datas); - - return $this; - } - - /** - * - * @param $order - * @return basket_adapter - */ - public function sort($order) - { - if (!$this->valid || !in_array($order, array('asc', 'desc'))) - - return; - - $this->load_elements(); - - if ($order == 'asc') - uasort($this->elements, array('basket_adapter', 'order_validation_asc')); - else - uasort($this->elements, array('basket_adapter', 'order_validation_desc')); - - return $this; - } - - /** - * - * @todo change this shit - * @param mixed $lst - * @param boolean $fixing - * @return array - */ - public function push_list($lst, $fixing) - { - $ret = array('error' => false, 'datas' => array()); - - if (!is_array($lst)) - $lst = explode(';', $lst); - - foreach ($lst as $basrec) - { - try - { - if (!is_array($basrec)) - $basrec = explode('_', $basrec); - if (count($basrec) != 2) - continue; - $sbas_id = $basrec[0]; - $record = new record_adapter($sbas_id, $basrec[1]); - $push = $this->push_element($record, $this->record_id, $fixing); - unset($record); - if ($push['error']) - $ret['error'] = $push['error']; - else - $ret['datas'] = array_merge($ret['datas'], $push['datas']); - } - catch (Exception_Record_AdapterNotFound $e) - { - - } - catch (Exception $e) - { - $ret['error'] = "an error occured"; - } - } - - return $ret; - } - - /** - * - * @param record_Interface $record - * @param int $parent_record_id - * @param boolean $fixing - * @return array - */ - public function push_element(record_Interface $record, $parent_record_id, $fixing) - { - $base_id = $record->get_base_id(); - $record_id = $record->get_record_id(); - if ($parent_record_id === true && phrasea::sbasFromBas($base_id) != $this->sbas_id) - { - return array( - 'error' => _('panier:: Un reportage ne peux recevoir que des elements provenants de la base ou il est enregistre'), - 'datas' => array() - ); - } - - if ($this->valid && !$this->is_mine) - { - return array('error' => _('Ce panier est en lecture seule'), 'datas' => array()); - } - - try - { - $sselcont_id = basket_element_adapter::create($this, $base_id, $record_id, $parent_record_id, $this->valid, $fixing); - - $this->add_element($sselcont_id); - - $this->delete_data_from_cache(self::CACHE_ELEMENTS); - - $ret['error'] = false; - $ret['datas'] = array($sselcont_id->get_sselcont_id()); - } - catch (Exception $e) - { - $ret['error'] = $e->getMessage(); - $ret['datas'] = array(); - } - - return $ret; - } - - /** - * - * @return string - */ - public function get_excerpt() - { - $ret = ''; - - $i = 0; - - foreach ($this->get_elements() as $basket_element) - { - $i++; - if ($i > 9) - break; - - $thumbnail = $basket_element->get_record()->get_thumbnail(); - - $ratio = $thumbnail->get_width() / $thumbnail->get_height(); - $top = $left = 0; - if ($thumbnail->get_width() > $thumbnail->get_height())//paysage - { - $h = 80; - $w = $h * $ratio; - $left = round((80 - $w) / 2); - } - else - { - $w = 80; - $h = $w / $ratio; - $top = round((80 - $h) / 2); - } - $ret .= '
- -
'; - } - - return $ret; - } - - /** - * - * Return the total HD size of documents inside the basket - * @return - */ - public function get_size() - { - $totSize = 0; - $session = $this->appbox->get_session(); - - foreach ($this->get_elements() as $basket_element) - { - try - { - $sd = $basket_element->get_record()->get_subdef('document'); - $totSize += $sd->get_size(); - } - catch (Exception $e) - { - - } - } - - $totSize = round($totSize / (1024 * 1024), 2); - - return $totSize; - } - - /** - * - * @return - */ - public function getOrderDatas() - { - $out = ''; - $n = 0; - - foreach ($this->get_elements() as $basket_element) - { - $thumbnail = $basket_element->get_record()->get_thumbnail(); - if ($thumbnail->get_width() > $thumbnail->get_height()) - { - $h = (int) (82 * $thumbnail->get_height() / $thumbnail->get_width()); - $w = 82; - } - else - { - $w = (int) (82 * $thumbnail->get_width() / $thumbnail->get_height()); - $h = 82; - } - - $title = $basket_element->get_record()->get_title(); - $record = $basket_element->get_record(); - - $out .= '
' . - '
- ' . $title . '
' . - ''; - $out .= '
- '; - - $out .= ''; - - $out .= ' - - -
'; - $out .= '
'; - - $n++; - } - - return $out . '
- -
'; - } - - /** - * Save re-ordered basket - * @param Json serialized array - * @return Json serialized array - */ - public function saveOrderDatas($value) - { - $conn = connection::getPDOConnection(); - - $conn->beginTransaction(); - - $error = false; - - $value = json_decode($value); - - $rid_parent = (int) $this->record_id; - $ssel_id = (int) $this->ssel_id; - $sbas_id = (int) $this->sbas_id; - - $cacheusers = array(); - $sselcont_equiv = array(); - - - if ($this->is_grouping) - { - $sql = 'SELECT c1.sselcont_id, s.usr_id, s.ssel_id, c2.sselcont_id as equiv FROM sselcont c1, sselcont c2, ssel s - WHERE temporaryType="1" AND s.rid = :record_id AND s.sbas_id = :sbas_id - AND s.ssel_id = c1.ssel_id AND s.ssel_id != :ssel_id_dif AND c1.base_id = c2.base_id - AND c1.record_id = c2.record_id AND c2.ssel_id = :ssel_id'; - - $params = array( - ':record_id' => $this->get_record_id() - , ':sbas_id' => $this->get_sbas_id() - , ':ssel_id_dif' => $this->get_ssel_id() - , ':ssel_id' => $ssel_id - ); - - $stmt = $conn->prepare($sql); - $stmt->execute($params); - $row = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - foreach ($rs as $row) - { - if (!isset($cacheusers[$row['usr_id']])) - $cacheusers[$row['usr_id']] = array(); - - $cacheusers[$row['usr_id']][$row['ssel_id']] = $row['ssel_id']; - - $sselcont_equiv[$row['equiv']][] = $row['sselcont_id']; - } - } - - foreach ($value as $id => $infos) - { - $infos->order = trim($infos->order); - $infos->record_id = (int) $infos->record_id; - $id = trim($id); - - if ($this->is_grouping) - { - try - { - $connbas = connection::getPDOConnection($sbas_id); - - $sql = 'UPDATE regroup SET ord = :ordre - WHERE rid_parent = :record_id_parent - AND rid_child = :record_id'; - - $params = array( - ':ordre' => $infos->order - , ':record_id_parent' => $rid_parent - , ':record_id' => $infos->record_id - ); - - $stmt = $connbas->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - - if (isset($sselcont_equiv[trim($id)])) - { - try - { - $sql = "UPDATE sselcont SET ord = :ordre'' - WHERE sselcont_id IN (" . implode(', ', $sselcont_equiv[$id]) . ")"; - $stmt = $conn->prepare($sql); - $stmt->execute(array(':ordre' => $infos->order)); - $stmt->closeCursor(); - } - catch (Exception $e) - { - - } - } - } - catch (Exception $e) - { - $error = true; - } - } - - try - { - $sql = "UPDATE sselcont SET ord = :ordre - WHERE sselcont_id = :sselcont_id AND ssel_id = :ssel_id"; - - $params = array( - ':ordre' => $infos->order - , ':sselcont_id' => $id - , ':ssel_id' => $ssel_id - ); - $stmt = $conn->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - } - catch (Exception $e) - { - $error = true; - } - } - - foreach ($cacheusers as $usr_id => $ssel_ids) - { - foreach ($ssel_ids as $ssel_id) - { - $basket_usr = self::getInstance($this->appbox, $ssel_id, $usr_id); - $basket_usr->set_unread(); - } - } - - if (!$error) - { - $conn->commit(); - } - else - { - $conn->rollBack(); - } - $this->delete_cache(); - - $ret = array('error' => $error); - - return p4string::jsonencode($ret); - } - - /** - * Delete the basket - * @return boolean - */ - public function delete() - { - $sql = 'DELETE FROM ssel WHERE ssel_id = :ssel_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $this->ssel_id)); - $stmt->closeCursor(); - - $sql = 'DELETE FROM sselcont WHERE ssel_id = :ssel_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $this->ssel_id)); - $stmt->closeCursor(); - - $sql = 'DELETE FROM sselnew WHERE ssel_id = :ssel_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $this->ssel_id)); - $stmt->closeCursor(); - - $this->delete_cache(); - unset(self::$_instance[$this->instance_key]); - - return false; - } - - /** - * Set the basket unread for the user - * @return boolean - */ - public function set_unread($usr_id = null) - { - if (is_null($usr_id)) - $usr_id = $this->usr_id; - - try - { - $sql = 'INSERT INTO sselnew (id, ssel_id, usr_id) - VALUES (null, :ssel_id, :usr_id)'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $this->ssel_id, ':usr_id' => $usr_id)); - $stmt->closeCursor(); - - $this->noview = true; - } - catch (Exception $e) - { - return false; - } - $this->delete_cache(); - - return true; - } - - /** - * Set the basket read for the user - * @return boolean - */ - public function set_read() - { - if (!$this->noview) - - return true; - $session = $this->appbox->get_session(); - - try - { - $sql = 'DELETE FROM sselnew WHERE ssel_id = :ssel_id AND usr_id = :usr_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $this->ssel_id, ':usr_id' => $session->get_usr_id())); - $stmt->closeCursor(); - - $this->noview = false; - } - catch (Exception $e) - { - return false; - } - $this->delete_cache(); - - return true; - } - - /** - * Add users to the validation process - * - * @param Integer $usr_id - * @param boolean $can_agree - * @param boolean $can_see_others - * @param boolean $can_hd - * @param DateTime $expire - */ - public function validation_to_users(User_Adapter $user, $can_agree, $can_see_others, $can_hd, DateTime $expire = null) - { - try - { - $sql = 'REPLACE INTO validate (id, ssel_id, created_on, updated_on, expires_on, - last_reminder, usr_id, confirmed, can_agree, can_see_others) - VALUES - (null, :ssel_id, NOW(), NOW(), :expire, - null, :usr_id, 0, :can_agree, :can_see_others)'; - - $stmt = $this->appbox->get_connection()->prepare($sql); - - $params = array( - ':ssel_id' => $this->ssel_id - , ':expire' => (is_null($expire) ? null : $expire->format(DATE_ISO8601)) - , ':usr_id' => $user->get_id() - , ':can_agree' => ($can_agree ? '1' : '0') - , ':can_see_others' => ($can_see_others ? '1' : '0') - ); - - $stmt->execute($params); - $insert_id = $this->appbox->get_connection()->lastInsertId(); - $stmt->closeCursor(); - - $me = User_Adapter::getInstance($this->appbox->get_session()->get_usr_id(), $this->appbox); - - foreach ($this->get_elements() as $basket_element) - { - $basket_element->validate($me, $user, $insert_id, $can_hd); - } - - $this->valid = 'myvalid'; - - $this->set_unread($user->get_id()); - $this->delete_data_from_cache(self::CACHE_VALIDATING_USERS); - } - catch (Exception $e) - { - return false; - } - - $this->delete_cache(); - - return true; - } - - /** - * - * @return string - */ - public function get_validation_infos() - { - if ($this->is_mine) - { - if ($this->is_validation_finished()) - - return sprintf(_('Vous aviez envoye cette demande a %d utilisateurs'), (count($this->validating_users) - 1)); - else - - return sprintf(_('Vous avez envoye cette demande a %d utilisateurs'), (count($this->validating_users) - 1)); - } - else - { - if ($this->validation_see_others) - - return sprintf(_('Processus de validation recu de %s et concernant %d utilisateurs'), User_Adapter::getInstance($this->usr_id, $this->appbox)->get_display_name(), (count($this->validating_users) - 1)); - else - - return sprintf(_('Processus de validation recu de %s'), User_Adapter::getInstance($this->usr_id, $this->appbox)->get_display_name()); - } - } - - /** - * - * @return basket_adapter - */ - public function set_released() - { - if(!$this->is_valid()) - throw new Exception('Not a validation basket'); - - $Core = bootstrap::getCore(); - $session = $this->appbox->get_session(); - - $sql = 'UPDATE validate SET confirmed="1" - WHERE ssel_id = :ssel_id AND usr_id = :usr_id'; - - $params = array( - ':ssel_id' => $this->get_ssel_id() - , ':usr_id' => $session->get_usr_id() - ); - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - $evt_mngr = eventsmanager_broker::getInstance($this->appbox, $Core); - - $sql = 'SELECT s.usr_id FROM validate v, ssel s - WHERE s.ssel_id = v.ssel_id - AND v.usr_id = :usr_id AND v.ssel_id = :ssel_id'; - - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute($params); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ($row) - { - $to = $row['usr_id']; - $params = array( - 'ssel_id' => $this->ssel_id, - 'from' => $session->get_usr_id(), - 'to' => $to - ); - $evt_mngr->trigger('__VALIDATION_DONE__', $params); - } - - return $this; - } - - /** - * - * @param appbox $appbox - * @param $ssel_id - * @param $usr_id - * @return basket_adapter - */ - public static function getInstance(appbox &$appbox, $ssel_id, $usr_id) - { - $instance_key = 'basket_' . $usr_id . '_' . $ssel_id; - if (!isset(self::$_instance[$instance_key])) - { - self::$_instance[$instance_key] = new self($appbox, $ssel_id, $usr_id); - } - - return array_key_exists($instance_key, self::$_instance) ? self::$_instance[$instance_key] : false; - } - - /** - * @todo ameliorer les tests connbas - * @return basket_adapter - */ - protected function load_elements() - { - if (!is_null($this->elements)) - - return; - - $this->elements = array(); - - $user = User_Adapter::getInstance($this->usr_id, $this->appbox); - - $rs = array(); - - try - { - $rs = $this->get_data_from_cache(self::CACHE_ELEMENTS); - } - catch (Exception $e) - { - - try - { - $sql = 'SELECT sselcont_id FROM sselcont WHERE ssel_id = :ssel_id ORDER BY ord ASC'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $this->ssel_id)); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $this->set_data_to_cache($rs, self::CACHE_ELEMENTS); - $stmt->closeCursor(); - } - catch (Exception $e) - { - - } - } - - foreach ($rs as $row) - { - try - { - $this->add_element(basket_element_adapter::getInstance($row['sselcont_id'])); - } - catch (Exception $e) - { - /** - * @todo - * manage case where record has been deleted and not removed from basket - */ - } - } - - return $this; - } - - public function set_name($name) - { - $sql = 'UPDATE ssel SET name = :name WHERE ssel_id = :ssel_id'; - - $name = trim(strip_tags($name)); - if ($name === '') - throw new Exception_InvalidArgument (); - - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':name' => $name, ':ssel_id' => $this->get_ssel_id())); - $stmt->closeCursor(); - - $this->name = $name; - - $this->delete_data_from_cache(); - - return $this; - } - - public function set_description($desc) - { - - $sql = 'UPDATE ssel SET descript = :description WHERE ssel_id = :ssel_id'; - - $desc = trim(strip_tags($desc)); - - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':description' => $desc, ':ssel_id' => $this->get_ssel_id())); - $stmt->closeCursor(); - - $this->desc = $desc; - - $this->delete_data_from_cache(); - - return $this; - } - - /** - * Add an element to the basket - * - * @param basket_element_adapter $basket_element - * @return basket_adapter - */ - protected function add_element(basket_element_adapter &$basket_element) - { - $this->elements[$basket_element->get_sselcont_id()] = $basket_element; - $this->elements[$basket_element->get_sselcont_id()]->set_order(count($this->elements) + 1); - - return $this; - } - - /** - * - * @param $sselcont_id - * @return - */ - protected function remove_basket_elements($sselcont_id) - { - try - { - $sql = 'DELETE FROM sselcont - WHERE sselcont_id = :sselcont_id AND ssel_id = :ssel_id'; - - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':sselcont_id' => $sselcont_id, ':ssel_id' => $this->ssel_id)); - - $sql = 'DELETE FROM validate_datas WHERE sselcont_id = :sselcont_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':sselcont_id' => $sselcont_id)); - - $this->delete_data_from_cache(self::CACHE_ELEMENTS); - - return array('error' => false, 'status' => 1); - } - catch (Exception $e) - { - - } - - return array('error' => true, 'status' => 0); - } - - /** - * - * @param $sselcont_id - * @return - */ - protected function remove_grouping_elements($sselcont_id) - { - $session = $this->appbox->get_session(); - - $sbas_id = $parent_record_id = $collid = $base_id = $record_id = null; - - $ssel_id = $this->ssel_id; - - try - { - $sql = 'SELECT s.sbas_id, s.ssel_id, s.rid, c.record_id, c.base_id - FROM ssel s, sselcont c - WHERE c.sselcont_id = :sselcont_id - AND c.ssel_id = s.ssel_id AND s.ssel_id = :ssel_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':sselcont_id' => $sselcont_id, ':ssel_id' => $this->ssel_id)); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ($row) - { - $parent_record_id = $row["rid"]; - $base_id = $row['base_id']; - $sbas_id = $row['sbas_id']; - $record_id = $row['record_id']; - } - } - catch (Exception $e) - { - - } - - $ret = array('error' => false, 'status' => 0); - - try - { - $user = User_Adapter::getInstance($session->get_usr_id(), $this->appbox); - - if (!$user->ACL()->has_right_on_base($base_id, 'canmodifrecord')) - throw new Exception('Not enough rights'); - $connbas = connection::getPDOConnection($sbas_id); - - $sql = "DELETE FROM regroup WHERE rid_parent = :parent_record_id - AND rid_child = :record_id"; - $stmt = $connbas->prepare($sql); - $stmt->execute(array(':parent_record_id' => $parent_record_id, ':record_id' => $record_id)); - $stmt->closeCursor(); - - $sql = 'SELECT sselcont_id, s.ssel_id, s.usr_id FROM ssel s, sselcont c - WHERE s.rid = :parent_record_id AND s.sbas_id = :sbas_id - AND temporaryType="1" AND c.ssel_id = s.ssel_id - AND c.base_id = :base_id AND c.record_id = :record_id'; - - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute( - array( - ':parent_record_id' => $parent_record_id - , ':sbas_id' => $sbas_id - , ':base_id' => $base_id - , ':record_id' => $record_id - ) - ); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $first = true; - $good = false; - - foreach ($rs as $row) - { - $sql = 'DELETE FROM sselcont WHERE sselcont_id = :sselcont_id'; - $stmt = $this->appbox->get_connection()->prepare($sql); - if ($first) - $good = true; - $first = false; - try - { - $stmt->execute(array(':sselcont_id' => $row['sselcont_id'])); - - $basket_usr = self::getInstance($this->appbox, $row['ssel_id'], $row['usr_id']); - $basket_usr->set_unread(); - $stmt->closeCursor(); - } - catch (Exception $e) - { - $good = false; - } - } - - if (!$good) - $ret = array('error' => _('panier:: erreur lors de la suppression'), 'status' => 0); - else - $ret = array('error' => false, 'status' => 1); - $this->delete_data_from_cache(self::CACHE_ELEMENTS); - } - catch (Exception $e) - { - - $ret = array( - 'error' => _('phraseanet :: droits insuffisants, vous devez avoir les doits d\'edition sur le regroupement '), - 'status' => 0); - } - - return $ret; - } - - /** - * Flattent a basket - * Remove groupings from the basket and and their contents - * - * @return basket_adapter - */ - public function flatten() - { - foreach ($this->get_elements() as $basket_element) - { - $record = $basket_element->get_record(); - if ($record->is_grouping()) - { - $lst = array(); - foreach ($record->get_children() as $tmp_record) - { - $lst[] = sprintf("%s_%s", $tmp_record->get_base_id(), $tmp_record->get_record_id()); - } - - $this->push_list($lst, true); - $this->remove_from_ssel($basket_element); - } - unset($record); - } - - return $this; - } - - /** - * - * @param $sselcont_id - * @return - */ - public function remove_from_ssel($sselcont_id) - { - if (!$this->is_mine) - - return array('error' => 'error', 'status' => 0); - - if ($this->is_grouping) - - return $this->remove_grouping_elements($sselcont_id); - else - - return $this->remove_basket_elements($sselcont_id); - } - - /** - * - * @return basket_adapter - */ - public function delete_cache() - { - $keys = array(); - - if ($this->is_valid()) - { - foreach ($this->get_validating_users() as $user_data) - { - $keys[] = 'basket_' . $user_data['usr_id'] . '_' . $this->get_ssel_id(); - $keys[] = 'basket_' . $user_data['usr_id'] . '_' . $this->get_ssel_id().'_'.self::CACHE_ELEMENTS; - $keys[] = 'basket_' . $user_data['usr_id'] . '_' . $this->get_ssel_id().'_'.self::CACHE_VALIDATING_USERS; - } - } - - $keys[] = 'basket_' . $this->usr_id . '_' . $this->get_ssel_id(); - $keys[] = 'basket_' . $this->usr_id . '_' . $this->get_ssel_id().'_'.self::CACHE_ELEMENTS; - $keys[] = 'basket_' . $this->usr_id . '_' . $this->get_ssel_id().'_'.self::CACHE_VALIDATING_USERS; - - $this->appbox->delete_data_from_cache($keys); - - return $this; - } - - /** - * - * @param $lst - * @return - */ - public static function fix_grouping($lst) - { - $appbox = appbox::get_instance(); - $session = $appbox->get_session(); - $usr_id = $session->get_usr_id(); - $registry = $appbox->get_registry(); - - $retour = array(); - - if (!is_array($lst)) - $lst = explode(";", $lst); - - foreach ($lst as $basrec) - { - $basrec = explode('_', $basrec); - $record_id = (int) $basrec[1]; - $sbas_id = (int) $basrec[0]; - - $record = new record_adapter($sbas_id, $record_id); - $base_id = $record->get_base_id(); - - $regfield = self::getRegFields($sbas_id, $record->get_caption()); - $connbas = connection::getPDOConnection($sbas_id); - - $sql = 'SELECT moddate FROM record WHERE record_id = :record_id'; - $stmt = $connbas->prepare($sql); - $stmt->execute(array(':record_id' => $record_id)); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $moddate = $row ? $row['moddate'] : ''; - - $sql = 'SELECT ssel_id FROM ssel - WHERE usr_id = :usr_id - AND temporaryType=1 AND rid = :record_id AND sbas_id = :base_id'; - - $params = array( - ':usr_id' => $usr_id - , ':record_id' => $record_id - , ':base_id' => $record->get_sbas_id() - ); - - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute($params); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if (!$row) - { - $sql = 'INSERT INTO ssel (ssel_id, usr_id, date,temporaryType , rid , sbas_id, updater,name,descript ) - VALUES (null, :usr_id, :date, "1" , :record_id ,:sbas_id, :moddate, :name, :desc )'; - - $params = array( - ':usr_id' => $usr_id - , ':date' => $regfield['regdate'] - , ':record_id' => $record_id - , ':sbas_id' => $sbas_id - , ':moddate' => $moddate - , ':name' => $regfield['regname'] - , ':desc' => $regfield['regdesc'] - ); - - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - $id = $appbox->get_connection()->lastInsertId(); - $basket = self::getInstance($appbox, $id, $usr_id); - - $lst = $record->get_children(); - $lst = $lst->serialize_list(); - $basket->push_list($lst, true); - $retour[] = $id; - } - else - { - $retour[] = $row['ssel_id']; - } - } - - return p4string::jsonencode($retour); - } - - /** - * - * @param $sselid - * @return boolean - */ - public static function unfix_grouping($sselid) - { - $appbox = appbox::get_instance(); - $session = $appbox->get_session(); - - try - { - $appbox->get_connection()->beginTransaction(); - $sql = 'DELETE FROM ssel WHERE ssel_id = :ssel_id AND usr_id = :usr_id'; - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $sselid, ':usr_id' => $session->get_usr_id())); - $stmt->closeCursor(); - - $sql = 'DELETE FROM sselcont WHERE ssel_id = :ssel_id'; - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $sselid)); - $stmt->closeCursor(); - $ret = true; - $appbox->get_connection()->commit(); - } - catch (Exception $e) - { - $appbox->get_connection()->rollBack(); - $ret = false; - } - - return $ret; - } - - /** - * - * @param appbox $appbox - * @param $name - * @param User_Interface $user - * @param $desc - * @param User_Adapter $pusher - * @param $base_id - * @return - */ - public static function create(appbox $appbox, $name, User_Interface $user, $desc = '', User_Adapter $pusher=null, $base_id = null) - { - $conn = $appbox->get_connection(); - - $record = false; - - $desc = trim(strip_tags(str_replace('
', "\n", $desc))); - $name = trim(strip_tags($name)); - - - if ($base_id) - { - $databox = $appbox->get_databox(phrasea::sbasFromBas($base_id)); - $meta_struct = $databox->get_meta_structure(); - - try - { - if (!$user->ACL()->has_right_on_base($base_id, 'canaddrecord')) - throw new Exception('No rights'); - - $ret = FALSE; - - $registry = $appbox->get_registry(); - $collection = collection::get_from_base_id($base_id); - - $record = record_adapter::create( - $collection - , new system_file($registry->get('GV_RootPath') . 'www/skins/icons/substitution/regroup_doc.png') - , false - , true - ); - - - $record_id = $record->get_record_id(); - - $metadatas = array(); - - foreach ($meta_struct as $meta) - { - if ($meta->is_regname()) - $value = $name; - elseif ($meta->is_regdesc()) - $value = $desc; - else - continue; - - $metadatas[] = array( - 'meta_struct_id' => $meta->get_id() - , 'meta_id' => null - , 'value' => array($value) - ); - } - - $record->set_metadatas($metadatas) - ->rebuild_subdefs(); - - $ret = true; - } - catch (Exception $e) - { - $ret = false; - } - } - - $sql = 'INSERT INTO ssel (ssel_id, name, descript, usr_id, pushFrom, date, updater, temporaryType, rid, sbas_id) - VALUES (null, :name, :description, :usr_id, :pushFrom, NOW(), NOW(), :temporaryType, :record_id, :sbas_id)'; - - $stmt = $conn->prepare($sql); - - $params = array( - ':name' => $name - , ':usr_id' => $user->get_id() - , ':description' => $desc - , ':pushFrom' => ($pusher instanceof User_Interface ? $pusher->get_id() : '0') - , ':temporaryType' => ($record instanceof record_adapter ? '1' : '0') - , ':record_id' => ($record instanceof record_adapter ? $record->get_record_id() : '0') - , ':sbas_id' => ($record instanceof record_adapter ? $record->get_sbas_id() : '0') - ); - - if (!$stmt->execute($params)) - { - throw new Exception('Error while creating basket'); - } - $ssel_id = $conn->lastInsertId(); - - return self::getInstance($appbox, $ssel_id, $user->get_id()); - } - - /** - * Revoke cache when user documents have their collection changed or status - * - do not cache datas which are now forbidden - * - * @param $usr_id - * @return boolean - */ - public static function revoke_baskets_record(record_adapter &$record, appbox &$appbox) - { - $keys = array(); - - $sql = 'SELECT s.ssel_id, s.usr_id FROM ssel s, sselcont c - WHERE base_id = "' . $record->get_base_id() . '" - AND record_id="' . $record->get_record_id() . '" - AND c.ssel_id = s.ssel_id'; - - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - foreach ($rs as $row) - { - $keys[] = 'basket_' . $row['usr_id'] . '_' . $row['ssel_id']; - } - - return $appbox->delete_data_from_cache($keys); - } - - /** - * - * @param User_Interface $user - * @return - */ - public static function revoke_baskets_usr(User_Interface $user) - { - $ssel_ids = array(); - $appbox = appbox::get_instance(); - try - { - $sql = 'SELECT distinct s.ssel_id FROM ssel s, validate v - WHERE s.usr_id=:usr_id - OR (v.usr_id=:other_usr_id AND v.ssel_id = s.ssel_id)'; - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':usr_id' => $user->get_id(), ':other_usr_id' => $user->get_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - foreach ($rs as $row) - { - $ssel_ids[] = 'basket_' . $user->get_id() . '_' . $row['ssel_id']; - } - } - catch (Exception $e) - { - - } - - return $appbox->delete_data_from_cache($ssel_ids); - } - - /** - * Load users in current validation process - * @return void - */ - protected function load_validation_users() - { - try - { - $datas = $this->get_data_from_cache(self::CACHE_VALIDATING_USERS); - $this->validating_users = $datas; - - foreach ($this->validating_users as $row) - { - $user = User_Adapter::getInstance($row['usr_id'], $this->appbox); - $name = $user->get_display_name(); - $this->validating_users[$row['usr_id']]['usr_name'] = $name; - } - - return $this; - } - catch (Exception $e) - { - - } - - $sql = 'SELECT id, usr_id, confirmed, can_agree, can_see_others - FROM validate WHERE ssel_id = :ssel_id'; - - $stmt = $this->appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $this->get_ssel_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - foreach ($rs as $row) - { - $this->validating_users[$row['usr_id']] = array( - 'usr_id' => $row['usr_id'], - 'usr_name' => User_Adapter::getInstance($row['usr_id'], $this->appbox)->get_display_name(), - 'confirmed' => $row['confirmed'], - 'can_agree' => $row['can_agree'], - 'can_see_others' => $row['can_see_others'] - ); - } - - $this->set_data_to_cache($this->validating_users, self::CACHE_VALIDATING_USERS); - - return $this; - } - - /** - * - * @param $a - * @param $b - * @return - */ - protected function order_validation_asc($a, $b) - { - if (is_null($a->get_avrDisAgree()) || is_null($b->get_avrDisAgree())) - { - return 0; - } - $comp = $a->get_avrDisAgree() - $b->get_avrDisAgree(); - - if ($comp == 0) - { - $comp = $b->get_avrAgree() - $a->get_avrAgree(); - if ($comp == 0) - { - return 0; - } - } - - return $comp > 0 ? -1 : 1; - } - - /** - * - * @param $a - * @param $b - * @return - */ - protected function order_validation_desc($a, $b) - { - if (is_null($a->get_avrAgree()) || is_null($b->get_avrAgree())) - { - return 0; - } - $comp = $a->get_avrAgree() - $b->get_avrAgree(); - - if ($comp == 0) - { - $comp = $b->get_avrDisAgree() - $a->get_avrDisAgree(); - if ($comp == 0) - { - return 0; - } - } - - return $comp > 0 ? -1 : 1; - } - -} diff --git a/lib/classes/basket/element/adapter.class.php b/lib/classes/basket/element/adapter.class.php deleted file mode 100644 index 7ae6a0797f..0000000000 --- a/lib/classes/basket/element/adapter.class.php +++ /dev/null @@ -1,832 +0,0 @@ -get_session(); - $this->usr_id = $session->get_usr_id(); - $this->sselcont_id = (int) $sselcont_id; - - $this->load(); - - return $this; - } - - protected function load() - { - - try - { - $datas = $this->get_data_from_cache(); - - $this->ssel_id = $datas['ssel_id']; - $this->order = $datas['order']; - $this->record = new record_adapter($datas['sbas_id'], $datas['record_id'], $this->order); - $this->avrDisAgree = $datas['avrDisAgree']; - $this->avrAgree = $datas['avrAgree']; - $this->is_validation_item = $datas['is_validation_item']; - $this->my_agreement = $datas['my_agreement']; - $this->my_note = $datas['my_note']; - $this->validate_id = $datas['validate_id']; - $this->choices = $datas['choices']; - $this->avrAgree = $datas['avrAgree']; - $this->avrDisAgree = $datas['avrDisAgree']; - - return $this; - } - catch (Exception $e) - { - - } - - $sql = 'SELECT s.usr_id as owner, v.id as validate_id, v.can_see_others, - c.base_id, c.record_id, c.ord, c.ssel_id, v.usr_id, - d.agreement, d.note, d.updated_on - FROM (sselcont c, ssel s) - LEFT JOIN (validate v, validate_datas d) - ON (d.sselcont_id = c.sselcont_id AND d.validate_id = v.id ) - WHERE s.ssel_id = c.ssel_id - AND c.sselcont_id = :sselcont_id'; - - try - { - $conn = connection::getPDOConnection(); - $stmt = $conn->prepare($sql); - $stmt->execute(array(':sselcont_id' => $this->sselcont_id)); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - } - catch (Exception $e) - { - - } - - $first = true; - - - foreach ($rs as $row) - { - if ($row['validate_id']) - { - $this->is_validation_item = true; - - if ($row['owner'] == $this->usr_id) - $see_others = true; - else - $see_others = ($row['can_see_others'] == '1'); - - if (!$see_others) - { - if ($row['usr_id'] != $this->usr_id) - continue; - } - } - - if ($first) - { - $sbas_id = (int) phrasea::sbasFromBas($row['base_id']); - $record_id = (int) $row['record_id']; - $this->ssel_id = (int) $row['ssel_id']; - $this->order = $number = (int) $row['ord']; - - $this->record = new record_adapter($sbas_id, $record_id, $number); - - if ($this->is_validation_item) - { - $this->choices = array(); - $this->avrAgree = 0; - $this->avrDisAgree = 0; - } - - $first = false; - } - - if ($this->is_validation_item) - { - if ($row['usr_id'] == $this->usr_id) - { - $this->my_agreement = (int) $row['agreement']; - $this->my_note = $row['note']; - $this->validate_id = (int) $row['validate_id']; - } - $this->choices[$row['usr_id']] = array( - 'usr_id' => $row['usr_id'], - 'usr_name' => User_Adapter::getInstance($row['usr_id'], appbox::get_instance())->get_display_name(), - 'is_mine' => ($row['usr_id'] == $this->usr_id), - 'agreement' => $row['agreement'], - 'updated_on' => $row['updated_on'], - 'note' => $row['note'] - ); - $this->avrAgree += $row["agreement"] > 0 ? 1 : 0; - $this->avrDisAgree += $row["agreement"] < 0 ? 1 : 0; - } - } - - $datas = array( - 'ssel_id' => $this->ssel_id - , 'sbas_id' => (int) $sbas_id - , 'record_id' => $record_id - , 'order' => $this->order - , 'is_validation_item' => $this->is_validation_item - , 'my_agreement' => $this->my_agreement - , 'my_note' => $this->my_note - , 'validate_id' => $this->validate_id - , 'choices' => $this->choices - , 'avrAgree' => $this->avrAgree - , 'avrDisAgree' => $this->avrDisAgree - ); - - $this->set_data_to_cache($datas); - - return $this; - } - - public function get_record() - { - return $this->record; - } - - /** - * - * @return int - */ - public function get_order() - { - return $this->order; - } - - /** - * - * @param int $number - * @return basket_element_adapter - */ - public function set_order($order) - { - $this->order = (int) $order; - - return $this; - } - - /** - * @return basket_element_adapter - */ - public static function getInstance($sselcont_id) - { - if (!isset(self::$_instance[$sselcont_id])) - { - self::$_instance[$sselcont_id] = new self($sselcont_id); - } - - return array_key_exists($sselcont_id, self::$_instance) ? self::$_instance[$sselcont_id] : false; - } - - /** - * - * @param basket_adapter $basket - * @param int $base_id - * @param int $record_id - * @param int $parent_record_id - * @param string $adjust_validation_datas - * @param boolean $fixing - * @return basket_element_adapter - */ - public static function create(basket_adapter $basket, $base_id, $record_id, $parent_record_id, $adjust_validation_datas, $fixing) - { - $appbox = appbox::get_instance(); - $session = $appbox->get_session(); - $user = User_Adapter::getInstance($session->get_usr_id(), $appbox); - $sbas_id = phrasea::sbasFromBas($base_id); - $record = new record_adapter($sbas_id, $record_id); - - $ssel_id = $basket->get_ssel_id(); - - if (!$user->ACL()->has_right_on_base($base_id, 'canputinalbum')) - throw new Exception('You do not have rights' . - ' to use this document in basket.'); - - $exists = false; - - $sql = 'SELECT sselcont_id FROM sselcont - WHERE ssel_id = :ssel_id AND base_id = :base_id AND record_id = :record_id '; - $stmt = $appbox->get_connection()->prepare($sql); - $params = array( - ':ssel_id' => $basket->get_ssel_id() - , ':base_id' => $base_id - , ':record_id' => $record_id - ); - $stmt->execute($params); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ($row) - { - return new self($row['sselcont_id']); - } - - $connbas = connection::getPDOConnection($sbas_id); - - if (!$sbas_id) - throw new Exception('Unknown database'); - - if ($parent_record_id && $fixing === false) - { - if (!$user->ACL()->has_right_on_base($base_id, 'canaddrecord')) - throw new Exception('You do not have the right'); - - if ($record->is_grouping()) - throw new Exception('Can\'t add grouping to grouping'); - - $ord = 0; - $sql = "SELECT (max(ord)+1) as ord - FROM regroup WHERE rid_parent = :parent_record_id"; - - $stmt = $connbas->prepare($sql); - $stmt->execute(array(':parent_record_id' => $parent_record_id)); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ($row) - { - $ord = is_null($row["ord"]) ? 0 : $row["ord"]; - } - else - { - $ord = 0; - } - - $sql = 'INSERT INTO regroup (id, rid_parent, rid_child, dateadd, ord) - VALUES (null, :parent_record_id, :record_id, NOW(), :ord)'; - - $params = array( - ':parent_record_id' => $parent_record_id - , ':record_id' => $record_id - , ':ord' => $ord - ); - - $stmt = $connbas->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - $sql = 'UPDATE record SET moddate = NOW() WHERE record_id = :parent_record_id'; - $stmt = $connbas->prepare($sql); - $stmt->execute(array(':parent_record_id' => $parent_record_id)); - $stmt->closeCursor(); - } - - $sql = 'SELECT max(ord) as ord FROM sselcont WHERE ssel_id = :ssel_id'; - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $basket->get_ssel_id())); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ($row) - { - $ord = (int) $row['ord'] + 1; - } - else - { - $ord = 0; - } - - $sql = ' INSERT INTO sselcont - (sselcont_id, ssel_id, base_id, record_id, ord) - VALUES (null, :ssel_id, :base_id, :record_id, :ord) '; - - $stmt = $appbox->get_connection()->prepare($sql); - $params = array( - ':ssel_id' => $basket->get_ssel_id() - , ':base_id' => $base_id - , ':record_id' => $record_id - , ':ord' => $ord - ); - $stmt->execute($params); - $stmt->closeCursor(); - - $sselcont_id = $appbox->get_connection()->lastInsertId(); - - $ret['error'] = false; - $ret['datas'][] = $sselcont_id; - - $sql = 'UPDATE ssel SET updater=NOW() WHERE ssel_id = :ssel_id'; - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $basket->get_ssel_id())); - $stmt->closeCursor(); - - - if ($adjust_validation_datas == 'myvalid') - { - $sql = 'INSERT INTO validate_datas - (SELECT distinct null as id, id as validate_id - , :sselcont_id as sselcont_id - , null as updated_on, 0 as agreement, "" as note - FROM validate - WHERE ssel_id = :ssel_id)'; - - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':sselcont_id' => $sselcont_id, ':ssel_id' => $basket->get_ssel_id())); - $stmt->closeCursor(); - - $sql = 'SELECT usr_id FROM validate WHERE ssel_id = :ssel_id'; - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $basket->get_ssel_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - foreach ($rs as $row) - { - if ($session->get_usr_id() != $row['usr_id']) - { - $basket->set_unread($row['usr_id']); - } - } - } - - if ($parent_record_id) - { - $sql = 'SELECT null as id, ssel_id, usr_id - FROM ssel - WHERE usr_id != :usr_id AND rid = :parent_record_id - AND sbas_id = :sbas_id AND temporaryType="1"'; - - $stmt = $appbox->get_connection()->prepare($sql); - $params = array( - ':usr_id' => $session->get_usr_id() - , ':parent_record_id' => $parent_record_id - , ':sbas_id' => $sbas_id - ); - $stmt->execute($params); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - foreach ($rs as $row) - { - $sql = 'SELECT max(ord) as ord FROM sselcont WHERE ssel_id = :ssel_id'; - - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $row['ssel_id'])); - $row2 = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if ($row) - { - $ord = (int) $row2['ord'] + 1; - } - else - { - $ord = 0; - } - - $sqlUp = ' INSERT INTO sselcont - (sselcont_id, ssel_id, base_id, record_id,ord) - VALUES (null, :ssel_id, :base_id, :record_id, :ord) '; - - $stmt = $appbox->get_connection()->prepare($sql); - $params = array( - ':ssel_id' => $row['ssel_id'] - , ':base_id' => $base_id - , ':record_id' => $record_id - , ':ord' => $ord - ); - $stmt->execute($params); - $stmt->closeCursor(); - - $sql = 'UPDATE ssel SET updater=NOW() WHERE ssel_id = :ssel_id'; - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':ssel_id' => $row['ssel_id'])); - $stmt->closeCursor(); - - try - { - $basket_to_clean = basket_adapter::getInstance($appbox, $row['ssel_id'], $user->get_id()); - $basket_to_clean->set_unread($row['usr_id']); - } - catch (Exception $e) - { - - } - } - } - - $basket->delete_cache(); - - return new self($sselcont_id); - } - - /** - * - * @param string $note - * @return boolean - */ - function set_note($note) - { - if (!$this->is_validation_item) - { - throw new Exception('Element ' . $this->sselcont_id . ' is not a validation item'); - } - - $note = strip_tags($note); - - if (!$this->validate_id) - return false; - - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); - - $sql = 'UPDATE validate_datas SET note = :note - WHERE sselcont_id = :sselcont_id AND validate_id = :validate_id '; - $stmt = $appbox->get_connection()->prepare($sql); - - $params = array( - ':note' => $note - , ':sselcont_id' => $this->sselcont_id - , ':validate_id' => $this->validate_id - ); - - $stmt->execute($params); - $stmt->closeCursor(); - - $this->my_note = $note; - foreach ($this->choices as $key => $values) - { - if ($values['is_mine']) - { - $this->choices[$key]['note'] = $note; - break; - } - } - - try - { - $basket = basket_adapter::getInstance($appbox, $this->ssel_id, $usr_id); - $basket->delete_cache(); - } - catch (Exception $e) - { - - } - - return $this; - } - - /** - * - * @return void - */ - function load_users_infos() - { - if (!$this->is_validation_item) - { - throw new Exception('Element is not a validation item'); - - return false; - } - - foreach ($this->choices as $key => $value) - { - $this->choices[$key]['usr_display'] = User_Adapter::getInstance($value['usr_id'], appbox::get_instance())->get_display_name(); - } - } - - /** - * - * @return int - */ - function get_note_count() - { - if (!$this->is_validation_item) - { - throw new Exception('Element is not a validation item'); - - return false; - } - - $n = 0; - foreach ($this->choices as $key => $value) - { - if (trim($value['note']) != '') - { - $n++; - } - } - - return $n; - } - - /** - * - * @param boolean $boolean - * @return string - */ - function set_agreement($boolean) - { - - if (!$this->is_validation_item) - { - throw new Exception('not a validation item'); - } - - if (!$this->validate_id) - throw new Exception('not a validation item'); - - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); - - $boolean = in_array($boolean, array('1', '-1')) ? $boolean : '0'; - - $sql = 'UPDATE validate_datas - SET agreement = :agreement - WHERE sselcont_id = :sselcont_id - AND validate_id = :validate_id'; - - $params = array( - ':agreement' => $boolean - , ':sselcont_id' => $this->sselcont_id - , ':validate_id' => $this->validate_id - ); - - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute($params); - $stmt->closeCursor(); - - $this->delete_data_from_cache(); - $basket = basket_adapter::getInstance($appbox, $this->ssel_id, $usr_id); - $basket->delete_cache(); - - return $this; - } - - /** - * - * @return int - */ - public function get_sselcont_id() - { - return $this->sselcont_id; - } - - /** - * - * @return boolean - */ - public function is_validation_item() - { - return $this->is_validation_item; - } - - /** - * - * @return int - */ - public function get_my_agreement() - { - return $this->my_agreement; - } - - /** - * - * @return string - */ - public function get_my_note() - { - return $this->my_note; - } - - /** - * - * @return Array - */ - public function get_choices() - { - return $this->choices; - } - - /** - * - * @return int - */ - public function get_ssel_id() - { - return $this->ssel_id; - } - - public static function is_in_validation_session(record_Interface $record, User_Interface $user) - { - $conn = connection::getPDOConnection(); - $sql = 'SELECT v.id FROM sselcont c, validate v - WHERE c.base_id = :base_id AND c.record_id = :record_id - AND v.usr_id = :usr_id AND c.ssel_id = v.ssel_id'; - - $params = array( - ':base_id' => $record->get_base_id() - , ':record_id' => $record->get_record_id() - , ':usr_id' => $user->get_id() - ); - - $stmt = $conn->prepare($sql); - $stmt->execute($params); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - return!!$row; - } - - public static function has_been_received(record_Interface $record, User_Interface $user) - { - $conn = connection::getPDOConnection(); - $sql = 'SELECT sselcont_id FROM sselcont c, ssel s - WHERE c.ssel_id=s.ssel_id AND c.record_id = :record_id - AND c.base_id = :base_id AND s.pushFrom > 0 - AND s.usr_id = :usr_id'; - - $params = array( - ':base_id' => $record->get_base_id() - , ':record_id' => $record->get_record_id() - , ':usr_id' => $user->get_id() - ); - - $stmt = $conn->prepare($sql); - $stmt->execute($params); - $row = $stmt->fetch(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - return!!$row; - } - - public function get_avrAgree() - { - return $this->avrAgree; - } - - public function get_avrDisAgree() - { - return $this->avrDisAgree; - } - - public function validate(user_adapter $from_user, User_Adapter $to_user, $validate_id, $can_hd) - { - $appbox = appbox::get_instance(); - - if ($can_hd) - $to_user->ACL()->grant_hd_on($this->get_record(), $from_user, 'validate'); - else - $to_user->ACL()->grant_preview_on($this->get_record(), $from_user, 'validate'); - - $sql = 'REPLACE INTO validate_datas - (id, validate_id, sselcont_id, updated_on, agreement) - VALUES - (null, :validate_id, :sselcont_id, null, 0)'; - $stmt = $appbox->get_connection()->prepare($sql); - - $params = array( - ':validate_id' => $validate_id - , ':sselcont_id' => $this->get_sselcont_id() - ); - $stmt->execute($params); - - $stmt->closeCursor(); - - if (!$this->is_validation_item) - { - $this->choices = array(); - $this->avrAgree = 0; - $this->avrDisAgree = 0; - } - - $this->is_validation_item = true; - $this->choices[$to_user->get_id()] = array( - 'usr_id' => $to_user->get_id(), - 'usr_name' => $to_user->get_display_name(), - 'is_mine' => ($to_user->get_id() == $this->usr_id), - 'agreement' => 0, - 'updated_on' => new DateTime(), - 'note' => '' - ); - if ($to_user->get_id() == $this->usr_id) - { - $this->validate_id = (int) $validate_id; - } - - $this->delete_data_from_cache(); - - return $this; - } - - public function get_cache_key($option = null) - { - return 'basket_element_' . $this->usr_id . '_' . $this->sselcont_id . ($option ? '_' . $option : ''); - ; - } - - public function get_data_from_cache($option = null) - { - $appbox = appbox::get_instance(); - - return $appbox->get_data_from_cache($this->get_cache_key($option)); - } - - public function set_data_to_cache($value, $option = null, $duration = 0) - { - $appbox = appbox::get_instance(); - - return $appbox->set_data_to_cache($value, $this->get_cache_key($option), $duration); - } - - public function delete_data_from_cache($option = null) - { - $appbox = appbox::get_instance(); - - return $appbox->delete_data_from_cache($this->get_cache_key($option)); - } - -} diff --git a/lib/classes/basketCollection.class.php b/lib/classes/basketCollection.class.php deleted file mode 100644 index 584cdcbaa5..0000000000 --- a/lib/classes/basketCollection.class.php +++ /dev/null @@ -1,179 +0,0 @@ -format('U'); - - $sql = 'SELECT ssel_id FROM ssel WHERE usr_id = :usr_id - AND temporaryType="0"'; - $stmt = $appbox->get_connection()->prepare($sql); - $stmt->execute(array(':usr_id' => $usr_id)); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - if (count($rs) === 0) - { - $basket = basket_adapter::create($appbox, '', $user); - } - - $baskets = array(); - $baskets['baskets'] = $baskets['recept'] = $baskets['regroup'] = array(); - - - $core = bootstrap::getCore(); - $em = $core->getEntityManager(); - - $baskets['baskets'] = $em->getRepository('Entities\Basket') - ->findBy(array('usr_id' => $usr_id, 'pusher_id' => null)); - - $baskets['regroup'] = $em->getRepository('Entities\StoryWZ') - ->findBy(array('usr_id' => $usr_id)); - -// $sql = 'SELECT s.ssel_id, s.usr_id as owner, v.id as validate_id, -// s.temporaryType, s.pushFrom, v.expires_on FROM ssel s -// LEFT JOIN validate v -// ON (v.ssel_id = s.ssel_id AND v.usr_id = :usr_id_v) -// WHERE (s.usr_id = :usr_id_o OR v.id IS NOT NULL)'; -// -// $stmt = $appbox->get_connection()->prepare($sql); -// $stmt->execute(array(':usr_id_o' => $usr_id, ':usr_id_v' => $usr_id)); -// $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); -// $stmt->closeCursor(); - -// foreach ($rs as $row) -// { -// $is_mine = ($row['owner'] == $usr_id); -// -// $expires_on_obj = new DateTime($row['expires_on']); -// $expires_on = $expires_on_obj->format('U'); -// -// if ($row['validate_id'] != null && !$is_mine && $expires_on < $current_timestamp) -// continue; -// -// if ($row['temporaryType'] == '1') -// $baskets['regroup'][] = basket_adapter::getInstance($appbox, $row['ssel_id'], $usr_id); -// elseif (!is_null($row['validate_id'])) -// { -//// $baskets['baskets'][] = basket_adapter::getInstance($appbox, $row['ssel_id'], $usr_id); -// } -// elseif ((int) $row['pushFrom'] > 0) -// $baskets['recept'][] = basket_adapter::getInstance($appbox, $row['ssel_id'], $usr_id); -//// else -//// $baskets['baskets'][] = basket_adapter::getInstance($appbox, $row['ssel_id'], $usr_id); -// } - - $to_remove = array_intersect(array('recept', 'regroup', 'baskets'), $except); - - foreach ($to_remove as $type) - $baskets[$type] = array(); - - if ($order == 'name asc') - { - uasort($baskets['baskets'], array('basketCollection', 'story_name_sort')); - uasort($baskets['regroup'], array('basketCollection', 'story_name_sort')); - uasort($baskets['recept'], array('basketCollection', 'story_name_sort')); - } - if ($order == 'date desc') - { - uasort($baskets['baskets'], array('basketCollection', 'story_date_sort')); - uasort($baskets['regroup'], array('basketCollection', 'story_date_sort')); - uasort($baskets['recept'], array('basketCollection', 'story_date_sort')); - } - - - $this->baskets = $baskets; - - return $this; - } - - public function get_baskets() - { - return $this->baskets; - } - - function get_names() - { - $array_names = array(); - - foreach ($this->baskets as $type_name => $type) - { - foreach ($type as $basket) - { - - $array_names[] = array('ssel_id' => $basket->get_ssel_id(), 'name' => $basket->get_name(), 'type' => $type_name); - } - } - - return $array_names; - } - - function story_date_sort($a, $b) - { - if (!$a->create || !$b->create) - return 0; - - $comp = strcasecmp($a->create, $b->create); - - if ($comp == 0) - return 0; - - return $comp < 0 ? -1 : 1; - } - - function story_name_sort($a, $b) - { - if (!$a->getName() || !$b->getName()) - { - return 0; - } - $comp = strcasecmp($a->getName(), $b->getName()); - - if ($comp == 0) - return 0; - - return $comp < 0 ? -1 : 1; - } - - public static function get_updated_baskets() - { - $appbox = appbox::get_instance(); - $conn = $appbox->get_connection(); - $session = $appbox->get_session(); - $sql = 'SELECT ssel_id FROM sselnew WHERE usr_id = :usr_id'; - $stmt = $conn->prepare($sql); - $stmt->execute(array(':usr_id' => $session->get_usr_id())); - $rs = $stmt->fetchAll(PDO::FETCH_ASSOC); - $stmt->closeCursor(); - - $baskets = array(); - foreach ($rs as $row) - { - $baskets[] = basket_adapter::getInstance($appbox, $row['ssel_id'], $session->get_usr_id()); - } - - return $baskets; - } - -} diff --git a/lib/classes/record/adapter.class.php b/lib/classes/record/adapter.class.php index fc546bf9e4..5e01615d3b 100644 --- a/lib/classes/record/adapter.class.php +++ b/lib/classes/record/adapter.class.php @@ -1923,7 +1923,7 @@ class record_adapter implements record_Interface, cache_cacheableInterface $Core = bootstrap::getCore(); $em = $Core->getEntityManager(); - $repo = $em->getRepository('\Entities\Baskets'); + $repo = $em->getRepository('\Entities\Basket'); /* @var $$repo \Repositories\BasketRepository */ return $repo->findContainingRecord($this); diff --git a/lib/classes/record/preview.class.php b/lib/classes/record/preview.class.php index 72303206f7..489ebb60ab 100644 --- a/lib/classes/record/preview.class.php +++ b/lib/classes/record/preview.class.php @@ -225,7 +225,7 @@ class record_preview extends record_adapter $this->train = $results->get_datas(); break; case 'BASK': - $this->train = $this->container->get_elements(); + $this->train = $this->container->getElements(); break; case 'REG': $this->train = $this->container->get_children(); diff --git a/lib/classes/set/export.class.php b/lib/classes/set/export.class.php index 9e5acbf4a0..6aa6c29aa9 100644 --- a/lib/classes/set/export.class.php +++ b/lib/classes/set/export.class.php @@ -78,7 +78,7 @@ class set_export extends set_abstract new record_exportElement( $basket_element->getRecord()->get_sbas_id(), $record_id, - $basket->get_name() . '/', + $basket->getName() . '/', $remain_hd[$base_id] ); diff --git a/lib/classes/set/order.class.php b/lib/classes/set/order.class.php index 1f39347c26..327f0d0bed 100644 --- a/lib/classes/set/order.class.php +++ b/lib/classes/set/order.class.php @@ -264,20 +264,28 @@ class set_order extends set_abstract { $sbas_id = phrasea::sbasFromBas($basrec['base_id']); $record = new record_adapter($sbas_id, $basrec['record_id']); - $ret = $basket->push_element($record, false, false); - if ($ret['error'] === false) - { - $params = array( - ':usr_id' => $session->get_usr_id() - , ':order_id' => $this->id - , ':order_element_id' => $order_element_id - ); + + $BasketElement = new BasketElement(); + $BasketElement->setRecord($record); + $BasketElement->setBasket($Basket); + + $Basket->addBasketElement($BasketElement); + + $em->persist($BasketElement); + + $em->merge($Basket); + + $params = array( + ':usr_id' => $session->get_usr_id() + , ':order_id' => $this->id + , ':order_element_id' => $order_element_id + ); - $stmt->execute($params); + $stmt->execute($params); - $n++; - $this->user->ACL()->grant_hd_on($record, $pusher, 'order'); - } + $n++; + $this->user->ACL()->grant_hd_on($record, $pusher, 'order'); + unset($record); } catch (Exception $e) @@ -285,6 +293,8 @@ class set_order extends set_abstract } } + + $em->flush(); $stmt->closeCursor(); if ($n > 0) diff --git a/lib/unitTest/Bridge/ApplicationTest.php b/lib/unitTest/Bridge/ApplicationTest.php index 3dbd945714..03ad1c4590 100644 --- a/lib/unitTest/Bridge/ApplicationTest.php +++ b/lib/unitTest/Bridge/ApplicationTest.php @@ -71,24 +71,13 @@ class Bridge_Application extends PhraseanetWebTestCaseAuthenticatedAbstract $accounts = Bridge_Account::get_accounts_by_user($appbox, self::$user); $usr_id = self::$user->get_id(); - try - { - $basket_coll = new basketCollection($appbox, $usr_id); - $baskets = $basket_coll->get_baskets(); - if (count($baskets["baskets"]) > 0) - { - $basket = array_shift($baskets["baskets"]); - $crawler = $this->client->request('POST', '/bridge/manager/', array('ssel' => $basket->get_ssel_id())); - $pageContent = $this->client->getResponse()->getContent(); - $this->assertNotContains("Oups ! something went wrong !", $pageContent); - $this->assertEquals(count($accounts) + 2, $crawler->filter('form')->count()); - $this->assertTrue($this->client->getResponse()->isOk()); - } - } - catch (Exception $e) - { - - } + $basket = $this->insertOneBasket(); + + $crawler = $this->client->request('POST', '/bridge/manager/', array('ssel' => $basket->getId())); + $pageContent = $this->client->getResponse()->getContent(); + $this->assertNotContains("Oups ! something went wrong !", $pageContent); + $this->assertEquals(count($accounts) + 2, $crawler->filter('form')->count()); + $this->assertTrue($this->client->getResponse()->isOk()); } public function testLogin() diff --git a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc index 0563817ced..145ede830e 100644 --- a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc +++ b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc @@ -1058,6 +1058,77 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase $this->fail('Fail load one Basket : ' . $e->getMessage()); } } + + /** + * + * @return \Entities\BasketElement + */ + protected function insertOneBasketElement() + { + $basket = $this->insertOneBasket(); + + $basketElement = new \Entities\BasketElement(); + $basketElement->setRecord(self::$record_1); + $basketElement->setBasket($basket); + + $basket->addBasketElement($basketElement); + + $em = self::$core->getEntityManager(); + + $em->persist($basketElement); + + $em->merge($basket); + + $em->flush(); + + return $basketElement; + } + + + /** + * + * @return \Entities\Basket + */ + protected function insertOneValidationBasket() + { + $em = self::$core->getEntityManager(); + + $basketElement = $this->insertOneBasketElement(); + $basket = $basketElement->getBasket(); + + $Validation = new Entities\ValidationSession(); + $Validation->setBasket($basket); + $Validation->setInitiator(self::$user); + + $basket->setValidation($Validation); + + $em->persist($Validation); + $em->merge($basket); + + $Participant = new Entities\ValidationParticipant(); + $Participant->setUser(self::$user); + $Participant->setCanAgree(true); + $Participant->setCanSeeOthers(true); + + $Validation->addValidationParticipant($Participant); + $Participant->setSession($Validation); + + $em->persist($Participant); + $em->merge($Validation); + + $Data = new Entities\ValidationData(); + $Data->setBasketElement($basketElement); + $Data->setParticipant($Participant); + $basketElement->addValidationData($Data); + + $em->persist($Data); + $em->merge($basketElement); + + $em->flush(); + + return $basket; + + } /** * Create a new basket with current auhtenticated user as owner diff --git a/lib/unitTest/api/v1/api_v1_adapterTest.php b/lib/unitTest/api/v1/api_v1_adapterTest.php index f457efa3c2..22c20babd7 100644 --- a/lib/unitTest/api/v1/api_v1_adapterTest.php +++ b/lib/unitTest/api/v1/api_v1_adapterTest.php @@ -397,7 +397,7 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract $em->persist($Basket); $em->flush(); - $ssel_id = $basket->getId(); + $ssel_id = $Basket->getId(); $request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json')); $result = $this->object->delete_basket($request, $ssel_id); @@ -422,12 +422,11 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract { $appbox = appbox::get_instance(); $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); - $baskets = $basket_coll->get_baskets(); - $basket = array_pop($baskets['baskets']); + + $basket = $this->insertOneBasket(); $request = new Request(array(), array(), array(), array(), array(), array('HTTP_Accept' => 'application/json')); - $result = $this->object->get_basket($request, $basket->get_ssel_id()); + $result = $this->object->get_basket($request, $basket->getId()); $this->assertEquals(200, $result->get_http_code()); $this->assertEquals('application/json', $result->get_content_type()); $this->assertTrue(is_object(json_decode($result->format()))); @@ -437,36 +436,38 @@ class API_V1_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract { $appbox = appbox::get_instance(); $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); - $baskets = $basket_coll->get_baskets(); - $basket = array_pop($baskets['baskets']); - + + $basket = $this->insertOneBasket(); + $request = new Request(array(), array(), array('name' => 'PROUTO'), array(), array(), array('HTTP_Accept' => 'application/json')); - $result = $this->object->set_basket_title($request, $basket->get_ssel_id()); + $result = $this->object->set_basket_title($request, $basket->getId()); $this->assertEquals(200, $result->get_http_code()); $this->assertEquals('application/json', $result->get_content_type()); $this->assertTrue(is_object(json_decode($result->format()))); - $basket = basket_adapter::getInstance($appbox, $basket->get_ssel_id(), $usr_id); - $this->assertEquals('PROUTO', $basket->get_name()); + self::$core->getEntityManager()->refresh($basket); + + $this->assertEquals('PROUTO', $basket->getName()); } public function testSet_basket_description() { $appbox = appbox::get_instance(); $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); - $baskets = $basket_coll->get_baskets(); - $basket = array_pop($baskets['baskets']); + + $basket = $this->insertOneBasket(); $request = new Request(array(), array(), array('description' => 'une belle description'), array(), array(), array('HTTP_Accept' => 'application/json')); - $result = $this->object->set_basket_description($request, $basket->get_ssel_id()); + $result = $this->object->set_basket_description($request, $basket->getId()); $this->assertEquals(200, $result->get_http_code()); $this->assertEquals('application/json', $result->get_content_type()); $this->assertTrue(is_object(json_decode($result->format()))); - $basket = basket_adapter::getInstance($appbox, $basket->get_ssel_id(), $usr_id); - $this->assertEquals('une belle description', $basket->get_description()); + $em = self::$core->getEntityManager(); + /* @var $em \Doctrine\ORM\EntityManager */ + $em->refresh($basket); + + $this->assertEquals('une belle description', $basket->getDescription()); } public function testSearch_publications() diff --git a/lib/unitTest/api/v1/aplicationTest.php b/lib/unitTest/api/v1/aplicationTest.php index 5ba8cc9511..79a8130567 100644 --- a/lib/unitTest/api/v1/aplicationTest.php +++ b/lib/unitTest/api/v1/aplicationTest.php @@ -795,8 +795,6 @@ class API_V1_test_adapter extends PhraseanetWebTestCaseAbstract { $this->evaluateGoodBasket($basket); $this->assertEquals('un Joli Nom', $basket->name); - $basket_obj = basket_adapter::getInstance($appbox, $basket->ssel_id, $appbox->get_session()->get_usr_id()); - $basket_obj->delete(); } } @@ -804,180 +802,132 @@ class API_V1_test_adapter extends PhraseanetWebTestCaseAbstract { $appbox = appbox::get_instance(); $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); + + $basket = $this->insertOneBasket(); + + $route = '/baskets/' . $basket->getId() . '/content/?oauth_token=' . self::$token; - $found = false; - foreach ($basket_coll->get_baskets() as $bask_group => $baskets) + $this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE')); + + $crawler = $this->client->request('GET', $route); + $content = json_decode($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaJson200($content); + + $this->assertEquals(1, count((array) $content->response)); + + $this->assertObjectHasAttribute("basket_elements", $content->response); + + foreach ($content->response->basket_elements as $basket_str) { - if (!in_array($bask_group, array('recept', 'baskets'))) - continue; - foreach ($baskets as $basket) + $this->evaluateGoodBasket($basket_str); + + $this->assertEquals(count($basket->getElements()), count((array) $basket_str->basket_elements)); + foreach ($basket_str->basket_elements as $basket_element) { - $found = true; - $route = '/baskets/' . $basket->get_ssel_id() . '/content/?oauth_token=' . self::$token; - - $this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE')); - - $crawler = $this->client->request('GET', $route); - $content = json_decode($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaJson200($content); - - $this->assertEquals(1, count((array) $content->response)); - - $this->assertObjectHasAttribute("basket_elements", $content->response); - - foreach ($content->response->basket_elements as $basket_str) - { - $this->evaluateGoodBasket($basket_str); - - $this->assertEquals(count($basket->get_elements()), count((array) $basket_str->basket_elements)); - foreach ($basket_str->basket_elements as $basket_element) - { - $this->assertObjectHasAttribute('basket_element_id', $basket_element); - $this->assertObjectHasAttribute('order', $basket_element); - $this->assertObjectHasAttribute('record', $basket_element); - $this->assertObjectHasAttribute('validation_item', $basket_element); - $this->assertTrue(is_bool($basket_element->validation_item)); - $this->assertTrue(is_int($basket_element->order)); - $this->assertTrue(is_int($basket_element->basket_element_id)); - $this->evaluateGoodRecord($basket_element->record); - } - } + $this->assertObjectHasAttribute('basket_element_id', $basket_element); + $this->assertObjectHasAttribute('order', $basket_element); + $this->assertObjectHasAttribute('record', $basket_element); + $this->assertObjectHasAttribute('validation_item', $basket_element); + $this->assertTrue(is_bool($basket_element->validation_item)); + $this->assertTrue(is_int($basket_element->order)); + $this->assertTrue(is_int($basket_element->basket_element_id)); + $this->evaluateGoodRecord($basket_element->record); } } - if (!$found) - $this->markTestSkipped('Unable to test basket set title'); } public function testSetBasketTitle() { - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); + $basket = $this->insertOneBasket(); + + $route = '/baskets/' . $basket->getId() . '/setname/?oauth_token=' . self::$token; - $found = false; + $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); - foreach ($basket_coll->get_baskets() as $bask_group => $baskets) + $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom')); + $content = json_decode($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaJson200($content); + + $this->assertEquals(1, count((array) $content->response)); + $this->assertObjectHasAttribute("basket", $content->response); + foreach ($content->response->basket as $basket_str) { - if (!in_array($bask_group, array('recept', 'baskets'))) - continue; - foreach ($baskets as $basket) - { + $this->evaluateGoodBasket($basket_str); - $found = true; - $route = '/baskets/' . $basket->get_ssel_id() . '/setname/?oauth_token=' . self::$token; - - $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); - - $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom')); - $content = json_decode($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaJson200($content); - - $this->assertEquals(1, count((array) $content->response)); - $this->assertObjectHasAttribute("basket", $content->response); - foreach ($content->response->basket as $basket_str) - { - $this->evaluateGoodBasket($basket_str); - - $this->assertEquals($basket_str->name, 'un Joli Nom'); - } - - $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom')); - $content = json_decode($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaJson200($content); - - $this->assertEquals(1, count((array) $content->response)); - - $this->assertObjectHasAttribute("basket", $content->response); - - foreach ($content->response->basket as $basket) - { - $this->evaluateGoodBasket($basket_str); - - $this->assertEquals($basket_str->name, 'un Joli Nom'); - } - - $crawler = $this->client->request('POST', $route, array('name' => 'aéaa')); - $content = json_decode($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaJson200($content); - - $this->assertEquals(1, count((array) $content->response)); - $this->assertObjectHasAttribute("basket", $content->response); - foreach ($content->response->basket as $basket_str) - { - $this->evaluateGoodBasket($basket_str); - $this->assertEquals($basket_str->name, 'aéaa'); - } - - - break; - } + $this->assertEquals($basket_str->name, 'un Joli Nom'); } - if (!$found) - $this->markTestSkipped('Unable to test basket set title'); + + $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom')); + $content = json_decode($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaJson200($content); + + $this->assertEquals(1, count((array) $content->response)); + + $this->assertObjectHasAttribute("basket", $content->response); + + foreach ($content->response->basket as $basket) + { + $this->evaluateGoodBasket($basket_str); + + $this->assertEquals($basket_str->name, 'un Joli Nom'); + } + + $crawler = $this->client->request('POST', $route, array('name' => 'aéaa')); + $content = json_decode($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaJson200($content); + + $this->assertEquals(1, count((array) $content->response)); + $this->assertObjectHasAttribute("basket", $content->response); + foreach ($content->response->basket as $basket_str) + { + $this->evaluateGoodBasket($basket_str); + $this->assertEquals($basket_str->name, 'aéaa'); + } + } public function testSetBasketDescription() { - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); + $basket = $this->insertOneBasket(); + + $route = '/baskets/' . $basket->getId() . '/setdescription/?oauth_token=' . self::$token; - $found = false; + $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); - foreach ($basket_coll->get_baskets() as $bask_group => $baskets) + $crawler = $this->client->request('POST', $route, array('description' => 'une belle desc')); + $content = json_decode($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaJson200($content); + + $this->assertEquals(1, count((array) $content->response)); + + $this->assertObjectHasAttribute("basket", $content->response); + foreach ($content->response->basket as $basket_str) { - if (!in_array($bask_group, array('recept', 'baskets'))) - continue; - foreach ($baskets as $basket) - { + $this->evaluateGoodBasket($basket_str); - $found = true; - $route = '/baskets/' . $basket->get_ssel_id() . '/setdescription/?oauth_token=' . self::$token; - - $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); - - $crawler = $this->client->request('POST', $route, array('description' => 'une belle desc')); - $content = json_decode($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaJson200($content); - - $this->assertEquals(1, count((array) $content->response)); - - $this->assertObjectHasAttribute("basket", $content->response); - foreach ($content->response->basket as $basket_str) - { - $this->evaluateGoodBasket($basket_str); - - $this->assertEquals($basket_str->description, 'une belle desc'); - } - - - break; - } + $this->assertEquals($basket_str->description, 'une belle desc'); } - if (!$found) - $this->markTestSkipped('Unable to test basket set description'); + + } public function testDeleteBasket() { - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); + $basket = $this->insertOneBasket(); + $basket2 = $this->insertOneBasket(); - $basket = basket_adapter::create($appbox, 'test suppression panier', User_Adapter::getInstance($usr_id, $appbox)); - - $route = '/baskets/' . $basket->get_ssel_id() . '/delete/?oauth_token=' . self::$token; + $route = '/baskets/' . $basket->getId() . '/delete/?oauth_token=' . self::$token; $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); @@ -988,9 +938,16 @@ class API_V1_test_adapter extends PhraseanetWebTestCaseAbstract $this->evaluateMetaJson200($content); $this->assertObjectHasAttribute("baskets", $content->response); + + $found = false; foreach ($content->response->baskets as $basket) { $this->evaluateGoodBasket($basket); + $found = true; + } + if(!$found) + { + $this->fail('There should be a basket left'); } } diff --git a/lib/unitTest/api/v1/aplicationYamlTest.php b/lib/unitTest/api/v1/aplicationYamlTest.php index 7ca063191b..5174f999a7 100644 --- a/lib/unitTest/api/v1/aplicationYamlTest.php +++ b/lib/unitTest/api/v1/aplicationYamlTest.php @@ -215,7 +215,7 @@ class API_V1_test_adapterYaml extends PhraseanetWebTestCaseAbstract } catch (Exception_Databox_FieldNotFound $e) { - + } $route = '/databoxes/' . $databox_id . '/metadatas/?oauth_token=' . self::$token; @@ -254,7 +254,7 @@ class API_V1_test_adapterYaml extends PhraseanetWebTestCaseAbstract $this->assertTrue((strlen($metadatas["separator"]) > 0)); $this->assertTrue(is_string($metadatas["thesaurus_branch"])); - $this->assertTrue(in_array($metadatas["type"], array(databox_field::TYPE_DATE,databox_field::TYPE_STRING, databox_field::TYPE_NUMBER, databox_field::TYPE_TEXT))); + $this->assertTrue(in_array($metadatas["type"], array(databox_field::TYPE_DATE, databox_field::TYPE_STRING, databox_field::TYPE_NUMBER, databox_field::TYPE_TEXT))); $this->assertTrue(is_bool($metadatas["indexable"])); $this->assertTrue(is_bool($metadatas["multivalue"])); $this->assertTrue(is_bool($metadatas["readonly"])); @@ -487,7 +487,7 @@ class API_V1_test_adapterYaml extends PhraseanetWebTestCaseAbstract $this->assertNotEquals($subdef->get_size(), $headers["download_content_length"]); break; case "url" : - $this->assertTrue(strpos($headers['content_type'], $subdef->get_mime()) === 0, 'Verify that header '.$headers['content_type'].' contains subdef mime type '.$subdef->get_mime()); + $this->assertTrue(strpos($headers['content_type'], $subdef->get_mime()) === 0, 'Verify that header ' . $headers['content_type'] . ' contains subdef mime type ' . $subdef->get_mime()); $this->assertEquals($subdef->get_size(), $headers["download_content_length"]); break; } @@ -805,189 +805,133 @@ class API_V1_test_adapterYaml extends PhraseanetWebTestCaseAbstract { $this->evaluateGoodBasket($basket); $this->assertEquals('un Joli Nom', $basket["name"]); - $basket_obj = basket_adapter::getInstance($appbox, $basket["ssel_id"], $appbox->get_session()->get_usr_id()); - $basket_obj->delete(); } } public function testBasketContent() { - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); + $basket = $this->insertOneBasket(); - $found = false; - foreach ($basket_coll->get_baskets() as $bask_group => $baskets) + $route = '/baskets/' . $basket->getId() . '/content/?oauth_token=' . self::$token; + + $this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE')); + + $crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml")); + $content = self::$yaml->parse($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaYaml200($content); + + $this->assertEquals(1, count((array) $content["response"])); + + $this->assertArrayHasKey("basket_elements", $content["response"]); + + foreach ($content["response"]["basket_elements"] as $basket_str) { - if (!in_array($bask_group, array('recept', 'baskets'))) - continue; - foreach ($baskets as $basket) + $this->evaluateGoodBasket($basket_str); + + $this->assertEquals(count($basket->getElements()), count((array) $basket_str["basket_elements"])); + foreach ($basket_str["basket_elements"] as $basket_element) { - $found = true; - $route = '/baskets/' . $basket->get_ssel_id() . '/content/?oauth_token=' . self::$token; - - $this->evaluateMethodNotAllowedRoute($route, array('POST', 'PUT', 'DELETE')); - - $crawler = $this->client->request('GET', $route, array(), array(), array("HTTP_ACCEPT" => "application/yaml")); - $content = self::$yaml->parse($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaYaml200($content); - - $this->assertEquals(1, count((array) $content["response"])); - - $this->assertArrayHasKey("basket_elements", $content["response"]); - - foreach ($content["response"]["basket_elements"] as $basket_str) - { - $this->evaluateGoodBasket($basket_str); - - $this->assertEquals(count($basket->get_elements()), count((array) $basket_str["basket_elements"])); - foreach ($basket_str["basket_elements"] as $basket_element) - { - $this->assertArrayHasKey('basket_element_id', $basket_element); - $this->assertArrayHasKey('order', $basket_element); - $this->assertArrayHasKey('record', $basket_element); - $this->assertArrayHasKey('validation_item', $basket_element); - $this->assertTrue(is_bool($basket_element["validation_item"])); - $this->assertTrue(is_int($basket_element["order"])); - $this->assertTrue(is_int($basket_element["basket_element_id"])); - $this->evaluateGoodRecord($basket_element["record"]); - } - } + $this->assertArrayHasKey('basket_element_id', $basket_element); + $this->assertArrayHasKey('order', $basket_element); + $this->assertArrayHasKey('record', $basket_element); + $this->assertArrayHasKey('validation_item', $basket_element); + $this->assertTrue(is_bool($basket_element["validation_item"])); + $this->assertTrue(is_int($basket_element["order"])); + $this->assertTrue(is_int($basket_element["basket_element_id"])); + $this->evaluateGoodRecord($basket_element["record"]); } } - if (!$found) - $this->markTestSkipped('Unable to test basket set title'); } public function testSetBasketTitle() { - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); + $basket = $this->insertOneBasket(); - $found = false; + $route = '/baskets/' . $basket->getId() . '/setname/?oauth_token=' . self::$token; - foreach ($basket_coll->get_baskets() as $bask_group => $baskets) + $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); + + $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array("HTTP_ACCEPT" => "application/yaml")); + $content = self::$yaml->parse($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaYaml200($content); + + $this->assertEquals(1, count((array) $content["response"])); + $this->assertArrayHasKey("basket", $content["response"]); + foreach ($content["response"]["basket"] as $basket_str) { - if (!in_array($bask_group, array('recept', 'baskets'))) - continue; - foreach ($baskets as $basket) - { + $this->evaluateGoodBasket($basket_str); - $found = true; - $route = '/baskets/' . $basket->get_ssel_id() . '/setname/?oauth_token=' . self::$token; - - $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); - - $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array("HTTP_ACCEPT" => "application/yaml")); - $content = self::$yaml->parse($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaYaml200($content); - - $this->assertEquals(1, count((array) $content["response"])); - $this->assertArrayHasKey("basket", $content["response"]); - foreach ($content["response"]["basket"] as $basket_str) - { - $this->evaluateGoodBasket($basket_str); - - $this->assertEquals($basket_str["name"], 'un Joli Nom'); - } - - $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array("HTTP_ACCEPT" => "application/yaml")); - $content = self::$yaml->parse($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaYaml200($content); - - $this->assertEquals(1, count((array) $content["response"])); - - $this->assertArrayHasKey("basket", $content["response"]); - - foreach ($content["response"]["basket"] as $basket) - { - $this->evaluateGoodBasket($basket_str); - - $this->assertEquals($basket_str["name"], 'un Joli Nom'); - } - - $crawler = $this->client->request('POST', $route, array('name' => 'aéaa'), array(), array("HTTP_ACCEPT" => "application/yaml")); - $content = self::$yaml->parse($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaYaml200($content); - - $this->assertEquals(1, count((array) $content["response"])); - $this->assertArrayHasKey("basket", $content["response"]); - foreach ($content["response"]["basket"] as $basket_str) - { - $this->evaluateGoodBasket($basket_str); - $this->assertEquals($basket_str["name"], 'aéaa'); - } - - - break; - } + $this->assertEquals($basket_str["name"], 'un Joli Nom'); + } + + $crawler = $this->client->request('POST', $route, array('name' => 'un Joli Nom'), array(), array("HTTP_ACCEPT" => "application/yaml")); + $content = self::$yaml->parse($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaYaml200($content); + + $this->assertEquals(1, count((array) $content["response"])); + + $this->assertArrayHasKey("basket", $content["response"]); + + foreach ($content["response"]["basket"] as $basket) + { + $this->evaluateGoodBasket($basket_str); + + $this->assertEquals($basket_str["name"], 'un Joli Nom'); + } + + $crawler = $this->client->request('POST', $route, array('name' => 'aéaa'), array(), array("HTTP_ACCEPT" => "application/yaml")); + $content = self::$yaml->parse($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaYaml200($content); + + $this->assertEquals(1, count((array) $content["response"])); + $this->assertArrayHasKey("basket", $content["response"]); + foreach ($content["response"]["basket"] as $basket_str) + { + $this->evaluateGoodBasket($basket_str); + $this->assertEquals($basket_str["name"], 'aéaa'); } - if (!$found) - $this->markTestSkipped('Unable to test basket set title'); } public function testSetBasketDescription() { - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); + $basket = $this->insertOneBasket(); - $found = false; + $route = '/baskets/' . $basket->getId() . '/setdescription/?oauth_token=' . self::$token; - foreach ($basket_coll->get_baskets() as $bask_group => $baskets) + $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); + + $crawler = $this->client->request('POST', $route, array('description' => 'une belle desc'), array(), array("HTTP_ACCEPT" => "application/yaml")); + $content = self::$yaml->parse($this->client->getResponse()->getContent()); + + $this->evaluateResponse200($this->client->getResponse()); + $this->evaluateMetaYaml200($content); + + $this->assertEquals(1, count((array) $content["response"])); + + $this->assertArrayHasKey("basket", $content["response"]); + foreach ($content["response"]["basket"] as $basket_str) { - if (!in_array($bask_group, array('recept', 'baskets'))) - continue; - foreach ($baskets as $basket) - { + $this->evaluateGoodBasket($basket_str); - $found = true; - $route = '/baskets/' . $basket->get_ssel_id() . '/setdescription/?oauth_token=' . self::$token; - - $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); - - $crawler = $this->client->request('POST', $route, array('description' => 'une belle desc'), array(), array("HTTP_ACCEPT" => "application/yaml")); - $content = self::$yaml->parse($this->client->getResponse()->getContent()); - - $this->evaluateResponse200($this->client->getResponse()); - $this->evaluateMetaYaml200($content); - - $this->assertEquals(1, count((array) $content["response"])); - - $this->assertArrayHasKey("basket", $content["response"]); - foreach ($content["response"]["basket"] as $basket_str) - { - $this->evaluateGoodBasket($basket_str); - - $this->assertEquals($basket_str["description"], 'une belle desc'); - } - - - break; - } + $this->assertEquals($basket_str["description"], 'une belle desc'); } - if (!$found) - $this->markTestSkipped('Unable to test basket set description'); } public function testDeleteBasket() { - $appbox = appbox::get_instance(); - $usr_id = $appbox->get_session()->get_usr_id(); + $basket = $this->insertOneBasket(); + $basket2 = $this->insertOneBasket(); - $basket = basket_adapter::create($appbox, 'test suppression panier', User_Adapter::getInstance($usr_id, $appbox)); - - $route = '/baskets/' . $basket->get_ssel_id() . '/delete/?oauth_token=' . self::$token; + $route = '/baskets/' . $basket->getId() . '/delete/?oauth_token=' . self::$token; $this->evaluateMethodNotAllowedRoute($route, array('GET', 'PUT', 'DELETE')); @@ -998,9 +942,16 @@ class API_V1_test_adapterYaml extends PhraseanetWebTestCaseAbstract $this->evaluateMetaYaml200($content); $this->assertArrayHasKey("baskets", $content["response"]); + + $found = false; foreach ($content["response"]["baskets"] as $basket) { $this->evaluateGoodBasket($basket); + $found = true; + } + if (!$found) + { + $this->fail('There should be a basket left'); } } diff --git a/lib/unitTest/module/lightboxTest.php b/lib/unitTest/module/lightboxTest.php index dbc5573985..62c92a14cb 100644 --- a/lib/unitTest/module/lightboxTest.php +++ b/lib/unitTest/module/lightboxTest.php @@ -14,6 +14,7 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract protected $item; protected $validation_basket; protected static $need_records = 1; + // protected static $need_subdefs = true; public function setUp() @@ -25,16 +26,11 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract $publisher = array_shift($this->feed->get_publishers()); $this->entry = Feed_Entry_Adapter::create($appbox, $this->feed, $publisher, 'title', "sub Titkle", " jean pierre", "jp@test.com"); $this->item = Feed_Entry_Item::create($appbox, $this->entry, self::$record_1); - $basket = basket_adapter::create($appbox, 'bask validation', self::$user); - $basket->push_element(self::$record_1, false, false); - $basket->validation_to_users(self::$user, true, true, true); - $this->validation_basket = $basket; } public function tearDown() { $this->feed->delete(); -// $this->validation_basket->delete(); parent::tearDown(); } @@ -43,79 +39,21 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract return require dirname(__FILE__) . '/../../Alchemy/Phrasea/Application/Lightbox.php'; } - /** - * - * @return array - */ - protected function get_baskets() - { - $appbox = appbox::get_instance(); - $basketcoll = new basketCollection($appbox, self::$user->get_id()); - $basket_coll = $basketcoll->get_baskets(); - - return $basket_coll['baskets']; - } - - /** - * - * @return basket_adapter - */ - protected function get_basket() - { - $appbox = appbox::get_instance(); - $basketcoll = new basketCollection($appbox, self::$user->get_id()); - $basket_coll = $basketcoll->get_baskets(); - while(($basket = array_shift($basket_coll['baskets']))) - { - if(!$basket->is_valid()) - - return $basket; - } - $this->fail('Unable to find a basket'); - } - protected function get_validation_basket() - { - return $this->validation_basket; - } - - /** - * - * @return basket_element_adapter - */ - protected function get_basket_element() - { - $basket = $this->get_basket(); - $basket->push_element(self::$record_1, false, false); - - foreach($basket->get_elements() as $basket_element) - { - return $basket_element; - } - } - /** - * - * @return basket_element_adapter - */ - protected function get_validation_basket_element() - { - $basket = $this->get_validation_basket(); - - foreach($basket->get_elements() as $basket_element) - { - return $basket_element; - } - } - public function testRouteSlash() { - $baskets = $this->get_baskets(); + $n = mt_rand(2, 8); + + for ($i = 0; $i != $n; $i++) + { + $basket = $this->insertOneBasket(); + } $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); $crawler = $this->client->request('GET', '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); - $this->assertEquals($crawler->filter('div.basket_wrapper')->count(), count($baskets)); + $this->assertEquals($crawler->filter('div.basket_wrapper')->count(), $n); $this->set_user_agent(self::USER_AGENT_IE6); @@ -133,34 +71,34 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract public function testAjaxNoteForm() { - $basket_element = $this->get_basket_element(); + $basket_element = $this->insertOneBasketElement(); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); - $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/'.$basket_element->get_sselcont_id().'/'); + $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('', trim($this->client->getResponse()->getContent())); $this->set_user_agent(self::USER_AGENT_IE6); - $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/'.$basket_element->get_sselcont_id().'/'); + $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('', trim($this->client->getResponse()->getContent())); $this->set_user_agent(self::USER_AGENT_IPHONE); - $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/'.$basket_element->get_sselcont_id().'/'); + $crawler = $this->client->request('GET', '/ajax/NOTE_FORM/' . $basket_element->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertNotEquals('', trim($this->client->getResponse()->getContent())); } public function testAjaxElement() { - $basket_element = $this->get_basket_element(); + $basket_element = $this->insertOneBasketElement(); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); - $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/'.$basket_element->get_sselcont_id().'/'); + $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $datas = json_decode($this->client->getResponse()->getContent()); @@ -176,7 +114,7 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->set_user_agent(self::USER_AGENT_IE6); - $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/'.$basket_element->get_sselcont_id().'/'); + $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $datas = json_decode($this->client->getResponse()->getContent()); @@ -192,7 +130,7 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->set_user_agent(self::USER_AGENT_IPHONE); - $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/'.$basket_element->get_sselcont_id().'/'); + $crawler = $this->client->request('GET', '/ajax/LOAD_BASKET_ELEMENT/' . $basket_element->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertNotEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); } @@ -201,7 +139,7 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract { $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); - $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/'.$this->entry->get_id().'/'.$this->item->get_id().'/'); + $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $datas = json_decode($this->client->getResponse()->getContent()); @@ -217,7 +155,7 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->set_user_agent(self::USER_AGENT_IE6); - $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/'.$this->entry->get_id().'/'.$this->item->get_id().'/'); + $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $datas = json_decode($this->client->getResponse()->getContent()); @@ -233,7 +171,7 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->set_user_agent(self::USER_AGENT_IPHONE); - $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/'.$this->entry->get_id().'/'.$this->item->get_id().'/'); + $crawler = $this->client->request('GET', '/ajax/LOAD_FEED_ITEM/' . $this->entry->get_id() . '/' . $this->item->get_id() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertNotEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); } @@ -241,46 +179,46 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract public function testValidate() { - $basket = $this->get_basket(); + $basket = $this->insertOneBasket(); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); - $crawler = $this->client->request('GET', '/validate/'.$basket->get_ssel_id().'/'); + $crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->set_user_agent(self::USER_AGENT_IE6); - $crawler = $this->client->request('GET', '/validate/'.$basket->get_ssel_id().'/'); + $crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->set_user_agent(self::USER_AGENT_IPHONE); - $crawler = $this->client->request('GET', '/validate/'.$basket->get_ssel_id().'/'); + $crawler = $this->client->request('GET', '/validate/' . $basket->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); } public function testCompare() { - $basket = $this->get_basket(); + $basket = $this->insertOneBasket(); $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); - $crawler = $this->client->request('GET', '/compare/'.$basket->get_ssel_id().'/'); + $crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->set_user_agent(self::USER_AGENT_IE6); - $crawler = $this->client->request('GET', '/compare/'.$basket->get_ssel_id().'/'); + $crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->set_user_agent(self::USER_AGENT_IPHONE); - $crawler = $this->client->request('GET', '/compare/'.$basket->get_ssel_id().'/'); + $crawler = $this->client->request('GET', '/compare/' . $basket->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); } @@ -289,54 +227,66 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract { $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); - $crawler = $this->client->request('GET', '/feeds/entry/'.$this->entry->get_id().'/'); + $crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->set_user_agent(self::USER_AGENT_IE6); - $crawler = $this->client->request('GET', '/feeds/entry/'.$this->entry->get_id().'/'); + $crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); $this->set_user_agent(self::USER_AGENT_IPHONE); - $crawler = $this->client->request('GET', '/feeds/entry/'.$this->entry->get_id().'/'); + $crawler = $this->client->request('GET', '/feeds/entry/' . $this->entry->get_id() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); } public function testAjaxReport() { + $validationBasket = $this->insertOneValidationBasket(); + $this->set_user_agent(self::USER_AGENT_FIREFOX8MAC); - $crawler = $this->client->request('GET', '/ajax/LOAD_REPORT/'.$this->validation_basket->get_ssel_id().'/'); + $crawler = $this->client->request('GET', '/ajax/LOAD_REPORT/' . $validationBasket->getId() . '/'); $this->assertEquals(200, $this->client->getResponse()->getStatusCode()); $this->assertEquals('UTF-8', $this->client->getResponse()->getCharset()); } + public function testAjaxSetNote() { - $crawler = $this->client->request('POST', '/ajax/SET_NOTE/'.$this->get_basket_element()->get_sselcont_id().'/'); + $crawler = $this->client->request('POST', '/ajax/SET_NOTE/' . $this->insertOneBasketElement()->getId() . '/'); $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); - $crawler = $this->client->request('POST', '/ajax/SET_NOTE/'.$this->get_validation_basket_element()->get_sselcont_id().'/'); + $validationBasket = $this->insertOneValidationBasket(); + $validationBasketElement = $validationBasket->getElements()->first(); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ',$this->get_validation_basket_element()->get_sselcont_id())); + $crawler = $this->client->request('POST', '/ajax/SET_NOTE/' . $validationBasketElement->getId() . '/'); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasketElement->getId())); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $datas = json_decode($this->client->getResponse()->getContent()); $this->assertTrue(is_object($datas), 'asserting good json datas'); $this->assertObjectHasAttribute('datas', $datas); $this->assertObjectHasAttribute('error', $datas); - } + public function testAjaxSetAgreement() { - $crawler = $this->client->request('POST', '/ajax/SET_ELEMENT_AGREEMENT/'.$this->get_basket_element()->get_sselcont_id().'/'); + $basket = $this->insertOneBasket(); + $basketElement = $basket->getElements()->first(); + + $crawler = $this->client->request('POST', '/ajax/SET_ELEMENT_AGREEMENT/' . $basketElement->getId() . '/'); $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); - $crawler = $this->client->request('POST', '/ajax/SET_ELEMENT_AGREEMENT/'.$this->get_validation_basket_element()->get_sselcont_id().'/'); + $validationBasket = $this->insertOneValidationBasket(); + $validationBasketElement = $validationBasket->getElements()->first(); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ',$this->get_validation_basket_element()->get_sselcont_id())); + $crawler = $this->client->request('POST', '/ajax/SET_ELEMENT_AGREEMENT/' . $validationBasketElement->getId() . '/'); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasketElement->getId())); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $datas = json_decode($this->client->getResponse()->getContent()); @@ -344,14 +294,19 @@ class Module_LightboxTest extends PhraseanetWebTestCaseAuthenticatedAbstract $this->assertObjectHasAttribute('datas', $datas); $this->assertObjectHasAttribute('error', $datas); } + public function testAjaxSetRelease() { - $crawler = $this->client->request('POST', '/ajax/SET_RELEASE/'.$this->get_basket()->get_ssel_id().'/'); + $basket = $this->insertOneBasket(); + + $crawler = $this->client->request('POST', '/ajax/SET_RELEASE/' . $basket->getId() . '/'); $this->assertEquals(400, $this->client->getResponse()->getStatusCode()); - $crawler = $this->client->request('POST', '/ajax/SET_RELEASE/'.$this->get_validation_basket()->get_ssel_id().'/'); + $validationBasket = $this->insertOneValidationBasket(); - $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ',$this->get_validation_basket()->get_ssel_id())); + $crawler = $this->client->request('POST', '/ajax/SET_RELEASE/' . $validationBasket->getId() . '/'); + + $this->assertEquals(200, $this->client->getResponse()->getStatusCode(), sprintf('set note to element %s ', $validationBasket->getId())); $this->assertEquals('application/json', $this->client->getResponse()->headers->get('Content-type')); $datas = json_decode($this->client->getResponse()->getContent()); diff --git a/lib/unitTest/module/prod/route/tooltipapplicationTest.php b/lib/unitTest/module/prod/route/tooltipapplicationTest.php index f87b4201cd..b6d4f94005 100644 --- a/lib/unitTest/module/prod/route/tooltipapplicationTest.php +++ b/lib/unitTest/module/prod/route/tooltipapplicationTest.php @@ -27,10 +27,8 @@ class Module_Prod_Route_TooltipTest extends PhraseanetWebTestCaseAuthenticatedAb public function testRouteBasket() { $appbox = appbox::get_instance(); - $basketcoll = new basketCollection($appbox, self::$user->get_id()); - $basket_coll = $basketcoll->get_baskets(); - $basket = array_shift($basket_coll['baskets']); + $basket = $this->insertOneBasket(); $crawler = $this->client->request('POST', '/tooltip/basket/' . $basket->getId() . '/'); $pageContent = $this->client->getResponse()->getContent(); diff --git a/lib/unitTest/record/adapterTest.php b/lib/unitTest/record/adapterTest.php index 7be9f8593c..c4f55049b3 100644 --- a/lib/unitTest/record/adapterTest.php +++ b/lib/unitTest/record/adapterTest.php @@ -473,15 +473,25 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract { $appbox = appbox::get_instance(); $usr_id = $appbox->get_session()->get_usr_id(); - $basket_coll = new basketCollection($appbox, $usr_id); - $baskets = $basket_coll->get_baskets(); - $baskets = $baskets['baskets']; + + $em = self::$core->getEntityManager(); - $basket = array_shift($baskets); + $basket = $this->insertOneBasket(); $this->assertInstanceOf('\Entities\Basket', $basket); - - $basket->push_element(self::$record_1, false, false); - + + /* @var $basket \Entities\Basket */ + $basket_element = new \Entities\BasketElement(); + $basket_element->setRecord(self::$record_1); + $basket_element->setBasket($basket); + + $em->persist($basket_element); + + $basket->addBasketElement($basket_element); + + $em->merge($basket); + + $em->flush(); + $found = $sselcont_id = false; $sbas_id = self::$record_1->get_sbas_id(); @@ -489,7 +499,7 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract foreach (self::$record_1->get_container_baskets() as $c_basket) { - if ($c_basket->getId() == $basket->get_ssel_id()) + if ($c_basket->getId() == $basket->getId()) { $found = true; foreach ($c_basket->getElements() as $b_el) @@ -504,7 +514,6 @@ class record_adapterTest extends PhraseanetPHPUnitAuthenticatedAbstract if (!$found) $this->fail(); - $basket->remove_from_ssel($sselcont_id); } } diff --git a/lib/vendor/symfony b/lib/vendor/symfony index 6924e63587..4316595dbb 160000 --- a/lib/vendor/symfony +++ b/lib/vendor/symfony @@ -1 +1 @@ -Subproject commit 6924e63587466c865ca8dc746ff3fcf5cd1a1dcf +Subproject commit 4316595dbb7be9dcf2156d090d52f23f11b1ea90 diff --git a/templates/mobile/lightbox/index.twig b/templates/mobile/lightbox/index.twig index 325fd98d3a..dd804c3f66 100644 --- a/templates/mobile/lightbox/index.twig +++ b/templates/mobile/lightbox/index.twig @@ -13,27 +13,23 @@ {% endblock %} {% macro valid_baskets_length(baskets) %} - {% set foo = 0 %} + {% set number = 0 %} {% for item in baskets %} - {% if item.is_valid() %} - {% set foo = foo + 1 %} + {% if item.getValidation() %} + {% set number = number + 1 %} {% endif %} {% endfor %} - {{foo}} + {{number}} {% endmacro %} -{% macro baskets_length(baskets_collection) %} - {% set foo = 0 %} - {% for key,baskets in baskets_collection.get_baskets() %} - {% if key == 'baskets' or key == 'recept' %} - {% for item in baskets %} - {% if item.is_valid() == false %} - {% set foo = foo + 1 %} - {% endif %} - {% endfor %} +{% macro baskets_length(baskets) %} + {% set number = 0 %} + {% for item in baskets %} + {% if item.getValidation() == false %} + {% set number = number + 1 %} {% endif %} {% endfor %} - {{foo}} + {{number}} {% endmacro %} {% block content %} @@ -46,7 +42,7 @@