Ejemplo n.º 1
1
 /**
  * Prepare and sanitise the table data prior to saving.
  *
  * @param   JTable  $table  A reference to a JTable object.
  *
  * @return  void
  *
  * @since   12.2
  */
 protected function prepareTable($table)
 {
     require_once JDeveloperLIB . "/template.php";
     $type = $table->get("type", "");
     $dir = JDeveloperTEMPLATES . "/fields/formfields/" . $type . ".php";
     if ($table->id == 0 && JFile::exists($dir)) {
         $template = new JDeveloperTemplate($dir);
         $template->addAreas(array("header" => false));
         $template->addPlaceholders(array("name" => $table->name), true);
         $table->source = $template->getBuffer();
     }
 }
Ejemplo n.º 2
0
 /**
  * Get a connection table object
  *
  * @param   int  $id  connection id
  *
  * @return  FabrikTableConnection  Connection tables
  */
 public function &getConnection($id = null)
 {
     if (!is_null($id)) {
         $this->setId($id);
     }
     if (!is_object($this->connection)) {
         if ($this->id == -1 || $this->id == '') {
             $this->connection = $this->loadDefaultConnection();
         } else {
             $this->connection = FabTable::getInstance('Connection', 'FabrikTable');
             $this->connection->load($this->id);
         }
         $this->decryptPw($this->connection);
     }
     if ($this->connection->get('published') !== '1') {
         throw new RuntimeException('Connection ID #' . $this->connection->get('id') . ' is unpublished or trashed', E_ERROR);
     }
     return $this->connection;
 }
Ejemplo n.º 3
0
 /**
  * Set element data into table format, called from JModelAdmin::perpareTable();
  *
  * @param    \JTable $table  The JTable object prepare save to DB.
  * @param    array  $attrs  Field's attributes.
  * @param    array  $option Some option.
  */
 public function setFieldTable($table, $attrs = null, $option = array())
 {
     $field_type = $table->get('field_type', 'text');
     $input = $this->container->get('input');
     if (!is_array($attrs)) {
         $attrs = $input->getVar('attrs', array());
     }
     $context = \JArrayHelper::getValue($option, 'context', 'lib_windwalker.field');
     $this->event->trigger('onCCKEngineBeforeSaveField', array($context, &$table, &$attrs, $option));
     // Check is table have all needed column
     // ==================================================================
     $this->checkTable($table, $context);
     // Filter Attrs
     // ==================================================================
     $attrs = $this->filterFields($field_type, $attrs);
     // Convert Name to uppercase and safe ID
     // ==================================================================
     $name = \JArrayHelper::getValue($attrs, 'name');
     $name = $this->regularizeName($name);
     $attrs['name'] = $name;
     // Set Name as Field ID
     if (isset($table->name)) {
         $table->set('name', $name);
     }
     // Remove empty options
     // ==================================================================
     if (!empty($attrs['options']['value'])) {
         foreach ($attrs['options']['value'] as $k => $val) {
             if (!$attrs['options']['value'][$k] && !$attrs['options']['text'][$k]) {
                 unset($attrs['options']['value'][$k]);
                 unset($attrs['options']['text'][$k]);
             }
         }
     }
     // Build Element
     // ==================================================================
     $table->element = $this->buildElement($field_type, $attrs, $option);
     $table->name = $name;
     $table->label = $attrs['label'];
     $table->attrs = json_encode($attrs);
     $table->required = CCKHelper::isBool($attrs['required']);
     $this->event->trigger('onCCKEngineAfterSaveField', array($context, &$table, &$attrs, $option));
 }
