Exemple #1
0
 public function onBeforeStore($updateNulls)
 {
     if (!$this->alias) {
         $this->alias = FOFStringUtils::toSlug($this->name);
     }
     return parent::onBeforeStore($updateNulls);
 }
Exemple #2
0
 protected function onBeforeStore($updateNulls)
 {
     if (!$this->alias) {
         $this->alias = FOFStringUtils::toSlug($this->title);
     }
     if (isset($this->params)) {
         $this->params = json_encode($this->params);
     }
     return parent::onBeforeStore($updateNulls);
 }
 /**
  * Overrides the automated table checks to handle the 'hash' column for faster searching
  *
  * @return boolean
  */
 public function check()
 {
     // Create a slug if there is a title and an empty slug
     if ($this->hasField('title') && $this->hasField('slug') && empty($this->slug)) {
         $this->slug = FOFStringUtils::toSlug($this->title);
     }
     // Create the SHA-1 hash of the slug for faster searching (make sure the hash column is CHAR(64) to take
     // advantage of MySQL's optimised searching for fixed size CHAR columns)
     if ($this->hasField('hash') && $this->hasField('slug')) {
         $this->hash = sha1($this->slug);
     }
     // Reset cached values
     $this->resetTreeCache();
     return parent::check();
 }
 /**
  * Get the field configuration
  *
  * @return  array
  */
 protected function getConfig()
 {
     // If no custom options were defined let's figure out which ones of the
     // defaults we shall use...
     $config = array('published' => 1, 'unpublished' => 1, 'archived' => 0, 'trash' => 0, 'all' => 0);
     $stack = array();
     if (isset($this->element['show_published'])) {
         $config['published'] = FOFStringUtils::toBool($this->element['show_published']);
     }
     if (isset($this->element['show_unpublished'])) {
         $config['unpublished'] = FOFStringUtils::toBool($this->element['show_unpublished']);
     }
     if (isset($this->element['show_archived'])) {
         $config['archived'] = FOFStringUtils::toBool($this->element['show_archived']);
     }
     if (isset($this->element['show_trash'])) {
         $config['trash'] = FOFStringUtils::toBool($this->element['show_trash']);
     }
     if (isset($this->element['show_all'])) {
         $config['all'] = FOFStringUtils::toBool($this->element['show_all']);
     }
     return $config;
 }
