| @@ -102,7 +102,7 @@ discard block | ||
| 102 | 102 | public function __construct(Func_App $app, $id = null, Widget_Layout $layout = null) | 
| 103 | 103 |      { | 
| 104 | 104 | parent::__construct($app); | 
| 105 | - // We simulate inheritance from Widget_VBoxLayout. | |
| 105 | + // We simulate inheritance from Widget_VBoxLayout. | |
| 106 | 106 | $W = $this->widgets = bab_Widgets(); | 
| 107 | 107 | |
| 108 | 108 | |
| @@ -307,9 +307,9 @@ discard block | ||
| 307 | 307 |              $cancelLabel = isset($this->cancelLabel) ? $this->cancelLabel : $App->translate('Cancel'); | 
| 308 | 308 | $this->addButton( | 
| 309 | 309 | $W->SubmitButton(/*'cancel'*/) | 
| 310 | -                     ->addClass('widget-close-dialog') | |
| 310 | +                        ->addClass('widget-close-dialog') | |
| 311 | 311 | ->setAction($this->cancelAction) | 
| 312 | - ->setLabel($cancelLabel) | |
| 312 | + ->setLabel($cancelLabel) | |
| 313 | 313 | ); | 
| 314 | 314 | } | 
| 315 | 315 | |
| @@ -1148,21 +1148,21 @@ discard block | ||
| 1148 | 1148 | |
| 1149 | 1149 | |
| 1150 | 1150 | |
| 1151 | - protected function addCustomFields(app_RecordSet $recordSet) | |
| 1152 | -	{ | |
| 1153 | - $customFields = $recordSet->getCustomFields(); | |
| 1151 | + protected function addCustomFields(app_RecordSet $recordSet) | |
| 1152 | +    { | |
| 1153 | + $customFields = $recordSet->getCustomFields(); | |
| 1154 | 1154 | |
| 1155 | 1155 |          foreach ($customFields as $customField) { | 
| 1156 | 1156 | $fieldname = $customField->fieldname; | 
| 1157 | 1157 | $this->addColumn( | 
| 1158 | 1158 | widget_TableModelViewColumn($recordSet->$fieldname, $customField->name) | 
| 1159 | - ->setSortable(true) | |
| 1160 | - ->setExportable(true) | |
| 1161 | - ->setSearchable($customField->searchable) | |
| 1162 | - ->setVisible($customField->visible) | |
| 1159 | + ->setSortable(true) | |
| 1160 | + ->setExportable(true) | |
| 1161 | + ->setSearchable($customField->searchable) | |
| 1162 | + ->setVisible($customField->visible) | |
| 1163 | 1163 | ); | 
| 1164 | 1164 | } | 
| 1165 | - } | |
| 1165 | + } | |
| 1166 | 1166 | |
| 1167 | 1167 | |
| 1168 | 1168 | /** | 
| @@ -1642,7 +1642,7 @@ | ||
| 1642 | 1642 | $W->SubmitButton() | 
| 1643 | 1643 | ->setAjaxAction($confirmedAction) | 
| 1644 | 1644 |                  ->setLabel($App->translate('Delete')) | 
| 1645 | - ); | |
| 1645 | + ); | |
| 1646 | 1646 |          $form->addButton($W->SubmitButton()->setLabel($App->translate('Cancel'))->addClass('widget-close-dialog')); | 
| 1647 | 1647 | $page->addItem($form); | 
| 1648 | 1648 | |
| @@ -94,13 +94,13 @@ discard block | ||
| 94 | 94 | |
| 95 | 95 | |
| 96 | 96 | |
| 97 | - /** | |
| 98 | - * @return Widget_Page | |
| 99 | - */ | |
| 100 | - public function edit($customfield = null) | |
| 101 | -	{ | |
| 102 | - $W = bab_Widgets(); | |
| 103 | - $App = $this->App(); | |
| 97 | + /** | |
| 98 | + * @return Widget_Page | |
| 99 | + */ | |
| 100 | + public function edit($customfield = null) | |
| 101 | +    { | |
| 102 | + $W = bab_Widgets(); | |
| 103 | + $App = $this->App(); | |
| 104 | 104 | // $access = $Crm->Access(); | 
| 105 | 105 | |
| 106 | 106 |  // 		if (!$access->viewShopAdmin()) { | 
| @@ -109,134 +109,134 @@ discard block | ||
| 109 | 109 | |
| 110 | 110 |  // 		crm_BreadCrumbs::setCurrentPosition($this->proxy()->edit($customfield), $Crm->translate('Edit custom field')); | 
| 111 | 111 | |
| 112 | - /* @var $Ui app_Ui */ | |
| 113 | - $Ui = $App->Ui(); | |
| 114 | - $page = $Ui->Page(); | |
| 112 | + /* @var $Ui app_Ui */ | |
| 113 | + $Ui = $App->Ui(); | |
| 114 | + $page = $Ui->Page(); | |
| 115 | 115 | |
| 116 | -		$page->addClass('app-page-editor'); | |
| 117 | -		$page->setTitle($App->translate('Edit custom field')); | |
| 116 | +        $page->addClass('app-page-editor'); | |
| 117 | +        $page->setTitle($App->translate('Edit custom field')); | |
| 118 | 118 | |
| 119 | -		if (null !== $customfield) { | |
| 120 | - $set = $App->CustomFieldSet(); | |
| 121 | - $customfield = $set->request($customfield); | |
| 122 | - } | |
| 119 | +        if (null !== $customfield) { | |
| 120 | + $set = $App->CustomFieldSet(); | |
| 121 | + $customfield = $set->request($customfield); | |
| 122 | + } | |
| 123 | 123 | |
| 124 | 124 | |
| 125 | 125 | |
| 126 | - $form = $Ui->CustomFieldEditor($customfield); | |
| 126 | + $form = $Ui->CustomFieldEditor($customfield); | |
| 127 | 127 | |
| 128 | - $page->addItem($form); | |
| 128 | + $page->addItem($form); | |
| 129 | 129 | |
| 130 | -		if ($customfield instanceof app_CustomField) { | |
| 131 | - $actionsFrame = $page->ActionsFrame(); | |
| 132 | - $page->addContextItem($actionsFrame); | |
| 130 | +        if ($customfield instanceof app_CustomField) { | |
| 131 | + $actionsFrame = $page->ActionsFrame(); | |
| 132 | + $page->addContextItem($actionsFrame); | |
| 133 | 133 | |
| 134 | -			$actionsFrame->addItem($W->Link($W->Icon($App->translate('Delete'), Func_Icons::ACTIONS_EDIT_DELETE), $this->proxy()->delete($customfield->id))); | |
| 135 | - } | |
| 134 | +            $actionsFrame->addItem($W->Link($W->Icon($App->translate('Delete'), Func_Icons::ACTIONS_EDIT_DELETE), $this->proxy()->delete($customfield->id))); | |
| 135 | + } | |
| 136 | 136 | |
| 137 | - return $page; | |
| 138 | - } | |
| 137 | + return $page; | |
| 138 | + } | |
| 139 | 139 | |
| 140 | 140 | |
| 141 | - /** | |
| 142 | - * @return bool | |
| 143 | - */ | |
| 144 | - public function save($customfield = null) | |
| 145 | -	{ | |
| 146 | - $App = $this->App(); | |
| 141 | + /** | |
| 142 | + * @return bool | |
| 143 | + */ | |
| 144 | + public function save($customfield = null) | |
| 145 | +    { | |
| 146 | + $App = $this->App(); | |
| 147 | 147 | // $access = $Crm->Access(); | 
| 148 | 148 | |
| 149 | 149 |  // 		if (!$access->viewShopAdmin()) { | 
| 150 | 150 |  // 			throw new crm_AccessException($Crm->translate('Access denied to online shop administration')); | 
| 151 | 151 | // } | 
| 152 | 152 | |
| 153 | - $set = $App->CustomFieldSet(); | |
| 153 | + $set = $App->CustomFieldSet(); | |
| 154 | 154 | |
| 155 | -		if (empty($customfield['id'])) { | |
| 156 | - $record = $set->newRecord(); | |
| 157 | -		} else { | |
| 158 | - $record = $set->get($customfield['id']); | |
| 155 | +        if (empty($customfield['id'])) { | |
| 156 | + $record = $set->newRecord(); | |
| 157 | +        } else { | |
| 158 | + $record = $set->get($customfield['id']); | |
| 159 | 159 |  // 			if (null == $record) { | 
| 160 | 160 |  // 				throw new crm_SaveException($Crm->translate('This custom field does not exists')); | 
| 161 | 161 | // } | 
| 162 | - } | |
| 162 | + } | |
| 163 | 163 | |
| 164 | -		if ('Enum' === $customfield['fieldtype'] || 'Set' === $customfield['fieldtype']) { | |
| 165 | - $enumvalues = array(); | |
| 166 | -		    foreach ($customfield['enumvalues'] as $enumkey => $enumvalue) { | |
| 167 | - $enumvalues[$enumkey] = $set->enumvalues->input($enumvalue); | |
| 168 | - } | |
| 169 | - $record->enumvalues = serialize($enumvalues); | |
| 170 | -		} else { | |
| 171 | - $record->enumvalues = ''; | |
| 172 | - } | |
| 164 | +        if ('Enum' === $customfield['fieldtype'] || 'Set' === $customfield['fieldtype']) { | |
| 165 | + $enumvalues = array(); | |
| 166 | +            foreach ($customfield['enumvalues'] as $enumkey => $enumvalue) { | |
| 167 | + $enumvalues[$enumkey] = $set->enumvalues->input($enumvalue); | |
| 168 | + } | |
| 169 | + $record->enumvalues = serialize($enumvalues); | |
| 170 | +        } else { | |
| 171 | + $record->enumvalues = ''; | |
| 172 | + } | |
| 173 | 173 | |
| 174 | - unset($customfield['enumvalues']); | |
| 175 | - $record->setFormInputValues($customfield); | |
| 174 | + unset($customfield['enumvalues']); | |
| 175 | + $record->setFormInputValues($customfield); | |
| 176 | 176 | |
| 177 | 177 | |
| 178 | - $record->save(); | |
| 178 | + $record->save(); | |
| 179 | 179 | |
| 180 | 180 | |
| 181 | - // refresh target table structure | |
| 181 | + // refresh target table structure | |
| 182 | 182 | |
| 183 | - $object = $record->object.'Set'; | |
| 184 | - $mysqlbackend = new ORM_MySqlBackend($GLOBALS['babDB']); | |
| 183 | + $object = $record->object.'Set'; | |
| 184 | + $mysqlbackend = new ORM_MySqlBackend($GLOBALS['babDB']); | |
| 185 | 185 | |
| 186 | - $recordSet = $App->$object(); | |
| 187 | -		if (method_exists($recordSet, 'useLang')) { | |
| 188 | - // This is necessary if the recordSet constructor uses a setLang(). | |
| 189 | - // We need to revert to multilang fields before synchronizing. | |
| 190 | - $recordSet->useLang(false); | |
| 191 | - } | |
| 186 | + $recordSet = $App->$object(); | |
| 187 | +        if (method_exists($recordSet, 'useLang')) { | |
| 188 | + // This is necessary if the recordSet constructor uses a setLang(). | |
| 189 | + // We need to revert to multilang fields before synchronizing. | |
| 190 | + $recordSet->useLang(false); | |
| 191 | + } | |
| 192 | 192 | |
| 193 | - $sql = $mysqlbackend->setToSql($recordSet); | |
| 193 | + $sql = $mysqlbackend->setToSql($recordSet); | |
| 194 | 194 | |
| 195 | - require_once $GLOBALS['babInstallPath'].'utilit/devtools.php'; | |
| 196 | - $synchronize = new bab_synchronizeSql(); | |
| 197 | - $synchronize->fromSqlString($sql); | |
| 195 | + require_once $GLOBALS['babInstallPath'].'utilit/devtools.php'; | |
| 196 | + $synchronize = new bab_synchronizeSql(); | |
| 197 | + $synchronize->fromSqlString($sql); | |
| 198 | 198 | |
| 199 | - return true; | |
| 200 | - } | |
| 199 | + return true; | |
| 200 | + } | |
| 201 | 201 | |
| 202 | 202 | |
| 203 | 203 | /** | 
| 204 | 204 |       * {@inheritDoc} | 
| 205 | 205 | * @see app_CtrlRecord::delete() | 
| 206 | 206 | */ | 
| 207 | - public function delete($customfield) | |
| 208 | -	{ | |
| 209 | - $App = $this->App(); | |
| 207 | + public function delete($customfield) | |
| 208 | +    { | |
| 209 | + $App = $this->App(); | |
| 210 | 210 | // $access = $Crm->Access(); | 
| 211 | 211 | |
| 212 | 212 |  // 		if (!$access->viewShopAdmin()) { | 
| 213 | 213 |  // 			throw new crm_AccessException($Crm->translate('Access denied to online shop administration')); | 
| 214 | 214 | // } | 
| 215 | 215 | |
| 216 | - if (!$customfield) | |
| 217 | -		{ | |
| 218 | -		    throw new app_AccessException($App->translate('Access denied')); | |
| 219 | - } | |
| 216 | + if (!$customfield) | |
| 217 | +        { | |
| 218 | +            throw new app_AccessException($App->translate('Access denied')); | |
| 219 | + } | |
| 220 | 220 | |
| 221 | - $set = $App->CustomFieldSet(); | |
| 222 | - $record = $set->request($customfield); | |
| 223 | - $object = $record->object.'Set'; | |
| 224 | - $set->delete($set->id->is($customfield)); | |
| 221 | + $set = $App->CustomFieldSet(); | |
| 222 | + $record = $set->request($customfield); | |
| 223 | + $object = $record->object.'Set'; | |
| 224 | + $set->delete($set->id->is($customfield)); | |
| 225 | 225 | |
| 226 | - $recordSet = $App->$object(); | |
| 227 | -		if (method_exists($recordSet, 'useLang')) { | |
| 228 | - // This is necessary if the recordSet constructor uses a setLang(). | |
| 229 | - // We need to revert to multilang fields before synchronizing. | |
| 230 | - $recordSet->useLang(false); | |
| 231 | - } | |
| 226 | + $recordSet = $App->$object(); | |
| 227 | +        if (method_exists($recordSet, 'useLang')) { | |
| 228 | + // This is necessary if the recordSet constructor uses a setLang(). | |
| 229 | + // We need to revert to multilang fields before synchronizing. | |
| 230 | + $recordSet->useLang(false); | |
| 231 | + } | |
| 232 | 232 | |
| 233 | - $mysqlbackend = new ORM_MySqlBackend($GLOBALS['babDB']); | |
| 234 | - $sql = $mysqlbackend->setToSql($recordSet); | |
| 233 | + $mysqlbackend = new ORM_MySqlBackend($GLOBALS['babDB']); | |
| 234 | + $sql = $mysqlbackend->setToSql($recordSet); | |
| 235 | 235 | |
| 236 | - require_once $GLOBALS['babInstallPath'].'utilit/devtools.php'; | |
| 237 | - $synchronize = new bab_synchronizeSql(); | |
| 238 | - $synchronize->fromSqlString($sql); | |
| 236 | + require_once $GLOBALS['babInstallPath'].'utilit/devtools.php'; | |
| 237 | + $synchronize = new bab_synchronizeSql(); | |
| 238 | + $synchronize->fromSqlString($sql); | |
| 239 | 239 | |
| 240 | - return true; | |
| 241 | - } | |
| 240 | + return true; | |
| 241 | + } | |
| 242 | 242 | } | 
| @@ -30,11 +30,11 @@ | ||
| 30 | 30 | |
| 31 | 31 | class app_UnknownActionException extends Exception | 
| 32 | 32 |  { | 
| 33 | - public function __construct($action, $code = 0) | |
| 34 | -	{ | |
| 35 | - $message = 'Unknown method "' . $action->getController() . '::' . $action->getMethod() . '"'; | |
| 36 | - parent::__construct($message, $code); | |
| 37 | - } | |
| 33 | + public function __construct($action, $code = 0) | |
| 34 | +    { | |
| 35 | + $message = 'Unknown method "' . $action->getController() . '::' . $action->getMethod() . '"'; | |
| 36 | + parent::__construct($message, $code); | |
| 37 | + } | |
| 38 | 38 | } | 
| 39 | 39 | |
| 40 | 40 | |
| @@ -69,205 +69,205 @@ | ||
| 69 | 69 | |
| 70 | 70 | |
| 71 | 71 | |
| 72 | - /** | |
| 73 | - * @param string $sourceClass | |
| 74 | - */ | |
| 75 | - public function joinSource($sourceClass) | |
| 76 | -	{ | |
| 77 | -	    if (get_class($this->sourceId) !== $sourceClass . 'Set') { | |
| 78 | -    	    $this->hasOne('sourceId', $sourceClass . 'Set'); | |
| 79 | -    		$this->join('sourceId'); | |
| 80 | - } | |
| 81 | - } | |
| 82 | - | |
| 83 | - | |
| 84 | - /** | |
| 85 | - * @param string $targetClass | |
| 86 | - */ | |
| 87 | - public function joinTarget($targetClass = null) | |
| 88 | -	{ | |
| 89 | -	    if (get_class($this->targetId) !== $targetClass . 'Set') { | |
| 90 | -    		$this->hasOne('targetId', $targetClass . 'Set'); | |
| 91 | -    		$this->join('targetId'); | |
| 92 | - } | |
| 93 | - } | |
| 94 | - | |
| 95 | - | |
| 96 | - | |
| 97 | - public function sourceIsA($recordClass) | |
| 98 | -	{ | |
| 99 | - return $this->sourceClass->is($recordClass); | |
| 100 | - } | |
| 101 | - | |
| 102 | - /** | |
| 103 | - * | |
| 104 | - * @return ORM_Iterator | |
| 105 | - */ | |
| 106 | - public function selectForSource(app_Record $object, $targetClass = null, $linkType = null) | |
| 107 | -	{ | |
| 108 | - $criteria = $this->sourceId->is($object->id) | |
| 72 | + /** | |
| 73 | + * @param string $sourceClass | |
| 74 | + */ | |
| 75 | + public function joinSource($sourceClass) | |
| 76 | +    { | |
| 77 | +        if (get_class($this->sourceId) !== $sourceClass . 'Set') { | |
| 78 | +            $this->hasOne('sourceId', $sourceClass . 'Set'); | |
| 79 | +            $this->join('sourceId'); | |
| 80 | + } | |
| 81 | + } | |
| 82 | + | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * @param string $targetClass | |
| 86 | + */ | |
| 87 | + public function joinTarget($targetClass = null) | |
| 88 | +    { | |
| 89 | +        if (get_class($this->targetId) !== $targetClass . 'Set') { | |
| 90 | +            $this->hasOne('targetId', $targetClass . 'Set'); | |
| 91 | +            $this->join('targetId'); | |
| 92 | + } | |
| 93 | + } | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + public function sourceIsA($recordClass) | |
| 98 | +    { | |
| 99 | + return $this->sourceClass->is($recordClass); | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * | |
| 104 | + * @return ORM_Iterator | |
| 105 | + */ | |
| 106 | + public function selectForSource(app_Record $object, $targetClass = null, $linkType = null) | |
| 107 | +    { | |
| 108 | + $criteria = $this->sourceId->is($object->id) | |
| 109 | 109 | ->_AND_($this->sourceClass->is(get_class($object))); | 
| 110 | 110 | |
| 111 | -		if (isset($targetClass)) { | |
| 112 | - $this->joinTarget($targetClass); | |
| 113 | - $criteria = $criteria->_AND_($this->targetClass->is($targetClass)); | |
| 114 | - } | |
| 115 | - | |
| 116 | -		if (isset($linkType)) { | |
| 117 | -			if (is_array($linkType)) { | |
| 118 | - $criteria = $criteria->_AND_($this->type->in($linkType)); | |
| 119 | -			} else { | |
| 120 | - $criteria = $criteria->_AND_($this->type->is($linkType)); | |
| 121 | - } | |
| 122 | - } | |
| 123 | - | |
| 124 | -		if (is_a($this->targetId, 'app_TraceableRecordSet')) { | |
| 125 | - $criteria = $criteria->_AND_($this->targetId->deleted->is(false)); | |
| 126 | - } | |
| 127 | - | |
| 128 | - return $this->select($criteria); | |
| 129 | - } | |
| 130 | - | |
| 131 | - | |
| 132 | - /** | |
| 133 | - * | |
| 134 | - * @return ORM_Iterator | |
| 135 | - */ | |
| 136 | - public function selectForSources($objects, $targetClass, $linkType = null) | |
| 137 | -	{ | |
| 138 | - $sourceClass = null; | |
| 139 | - $sourceIds = array(); | |
| 140 | - | |
| 141 | -		foreach ($objects as $obj) { | |
| 142 | -			if (is_null($sourceClass)) { | |
| 143 | - $sourceClass = get_class($obj); | |
| 144 | - } | |
| 145 | - $sourceIds[] = $obj->id; | |
| 146 | - } | |
| 147 | - $criteria = $this->sourceId->in($sourceIds) | |
| 148 | - ->_AND_($this->sourceClass->is($sourceClass)); | |
| 149 | - | |
| 150 | -		if (isset($targetClass)) { | |
| 151 | - $this->joinTarget($targetClass); | |
| 152 | - $criteria = $criteria->_AND_($this->targetClass->is($targetClass)); | |
| 153 | - } | |
| 154 | - | |
| 155 | -		if (isset($linkType)) { | |
| 156 | -			if (is_array($linkType)) { | |
| 157 | - $criteria = $criteria->_AND_($this->type->in($linkType)); | |
| 158 | -			} else { | |
| 159 | - $criteria = $criteria->_AND_($this->type->is($linkType)); | |
| 160 | - } | |
| 161 | - } | |
| 162 | - return $this->select($criteria); | |
| 163 | - } | |
| 164 | - | |
| 165 | - | |
| 166 | - /** | |
| 167 | - * | |
| 168 | - * @return ORM_Iterator | |
| 169 | - */ | |
| 170 | - public function selectForTarget(app_Record $object, $sourceClass = null, $linkType = null) | |
| 171 | -	{ | |
| 172 | - $criteria = $this->targetId->is($object->id) | |
| 173 | - ->_AND_($this->targetClass->is(get_class($object))); | |
| 174 | - | |
| 175 | -		if (isset($sourceClass)) { | |
| 176 | - $this->joinSource($sourceClass); | |
| 177 | - $criteria = $criteria->_AND_($this->sourceClass->is($sourceClass)); | |
| 178 | - } | |
| 179 | - | |
| 180 | -		if (isset($linkType)) { | |
| 181 | -			if (is_array($linkType)) { | |
| 182 | - $criteria = $criteria->_AND_($this->type->in($linkType)); | |
| 183 | -			} else { | |
| 184 | - $criteria = $criteria->_AND_($this->type->is($linkType)); | |
| 185 | - } | |
| 186 | - } | |
| 187 | - | |
| 188 | - return $this->select($criteria); | |
| 189 | - } | |
| 190 | - | |
| 191 | - | |
| 192 | - /** | |
| 193 | - * | |
| 194 | - * @return ORM_Iterator | |
| 195 | - */ | |
| 196 | - public function selectForTargets($objects, $sourceClass = null, $linkType = null) | |
| 197 | -	{ | |
| 198 | - $targetClass = null; | |
| 199 | - $targetIds = array(); | |
| 200 | - | |
| 201 | -		foreach ($objects as $obj) { | |
| 202 | -			if (is_null($targetClass)) { | |
| 203 | - $targetClass = get_class($obj); | |
| 204 | - } | |
| 205 | - $targetIds[] = $obj->id; | |
| 206 | - } | |
| 207 | - $criteria = $this->targetId->in($targetIds) | |
| 208 | - ->_AND_($this->targetClass->is($targetClass)); | |
| 209 | - | |
| 210 | -		if (isset($sourceClass)) { | |
| 211 | - $this->joinSource($sourceClass); | |
| 212 | - $criteria = $criteria->_AND_($this->sourceClass->is($sourceClass)); | |
| 213 | - } | |
| 214 | - | |
| 215 | -		if (isset($linkType)) { | |
| 216 | -			if (is_array($linkType)) { | |
| 217 | - $criteria = $criteria->_AND_($this->type->in($linkType)); | |
| 218 | -			} else { | |
| 219 | - $criteria = $criteria->_AND_($this->type->is($linkType)); | |
| 220 | - } | |
| 221 | - } | |
| 222 | - | |
| 223 | - return $this->select($criteria); | |
| 224 | - } | |
| 225 | - | |
| 226 | - | |
| 227 | - | |
| 228 | - /** | |
| 229 | - * delete all links to an object | |
| 230 | - * | |
| 231 | - * @param app_Record $object | |
| 232 | - * @param string $targetClass if target class is set, links will be deleted only for target classes | |
| 233 | - * @param bool $deleteTarget if set to true, the target will be deleted to | |
| 234 | - */ | |
| 235 | - public function deleteForSource(app_Record $object, $targetClass = null, $deleteTarget = false, $linkType = null) | |
| 236 | -	{ | |
| 237 | - $set = clone $this; | |
| 238 | - $App = $object->App(); | |
| 239 | - | |
| 240 | - $criteria = $set->sourceId->is($object->id)->_AND_( | |
| 241 | - $set->sourceClass->is(get_class($object)) | |
| 242 | - ); | |
| 243 | - | |
| 244 | -		if (null !== $targetClass) { | |
| 245 | - $criteria = $criteria->_AND_( | |
| 246 | - $set->targetClass->is($targetClass) | |
| 247 | - ); | |
| 248 | - } | |
| 249 | -		if (null !== $linkType) { | |
| 250 | - $criteria = $criteria->_AND_( | |
| 251 | - $set->type->is($linkType) | |
| 252 | - ); | |
| 253 | - } | |
| 254 | - | |
| 255 | -		if ($deleteTarget) { | |
| 256 | -			foreach($set->select($criteria) as $link) { | |
| 257 | - | |
| 258 | - $className = $link->targetClass.'Set'; | |
| 259 | - | |
| 260 | - // remove prefix | |
| 261 | - | |
| 262 | - $className = mb_substr($className, 1 + mb_strpos($className, '_')); | |
| 263 | - $targetSet = $App->$className(); | |
| 264 | - | |
| 265 | - $targetSet->delete($targetSet->id->is($link->targetId)); | |
| 266 | - } | |
| 267 | - } | |
| 268 | - | |
| 269 | - return $set->delete($criteria); | |
| 270 | - } | |
| 111 | +        if (isset($targetClass)) { | |
| 112 | + $this->joinTarget($targetClass); | |
| 113 | + $criteria = $criteria->_AND_($this->targetClass->is($targetClass)); | |
| 114 | + } | |
| 115 | + | |
| 116 | +        if (isset($linkType)) { | |
| 117 | +            if (is_array($linkType)) { | |
| 118 | + $criteria = $criteria->_AND_($this->type->in($linkType)); | |
| 119 | +            } else { | |
| 120 | + $criteria = $criteria->_AND_($this->type->is($linkType)); | |
| 121 | + } | |
| 122 | + } | |
| 123 | + | |
| 124 | +        if (is_a($this->targetId, 'app_TraceableRecordSet')) { | |
| 125 | + $criteria = $criteria->_AND_($this->targetId->deleted->is(false)); | |
| 126 | + } | |
| 127 | + | |
| 128 | + return $this->select($criteria); | |
| 129 | + } | |
| 130 | + | |
| 131 | + | |
| 132 | + /** | |
| 133 | + * | |
| 134 | + * @return ORM_Iterator | |
| 135 | + */ | |
| 136 | + public function selectForSources($objects, $targetClass, $linkType = null) | |
| 137 | +    { | |
| 138 | + $sourceClass = null; | |
| 139 | + $sourceIds = array(); | |
| 140 | + | |
| 141 | +        foreach ($objects as $obj) { | |
| 142 | +            if (is_null($sourceClass)) { | |
| 143 | + $sourceClass = get_class($obj); | |
| 144 | + } | |
| 145 | + $sourceIds[] = $obj->id; | |
| 146 | + } | |
| 147 | + $criteria = $this->sourceId->in($sourceIds) | |
| 148 | + ->_AND_($this->sourceClass->is($sourceClass)); | |
| 149 | + | |
| 150 | +        if (isset($targetClass)) { | |
| 151 | + $this->joinTarget($targetClass); | |
| 152 | + $criteria = $criteria->_AND_($this->targetClass->is($targetClass)); | |
| 153 | + } | |
| 154 | + | |
| 155 | +        if (isset($linkType)) { | |
| 156 | +            if (is_array($linkType)) { | |
| 157 | + $criteria = $criteria->_AND_($this->type->in($linkType)); | |
| 158 | +            } else { | |
| 159 | + $criteria = $criteria->_AND_($this->type->is($linkType)); | |
| 160 | + } | |
| 161 | + } | |
| 162 | + return $this->select($criteria); | |
| 163 | + } | |
| 164 | + | |
| 165 | + | |
| 166 | + /** | |
| 167 | + * | |
| 168 | + * @return ORM_Iterator | |
| 169 | + */ | |
| 170 | + public function selectForTarget(app_Record $object, $sourceClass = null, $linkType = null) | |
| 171 | +    { | |
| 172 | + $criteria = $this->targetId->is($object->id) | |
| 173 | + ->_AND_($this->targetClass->is(get_class($object))); | |
| 174 | + | |
| 175 | +        if (isset($sourceClass)) { | |
| 176 | + $this->joinSource($sourceClass); | |
| 177 | + $criteria = $criteria->_AND_($this->sourceClass->is($sourceClass)); | |
| 178 | + } | |
| 179 | + | |
| 180 | +        if (isset($linkType)) { | |
| 181 | +            if (is_array($linkType)) { | |
| 182 | + $criteria = $criteria->_AND_($this->type->in($linkType)); | |
| 183 | +            } else { | |
| 184 | + $criteria = $criteria->_AND_($this->type->is($linkType)); | |
| 185 | + } | |
| 186 | + } | |
| 187 | + | |
| 188 | + return $this->select($criteria); | |
| 189 | + } | |
| 190 | + | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * | |
| 194 | + * @return ORM_Iterator | |
| 195 | + */ | |
| 196 | + public function selectForTargets($objects, $sourceClass = null, $linkType = null) | |
| 197 | +    { | |
| 198 | + $targetClass = null; | |
| 199 | + $targetIds = array(); | |
| 200 | + | |
| 201 | +        foreach ($objects as $obj) { | |
| 202 | +            if (is_null($targetClass)) { | |
| 203 | + $targetClass = get_class($obj); | |
| 204 | + } | |
| 205 | + $targetIds[] = $obj->id; | |
| 206 | + } | |
| 207 | + $criteria = $this->targetId->in($targetIds) | |
| 208 | + ->_AND_($this->targetClass->is($targetClass)); | |
| 209 | + | |
| 210 | +        if (isset($sourceClass)) { | |
| 211 | + $this->joinSource($sourceClass); | |
| 212 | + $criteria = $criteria->_AND_($this->sourceClass->is($sourceClass)); | |
| 213 | + } | |
| 214 | + | |
| 215 | +        if (isset($linkType)) { | |
| 216 | +            if (is_array($linkType)) { | |
| 217 | + $criteria = $criteria->_AND_($this->type->in($linkType)); | |
| 218 | +            } else { | |
| 219 | + $criteria = $criteria->_AND_($this->type->is($linkType)); | |
| 220 | + } | |
| 221 | + } | |
| 222 | + | |
| 223 | + return $this->select($criteria); | |
| 224 | + } | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + /** | |
| 229 | + * delete all links to an object | |
| 230 | + * | |
| 231 | + * @param app_Record $object | |
| 232 | + * @param string $targetClass if target class is set, links will be deleted only for target classes | |
| 233 | + * @param bool $deleteTarget if set to true, the target will be deleted to | |
| 234 | + */ | |
| 235 | + public function deleteForSource(app_Record $object, $targetClass = null, $deleteTarget = false, $linkType = null) | |
| 236 | +    { | |
| 237 | + $set = clone $this; | |
| 238 | + $App = $object->App(); | |
| 239 | + | |
| 240 | + $criteria = $set->sourceId->is($object->id)->_AND_( | |
| 241 | + $set->sourceClass->is(get_class($object)) | |
| 242 | + ); | |
| 243 | + | |
| 244 | +        if (null !== $targetClass) { | |
| 245 | + $criteria = $criteria->_AND_( | |
| 246 | + $set->targetClass->is($targetClass) | |
| 247 | + ); | |
| 248 | + } | |
| 249 | +        if (null !== $linkType) { | |
| 250 | + $criteria = $criteria->_AND_( | |
| 251 | + $set->type->is($linkType) | |
| 252 | + ); | |
| 253 | + } | |
| 254 | + | |
| 255 | +        if ($deleteTarget) { | |
| 256 | +            foreach($set->select($criteria) as $link) { | |
| 257 | + | |
| 258 | + $className = $link->targetClass.'Set'; | |
| 259 | + | |
| 260 | + // remove prefix | |
| 261 | + | |
| 262 | + $className = mb_substr($className, 1 + mb_strpos($className, '_')); | |
| 263 | + $targetSet = $App->$className(); | |
| 264 | + | |
| 265 | + $targetSet->delete($targetSet->id->is($link->targetId)); | |
| 266 | + } | |
| 267 | + } | |
| 268 | + | |
| 269 | + return $set->delete($criteria); | |
| 270 | + } | |
| 271 | 271 | |
| 272 | 272 | |
| 273 | 273 | /** | 
| @@ -33,50 +33,50 @@ discard block | ||
| 33 | 33 | */ | 
| 34 | 34 | function app_genericSetEditor(ORM_RecordSet $set) | 
| 35 | 35 |  { | 
| 36 | -	$O = bab_functionality::get('LibOrm'); | |
| 37 | - $O->init(); | |
| 38 | - $W = bab_Widgets(); | |
| 39 | - $layout = $W->VBoxLayout(); | |
| 40 | - $layout->setVerticalSpacing(1, 'em'); | |
| 41 | - | |
| 42 | - | |
| 43 | - $fields = $set->getFields(); | |
| 44 | - | |
| 45 | -	foreach ($fields as $field) { | |
| 46 | - $description = $field->getDescription(); | |
| 47 | -		if (empty($description)) { | |
| 48 | - $description = $field->getName(); | |
| 49 | - } | |
| 50 | - $fieldLabel = $W->Label($description . ':'); | |
| 51 | - | |
| 52 | -		if ($field instanceof ORM_DateField) { | |
| 53 | - $widget = $W->DatePicker(); | |
| 54 | -		} else if ($field instanceof ORM_TimeField) { | |
| 55 | -			$widget = $W->LineEdit()->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); | |
| 56 | -		} else if ($field instanceof ORM_StringField) { | |
| 57 | - $widget = $W->LineEdit()->setSize(min(array(80, $field->getMaxLength()))); | |
| 58 | -		} else if ($field instanceof ORM_EnumField) { | |
| 59 | - $widget = $W->Select(); | |
| 60 | -			$widget->addOption('', ''); | |
| 61 | -			foreach ($field->getValues() as $key => $text) { | |
| 62 | - $widget->addOption($key, $text); | |
| 63 | - } | |
| 64 | -		} else if ($field instanceof ORM_IntField) { | |
| 65 | - $widget = $W->LineEdit()->setSize(9); | |
| 66 | -		} else if ($field instanceof ORM_TextField) { | |
| 67 | - $widget = $W->TextEdit()->setColumns(80)->setLines(5); | |
| 68 | -		} else if ($field instanceof ORM_RecordSet) { | |
| 69 | - $widget = app_genericSetEditor($field); | |
| 70 | -				$widget->addClass('sub-form'); | |
| 71 | -		} else { | |
| 72 | - $widget = null; | |
| 73 | - } | |
| 74 | -		if (isset($widget)) { | |
| 75 | - $layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); | |
| 76 | - } | |
| 77 | - } | |
| 78 | - | |
| 79 | - return $layout; | |
| 36 | +    $O = bab_functionality::get('LibOrm'); | |
| 37 | + $O->init(); | |
| 38 | + $W = bab_Widgets(); | |
| 39 | + $layout = $W->VBoxLayout(); | |
| 40 | + $layout->setVerticalSpacing(1, 'em'); | |
| 41 | + | |
| 42 | + | |
| 43 | + $fields = $set->getFields(); | |
| 44 | + | |
| 45 | +    foreach ($fields as $field) { | |
| 46 | + $description = $field->getDescription(); | |
| 47 | +        if (empty($description)) { | |
| 48 | + $description = $field->getName(); | |
| 49 | + } | |
| 50 | + $fieldLabel = $W->Label($description . ':'); | |
| 51 | + | |
| 52 | +        if ($field instanceof ORM_DateField) { | |
| 53 | + $widget = $W->DatePicker(); | |
| 54 | +        } else if ($field instanceof ORM_TimeField) { | |
| 55 | +            $widget = $W->LineEdit()->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); | |
| 56 | +        } else if ($field instanceof ORM_StringField) { | |
| 57 | + $widget = $W->LineEdit()->setSize(min(array(80, $field->getMaxLength()))); | |
| 58 | +        } else if ($field instanceof ORM_EnumField) { | |
| 59 | + $widget = $W->Select(); | |
| 60 | +            $widget->addOption('', ''); | |
| 61 | +            foreach ($field->getValues() as $key => $text) { | |
| 62 | + $widget->addOption($key, $text); | |
| 63 | + } | |
| 64 | +        } else if ($field instanceof ORM_IntField) { | |
| 65 | + $widget = $W->LineEdit()->setSize(9); | |
| 66 | +        } else if ($field instanceof ORM_TextField) { | |
| 67 | + $widget = $W->TextEdit()->setColumns(80)->setLines(5); | |
| 68 | +        } else if ($field instanceof ORM_RecordSet) { | |
| 69 | + $widget = app_genericSetEditor($field); | |
| 70 | +                $widget->addClass('sub-form'); | |
| 71 | +        } else { | |
| 72 | + $widget = null; | |
| 73 | + } | |
| 74 | +        if (isset($widget)) { | |
| 75 | + $layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); | |
| 76 | + } | |
| 77 | + } | |
| 78 | + | |
| 79 | + return $layout; | |
| 80 | 80 | } | 
| 81 | 81 | |
| 82 | 82 | |
| @@ -89,50 +89,50 @@ discard block | ||
| 89 | 89 | */ | 
| 90 | 90 | function app_genericSetFilterForm(ORM_RecordSet $set) | 
| 91 | 91 |  { | 
| 92 | -	$O = bab_functionality::get('LibOrm'); | |
| 93 | - $O->init(); | |
| 94 | - $W = bab_Widgets(); | |
| 95 | - $layout = $W->FlowLayout(); | |
| 96 | - $layout->setVerticalSpacing(1, 'em')->setHorizontalSpacing(1, 'em'); | |
| 97 | - | |
| 98 | - | |
| 99 | - $fields = $set->getFields(); | |
| 100 | - | |
| 101 | -	foreach ($fields as $field) { | |
| 102 | - $description = $field->getDescription(); | |
| 103 | -		if (empty($description)) { | |
| 104 | - $description = $field->getName(); | |
| 105 | - } | |
| 106 | - $fieldLabel = $W->Label($description . ':'); | |
| 107 | - | |
| 108 | -		if ($field instanceof ORM_DateField) { | |
| 109 | - $widget = $W->PeriodPicker(); | |
| 110 | -		} else if ($field instanceof ORM_TimeField) { | |
| 111 | - $widget = $W->TimePicker(); | |
| 112 | -		} else if ($field instanceof ORM_StringField) { | |
| 113 | - $widget = $W->LineEdit()->setSize(min(array(15, $field->getMaxLength()))); | |
| 114 | -		} else if ($field instanceof ORM_EnumField) { | |
| 115 | - $widget = $W->Select(); | |
| 116 | -			$widget->addOption('', ''); | |
| 117 | -			foreach ($field->getValues() as $key => $text) { | |
| 118 | - $widget->addOption($key, $text); | |
| 119 | - } | |
| 120 | -		} else if ($field instanceof ORM_IntField) { | |
| 121 | - $widget = $W->LineEdit()->setSize(9); | |
| 122 | -		} else if ($field instanceof ORM_TextField) { | |
| 123 | - $widget = $widget = $W->LineEdit()->setSize(15); | |
| 124 | -		} else if ($field instanceof ORM_RecordSet) { | |
| 125 | - $widget = app_genericSetFilterForm($field); | |
| 126 | -			$widget->addClass('sub-form'); | |
| 127 | -		} else { | |
| 128 | - $widget = null; | |
| 129 | - } | |
| 130 | -		if (isset($widget)) { | |
| 131 | - $layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); | |
| 132 | - } | |
| 133 | - } | |
| 134 | - | |
| 135 | - return $layout; | |
| 92 | +    $O = bab_functionality::get('LibOrm'); | |
| 93 | + $O->init(); | |
| 94 | + $W = bab_Widgets(); | |
| 95 | + $layout = $W->FlowLayout(); | |
| 96 | + $layout->setVerticalSpacing(1, 'em')->setHorizontalSpacing(1, 'em'); | |
| 97 | + | |
| 98 | + | |
| 99 | + $fields = $set->getFields(); | |
| 100 | + | |
| 101 | +    foreach ($fields as $field) { | |
| 102 | + $description = $field->getDescription(); | |
| 103 | +        if (empty($description)) { | |
| 104 | + $description = $field->getName(); | |
| 105 | + } | |
| 106 | + $fieldLabel = $W->Label($description . ':'); | |
| 107 | + | |
| 108 | +        if ($field instanceof ORM_DateField) { | |
| 109 | + $widget = $W->PeriodPicker(); | |
| 110 | +        } else if ($field instanceof ORM_TimeField) { | |
| 111 | + $widget = $W->TimePicker(); | |
| 112 | +        } else if ($field instanceof ORM_StringField) { | |
| 113 | + $widget = $W->LineEdit()->setSize(min(array(15, $field->getMaxLength()))); | |
| 114 | +        } else if ($field instanceof ORM_EnumField) { | |
| 115 | + $widget = $W->Select(); | |
| 116 | +            $widget->addOption('', ''); | |
| 117 | +            foreach ($field->getValues() as $key => $text) { | |
| 118 | + $widget->addOption($key, $text); | |
| 119 | + } | |
| 120 | +        } else if ($field instanceof ORM_IntField) { | |
| 121 | + $widget = $W->LineEdit()->setSize(9); | |
| 122 | +        } else if ($field instanceof ORM_TextField) { | |
| 123 | + $widget = $widget = $W->LineEdit()->setSize(15); | |
| 124 | +        } else if ($field instanceof ORM_RecordSet) { | |
| 125 | + $widget = app_genericSetFilterForm($field); | |
| 126 | +            $widget->addClass('sub-form'); | |
| 127 | +        } else { | |
| 128 | + $widget = null; | |
| 129 | + } | |
| 130 | +        if (isset($widget)) { | |
| 131 | + $layout->addItem($W->VBoxLayout()->addItem($fieldLabel)->addItem($widget)); | |
| 132 | + } | |
| 133 | + } | |
| 134 | + | |
| 135 | + return $layout; | |
| 136 | 136 | } | 
| 137 | 137 | |
| 138 | 138 | |
| @@ -145,47 +145,47 @@ discard block | ||
| 145 | 145 | */ | 
| 146 | 146 | function app_LabelledWidget($labelText, Widget_Displayable_Interface $widget) | 
| 147 | 147 |  { | 
| 148 | - $W = bab_Widgets(); | |
| 149 | - | |
| 150 | - $label = $W->Label($labelText); | |
| 151 | -	if ($widget instanceof Widget_InputWidget) { | |
| 152 | - $label->setAssociatedWidget($widget); | |
| 153 | - } | |
| 154 | - | |
| 155 | -	if ($widget instanceof Widget_CheckBox) { | |
| 156 | - $layout = $W->HBoxItems( | |
| 157 | - $widget->setSizePolicy(Widget_SizePolicy::MINIMUM), | |
| 158 | - $label | |
| 159 | -		)->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); | |
| 160 | -	} else { | |
| 161 | - $layout = $W->VBoxItems( | |
| 162 | - $label, | |
| 163 | - $widget | |
| 164 | - )->setVerticalSpacing(0.5, 'em'); | |
| 165 | - } | |
| 166 | - | |
| 167 | - return $layout; | |
| 148 | + $W = bab_Widgets(); | |
| 149 | + | |
| 150 | + $label = $W->Label($labelText); | |
| 151 | +    if ($widget instanceof Widget_InputWidget) { | |
| 152 | + $label->setAssociatedWidget($widget); | |
| 153 | + } | |
| 154 | + | |
| 155 | +    if ($widget instanceof Widget_CheckBox) { | |
| 156 | + $layout = $W->HBoxItems( | |
| 157 | + $widget->setSizePolicy(Widget_SizePolicy::MINIMUM), | |
| 158 | + $label | |
| 159 | +        )->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); | |
| 160 | +    } else { | |
| 161 | + $layout = $W->VBoxItems( | |
| 162 | + $label, | |
| 163 | + $widget | |
| 164 | + )->setVerticalSpacing(0.5, 'em'); | |
| 165 | + } | |
| 166 | + | |
| 167 | + return $layout; | |
| 168 | 168 | } | 
| 169 | 169 | |
| 170 | 170 | |
| 171 | 171 | |
| 172 | 172 | function app_LabelledCheckbox($labelText, $checkboxName, $options = null) | 
| 173 | 173 |  { | 
| 174 | - $W = bab_Widgets(); | |
| 174 | + $W = bab_Widgets(); | |
| 175 | 175 | |
| 176 | - $label = $W->Label($labelText)->colon(false); | |
| 177 | - $checkbox = $W->Checkbox()->setName($checkboxName); | |
| 178 | - $label->setAssociatedWidget($checkbox); | |
| 179 | -	if (isset($options)) { | |
| 180 | - $label->setSizePolicy(Widget_SizePolicy::FIXED)->setCanvasOptions($options); | |
| 181 | - } | |
| 176 | + $label = $W->Label($labelText)->colon(false); | |
| 177 | + $checkbox = $W->Checkbox()->setName($checkboxName); | |
| 178 | + $label->setAssociatedWidget($checkbox); | |
| 179 | +    if (isset($options)) { | |
| 180 | + $label->setSizePolicy(Widget_SizePolicy::FIXED)->setCanvasOptions($options); | |
| 181 | + } | |
| 182 | 182 | |
| 183 | - $layout = $W->HBoxItems( | |
| 184 | - $checkbox->setSizePolicy(Widget_SizePolicy::MINIMUM), | |
| 185 | - $label | |
| 186 | -				)->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); | |
| 183 | + $layout = $W->HBoxItems( | |
| 184 | + $checkbox->setSizePolicy(Widget_SizePolicy::MINIMUM), | |
| 185 | + $label | |
| 186 | +                )->setVerticalAlign('middle')->setHorizontalSpacing(0.5, 'em'); | |
| 187 | 187 | |
| 188 | - return $layout; | |
| 188 | + return $layout; | |
| 189 | 189 | } | 
| 190 | 190 | |
| 191 | 191 | |
| @@ -193,42 +193,42 @@ discard block | ||
| 193 | 193 | |
| 194 | 194 | function app_LabelledOrmSelect(ORM_MysqlIterator $iterator, $fieldName, $selectName, $label, $hidden = false, $groupFieldName = null) | 
| 195 | 195 |  { | 
| 196 | - $W = bab_Widgets(); | |
| 197 | - | |
| 198 | -	if (isset($groupFieldName)) { | |
| 199 | -		$groupPathElements = explode('/', $groupFieldName); | |
| 200 | - } | |
| 201 | - | |
| 202 | - $select = $W->Select()->setName($selectName); | |
| 203 | - | |
| 204 | -	$select->addOption('', ''); | |
| 205 | - | |
| 206 | - $nbOptions = 0; | |
| 207 | -	foreach ($iterator as $record) { | |
| 208 | -		if (isset($record->code)) { | |
| 209 | - $optionText = $record->code . ' - ' . $record->$fieldName; | |
| 210 | -		} else { | |
| 211 | - $optionText = $record->$fieldName; | |
| 212 | - } | |
| 213 | -		if (isset($groupFieldName)) { | |
| 214 | - $group = $record; | |
| 215 | -			foreach ($groupPathElements as $groupPathElement) { | |
| 216 | - $group = $group->$groupPathElement; | |
| 217 | - } | |
| 218 | - $select->addOption($record->id, $optionText, $group); | |
| 219 | -		} else { | |
| 220 | - $select->addOption($record->id, $optionText); | |
| 221 | - } | |
| 222 | - $nbOptions++; | |
| 223 | - $lastId = $record->id; | |
| 224 | - } | |
| 225 | - | |
| 226 | -	if ($nbOptions == 1) { | |
| 227 | - $select->setValue($lastId); | |
| 228 | - } | |
| 229 | - | |
| 230 | - | |
| 231 | - return app_LabelledWidget($label, $select); | |
| 196 | + $W = bab_Widgets(); | |
| 197 | + | |
| 198 | +    if (isset($groupFieldName)) { | |
| 199 | +        $groupPathElements = explode('/', $groupFieldName); | |
| 200 | + } | |
| 201 | + | |
| 202 | + $select = $W->Select()->setName($selectName); | |
| 203 | + | |
| 204 | +    $select->addOption('', ''); | |
| 205 | + | |
| 206 | + $nbOptions = 0; | |
| 207 | +    foreach ($iterator as $record) { | |
| 208 | +        if (isset($record->code)) { | |
| 209 | + $optionText = $record->code . ' - ' . $record->$fieldName; | |
| 210 | +        } else { | |
| 211 | + $optionText = $record->$fieldName; | |
| 212 | + } | |
| 213 | +        if (isset($groupFieldName)) { | |
| 214 | + $group = $record; | |
| 215 | +            foreach ($groupPathElements as $groupPathElement) { | |
| 216 | + $group = $group->$groupPathElement; | |
| 217 | + } | |
| 218 | + $select->addOption($record->id, $optionText, $group); | |
| 219 | +        } else { | |
| 220 | + $select->addOption($record->id, $optionText); | |
| 221 | + } | |
| 222 | + $nbOptions++; | |
| 223 | + $lastId = $record->id; | |
| 224 | + } | |
| 225 | + | |
| 226 | +    if ($nbOptions == 1) { | |
| 227 | + $select->setValue($lastId); | |
| 228 | + } | |
| 229 | + | |
| 230 | + | |
| 231 | + return app_LabelledWidget($label, $select); | |
| 232 | 232 | } | 
| 233 | 233 | |
| 234 | 234 | |
| @@ -236,108 +236,108 @@ discard block | ||
| 236 | 236 | |
| 237 | 237 | function app_OrmWidget(ORM_Field $field) | 
| 238 | 238 |  { | 
| 239 | - $W = bab_Widgets(); | |
| 239 | + $W = bab_Widgets(); | |
| 240 | 240 | |
| 241 | 241 | |
| 242 | -	if ($field instanceof ORM_DateField) { | |
| 243 | - $widget = $W->DatePicker(); | |
| 244 | -	} else if ($field instanceof ORM_TimeField) { | |
| 245 | -		$widget = $W->TimeEdit(); //->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); | |
| 246 | -	} else if ($field instanceof ORM_DatetimeField) { | |
| 247 | -	    $widget = $W->DateTimePicker(); //->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); | |
| 248 | -	} else if ($field instanceof ORM_EnumField) { | |
| 249 | - $widget = $W->Select(); | |
| 242 | +    if ($field instanceof ORM_DateField) { | |
| 243 | + $widget = $W->DatePicker(); | |
| 244 | +    } else if ($field instanceof ORM_TimeField) { | |
| 245 | +        $widget = $W->TimeEdit(); //->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); | |
| 246 | +    } else if ($field instanceof ORM_DatetimeField) { | |
| 247 | +        $widget = $W->DateTimePicker(); //->setMaxSize(5)->setSize(5)->addClass('widget-timepicker'); | |
| 248 | +    } else if ($field instanceof ORM_EnumField) { | |
| 249 | + $widget = $W->Select(); | |
| 250 | 250 | //// $widget = $W->MultiSelect()->setSingleSelect(); | 
| 251 | -		$widget->addOption('', ''); | |
| 252 | - $values = $field->getValues(); | |
| 253 | -		foreach ($values as $key => $value) { | |
| 254 | - $widget->addOption($key, $value); | |
| 255 | - } | |
| 256 | -	} else if ($field instanceof ORM_SetField) { | |
| 257 | - $widget = $W->MultiSelect()->setSelectedList(2); | |
| 258 | - $values = $field->getValues(); | |
| 259 | -		foreach ($values as $key => $value) { | |
| 260 | - $widget->addOption($key, $value); | |
| 261 | - } | |
| 262 | -	} else if ($field instanceof ORM_UserField) { | |
| 263 | - $widget = $W->SuggestUser() | |
| 264 | - ->setMinChars(0) | |
| 265 | - ->setSizePolicy(Func_Icons::ICON_LEFT_16); | |
| 266 | -	} else if ($field instanceof ORM_CurrencyField) { | |
| 267 | -		$widget = $W->LineEdit()->setSize(6)->addClass('widget-input-currency'); | |
| 268 | -	} else if ($field instanceof ORM_BoolField) { | |
| 269 | -		$widget = $W->CheckBox()->setCheckedValue('1'); | |
| 270 | -	} else if ($field instanceof ORM_IntField) { | |
| 271 | - $widget = $W->LineEdit() | |
| 272 | -						->setSize(6)->addClass('widget-input-numeric'); | |
| 273 | -	} else if ($field instanceof ORM_EmailField) { | |
| 274 | - $widget = $W->EmailLineEdit() | |
| 275 | - ->setMaxSize($field->getMaxLength()); | |
| 276 | -	} else if ($field instanceof ORM_FileField) { | |
| 277 | - $widget = $W->FilePicker(); | |
| 278 | -	} else if ($field instanceof ORM_StringField) { | |
| 279 | - $widget = $W->LineEdit() | |
| 280 | - ->setMaxSize($field->getMaxLength()); | |
| 281 | -	} else if ($field instanceof ORM_TextField) { | |
| 282 | - $widget = $W->TextEdit() | |
| 283 | -		  ->addClass('widget-autoresize'); | |
| 284 | -	} else if ($field instanceof ORM_PkField) { | |
| 285 | - $widget = $W->Hidden(); | |
| 286 | -	} else if ($field instanceof ORM_FkField) { | |
| 287 | - $widget = $W->Select(); | |
| 288 | - $fieldName = $field->getName(); | |
| 289 | - $parentSet = clone $field->getParentSet(); | |
| 290 | - $parentSet->join($fieldName); | |
| 291 | - $set = $parentSet->$fieldName; | |
| 292 | - $records = $set->select(); | |
| 293 | - $records->orderAsc($set->name); | |
| 294 | - $pkName = $set->getPrimaryKey(); | |
| 295 | -		$widget->addOption('', ''); | |
| 296 | -		foreach ($records as $record) { | |
| 297 | - $widget->addOption($record->$pkName, $record->name); | |
| 298 | - } | |
| 299 | -	} else if ($field instanceof ORM_RecordSet) { | |
| 300 | - $widget = $W->Select(); | |
| 251 | +        $widget->addOption('', ''); | |
| 252 | + $values = $field->getValues(); | |
| 253 | +        foreach ($values as $key => $value) { | |
| 254 | + $widget->addOption($key, $value); | |
| 255 | + } | |
| 256 | +    } else if ($field instanceof ORM_SetField) { | |
| 257 | + $widget = $W->MultiSelect()->setSelectedList(2); | |
| 258 | + $values = $field->getValues(); | |
| 259 | +        foreach ($values as $key => $value) { | |
| 260 | + $widget->addOption($key, $value); | |
| 261 | + } | |
| 262 | +    } else if ($field instanceof ORM_UserField) { | |
| 263 | + $widget = $W->SuggestUser() | |
| 264 | + ->setMinChars(0) | |
| 265 | + ->setSizePolicy(Func_Icons::ICON_LEFT_16); | |
| 266 | +    } else if ($field instanceof ORM_CurrencyField) { | |
| 267 | +        $widget = $W->LineEdit()->setSize(6)->addClass('widget-input-currency'); | |
| 268 | +    } else if ($field instanceof ORM_BoolField) { | |
| 269 | +        $widget = $W->CheckBox()->setCheckedValue('1'); | |
| 270 | +    } else if ($field instanceof ORM_IntField) { | |
| 271 | + $widget = $W->LineEdit() | |
| 272 | +                        ->setSize(6)->addClass('widget-input-numeric'); | |
| 273 | +    } else if ($field instanceof ORM_EmailField) { | |
| 274 | + $widget = $W->EmailLineEdit() | |
| 275 | + ->setMaxSize($field->getMaxLength()); | |
| 276 | +    } else if ($field instanceof ORM_FileField) { | |
| 277 | + $widget = $W->FilePicker(); | |
| 278 | +    } else if ($field instanceof ORM_StringField) { | |
| 279 | + $widget = $W->LineEdit() | |
| 280 | + ->setMaxSize($field->getMaxLength()); | |
| 281 | +    } else if ($field instanceof ORM_TextField) { | |
| 282 | + $widget = $W->TextEdit() | |
| 283 | +            ->addClass('widget-autoresize'); | |
| 284 | +    } else if ($field instanceof ORM_PkField) { | |
| 285 | + $widget = $W->Hidden(); | |
| 286 | +    } else if ($field instanceof ORM_FkField) { | |
| 287 | + $widget = $W->Select(); | |
| 288 | + $fieldName = $field->getName(); | |
| 289 | + $parentSet = clone $field->getParentSet(); | |
| 290 | + $parentSet->join($fieldName); | |
| 291 | + $set = $parentSet->$fieldName; | |
| 292 | + $records = $set->select(); | |
| 293 | + $records->orderAsc($set->name); | |
| 294 | + $pkName = $set->getPrimaryKey(); | |
| 295 | +        $widget->addOption('', ''); | |
| 296 | +        foreach ($records as $record) { | |
| 297 | + $widget->addOption($record->$pkName, $record->name); | |
| 298 | + } | |
| 299 | +    } else if ($field instanceof ORM_RecordSet) { | |
| 300 | + $widget = $W->Select(); | |
| 301 | 301 | //// $widget = $W->MultiSelect()->setSingleSelect(); | 
| 302 | 302 | // $fieldName = $field->getName(); | 
| 303 | 303 | // $parentSet = $field->getParentSet(); | 
| 304 | 304 | // $parentSet->join($fieldName); | 
| 305 | 305 | // $set = $parentSet->$fieldName; | 
| 306 | - $records = $field->select(); | |
| 307 | - $records->orderAsc($field->name); | |
| 308 | - $pkName = $field->getPrimaryKey(); | |
| 309 | -		$widget->addOption('', ''); | |
| 310 | -		foreach ($records as $record) { | |
| 311 | - $widget->addOption($record->$pkName, $record->name); | |
| 312 | - } | |
| 313 | -	} else { | |
| 314 | - $widget = $W->LineEdit(); | |
| 315 | - } | |
| 316 | - | |
| 317 | - $widget->setName($field->getName()); | |
| 318 | - | |
| 319 | - return $widget; | |
| 306 | + $records = $field->select(); | |
| 307 | + $records->orderAsc($field->name); | |
| 308 | + $pkName = $field->getPrimaryKey(); | |
| 309 | +        $widget->addOption('', ''); | |
| 310 | +        foreach ($records as $record) { | |
| 311 | + $widget->addOption($record->$pkName, $record->name); | |
| 312 | + } | |
| 313 | +    } else { | |
| 314 | + $widget = $W->LineEdit(); | |
| 315 | + } | |
| 316 | + | |
| 317 | + $widget->setName($field->getName()); | |
| 318 | + | |
| 319 | + return $widget; | |
| 320 | 320 | } | 
| 321 | 321 | |
| 322 | 322 | |
| 323 | 323 | |
| 324 | 324 | function app_LabelledOrmWidget(ORM_Field $field, $label = null, $hidden = false) | 
| 325 | 325 |  { | 
| 326 | - $W = bab_Widgets(); | |
| 326 | + $W = bab_Widgets(); | |
| 327 | 327 | |
| 328 | -	if ($hidden) { | |
| 329 | - $widget = $W->Hidden(); | |
| 330 | - $widget->setName($field->getName()); | |
| 331 | - return $widget; | |
| 332 | - } | |
| 328 | +    if ($hidden) { | |
| 329 | + $widget = $W->Hidden(); | |
| 330 | + $widget->setName($field->getName()); | |
| 331 | + return $widget; | |
| 332 | + } | |
| 333 | 333 | |
| 334 | -	if (is_null($label)) { | |
| 335 | - $label = $field->getDescription(); | |
| 336 | - } | |
| 334 | +    if (is_null($label)) { | |
| 335 | + $label = $field->getDescription(); | |
| 336 | + } | |
| 337 | 337 | |
| 338 | - $widget = app_OrmWidget($field); | |
| 338 | + $widget = app_OrmWidget($field); | |
| 339 | 339 | |
| 340 | - return app_LabelledWidget($label, $widget); | |
| 340 | + return app_LabelledWidget($label, $widget); | |
| 341 | 341 | } | 
| 342 | 342 | |
| 343 | 343 | |
| @@ -353,16 +353,16 @@ discard block | ||
| 353 | 353 | */ | 
| 354 | 354 |  function app_dateTime(ORM_Field $field, $value) { | 
| 355 | 355 | |
| 356 | -	$W = bab_functionality::get('Widgets'); | |
| 357 | - $name = $field->getName(); | |
| 358 | - $label = $W->Label($field->getDescription()); | |
| 356 | +    $W = bab_functionality::get('Widgets'); | |
| 357 | + $name = $field->getName(); | |
| 358 | + $label = $W->Label($field->getDescription()); | |
| 359 | 359 | |
| 360 | - $frame = app_dateTimeField($name, $label, $value); | |
| 360 | + $frame = app_dateTimeField($name, $label, $value); | |
| 361 | 361 | |
| 362 | - return $W->VBoxItems( | |
| 363 | - $label, | |
| 364 | - $frame | |
| 365 | - ); | |
| 362 | + return $W->VBoxItems( | |
| 363 | + $label, | |
| 364 | + $frame | |
| 365 | + ); | |
| 366 | 366 | |
| 367 | 367 | } | 
| 368 | 368 | |
| @@ -376,24 +376,24 @@ discard block | ||
| 376 | 376 | */ | 
| 377 | 377 | function app_dateTimeField($fieldName, Widget_Label $label, $value = null) | 
| 378 | 378 |  { | 
| 379 | -	$W = bab_functionality::get('Widgets'); | |
| 379 | +    $W = bab_functionality::get('Widgets'); | |
| 380 | 380 | |
| 381 | -	$datepart = $W->DatePicker()->setAssociatedLabel($label)->setName('date'); | |
| 382 | -	$timepart = $W->TimePicker()->setName('time'); | |
| 381 | +    $datepart = $W->DatePicker()->setAssociatedLabel($label)->setName('date'); | |
| 382 | +    $timepart = $W->TimePicker()->setName('time'); | |
| 383 | 383 | |
| 384 | -	if (isset($value)) { | |
| 384 | +    if (isset($value)) { | |
| 385 | 385 | |
| 386 | -		$value = explode(' ', $value); | |
| 386 | +        $value = explode(' ', $value); | |
| 387 | 387 | |
| 388 | - $datepart->setValue($value[0]); | |
| 389 | - $timepart->setValue($value[1]); | |
| 390 | - } | |
| 388 | + $datepart->setValue($value[0]); | |
| 389 | + $timepart->setValue($value[1]); | |
| 390 | + } | |
| 391 | 391 | |
| 392 | - $datetime = $W->Frame(null, $W->HBoxLayout())->setName($fieldName) | |
| 393 | - ->addItem($datepart) | |
| 394 | - ->addItem($timepart); | |
| 392 | + $datetime = $W->Frame(null, $W->HBoxLayout())->setName($fieldName) | |
| 393 | + ->addItem($datepart) | |
| 394 | + ->addItem($timepart); | |
| 395 | 395 | |
| 396 | - return $datetime; | |
| 396 | + return $datetime; | |
| 397 | 397 | } | 
| 398 | 398 | |
| 399 | 399 | |
| @@ -46,72 +46,72 @@ discard block | ||
| 46 | 46 | /** | 
| 47 | 47 | * @param Func_App $App | 
| 48 | 48 | */ | 
| 49 | - public function __construct(Func_App $App = null) | |
| 50 | -	{ | |
| 51 | - parent::__construct($App); | |
| 52 | - | |
| 53 | -		$this->setDescription('Custom field'); | |
| 54 | - | |
| 55 | -		$this->setPrimaryKey('id'); | |
| 56 | - | |
| 57 | - $this->addFields( | |
| 58 | -			ORM_StringField('name') | |
| 59 | -				->setDescription('Name of field used for display'), | |
| 60 | -			ORM_StringField('fieldname') | |
| 61 | -				->setDescription('Name of field used in table, not modifiable'), | |
| 62 | -			ORM_TextField('description') | |
| 63 | -				->setDescription('Optional description'), | |
| 64 | -			ORM_EnumField('object', $this->getObjects()) | |
| 65 | -				->setDescription('Name of object in App ex : Article, Contact, Organization...'), | |
| 66 | -			ORM_EnumField('fieldtype', $this->getFieldTypes()) | |
| 67 | -				->setDescription('Name of ORM field ex : Enum, String, Text, Bool...'), | |
| 68 | -			ORM_TextField('enumvalues') | |
| 69 | -				->setDescription('serialized array of values for enum fields'), | |
| 70 | -			ORM_BoolField('mandatory') | |
| 71 | -				->setDescription('Mandatory') | |
| 72 | - ); | |
| 73 | - } | |
| 74 | - | |
| 75 | - | |
| 76 | - | |
| 77 | - /** | |
| 78 | - * List of objects where custom fields are applicable. | |
| 79 | - * | |
| 80 | - * @return string[] | |
| 81 | - */ | |
| 82 | - public function getObjects() | |
| 83 | -	{ | |
| 84 | - $App = $this->App(); | |
| 85 | - | |
| 86 | - $arr = array(); | |
| 87 | - | |
| 88 | -		if (isset($App->Article)) { | |
| 89 | -			$arr['Article'] = $App->translate('Products database'); | |
| 90 | - } | |
| 91 | - | |
| 92 | - return $arr; | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * list of ORM fields to use for a custom field | |
| 97 | - */ | |
| 98 | - public function getFieldTypes() | |
| 99 | -	{ | |
| 100 | - $App = $this->App(); | |
| 101 | - | |
| 102 | - return array( | |
| 103 | -			'String' 	=> $App->translate('Line edit'), | |
| 104 | -			'Text'		=> $App->translate('Text edit'), | |
| 105 | -			'Bool'		=> $App->translate('Checkbox'), | |
| 106 | -			'Int'		=> $App->translate('Integer number'), | |
| 107 | -			'Decimal'	=> $App->translate('Decimal number'), | |
| 108 | -			'Date'		=> $App->translate('Date'), | |
| 109 | -			'DateTime'	=> $App->translate('Date and time'), | |
| 110 | -			'Enum' 		=> $App->translate('Selection list'), | |
| 111 | -			'Url' 		=> $App->translate('Url'), | |
| 112 | -			'Email' 	=> $App->translate('Email address'), | |
| 113 | - ); | |
| 114 | - } | |
| 49 | + public function __construct(Func_App $App = null) | |
| 50 | +    { | |
| 51 | + parent::__construct($App); | |
| 52 | + | |
| 53 | +        $this->setDescription('Custom field'); | |
| 54 | + | |
| 55 | +        $this->setPrimaryKey('id'); | |
| 56 | + | |
| 57 | + $this->addFields( | |
| 58 | +            ORM_StringField('name') | |
| 59 | +                ->setDescription('Name of field used for display'), | |
| 60 | +            ORM_StringField('fieldname') | |
| 61 | +                ->setDescription('Name of field used in table, not modifiable'), | |
| 62 | +            ORM_TextField('description') | |
| 63 | +                ->setDescription('Optional description'), | |
| 64 | +            ORM_EnumField('object', $this->getObjects()) | |
| 65 | +                ->setDescription('Name of object in App ex : Article, Contact, Organization...'), | |
| 66 | +            ORM_EnumField('fieldtype', $this->getFieldTypes()) | |
| 67 | +                ->setDescription('Name of ORM field ex : Enum, String, Text, Bool...'), | |
| 68 | +            ORM_TextField('enumvalues') | |
| 69 | +                ->setDescription('serialized array of values for enum fields'), | |
| 70 | +            ORM_BoolField('mandatory') | |
| 71 | +                ->setDescription('Mandatory') | |
| 72 | + ); | |
| 73 | + } | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * List of objects where custom fields are applicable. | |
| 79 | + * | |
| 80 | + * @return string[] | |
| 81 | + */ | |
| 82 | + public function getObjects() | |
| 83 | +    { | |
| 84 | + $App = $this->App(); | |
| 85 | + | |
| 86 | + $arr = array(); | |
| 87 | + | |
| 88 | +        if (isset($App->Article)) { | |
| 89 | +            $arr['Article'] = $App->translate('Products database'); | |
| 90 | + } | |
| 91 | + | |
| 92 | + return $arr; | |
| 93 | + } | |
| 94 | + | |
| 95 | + /** | |
| 96 | + * list of ORM fields to use for a custom field | |
| 97 | + */ | |
| 98 | + public function getFieldTypes() | |
| 99 | +    { | |
| 100 | + $App = $this->App(); | |
| 101 | + | |
| 102 | + return array( | |
| 103 | +            'String' 	=> $App->translate('Line edit'), | |
| 104 | +            'Text'		=> $App->translate('Text edit'), | |
| 105 | +            'Bool'		=> $App->translate('Checkbox'), | |
| 106 | +            'Int'		=> $App->translate('Integer number'), | |
| 107 | +            'Decimal'	=> $App->translate('Decimal number'), | |
| 108 | +            'Date'		=> $App->translate('Date'), | |
| 109 | +            'DateTime'	=> $App->translate('Date and time'), | |
| 110 | +            'Enum' 		=> $App->translate('Selection list'), | |
| 111 | +            'Url' 		=> $App->translate('Url'), | |
| 112 | +            'Email' 	=> $App->translate('Email address'), | |
| 113 | + ); | |
| 114 | + } | |
| 115 | 115 | |
| 116 | 116 | /** | 
| 117 | 117 | * @return ORM_Criteria | 
| @@ -175,7 +175,7 @@ discard block | ||
| 175 | 175 | case 'Bool': | 
| 176 | 176 | $field = ORM_BoolField($this->fieldname); | 
| 177 | 177 | $field->setOutputOptions( | 
| 178 | -                       $this->App()->translate('No'), | |
| 178 | +                        $this->App()->translate('No'), | |
| 179 | 179 |                      $this->App()->translate('Yes') | 
| 180 | 180 | ); | 
| 181 | 181 | break; | 
| @@ -192,80 +192,80 @@ discard block | ||
| 192 | 192 | } | 
| 193 | 193 | |
| 194 | 194 | |
| 195 | - /** | |
| 196 | - * @return string[] | |
| 197 | - */ | |
| 198 | - public function getEnumValues() | |
| 199 | -	{ | |
| 200 | - return unserialize($this->enumvalues); | |
| 201 | - } | |
| 202 | - | |
| 203 | - | |
| 204 | - /** | |
| 205 | - * @return Widget_LabelledWidget | |
| 206 | - */ | |
| 207 | - public function getWidget() | |
| 208 | -	{ | |
| 209 | - $W = bab_Widgets(); | |
| 210 | - $App = $this->App(); | |
| 211 | - | |
| 212 | -		switch ($this->fieldtype) { | |
| 213 | - case 'Text': | |
| 214 | - $widget = $W->TextEdit()->setLines(3)->setColumns(70); | |
| 215 | - break; | |
| 216 | - | |
| 217 | - case 'Bool': | |
| 218 | - $widget = $W->Checkbox(); | |
| 219 | - break; | |
| 220 | - | |
| 221 | - case 'Enum': | |
| 222 | -				$options = array('' => '') + $this->getEnumValues(); | |
| 223 | - $widget = $W->Select()->setOptions($options); | |
| 224 | - break; | |
| 225 | - | |
| 226 | - case 'Date': | |
| 227 | - $widget = $W->DatePicker(); | |
| 228 | - break; | |
| 229 | - | |
| 230 | - case 'DateTime': | |
| 231 | - $widget = $W->DateTimePicker(); | |
| 232 | - break; | |
| 233 | - | |
| 234 | - case 'Int': | |
| 235 | - $widget = $W->RegExpLineEdit(); | |
| 236 | - $widget->setRegExp(Widget_RegExpLineEdit::INT_FORMAT) | |
| 237 | -					->setSubmitMessage(sprintf($App->translate('The field %s should be a integer number'), $this->name)) | |
| 238 | - ->setSize(10); | |
| 239 | - break; | |
| 240 | - | |
| 241 | - case 'Decimal': | |
| 242 | - $widget = $W->RegExpLineEdit(); | |
| 243 | - $widget->setRegExp(Widget_RegExpLineEdit::FLOAT_FORMAT) | |
| 244 | -					->setSubmitMessage(sprintf($App->translate('The field %s should be a decimal number'), $this->name)) | |
| 245 | - ->setSize(10); | |
| 246 | - break; | |
| 247 | - | |
| 248 | - case 'Url': | |
| 249 | - $widget = $W->UrlLineEdit(); | |
| 250 | - break; | |
| 251 | - | |
| 252 | - case 'Email': | |
| 253 | - $widget = $W->EmailLineEdit(); | |
| 254 | - break; | |
| 255 | - | |
| 256 | - default: | |
| 257 | - case 'String': | |
| 258 | - $widget = $W->LineEdit()->setSize(70)->setMaxSize(255); | |
| 259 | - break; | |
| 260 | - } | |
| 261 | - | |
| 262 | - $labelledItem = $W->LabelledWidget($this->name, $widget, null); | |
| 263 | - $labelledItem->setName($this->fieldname); | |
| 264 | - | |
| 265 | -		if (!empty($this->description)) { | |
| 266 | - $labelledItem->setDescription($this->description); | |
| 267 | - } | |
| 268 | - | |
| 269 | - return $labelledItem; | |
| 270 | - } | |
| 195 | + /** | |
| 196 | + * @return string[] | |
| 197 | + */ | |
| 198 | + public function getEnumValues() | |
| 199 | +    { | |
| 200 | + return unserialize($this->enumvalues); | |
| 201 | + } | |
| 202 | + | |
| 203 | + | |
| 204 | + /** | |
| 205 | + * @return Widget_LabelledWidget | |
| 206 | + */ | |
| 207 | + public function getWidget() | |
| 208 | +    { | |
| 209 | + $W = bab_Widgets(); | |
| 210 | + $App = $this->App(); | |
| 211 | + | |
| 212 | +        switch ($this->fieldtype) { | |
| 213 | + case 'Text': | |
| 214 | + $widget = $W->TextEdit()->setLines(3)->setColumns(70); | |
| 215 | + break; | |
| 216 | + | |
| 217 | + case 'Bool': | |
| 218 | + $widget = $W->Checkbox(); | |
| 219 | + break; | |
| 220 | + | |
| 221 | + case 'Enum': | |
| 222 | +                $options = array('' => '') + $this->getEnumValues(); | |
| 223 | + $widget = $W->Select()->setOptions($options); | |
| 224 | + break; | |
| 225 | + | |
| 226 | + case 'Date': | |
| 227 | + $widget = $W->DatePicker(); | |
| 228 | + break; | |
| 229 | + | |
| 230 | + case 'DateTime': | |
| 231 | + $widget = $W->DateTimePicker(); | |
| 232 | + break; | |
| 233 | + | |
| 234 | + case 'Int': | |
| 235 | + $widget = $W->RegExpLineEdit(); | |
| 236 | + $widget->setRegExp(Widget_RegExpLineEdit::INT_FORMAT) | |
| 237 | +                    ->setSubmitMessage(sprintf($App->translate('The field %s should be a integer number'), $this->name)) | |
| 238 | + ->setSize(10); | |
| 239 | + break; | |
| 240 | + | |
| 241 | + case 'Decimal': | |
| 242 | + $widget = $W->RegExpLineEdit(); | |
| 243 | + $widget->setRegExp(Widget_RegExpLineEdit::FLOAT_FORMAT) | |
| 244 | +                    ->setSubmitMessage(sprintf($App->translate('The field %s should be a decimal number'), $this->name)) | |
| 245 | + ->setSize(10); | |
| 246 | + break; | |
| 247 | + | |
| 248 | + case 'Url': | |
| 249 | + $widget = $W->UrlLineEdit(); | |
| 250 | + break; | |
| 251 | + | |
| 252 | + case 'Email': | |
| 253 | + $widget = $W->EmailLineEdit(); | |
| 254 | + break; | |
| 255 | + | |
| 256 | + default: | |
| 257 | + case 'String': | |
| 258 | + $widget = $W->LineEdit()->setSize(70)->setMaxSize(255); | |
| 259 | + break; | |
| 260 | + } | |
| 261 | + | |
| 262 | + $labelledItem = $W->LabelledWidget($this->name, $widget, null); | |
| 263 | + $labelledItem->setName($this->fieldname); | |
| 264 | + | |
| 265 | +        if (!empty($this->description)) { | |
| 266 | + $labelledItem->setDescription($this->description); | |
| 267 | + } | |
| 268 | + | |
| 269 | + return $labelledItem; | |
| 270 | + } | |
| 271 | 271 | } |