Ejemplo n.º 4
0
 /**
  * Add the page title and toolbar.
  *
  * @since    1.6
  *
  * @return  null
  */
 protected function addToolbar()
 {
     $app = JFactory::getApplication();
     $app->input->set('hidemainmenu', true);
     $user = JFactory::getUser();
     $isNew = $this->item->get('id') == 0;
     $userId = $user->get('id');
     $checkedOutBy = $this->item->get('checked_out');
     $checkedOut = !($checkedOutBy == 0 || $checkedOutBy == $user->get('id'));
     $canDo = FabrikAdminHelper::getActions($this->state->get('filter.category_id'));
     $title = $isNew ? FText::_('COM_FABRIK_MANAGER_VISUALIZATION_NEW') : FText::_('COM_FABRIK_MANAGER_VISUALIZATION_EDIT');
     $title .= $isNew ? '' : ' "' . $this->item->get('label') . '"';
     JToolBarHelper::title($title, 'chart');
     if ($isNew) {
         // For new records, check the create permission.
         if ($canDo->get('core.create')) {
             JToolBarHelper::apply('visualization.apply', 'JTOOLBAR_APPLY');
             JToolBarHelper::save('visualization.save', 'JTOOLBAR_SAVE');
             JToolBarHelper::addNew('visualization.save2new', 'JTOOLBAR_SAVE_AND_NEW');
         }
         JToolBarHelper::cancel('visualization.cancel', 'JTOOLBAR_CANCEL');
     } else {
         // Can't save the record if it's checked out.
         if (!$checkedOut) {
             // Since it's an existing record, check the edit permission, or fall back to edit own if the owner.
             if ($canDo->get('core.edit') || $canDo->get('core.edit.own') && $this->item->get('created_by') == $userId) {
                 JToolBarHelper::apply('visualization.apply', 'JTOOLBAR_APPLY');
                 JToolBarHelper::save('visualization.save', 'JTOOLBAR_SAVE');
                 // We can save this record, but check the create permission to see if we can return to make a new one.
                 if ($canDo->get('core.create')) {
                     JToolBarHelper::addNew('visualization.save2new', 'JTOOLBAR_SAVE_AND_NEW');
                 }
             }
         }
         if ($canDo->get('core.create')) {
             JToolBarHelper::custom('visualization.save2copy', 'save-copy.png', 'save-copy_f2.png', 'JTOOLBAR_SAVE_AS_COPY', false);
         }
         JToolBarHelper::cancel('visualization.cancel', 'JTOOLBAR_CLOSE');
     }
     JToolBarHelper::divider();
     JToolBarHelper::help('JHELP_COMPONENTS_FABRIK_VISUALIZATIONS_EDIT', false, FText::_('JHELP_COMPONENTS_FABRIK_VISUALIZATIONS_EDIT'));
 }
Ejemplo n.º 5
0
 /**
  * Set element data into table format, called from JModelAdmin::perpareTable();
  * 
  * @param    JTable   $table    The JTable object prepare save to DB.
  * @param    array    $attrs    Field's attributes.
  * @param    array    $option   Some option.
  */
 public static function setFieldTable($table, $attrs = null, $option = array())
 {
     $field_type = $table->get('field_type', 'text');
     if (!is_array($attrs)) {
         $attrs = $_REQUEST['attrs'];
     }
     $context = JArrayHelper::getValue($option, 'context', 'lib_windwalker.field');
     JFactory::getApplication()->triggerEvent('onCCKEngineBeforeSaveField', array($context, &$table, &$attrs, $option));
     // Check is table have all needed column
     // ==================================================================
     self::checkTable($table, $context);
     // Filter Attrs
     // ==================================================================
     $attrs = self::filterFields($field_type, $attrs);
     // Convert Name to uppercase and safe ID
     // ==================================================================
     $name = JArrayHelper::getValue($attrs, 'name');
     $name = self::filterName($name);
     $attrs['name'] = $name;
     // Set Name as Field ID
     if (isset($table->name)) {
         $table->set('name', $name);
     }
     // Remove empty options
     // ==================================================================
     foreach ($attrs['options']['value'] as $k => $val) {
         if (!$attrs['options']['value'][$k] && !$attrs['options']['text'][$k]) {
             unset($attrs['options']['value'][$k]);
             unset($attrs['options']['text'][$k]);
         }
     }
     // Build Element
     // ==================================================================
     $table->element = self::buildElement($field_type, $attrs, $option);
     $table->name = $name;
     $table->label = $attrs['label'];
     $table->attrs = json_encode($attrs);
     JFactory::getApplication()->triggerEvent('onCCKEngineAfterSaveField', array($context, &$table, &$attrs, $option));
 }
Ejemplo n.º 6
0
 /**
  * Alter the db table's collation
  *
  * @param   FabrikFEModelList $feModel       Front end list model
  * @param   string            $origCollation Original collection name
  * @param   JTable            $row           New collation
  *
  * @since   3.0.7
  *
  * @return boolean
  */
 protected function collation($feModel, $origCollation, $row)
 {
     // Don't attempt to alter new table, or a view, or if we shouldn't alter the table
     if ($row->get('id') == 0 || $feModel->isView() || !$feModel->canAlterFields()) {
         return false;
     }
     $params = new Registry($row->get('params'));
     $newCollation = $params->get('collation');
     if ($newCollation !== $origCollation) {
         $db = $feModel->getDb();
         $item = $feModel->getTable();
         $db->setQuery('ALTER TABLE ' . $item->db_table_name . ' COLLATE  ' . $newCollation);
         $db->execute();
     }
     return true;
 }