Exemple #5
0
 /**
  * Render a toolbar element.
  *
  * @param   string  $type        The element type.
  * @param   mixed   $value       The element value.
  * @param   array   $attributes  The element attributes.
  *
  * @return  void
  *
  * @throws  InvalidArgumentException
  */
 private function renderToolbarElement($type, $value = null, array $attributes = array())
 {
     switch ($type) {
         case 'title':
             $icon = isset($attributes['icon']) ? $attributes['icon'] : 'generic.png';
             JToolbarHelper::title($value, $icon);
             break;
         case 'divider':
             JToolbarHelper::divider();
             break;
         case 'custom':
             $task = isset($attributes['task']) ? $attributes['task'] : '';
             $icon = isset($attributes['icon']) ? $attributes['icon'] : '';
             $iconOver = isset($attributes['icon_over']) ? $attributes['icon_over'] : '';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : '';
             $listSelect = isset($attributes['list_select']) ? FOFStringUtils::toBool($attributes['list_select']) : true;
             JToolbarHelper::custom($task, $icon, $iconOver, $alt, $listSelect);
             break;
         case 'preview':
             $url = isset($attributes['url']) ? $attributes['url'] : '';
             $update_editors = isset($attributes['update_editors']) ? FOFStringUtils::toBool($attributes['update_editors']) : false;
             JToolbarHelper::preview($url, $update_editors);
             break;
         case 'help':
             if (!isset($attributes['help'])) {
                 throw new InvalidArgumentException('The help attribute is missing in the help button type.');
             }
             $ref = $attributes['help'];
             $com = isset($attributes['com']) ? FOFStringUtils::toBool($attributes['com']) : false;
             $override = isset($attributes['override']) ? $attributes['override'] : null;
             $component = isset($attributes['component']) ? $attributes['component'] : null;
             JToolbarHelper::help($ref, $com, $override, $component);
             break;
         case 'back':
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_BACK';
             $href = isset($attributes['href']) ? $attributes['href'] : 'javascript:history.back();';
             JToolbarHelper::back($alt, $href);
             break;
         case 'media_manager':
             $directory = isset($attributes['directory']) ? $attributes['directory'] : '';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UPLOAD';
             JToolbarHelper::media_manager($directory, $alt);
             break;
         case 'assign':
             $task = isset($attributes['task']) ? $attributes['task'] : 'assign';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_ASSIGN';
             JToolbarHelper::assign($task, $alt);
             break;
         case 'new':
             if ($this->perms->create) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'add';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_NEW';
                 $check = isset($attributes['check']) ? FOFStringUtils::toBool($attributes['check']) : false;
                 JToolbarHelper::addNew($task, $alt, $check);
             }
             break;
         case 'publish':
             if ($this->perms->editstate) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'publish';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_PUBLISH';
                 $check = isset($attributes['check']) ? FOFStringUtils::toBool($attributes['check']) : false;
                 JToolbarHelper::publish($task, $alt, $check);
             }
             break;
         case 'publishList':
             if ($this->perms->editstate) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'publish';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_PUBLISH';
                 JToolbarHelper::publishList($task, $alt);
             }
             break;
         case 'unpublish':
             if ($this->perms->editstate) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'unpublish';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNPUBLISH';
                 $check = isset($attributes['check']) ? FOFStringUtils::toBool($attributes['check']) : false;
                 JToolbarHelper::unpublish($task, $alt, $check);
             }
             break;
         case 'unpublishList':
             if ($this->perms->editstate) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'unpublish';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNPUBLISH';
                 JToolbarHelper::unpublishList($task, $alt);
             }
             break;
         case 'archiveList':
             if ($this->perms->editstate) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'archive';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_ARCHIVE';
                 JToolbarHelper::archiveList($task, $alt);
             }
             break;
         case 'unarchiveList':
             if ($this->perms->editstate) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'unarchive';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_UNARCHIVE';
                 JToolbarHelper::unarchiveList($task, $alt);
             }
             break;
         case 'editList':
             if ($this->perms->edit) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'edit';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT';
                 JToolbarHelper::editList($task, $alt);
             }
             break;
         case 'editHtml':
             $task = isset($attributes['task']) ? $attributes['task'] : 'edit_source';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT_HTML';
             JToolbarHelper::editHtml($task, $alt);
             break;
         case 'editCss':
             $task = isset($attributes['task']) ? $attributes['task'] : 'edit_css';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_EDIT_CSS';
             JToolbarHelper::editCss($task, $alt);
             break;
         case 'deleteList':
             if ($this->perms->delete) {
                 $msg = isset($attributes['msg']) ? $attributes['msg'] : '';
                 $task = isset($attributes['task']) ? $attributes['task'] : 'remove';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_DELETE';
                 JToolbarHelper::deleteList($msg, $task, $alt);
             }
             break;
         case 'trash':
             if ($this->perms->editstate) {
                 $task = isset($attributes['task']) ? $attributes['task'] : 'remove';
                 $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_TRASH';
                 $check = isset($attributes['check']) ? FOFStringUtils::toBool($attributes['check']) : true;
                 JToolbarHelper::trash($task, $alt, $check);
             }
             break;
         case 'apply':
             $task = isset($attributes['task']) ? $attributes['task'] : 'apply';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_APPLY';
             JToolbarHelper::apply($task, $alt);
             break;
         case 'save':
             $task = isset($attributes['task']) ? $attributes['task'] : 'save';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE';
             JToolbarHelper::save($task, $alt);
             break;
         case 'save2new':
             $task = isset($attributes['task']) ? $attributes['task'] : 'save2new';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AND_NEW';
             JToolbarHelper::save2new($task, $alt);
             break;
         case 'save2copy':
             $task = isset($attributes['task']) ? $attributes['task'] : 'save2copy';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_SAVE_AS_COPY';
             JToolbarHelper::save2copy($task, $alt);
             break;
         case 'checkin':
             $task = isset($attributes['task']) ? $attributes['task'] : 'checkin';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_CHECKIN';
             $check = isset($attributes['check']) ? FOFStringUtils::toBool($attributes['check']) : true;
             JToolbarHelper::checkin($task, $alt, $check);
             break;
         case 'cancel':
             $task = isset($attributes['task']) ? $attributes['task'] : 'cancel';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JTOOLBAR_CANCEL';
             JToolbarHelper::cancel($task, $alt);
             break;
         case 'preferences':
             if (!isset($attributes['component'])) {
                 throw new InvalidArgumentException('The component attribute is missing in the preferences button type.');
             }
             $component = $attributes['component'];
             $height = isset($attributes['height']) ? $attributes['height'] : '550';
             $width = isset($attributes['width']) ? $attributes['width'] : '875';
             $alt = isset($attributes['alt']) ? $attributes['alt'] : 'JToolbar_Options';
             $path = isset($attributes['path']) ? $attributes['path'] : '';
             JToolbarHelper::preferences($component, $height, $width, $alt, $path);
             break;
         default:
             throw new InvalidArgumentException(sprintf('Unknown button type %s', $type));
     }
 }
