/** * pre-execution: * - get the request parameters, * - prepare variables */ public function preExecute() { $item_model = $this->getRequestParameter('item_model'); $item_pk = $this->getRequestParameter('item_pk'); $this->namespace = $this->getRequestParameter('namespace'); $this->item = deppPropelActAsLaunchableToolkit::retrieveLaunchableObject($item_model, $item_pk); }
/** * Return the HTML code for the launch/remove link * plus the list of launched object for the namespace * * @param BaseObject $object Propel object instance to launch * @param string $namespace The namespace where the object is *launched* * @param array $options Array of HTML options to apply on the HTML list * @return string **/ function depp_launcher($object, $namespace, $options = array()) { if (is_null($object)) { sfLogger::getInstance()->debug('A NULL object cannot be launched'); return ''; } if (is_null($namespace)) { sfLogger::getInstance()->debug('A namespace must be given'); return ''; } try { $options = _parse_attributes($options); if (!isset($options['id'])) { $options = array_merge($options, array('id' => 'launching-items')); } if (!isset($options['class'])) { $options = array_merge($options, array('class' => 'vote-administration')); } $object_model = get_class($object); $object_id = $object->getPrimaryKey(); // build launch/remove link if (in_array($namespace, $object->hasBeenLaunched())) { $action_link = link_to(__('Take the launch back'), sprintf('deppLaunching/remove?item_model=%s&item_pk=%s&namespace=%s', $object_model, $object_id, $namespace)); } else { $action_link = link_to(__('Launch the object'), sprintf('deppLaunching/launch?item_model=%s&item_pk=%s&namespace=%s', $object_model, $object_id, $namespace)); } $action = content_tag('div', $action_link); $list_content = ''; $launches = sfLaunchingPeer::getAllByNamespace($namespace); foreach ($launches as $i => $l) { $l_obj_model = $l->getObjectModel(); $l_obj_id = $l->getObjectId(); $l_obj = deppPropelActAsLaunchableToolkit::retrieveLaunchableObject($l_obj_model, $l_obj_id); $l_obj_short_string = $l_obj->getShortTitle(); $l_obj_remove_action = sprintf('deppLaunching/remove?item_model=%s&item_pk=%s&namespace=%s', $l_obj_model, $l_obj_id, $namespace); $l_obj_priority_up_action = sprintf('deppLaunching/priorityUp?item_model=%s&item_pk=%s&namespace=%s', $l_obj_model, $l_obj_id, $namespace); $l_obj_priority_dn_action = sprintf('deppLaunching/priorityDn?item_model=%s&item_pk=%s&namespace=%s', $l_obj_model, $l_obj_id, $namespace); $l_obj_remove_link = link_to('<img src="/images/ico-remove_alert.png" alt="X" title="Rimuovi" />', $l_obj_remove_action, array('title' => __('Take the launch back'), 'class' => 'remove-vote')); $l_obj_priority_up_link = link_to('<img src="/images/ico-thumb-up.png" alt="+" title="Aumenta priorità" />', $l_obj_priority_up_action, array('title' => __('Increase the priority'), 'class' => 'moveup-vote')); $l_obj_priority_dn_link = link_to('<img src="/images/ico-thumb-down.png" alt="-" title="Diminuisci priorità" />', $l_obj_priority_dn_action, array('title' => __('Decrease the priority'), 'class' => 'movedown-vote')); $l_obj_actions = ""; /*if ($i > 0)*/ $l_obj_actions .= " {$l_obj_priority_up_link} "; /*if ($i < count($launches) - 1 )*/ $l_obj_actions .= " {$l_obj_priority_dn_link} "; $l_obj_actions .= " {$l_obj_remove_link} "; /*$list_content .= content_tag('tr', content_tag('td', '<input type="text" value="'. $l->getPriority().'" name="priority['. $l_obj_id.']" size="3">'. $l_obj_short_string) . content_tag('td', $l_obj_actions, array('style' => 'text-align:right; width:36px;display:inline-block;')));*/ $list_content .= content_tag('li', content_tag('span', $l_obj_actions, array('style' => 'text-align:right; width:36px;display:inline-block;float:right;')) . $l_obj_short_string, array('style' => 'cursor:move; border-bottom: 1px dotted #CCC;')); } $list = content_tag('ul', $list_content, $options); // adding javascript for drag and drop //use_javascript('/js/jquery-ui-1.8.16.sortable.min.js'); return $action . $list; } catch (Exception $e) { sfLogger::getInstance()->err('Exception catched from deppLaunching helper: ' . $e->getMessage()); } }
public function decreasePriority(BaseObject $object, $namespace = 'home', $paths = 1) { if (!is_string($namespace)) { throw new deppPropelActAsLaunchableException('Namespace can only be a string'); } $l = sfLaunchingPeer::retrieveByModelIdNamespace(get_class($object), $object->getPrimaryKey(), $namespace); for ($i = 1; $i <= $paths; $i++) { //echo " $i/$paths ". $l->getPriority(); $prev_l = sfLaunchingPeer::retrievePrevByModelIdNamespace(get_class($object), $object->getPrimaryKey(), $namespace); deppPropelActAsLaunchableToolkit::swapPriorities($prev_l, $l); } }
$t->diag('List of launched objects'); $launched_ids = sfLaunchingPeer::getAllPositivelyLaunchedIds($user_1_id); $t->ok($launched_ids[TEST_CLASS][0] == $obj1->getId(), 'sfLaunchingPeer::getAllPositivelyLaunchedIds() - is working'); $launched_ids = sfLaunchingPeer::getAllPositivelyLaunchedIds($user_2_id); $t->ok($launched_ids == array(), 'sfLaunchingPeer::getAllPositivelyLaunchedIds() - empty case scenario'); $launched_ids = sfLaunchingPeer::getAllNegativelyLaunchedIds($user_2_id); $t->ok($launched_ids[TEST_CLASS][0] == $obj1->getId(), 'sfLaunchingPeer::getAllNegativelyLaunchedIds() - is working'); $launched_ids = sfLaunchingPeer::getAllNegativelyLaunchedIds($user_1_id); $t->ok($launched_ids == array(), 'sfLaunchingPeer::getAllNegativelyLaunchedIds() - empty case scenario'); $launched_objs = sfLaunchingPeer::getAllPositivelyLaunched($user_1_id); $t->ok($launched_objs[0] == $obj1, 'sfLaunchingPeer::getAllPositivelyLaunched() - is working'); $launched_objs = sfLaunchingPeer::getAllNegativelyLaunched($user_2_id); $t->ok($launched_objs[0] == $obj1, 'sfLaunchingPeer::getAllNegativelyLaunched() - is working'); $launched_objs = sfLaunchingPeer::getAllPositivelyLaunched($user_2_id); $t->ok($launched_objs == array(), 'sfLaunchingPeer::getAllPositivelyLaunched() - empty case'); $t->diag('List of some toolkit methods'); $t->ok(deppPropelActAsLaunchableToolkit::isLaunchable(TEST_CLASS) == true, 'deppPropelActAsLaunchableToolkit::isLaunchable() - is working'); $t->diag('Tests terminated'); // test object creation function _create_object() { $classname = TEST_CLASS; $method = TEST_METHOD_SETTER; if (!class_exists($classname)) { throw new Exception(sprintf('Unknow class "%s"', $classname)); } $obj = new $classname(); // set a field to set the status of the object to isModified and have the doSave() function work $obj->{$method}('Trial value'); return $obj; }