Ejemplo n.º 7
0
 /**
  * Method to add or update tags associated with an item.
  *
  * @param   integer  $ucmId    Id of the #__ucm_content item being tagged
  * @param   JTable   $table    JTable object being tagged
  * @param   array    $tags     Array of tags to be applied.
  * @param   boolean  $replace  Flag indicating if all exising tags should be replaced
  *
  * @return  boolean  true on success, otherwise false.
  *
  * @since   3.1
  */
 public function tagItem($ucmId, $table, $tags = array(), $replace = true)
 {
     $key = $table->get('_tbl_key');
     $oldTags = $this->getTagIds((int) $table->{$key}, $this->typeAlias);
     $oldTags = explode(',', $oldTags);
     $result = $this->unTagItem($ucmId, $table);
     if ($replace) {
         $newTags = $tags;
     } else {
         if ($tags == array()) {
             $newTags = $table->newTags;
         } else {
             $newTags = $tags;
         }
         if ($oldTags[0] != '') {
             $newTags = array_unique(array_merge($newTags, $oldTags));
         }
     }
     if (is_array($newTags) && count($newTags) > 0) {
         $result = $result && $this->addTagMapping($ucmId, $table, $newTags);
     }
     return $result;
 }
Ejemplo n.º 8
0
 /**
  * Prepare project images before saving.
  *
  * @param   JTable $table
  *
  * @throws Exception
  *
  * @since    1.6
  */
 protected function prepareTable($table)
 {
     // Set order value
     if (!$table->get('id') and !$table->get('ordering')) {
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select('MAX(a.ordering)')->from($db->quoteName('#__crowdf_rewards', 'a'))->where('a.project_id = ' . (int) $table->get('project_id'));
         $db->setQuery($query, 0, 1);
         $max = $db->loadResult();
         $table->set('ordering', $max + 1);
     }
 }
Ejemplo n.º 9
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @param JTable $table
  *
  * @since    1.6
  */
 protected function prepareTable($table)
 {
     // get maximum order number
     if (!$table->get("id")) {
         // Set ordering to the last item if not set
         if (!$table->get("ordering")) {
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             $query->select("MAX(a.ordering)")->from($db->quoteName("#__itpm_tags", "a"))->where("a.url_id =" . (int) $table->get("url_id"));
             $db->setQuery($query, 0, 1);
             $max = $db->loadResult();
             $table->set("ordering", $max + 1);
         }
     }
 }
Ejemplo n.º 10
0
 /**
  * Method to get an object containing all of the table columns and values.
  *
  * @param   JTable  $table  JTable object.
  *
  * @return  object Contains all of the columns and values.
  *
  * @since   3.2
  */
 public function getDataObject(JTable $table)
 {
     $fields = $table->getFields();
     $dataObject = new stdClass();
     foreach ($fields as $field) {
         $fieldName = $field->Field;
         $dataObject->{$fieldName} = $table->get($fieldName);
     }
     return $dataObject;
 }
Ejemplo n.º 11
0
 /**
  * Function that preProcesses data from a table prior to a store() to ensure proper tag handling
  *
  * @param   JTable  $table      JTable being processed
  *
  * @return  null
  *
  * @since   3.1
  */
 public function preStoreProcess($table)
 {
     if ($newMetadata = $this->createTagsFromMetadata($table->metadata)) {
         $table->metadata = $newMetadata;
     }
     // If existing row, check to see if tags have changed.
     $oldTable = clone $table;
     $oldTable->reset();
     $key = $oldTable->getKeyName();
     if ($oldTable->{$key} && $oldTable->load()) {
         $oldMetaObject = json_decode($oldTable->get('metadata'));
         $oldTags = isset($oldMetaObject->tags) ? $oldMetaObject->tags : null;
         $newMetaObject = json_decode($table->get('metadata'));
         $newTags = isset($newMetaObject->tags) ? $newMetaObject->tags : null;
     }
     // New items with no tags bypass this step.
     if (!empty($newTags) && !empty($oldTags)) {
         // We need to process tags if the tags have changed or if we have a new row
         $this->tagsChanged = $oldTags != $newTags || !$table->{$key};
     }
 }
Ejemplo n.º 12
0
 /**
  * Delete the images.
  *
  * @param JTable $row
  * @param string $mediaFolder
  * @param League\Flysystem\Filesystem  $filesystem
  */
 protected function deleteImages($row, $mediaFolder, $filesystem)
 {
     // Delete the profile pictures.
     if ($row->get('image') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image'))) {
         $filesystem->delete($mediaFolder . '/' . $row->get('image'));
     }
     if ($row->get('image_small') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_small'))) {
         $filesystem->delete($mediaFolder . '/' . $row->get('image_small'));
     }
     if ($row->get('image_square') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_square'))) {
         $filesystem->delete($mediaFolder . '/' . $row->get('image_square'));
     }
     if ($row->get('image_icon') !== '' and $filesystem->has($mediaFolder . '/' . $row->get('image_icon'))) {
         $filesystem->delete($mediaFolder . '/' . $row->get('image_icon'));
     }
 }