/** * 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 = F0FStringUtils::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(); }
/** * 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 = F0FPlatform::getInstance()->getUser()->id; if ($uid) { $this->{$created_by} = F0FPlatform::getInstance()->getUser()->id; } $date = F0FPlatform::getInstance()->getDate('now', null, false); $this->{$created_on} = method_exists($date, 'toSql') ? $date->toSql() : $date->toMySQL(); } elseif ($hasModifiedOn && $hasModifiedBy) { $uid = F0FPlatform::getInstance()->getUser()->id; if ($uid) { $this->{$modified_by} = F0FPlatform::getInstance()->getUser()->id; } $date = F0FPlatform::getInstance()->getDate('now', null, false); $this->{$modified_on} = method_exists($date, 'toSql') ? $date->toSql() : $date->toMySQL(); } } // 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} = F0FStringUtils::toSlug($this->{$title}); } else { // Filter the slug for invalid characters $this->{$slug} = F0FStringUtils::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 = F0FInflector::pluralize($this->getKeyName()); $result = F0FPlatform::getInstance()->runPlugins('onBeforeStore' . ucfirst($name), array(&$this, $updateNulls)); if (in_array(false, $result, true)) { return false; } else { return true; } } return true; }
<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&view=profiles&task=edit&id=' . $profile->id; $i = 1 - $i; $exportBaseName = F0FStringUtils::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