Exemple #6
0
 /**
  * The event which runs before storing (saving) data to the database
  *
  * @param   boolean  $updateNulls  Should nulls be saved as nulls (true) or just skipped over (false)?
  *
  * @return  boolean  True to allow saving
  */
 protected function onBeforeStore($updateNulls)
 {
     // Do we have a "Created" set of fields?
     $created_on = $this->getColumnAlias('created_on');
     $created_by = $this->getColumnAlias('created_by');
     $modified_on = $this->getColumnAlias('modified_on');
     $modified_by = $this->getColumnAlias('modified_by');
     $locked_on = $this->getColumnAlias('locked_on');
     $locked_by = $this->getColumnAlias('locked_by');
     $title = $this->getColumnAlias('title');
     $slug = $this->getColumnAlias('slug');
     $hasCreatedOn = in_array($created_on, $this->getKnownFields());
     $hasCreatedBy = in_array($created_by, $this->getKnownFields());
     if ($hasCreatedOn && $hasCreatedBy) {
         $hasModifiedOn = in_array($modified_on, $this->getKnownFields());
         $hasModifiedBy = in_array($modified_by, $this->getKnownFields());
         $nullDate = $this->_db->getNullDate();
         if (empty($this->{$created_by}) || $this->{$created_on} == $nullDate || empty($this->{$created_on})) {
             $uid = FOFPlatform::getInstance()->getUser()->id;
             if ($uid) {
                 $this->{$created_by} = FOFPlatform::getInstance()->getUser()->id;
             }
             $date = FOFPlatform::getInstance()->getDate('now', null, false);
             $this->{$created_on} = $date->toSql();
         } elseif ($hasModifiedOn && $hasModifiedBy) {
             $uid = FOFPlatform::getInstance()->getUser()->id;
             if ($uid) {
                 $this->{$modified_by} = FOFPlatform::getInstance()->getUser()->id;
             }
             $date = FOFPlatform::getInstance()->getDate('now', null, false);
             $this->{$modified_on} = $date->toSql();
         }
     }
     // Do we have a set of title and slug fields?
     $hasTitle = in_array($title, $this->getKnownFields());
     $hasSlug = in_array($slug, $this->getKnownFields());
     if ($hasTitle && $hasSlug) {
         if (empty($this->{$slug})) {
             // Create a slug from the title
             $this->{$slug} = FOFStringUtils::toSlug($this->{$title});
         } else {
             // Filter the slug for invalid characters
             $this->{$slug} = FOFStringUtils::toSlug($this->{$slug});
         }
         // Make sure we don't have a duplicate slug on this table
         $db = $this->getDbo();
         $query = $db->getQuery(true)->select($db->qn($slug))->from($this->_tbl)->where($db->qn($slug) . ' = ' . $db->q($this->{$slug}))->where('NOT ' . $db->qn($this->_tbl_key) . ' = ' . $db->q($this->{$this->_tbl_key}));
         $db->setQuery($query);
         $existingItems = $db->loadAssocList();
         $count = 0;
         $newSlug = $this->{$slug};
         while (!empty($existingItems)) {
             $count++;
             $newSlug = $this->{$slug} . '-' . $count;
             $query = $db->getQuery(true)->select($db->qn($slug))->from($this->_tbl)->where($db->qn($slug) . ' = ' . $db->q($newSlug))->where('NOT ' . $db->qn($this->_tbl_key) . ' = ' . $db->q($this->{$this->_tbl_key}));
             $db->setQuery($query);
             $existingItems = $db->loadAssocList();
         }
         $this->{$slug} = $newSlug;
     }
     // Call the behaviors
     $result = $this->tableDispatcher->trigger('onBeforeStore', array(&$this, $updateNulls));
     if (in_array(false, $result, true)) {
         // Behavior failed, return false
         return false;
     }
     // Execute onBeforeStore<tablename> events in loaded plugins
     if ($this->_trigger_events) {
         $name = FOFInflector::pluralize($this->getKeyName());
         $result = FOFPlatform::getInstance()->runPlugins('onBeforeStore' . ucfirst($name), array(&$this, $updateNulls));
         if (in_array(false, $result, true)) {
             return false;
         } else {
             return true;
         }
     }
     return true;
 }
		<tfoot>
			<tr>
				<td colspan="11"><?php 
echo $this->pagination->getListFooter();
?>
</td>
			</tr>
		</tfoot>
		<tbody>
		<?php 
