[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 use_helper('Form', 'Javascript', 'Helper'); 4 5 /* 6 * This file is part of the symfony package. 7 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com> 8 * 9 * For the full copyright and license information, please view the LICENSE 10 * file that was distributed with this source code. 11 */ 12 13 /** 14 * ObjectHelper for admin generator. 15 * 16 * @package symfony 17 * @subpackage helper 18 * @author Fabien Potencier <fabien.potencier@symfony-project.com> 19 * @version SVN: $Id: ObjectAdminHelper.php 3311 2007-01-20 06:24:41Z fabien $ 20 */ 21 22 function object_admin_input_file_tag($object, $method, $options = array()) 23 { 24 $options = _parse_attributes($options); 25 $name = _convert_method_to_name($method, $options); 26 27 $html = ''; 28 29 $value = _get_object_value($object, $method); 30 31 if ($value) 32 { 33 if ($include_link = _get_option($options, 'include_link')) 34 { 35 $image_path = image_path('/'.sfConfig::get('sf_upload_dir_name').'/'.$include_link.'/'.$value); 36 $image_text = ($include_text = _get_option($options, 'include_text')) ? __($include_text) : __('[show file]'); 37 38 $html .= sprintf('<a onclick="window.open(this.href);return false;" href="%s">%s</a>', $image_path, $image_text)."\n"; 39 } 40 41 if ($include_remove = _get_option($options, 'include_remove')) 42 { 43 $html .= checkbox_tag(strpos($name, ']') !== false ? substr($name, 0, -1).'_remove]' : $name).' '.($include_remove != true ? __($include_remove) : __('remove file'))."\n"; 44 } 45 } 46 47 return input_file_tag($name, $options)."\n<br />".$html; 48 } 49 50 function object_admin_double_list($object, $method, $options = array(), $callback = null) 51 { 52 $options = _parse_attributes($options); 53 54 $options['multiple'] = true; 55 $options['class'] = 'sf_admin_multiple'; 56 if (!isset($options['size'])) 57 { 58 $options['size'] = 10; 59 } 60 $label_all = __(isset($options['unassociated_label']) ? $options['unassociated_label'] : 'Unassociated'); 61 $label_assoc = __(isset($options['associated_label']) ? $options['associated_label'] : 'Associated'); 62 63 // get the lists of objects 64 list($all_objects, $objects_associated, $associated_ids) = _get_object_list($object, $method, $options, $callback); 65 66 $objects_unassociated = array(); 67 foreach ($all_objects as $object) 68 { 69 if (!in_array($object->getPrimaryKey(), $associated_ids)) 70 { 71 $objects_unassociated[] = $object; 72 } 73 } 74 75 // override field name 76 unset($options['control_name']); 77 $name = _convert_method_to_name($method, $options); 78 $name1 = 'unassociated_'.$name; 79 $name2 = 'associated_'.$name; 80 $select1 = select_tag($name1, options_for_select(_get_options_from_objects($objects_unassociated), '', $options), $options); 81 $options['class'] = 'sf_admin_multiple-selected'; 82 $select2 = select_tag($name2, options_for_select(_get_options_from_objects($objects_associated), '', $options), $options); 83 84 $html = 85 '<div> 86 <div style="float: left"> 87 <div style="font-weight: bold; padding-bottom: 0.5em">%s</div> 88 %s 89 </div> 90 <div style="float: left"> 91 %s<br /> 92 %s 93 </div> 94 <div style="float: left"> 95 <div style="font-weight: bold; padding-bottom: 0.5em">%s</div> 96 %s 97 </div> 98 <br style="clear: both" /> 99 </div> 100 '; 101 102 $response = sfContext::getInstance()->getResponse(); 103 $response->addJavascript(sfConfig::get('sf_prototype_web_dir').'/js/prototype'); 104 $response->addJavascript(sfConfig::get('sf_admin_web_dir').'/js/double_list'); 105 106 return sprintf($html, 107 $label_all, 108 $select1, 109 submit_image_tag(sfConfig::get('sf_admin_web_dir').'/images/next.png', "style=\"border: 0\" onclick=\"double_list_move(\$('{$name1}'), \$('{$name2}')); return false;\""), 110 submit_image_tag(sfConfig::get('sf_admin_web_dir').'/images/previous.png', "style=\"border: 0\" onclick=\"double_list_move(\$('{$name2}'), \$('{$name1}')); return false;\""), 111 $label_assoc, 112 $select2 113 ); 114 } 115 116 function object_admin_select_list($object, $method, $options = array(), $callback = null) 117 { 118 $options = _parse_attributes($options); 119 120 $options['multiple'] = true; 121 $options['class'] = 'sf_admin_multiple'; 122 if (!isset($options['size'])) 123 { 124 $options['size'] = 10; 125 } 126 127 // get the lists of objects 128 list($objects, $objects_associated, $ids) = _get_object_list($object, $method, $options, $callback); 129 // override field name 130 unset($options['control_name']); 131 $name = 'associated_'._convert_method_to_name($method, $options); 132 133 return select_tag($name, options_for_select(_get_options_from_objects($objects), $ids, $options), $options); 134 } 135 136 function object_admin_check_list($object, $method, $options = array(), $callback = null) 137 { 138 $options = _parse_attributes($options); 139 140 // get the lists of objects 141 list($objects, $objects_associated, $assoc_ids) = _get_object_list($object, $method, $options, $callback); 142 143 // override field name 144 unset($options['control_name']); 145 $name = 'associated_'._convert_method_to_name($method, $options).'[]'; 146 $html = ''; 147 148 if (!empty($objects)) 149 { 150 // which method to call? 151 $methodToCall = '__toString'; 152 foreach (array('__toString', 'toString', 'getPrimaryKey') as $method) 153 { 154 if (method_exists($objects[0], $method)) 155 { 156 $methodToCall = $method; 157 break; 158 } 159 } 160 161 $html .= "<ul class=\"sf_admin_checklist\">\n"; 162 foreach ($objects as $related_object) 163 { 164 $relatedPrimaryKey = $related_object->getPrimaryKey(); 165 166 // multi primary key handling 167 if (is_array($relatedPrimaryKey)) 168 { 169 $relatedPrimaryKeyHtmlId = implode('/', $relatedPrimaryKey); 170 } 171 else 172 { 173 $relatedPrimaryKeyHtmlId = $relatedPrimaryKey; 174 } 175 176 $html .= '<li>'.checkbox_tag($name, $relatedPrimaryKeyHtmlId, in_array($relatedPrimaryKey, $assoc_ids)).' <label for="'.get_id_from_name($name, $relatedPrimaryKeyHtmlId).'">'.$related_object->$methodToCall()."</label></li>\n"; 177 } 178 $html .= "</ul>\n"; 179 } 180 181 return $html; 182 } 183 184 function _get_propel_object_list($object, $method, $options) 185 { 186 // get the lists of objects 187 $through_class = _get_option($options, 'through_class'); 188 189 $objects = sfPropelManyToMany::getAllObjects($object, $through_class); 190 $objects_associated = sfPropelManyToMany::getRelatedObjects($object, $through_class); 191 $ids = array_map(create_function('$o', 'return $o->getPrimaryKey();'), $objects_associated); 192 193 return array($objects, $objects_associated, $ids); 194 } 195 196 function _get_object_list($object, $method, $options, $callback) 197 { 198 $object = get_class($object) == 'sfOutputEscaperObjectDecorator' ? $object->getRawValue() : $object; 199 // the default callback is the propel one 200 if (!$callback) 201 { 202 $callback = '_get_propel_object_list'; 203 } 204 205 return call_user_func($callback, $object, $method, $options); 206 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |