示例#1
0
 public function onBeforeStore($updateNulls)
 {
     if (!$this->alias) {
         $this->alias = FOFStringUtils::toSlug($this->name);
     }
     return parent::onBeforeStore($updateNulls);
 }
示例#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();
 }
示例#4
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 
示例#6
0
 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;
 }