$i = 1;
foreach ($this->items as $profile) {
    $id = JHTML::_('grid.id', ++$i, $profile->id);
    $link = 'index.php?option=com_akeeba&amp;view=profiles&amp;task=edit&amp;id=' . $profile->id;
    $i = 1 - $i;
    $exportBaseName = FOFStringUtils::toSlug($profile->description);
    ?>
			<tr class="row<?php 
    echo $i;
    ?>
">
				<td><?php 
    echo $id;
    ?>
</td>
				<td><?php 
    echo $profile->id;
    ?>
</td>
				<td>
					<button class="btn btn-mini btn-primary" onclick="window.location='index.php?option=com_akeeba&task=switchprofile&profileid=<?php 
 protected function onBeforeStore($updateNulls)
 {
     // Do we have a "Created" set of fields?
     $created_on = $this->getColumnAlias('created_on');
     $created_by = $this->getColumnAlias('created_by');
     $modified_on = $this->getColumnAlias('modified_on');
     $modified_by = $this->getColumnAlias('modified_by');
     $locked_on = $this->getColumnAlias('locked_on');
     $locked_by = $this->getColumnAlias('locked_by');
     $title = $this->getColumnAlias('title');
     $slug = $this->getColumnAlias('slug');
     $hasCreatedOn = isset($this->{$created_on}) || property_exists($this, $created_on);
     $hasCreatedBy = isset($this->{$created_by}) || property_exists($this, $created_by);
     // first of all, let's unset fields that aren't related to the table (ie joined fields)
     $fields = $this->getTableFields();
     $properties = $this->getProperties();
     foreach ($properties as $property => $value) {
         // 'input' property is a reserved name
         if ($property == 'input') {
             continue;
         }
         if (!isset($fields[$property])) {
             unset($this->{$property});
         }
     }
     if ($hasCreatedOn && $hasCreatedBy) {
         $hasModifiedOn = isset($this->{$modified_on}) || property_exists($this, $modified_on);
         $hasModifiedBy = isset($this->{$modified_by}) || property_exists($this, $modified_by);
         if (empty($this->{$created_by}) || $this->{$created_on} == '0000-00-00 00:00:00' || empty($this->{$created_on})) {
             $uid = JFactory::getUser()->id;
             if ($uid) {
                 $this->{$created_by} = JFactory::getUser()->id;
             }
             JLoader::import('joomla.utilities.date');
             $date = new JDate();
             if (version_compare(JVERSION, '3.0', 'ge')) {
                 $this->{$created_on} = $date->toSql();
             } else {
                 $this->{$created_on} = $date->toMysql();
             }
         } elseif ($hasModifiedOn && $hasModifiedBy) {
             $uid = JFactory::getUser()->id;
             if ($uid) {
                 $this->{$modified_by} = JFactory::getUser()->id;
             }
             JLoader::import('joomla.utilities.date');
             $date = new JDate();
             if (version_compare(JVERSION, '3.0', 'ge')) {
                 $this->{$modified_on} = $date->toSql();
             } else {
                 $this->{$modified_on} = $date->toMysql();
             }
         }
     }
     // Do we have a set of title and slug fields?
     $hasTitle = isset($this->{$title}) || property_exists($this, $title);
     $hasSlug = isset($this->{$slug}) || property_exists($this, $slug);
     if ($hasTitle && $hasSlug) {
         if (empty($this->{$slug})) {
             // Create a slug from the title
             $this->{$slug} = FOFStringUtils::toSlug($this->{$title});
         } else {
             // Filter the slug for invalid characters
             $this->{$slug} = FOFStringUtils::toSlug($this->{$slug});
         }
         // Make sure we don't have a duplicate slug on this table
         $db = $this->getDbo();
         $query = $db->getQuery(true)->select($db->qn($slug))->from($this->_tbl)->where($db->qn($slug) . ' = ' . $db->q($this->{$slug}))->where('NOT ' . $db->qn($this->_tbl_key) . ' = ' . $db->q($this->{$this->_tbl_key}));
         $db->setQuery($query);
         $existingItems = $db->loadAssocList();
         $count = 0;
         $newSlug = $this->{$slug};
         while (!empty($existingItems)) {
             $count++;
             $newSlug = $this->{$slug} . '-' . $count;
             $query = $db->getQuery(true)->select($db->qn($slug))->from($this->_tbl)->where($db->qn($slug) . ' = ' . $db->q($newSlug))->where($db->qn($this->_tbl_key) . ' = ' . $db->q($this->{$this->_tbl_key}), 'AND NOT');
             $db->setQuery($query);
             $existingItems = $db->loadAssocList();
         }
         $this->{$slug} = $newSlug;
     }
     // Execute onBeforeStore<tablename> events in loaded plugins
     if ($this->_trigger_events) {
         $name = FOFInflector::pluralize($this->getKeyName());
         $dispatcher = JDispatcher::getInstance();
         $result = $dispatcher->trigger('onBeforeStore' . ucfirst($name), array(&$this, $updateNulls));
         if (in_array(false, $result, true)) {
             return false;
         } else {
             return true;
         }
     }
     return true;
 }