Beispiel #1
0
 /**
  * Method to get an object.
  *
  * @param   integer  $id  The id of the object to get.
  *
  * @return  mixed    Object on success, false on failure.
  */
 public function &getData($id = null)
 {
     if ($this->_item === null) {
         $this->_item = false;
         if (empty($id)) {
             $id = $this->getState('course.id');
         }
         // Get a level row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         if ($table->load($id)) {
             // Check published state.
             if ($published = $this->getState('filter.published')) {
                 if ($table->state != $published) {
                     return $this->_item;
                 }
             }
             // Convert the JTable to a clean JObject.
             $properties = $table->getProperties(1);
             $this->_item = ArrayHelper::toObject($properties, 'JObject');
         }
     }
     if (isset($this->_item->created_by)) {
         $this->_item->created_by_name = JFactory::getUser($this->_item->created_by)->name;
     }
     return $this->_item;
 }
Beispiel #2
0
 /**
  * Can the row be edited
  *
  * @param   object  $row  Current row to test
  *
  * @return boolean
  */
 public function onCanEdit($row)
 {
     $params = $this->getParams();
     // If $row is null, we were called from the list's canEdit() in a per-table rather than per-row context,
     // and we don't have an opinion on per-table edit permissions, so just return true.
     if (is_null($row) || is_null($row[0])) {
         return true;
     }
     if (is_array($row[0])) {
         $data = ArrayHelper::toObject($row[0]);
     } else {
         $data = $row[0];
     }
     /**
      * If __pk_val is not set or empty, then we've probably been called from somewhere in form processing,
      * and this is a new row.  In which case this plugin cannot offer any opinion!
      */
     if (!isset($data->__pk_val) || empty($data->__pk_val)) {
         return true;
     }
     $field = str_replace('.', '___', $params->get('caneditrow_field'));
     // If they provided some PHP to eval, we ignore the other settings and just run their code
     $caneditrow_eval = $params->get('caneditrow_eval', '');
     // $$$ rob if no can edit field selected in admin return true
     if (trim($field) == '' && trim($caneditrow_eval) == '') {
         $this->acl[$data->__pk_val] = true;
         return true;
     }
     if (!empty($caneditrow_eval)) {
         $w = new FabrikWorker();
         $data = ArrayHelper::fromObject($data);
         $caneditrow_eval = $w->parseMessageForPlaceHolder($caneditrow_eval, $data);
         FabrikWorker::clearEval();
         $caneditrow_eval = @eval($caneditrow_eval);
         FabrikWorker::logEval($caneditrow_eval, 'Caught exception on eval in can edit row : %s');
         $this->acl[$data['__pk_val']] = $caneditrow_eval;
         return $caneditrow_eval;
     } else {
         // No PHP given, so just do a simple match on the specified element and value settings.
         if ($params->get('caneditrow_useraw', '0') == '1') {
             $field .= '_raw';
         }
         $value = $params->get('caneditrow_value');
         $operator = $params->get('operator', '=');
         if (is_object($data->{$field})) {
             $data->{$field} = ArrayHelper::fromObject($data->{$field});
         }
         switch ($operator) {
             case '=':
             default:
                 $return = is_array($data->{$field}) ? in_array($value, $data->{$field}) : $data->{$field} == $value;
                 break;
             case "!=":
                 $return = is_array($data->{$field}) ? !in_array($value, $data->{$field}) : $data->{$field} != $value;
                 break;
         }
         $this->acl[$data->__pk_val] = $return;
         return $return;
     }
 }
Beispiel #3
0
 /**
  * Method to get an object.
  *
  * @param   integer  $id  The id of the object to get.
  *
  * @return  mixed  Object on success, false on failure.
  */
 public function getItem($id = null)
 {
     if ($this->_item === null) {
         $this->_item = false;
         if (empty($id)) {
             $id = $this->getState('weblink.id');
         }
         // Get a level row instance.
         $table = JTable::getInstance('Weblink', 'WeblinksTable');
         // Attempt to load the row.
         if ($table->load($id)) {
             // Check published state.
             if ($published = $this->getState('filter.published')) {
                 if ($table->state != $published) {
                     return $this->_item;
                 }
             }
             // Convert the JTable to a clean JObject.
             $properties = $table->getProperties(1);
             $this->_item = ArrayHelper::toObject($properties, 'JObject');
         } elseif ($error = $table->getError()) {
             $this->setError($error);
         }
     }
     return $this->_item;
 }
Beispiel #4
0
 /**
  * Method to get article data.
  *
  * @param   integer  $itemId  The id of the article.
  *
  * @return  mixed  Content item data object on success, false on failure.
  */
 public function getItem($itemId = null)
 {
     $itemId = (int) (!empty($itemId)) ? $itemId : $this->getState('article.id');
     // Get a row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $return = $table->load($itemId);
     // Check for a table object error.
     if ($return === false && $table->getError()) {
         $this->setError($table->getError());
         return false;
     }
     $properties = $table->getProperties(1);
     $value = ArrayHelper::toObject($properties, 'JObject');
     // Convert attrib field to Registry.
     $value->params = new Registry();
     $value->params->loadString($value->attribs);
     // Compute selected asset permissions.
     $user = JFactory::getUser();
     $userId = $user->get('id');
     $asset = 'com_content.article.' . $value->id;
     // Check general edit permission first.
     if ($user->authorise('core.edit', $asset)) {
         $value->params->set('access-edit', true);
     } elseif (!empty($userId) && $user->authorise('core.edit.own', $asset)) {
         // Check for a valid user and that they are the owner.
         if ($userId == $value->created_by) {
             $value->params->set('access-edit', true);
         }
     }
     // Check edit state permission.
     if ($itemId) {
         // Existing item
         $value->params->set('access-change', $user->authorise('core.edit.state', $asset));
     } else {
         // New item.
         $catId = (int) $this->getState('article.catid');
         if ($catId) {
             $value->params->set('access-change', $user->authorise('core.edit.state', 'com_content.category.' . $catId));
             $value->catid = $catId;
         } else {
             $value->params->set('access-change', $user->authorise('core.edit.state', 'com_content'));
         }
     }
     $value->articletext = $value->introtext;
     if (!empty($value->fulltext)) {
         $value->articletext .= '<hr id="system-readmore" />' . $value->fulltext;
     }
     // Convert the metadata field to an array.
     $registry = new Registry();
     $registry->loadString($value->metadata);
     $value->metadata = $registry->toArray();
     if ($itemId) {
         $value->tags = new JHelperTags();
         $value->tags->getTagIds($value->id, 'com_content.article');
         $value->metadata['tags'] = $value->tags;
     }
     return $value;
 }
Beispiel #5
0
 /**
  * Method to get the field input markup.
  *
  * @return	string	The field input markup.
  */
 protected function getInput()
 {
     JText::script('COM_FABRIK_SUBOPTS_VALUES_ERROR');
     $default = new stdClass();
     $default->sub_values = array();
     $default->sub_labels = array();
     $default->sub_initial_selection = array();
     $opts = $this->value == '' ? $default : ArrayHelper::toObject($this->value);
     $j3 = FabrikWorker::j3();
     if ($j3) {
         $delButton = '<div class="btn-group">';
         $delButton .= '<a class="btn btn-success" href="#" data-button="addSuboption"><i class="icon-plus"></i> </a>';
         $delButton .= '<a class="btn btn-danger" href="#" data-button="deleteSuboption"><i class="icon-minus"></i> </a>';
         $delButton .= '</div>';
     } else {
         $delButton = '<a class="removeButton" href="#"><i class="icon-minus"></i> ' . FText::_('COM_FABRIK_DELETE') . '</a>';
     }
     if (is_array($opts)) {
         $opts['delButton'] = $delButton;
     } else {
         $opts->delButton = $delButton;
     }
     $opts->id = $this->id;
     $opts->j3 = $j3;
     $opts->defaultMax = (int) $this->getAttribute('default_max', 0);
     $opts = json_encode($opts);
     $script[] = "window.addEvent('domready', function () {";
     $script[] = "\tnew Suboptions('{$this->name}', {$opts});";
     $script[] = "});";
     FabrikHelperHTML::script('administrator/components/com_fabrik/models/fields/suboptions.js', implode("\n", $script));
     $html = array();
     if (!$j3) {
         $html[] = '<div style="float:left;width:100%">';
     }
     $html[] = '<table class="table table-striped" style="width: 100%" id="' . $this->id . '">';
     $html[] = '<thead>';
     $html[] = '<tr style="text-align:left">';
     $html[] = '<th style="width: 5%"></th>';
     $html[] = '<th style="width: 30%">' . FText::_('COM_FABRIK_VALUE') . '</th>';
     $html[] = '<th style="width: 30%">' . FText::_('COM_FABRIK_LABEL') . '</th>';
     $html[] = '<th style="width: 10%">' . FText::_('COM_FABRIK_DEFAULT') . '</th>';
     if ($j3) {
         $html[] = '<th style="width: 20%"><a class="btn btn-success" href="#" data-button="addSuboption"><i class="icon-plus"></i> </a></th>';
     }
     $html[] = '</tr>';
     $html[] = '</thead>';
     $html[] = '<tbody></tbody>';
     $html[] = '</table>';
     if (!$j3) {
         $html[] = '<ul id="sub_subElementBody" class="subelements">';
         $html[] = '<li></li>';
         $html[] = '</ul>';
         $html[] = '<a class="addButton" href="#" id="addSuboption"><i class="icon-plus"></i> ' . FText::_('COM_FABRIK_ADD') . '</a></div>';
     }
     FabrikHelperHTML::framework();
     FabrikHelperHTML::iniRequireJS();
     return implode("\n", $html);
 }
 /**
  * Utility function to map an array to a stdClass object.
  *
  * @param   array    &$array     The array to map.
  * @param   string   $class      Name of the class to create
  * @param   boolean  $recursive  Convert also any array inside the main array
  *
  * @return  object   The object mapped from the given array
  *
  * @since   11.1
  * @deprecated  4.0 Use Joomla\Utilities\ArrayHelper::toObject instead
  */
 public static function toObject(&$array, $class = 'stdClass', $recursive = true)
 {
     $obj = null;
     if (is_array($array)) {
         $obj = ArrayHelper::toObject($array, $class, $recursive);
     } else {
         JLog::add('This method is typehinted to be an array in \\Joomla\\Utilities\\ArrayHelper::toObject.', JLog::WARNING, 'deprecated');
     }
     return $obj;
 }
 /**
  * Method to setup the configuration file
  *
  * @param   array  $options  The session options
  *
  * @return  boolean  True on success
  *
  * @since   3.1
  */
 public function setup($options)
 {
     // Get the options as an object for easier handling.
     $options = ArrayHelper::toObject($options);
     // Attempt to create the root user.
     if (!$this->createConfiguration($options)) {
         return false;
     }
     // Attempt to create the root user.
     if (!$this->createRootUser($options)) {
         return false;
     }
     return true;
 }
Beispiel #8
0
 /**
  * Can the row be deleted
  *
  * @param   object  $row  Current row to test
  *
  * @return boolean
  */
 public function onCanDelete($row)
 {
     $params = $this->getParams();
     // If $row is null, we were called from the table's canEdit() in a per-table rather than per-row context,
     // and we don't have an opinion on per-table delete permissions, so just return true.
     if (is_null($row) || is_null($row[0])) {
         return true;
     }
     if (is_array($row[0])) {
         $data = ArrayHelper::toObject($row[0]);
     } else {
         $data = $row[0];
     }
     $field = str_replace('.', '___', $params->get('candeleterow_field'));
     // If they provided some PHP to eval, we ignore the other settings and just run their code
     $canDeleteRowEval = $params->get('candeleterow_eval', '');
     // $$$ rob if no can delete field selected in admin return true
     if (trim($field) == '' && trim($canDeleteRowEval) == '') {
         return true;
     }
     if (!empty($canDeleteRowEval)) {
         $w = new FabrikWorker();
         $data = ArrayHelper::fromObject($data);
         $canDeleteRowEval = $w->parseMessageForPlaceHolder($canDeleteRowEval, $data);
         FabrikWorker::clearEval();
         $canDeleteRowEval = @eval($canDeleteRowEval);
         FabrikWorker::logEval($canDeleteRowEval, 'Caught exception on eval in can delete row : %s');
         return $canDeleteRowEval;
     } else {
         // No PHP given, so just do a simple match on the specified element and value settings.
         if ($params->get('candeleterow_useraw', '0') == '1') {
             $field .= '_raw';
         }
         $value = $params->get('candeleterow_value');
         $operator = $params->get('operator', '=');
         if (!isset($data->{$field})) {
             return false;
         }
         switch ($operator) {
             case '=':
             default:
                 return $data->{$field} == $value;
                 break;
             case "!=":
                 return $data->{$field} != $value;
                 break;
         }
     }
 }
Beispiel #9
0
 /**
  * Set the canonical link - this is the definitive URL that Google et all, will use
  * to determine if duplicate URLs are the same content
  *
  * @return  string
  */
 public function getCanonicalLink()
 {
     $url = '';
     if (!$this->app->isAdmin() && !$this->isMambot) {
         /** @var FabrikFEModelForm $model */
         $model = $this->getModel();
         $data = $model->getData();
         $formId = $model->getId();
         $slug = $model->getListModel()->getSlug(ArrayHelper::toObject($data));
         $rowId = $slug === '' ? $model->getRowId() : $slug;
         $view = $model->isEditable() ? 'form' : 'details';
         $url = JRoute::_('index.php?option=com_' . $this->package . '&view=' . $view . '&formid=' . $formId . '&rowid=' . $rowId);
     }
     return $url;
 }
 /**
  * Method to get a single record.
  *
  * @param   integer  $pk  The id of the primary key.
  *
  * @return  mixed    Object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     $pk = !empty($pk) ? $pk : $this->state->get($this->getName() . '.id');
     $table = $this->getTable();
     if ($pk > 0) {
         // Attempt to load the row.
         $table->load($pk);
     }
     // Convert to the JObject before adding other data.
     $properties = $table->getProperties(1);
     $item = ArrayHelper::toObject($properties, 'stdClass');
     if (!$item) {
         return $item;
     }
     if (property_exists($item, 'params')) {
         $registry = new \JRegistry();
         $registry->loadString($item->params);
         $item->params = $registry->toArray();
     }
     $this->postGetItem($item);
     return $item;
 }
 /**
  * Method to get an object.
  *
  * @param    int  $id  The id of the object to get.
  * @param    int  $userId  User ID.
  *
  * @return    mixed    Object on success, false on failure.
  */
 public function getItem($id, $userId)
 {
     // If missing ID, I have to return null, because there is no item.
     if (!$id or !$userId) {
         return null;
     }
     $storedId = $this->getStoreId($id);
     if (!isset($this->item[$storedId])) {
         $this->item[$storedId] = null;
         // Get a level row instance.
         $table = JTable::getInstance('Notification', 'GamificationTable');
         /** @var $table GamificationTableNotification */
         $keys = array("id" => $id, "user_id" => $userId);
         // Attempt to load the row.
         if ($table->load($keys)) {
             $properties = $table->getProperties();
             $properties = ArrayHelper::toObject($properties);
             $this->item[$storedId] = $properties;
         }
     }
     return !isset($this->item[$storedId]) ? null : $this->item[$storedId];
 }
 /**
  * Verify the FTP settings as being functional and correct.
  *
  * @param   array  $options  Configuration options.
  *
  * @return  mixed  FTP root for given FTP user, or boolean false if not found.
  *
  * @since   3.1
  */
 public function verifyFtpSettings($options)
 {
     // Get the options as a object for easier handling.
     $options = ArrayHelper::toObject($options);
     // Connect and login to the FTP server.
     @($ftp = JClientFtp::getInstance($options->get('ftp_host'), $options->get('ftp_port')));
     // Check to make sure FTP is connected and authenticated.
     if (!$ftp->isConnected()) {
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NOCONNECT'), 'error');
         return false;
     }
     if (!$ftp->login($options->get('ftp_user'), $options->get('ftp_pass'))) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NOLOGIN'), 'error');
         return false;
     }
     // Since the root path will be trimmed when it gets saved to configuration.php,
     // we want to test with the same value as well.
     $root = rtrim($options->get('ftp_root'), '/');
     // Verify PWD function.
     if ($ftp->pwd() === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NOPWD'), 'error');
         return false;
     }
     // Verify root path exists.
     if (!$ftp->chdir($root)) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NOROOT'), 'error');
         return false;
     }
     // Verify NLST function.
     if (($rootList = $ftp->listNames()) === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NONLST'), 'error');
         return false;
     }
     // Verify LIST function.
     if ($ftp->listDetails() === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NOLIST'), 'error');
         return false;
     }
     // Verify SYST function.
     if ($ftp->syst() === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NOSYST'), 'error');
         return false;
     }
     // Verify valid root path, part one.
     $checkList = array('robots.txt', 'index.php');
     if (count(array_diff($checkList, $rootList))) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_INVALIDROOT'), 'error');
         return false;
     }
     // Verify RETR function
     $buffer = null;
     if ($ftp->read($root . '/libraries/cms/version/version.php', $buffer) === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NORETR'), 'error');
         return false;
     }
     // Verify valid root path, part two.
     $checkValue = file_get_contents(JPATH_ROOT . '/libraries/cms/version/version.php');
     if ($buffer !== $checkValue) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_INVALIDROOT'), 'error');
         return false;
     }
     // Verify STOR function.
     if ($ftp->create($root . '/ftp_testfile') === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NOSTOR'), 'error');
         return false;
     }
     // Verify DELE function.
     if ($ftp->delete($root . '/ftp_testfile') === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NODELE'), 'error');
         return false;
     }
     // Verify MKD function.
     if ($ftp->mkdir($root . '/ftp_testdir') === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NOMKD'), 'error');
         return false;
     }
     // Verify RMD function.
     if ($ftp->delete($root . '/ftp_testdir') === false) {
         $ftp->quit();
         JFactory::getApplication()->enqueueMessage(JText::_('INSTL_FTP_NORMD'), 'error');
         return false;
     }
     $ftp->quit();
     return true;
 }
Beispiel #13
0
 /**
  * Method to install the sample data.
  *
  * @param   array  $options  The options array.
  *
  * @return  boolean  True on success.
  *
  * @since   3.1
  */
 public function installSampleData($options)
 {
     if (!isset($options['db_created']) || !$options['db_created']) {
         return $this->createDatabase($options);
     }
     if (!($db = $this->initialise($options))) {
         return false;
     }
     // Get the options as an object for easier handling.
     $options = ArrayHelper::toObject($options);
     // Build the path to the sample data file.
     $type = $options->db_type;
     if ($type == 'mysqli' || $type == 'pdomysql') {
         $type = 'mysql';
     } elseif ($type == 'sqlsrv') {
         $type = 'sqlazure';
     }
     $data = JPATH_INSTALLATION . '/sql/' . $type . '/' . $options->sample_file;
     // Attempt to import the database schema if one is chosen.
     if ($options->sample_file != '') {
         if (!file_exists($data)) {
             JFactory::getApplication()->enqueueMessage(JText::sprintf('INSTL_DATABASE_FILE_DOES_NOT_EXIST', $data), 'error');
             return false;
         } elseif (!$this->populateDatabase($db, $data)) {
             return false;
         }
         $this->postInstallSampleData($db);
     }
     return true;
 }
Beispiel #14
0
 /**
  * Get a row of data from the table
  *
  * @param   int   $id        Id
  * @param   bool  $format    The data
  * @param   bool  $loadJoin  Load the rows joined data @since 2.0.5 (used in J Content plugin)
  *
  * @return  object	Row
  */
 public function getRow($id, $format = false, $loadJoin = false)
 {
     if (is_null($this->rows)) {
         $this->rows = array();
     }
     $sig = $id . '.' . $format . '.' . $loadJoin;
     if (array_key_exists($sig, $this->rows)) {
         return $this->rows[$sig];
     }
     $fabrikDb = $this->getDb();
     $formModel = $this->getFormModel();
     $formModel->reset();
     $this->reset();
     $formModel->rowId = $id;
     $sql = $formModel->buildQuery();
     $fabrikDb->setQuery($sql);
     if (!$loadJoin) {
         if ($format == true) {
             $row = $fabrikDb->loadObject();
             $row = array($row);
             $this->formatData($row);
             /* $$$ hugh - if table is grouped, formatData will have turned $row into an
              * assoc array, so can't assume 0 is first key.
              * $this->rows[$sig] = $row[0][0];
              */
             $row = FArrayHelper::getValue($row, FArrayHelper::firstKey($row), array());
             $this->rows[$sig] = FArrayHelper::getValue($row, 0, new stdClass());
         } else {
             $this->rows[$sig] = $fabrikDb->loadObject();
         }
     } else {
         $rows = $fabrikDb->loadObjectList();
         $formModel->setJoinData($rows);
         if ($format == true) {
             $rows = array(ArrayHelper::toObject($rows));
             $this->formatData($rows);
             $rows = $rows[0];
             /* $$$ hugh - if list is grouped, formatData will have re-index as assoc array,
             			 /* so can't assume 0 is first key.
             			*/
             $this->rows[$sig] = FArrayHelper::getValue($rows, FArrayHelper::firstKey($rows), array());
         } else {
             // Content plugin - rows is 1 dimensional array
             $this->rows[$sig] = $rows;
         }
     }
     if (is_array($this->rows[$sig])) {
         $this->rows[$sig] = ArrayHelper::toObject($this->rows[$sig]);
     }
     return $this->rows[$sig];
 }
Beispiel #15
0
 /**
  * Method to get an object.
  *
  * @param   integer  $id  The id of the object to get.
  *
  * @return  mixed    Object on success, false on failure.
  */
 public function &getData($id = null)
 {
     if ($this->_item === null) {
         $this->_item = false;
         if (empty($id)) {
             $id = $this->getState('recipe.id');
         }
         // Get a level row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         if ($table->load($id)) {
             // Check published state.
             if ($published = $this->getState('filter.published')) {
                 if ($table->state != $published) {
                     return $this->_item;
                 }
             }
             // Convert the JTable to a clean JObject.
             $properties = $table->getProperties(1);
             $this->_item = ArrayHelper::toObject($properties, 'JObject');
         }
     }
     if (isset($this->_item->tags)) {
         // Catch the item tags (string with ',' coma glue)
         $tags = explode(",", $this->_item->tags);
         $db = JFactory::getDbo();
         $namedTags = array();
         // Cleaning and initalization of named tags array
         // Get the tag names of each tag id
         foreach ($tags as $tag) {
             $query = $db->getQuery(true);
             $query->select("title");
             $query->from('`#__tags`');
             $query->where("id=" . intval($tag));
             $db->setQuery($query);
             $row = $db->loadObjectList();
             // Read the row and get the tag name (title)
             if (!is_null($row)) {
                 foreach ($row as $value) {
                     if ($value && isset($value->title)) {
                         $namedTags[] = trim($value->title);
                     }
                 }
             }
         }
         // Finally replace the data object with proper information
         if (!empty($namedTags)) {
             $this->_item->tags = implode(', ', $namedTags);
         } else {
             $this->_item->tags = !empty($this->_item->my_tags) ? $this->_item->my_tags : "";
         }
     }
     if (isset($this->_item->cuisines_id) && $this->_item->cuisines_id != '') {
         if (is_object($this->_item->cuisines_id)) {
             $this->_item->cuisines_id = JArrayHelper::fromObject($this->_item->cuisines_id);
         }
         $values = is_array($this->_item->cuisines_id) ? $this->_item->cuisines_id : explode(',', $this->_item->cuisines_id);
         $textValue = array();
         foreach ($values as $value) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('name')->from('`#__akrecipes_cuisines`')->where('id = ' . $db->quote($db->escape($value)));
             $db->setQuery($query);
             $results = $db->loadObject();
             if ($results) {
                 $textValue[] = $results->name;
             }
         }
         $this->_item->cuisines_id = !empty($textValue) ? implode(', ', $textValue) : $this->_item->cuisines_id;
     }
     if (isset($this->_item->meal_course_id) && $this->_item->meal_course_id != '') {
         if (is_object($this->_item->meal_course_id)) {
             $this->_item->meal_course_id = JArrayHelper::fromObject($this->_item->meal_course_id);
         }
         $values = is_array($this->_item->meal_course_id) ? $this->_item->meal_course_id : explode(',', $this->_item->meal_course_id);
         $textValue = array();
         foreach ($values as $value) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('name')->from('`#__akrecipes_meal_course`')->where('id = ' . $db->quote($db->escape($value)));
             $db->setQuery($query);
             $results = $db->loadObject();
             if ($results) {
                 $textValue[] = $results->name;
             }
         }
         $this->_item->meal_course_id = !empty($textValue) ? implode(', ', $textValue) : $this->_item->meal_course_id;
     }
     if (isset($this->_item->created_by)) {
         $this->_item->created_by_name = JFactory::getUser($this->_item->created_by)->name;
     }
     if (isset($this->_item->modified_by)) {
         $this->_item->modified_by_name = JFactory::getUser($this->_item->modified_by)->name;
     }
     return $this->_item;
 }
Beispiel #16
0
 /**
  * Method to get an ojbect.
  *
  * @param   integer  $id  The id of the object to get.
  *
  * @return Object|boolean Object on success, false on failure.
  *
  * @throws Exception
  */
 public function &getData($id = null)
 {
     if ($this->item === null) {
         $this->item = false;
         if (empty($id)) {
             $id = $this->getState('recipe.id');
         }
         // Get a level row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         if ($table !== false && $table->load($id)) {
             $user = JFactory::getUser();
             $id = $table->id;
             $canEdit = $user->authorise('core.edit', 'com_akrecipes') || $user->authorise('core.create', 'com_akrecipes');
             if (!$canEdit && $user->authorise('core.edit.own', 'com_akrecipes')) {
                 $canEdit = $user->id == $table->created_by;
             }
             if (!$canEdit) {
                 throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 500);
             }
             // Check published state.
             if ($published = $this->getState('filter.published')) {
                 if ($table->state != $published) {
                     return $this->item;
                 }
             }
             // Convert the JTable to a clean JObject.
             $properties = $table->getProperties(1);
             $this->item = ArrayHelper::toObject($properties, 'JObject');
             //error_log("item is " . print_r($this->item,true));
             // ingredient list is no longer stored as json.
             // $ingredients_list = $this->item->ingredients_list;
             // if ( !empty($ingredients_list) ) {
             // 	$this->item->ingredients_list = json_decode($ingredients_list,true);
             // }
         }
     }
     return $this->item;
 }
Beispiel #17
0
 /**
  * Method to get a menu item.
  *
  * @param   integer  $pk  An optional id of the object to get, otherwise the id from the model state is used.
  *
  * @return  mixed  Menu item data object on success, false on failure.
  *
  * @since   1.6
  */
 public function getItem($pk = null)
 {
     $pk = !empty($pk) ? $pk : (int) $this->getState('item.id');
     // Get a level row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $table->load($pk);
     // Check for a table object error.
     if ($error = $table->getError()) {
         $this->setError($error);
         return false;
     }
     // Prime required properties.
     if ($type = $this->getState('item.type')) {
         $table->type = $type;
     }
     if (empty($table->id)) {
         $table->parent_id = $this->getState('item.parent_id');
         $table->menutype = $this->getState('item.menutype');
         $table->params = '{}';
     }
     // If the link has been set in the state, possibly changing link type.
     if ($link = $this->getState('item.link')) {
         // Check if we are changing away from the actual link type.
         if (MenusHelper::getLinkKey($table->link) != MenusHelper::getLinkKey($link)) {
             $table->link = $link;
         }
     }
     switch ($table->type) {
         case 'alias':
             $table->component_id = 0;
             $args = array();
             parse_str(parse_url($table->link, PHP_URL_QUERY), $args);
             break;
         case 'separator':
         case 'heading':
             $table->link = '';
             $table->component_id = 0;
             break;
         case 'url':
             $table->component_id = 0;
             $args = array();
             parse_str(parse_url($table->link, PHP_URL_QUERY), $args);
             break;
         case 'component':
         default:
             // Enforce a valid type.
             $table->type = 'component';
             // Ensure the integrity of the component_id field is maintained, particularly when changing the menu item type.
             $args = array();
             parse_str(parse_url($table->link, PHP_URL_QUERY), $args);
             if (isset($args['option'])) {
                 // Load the language file for the component.
                 $lang = JFactory::getLanguage();
                 $lang->load($args['option'], JPATH_ADMINISTRATOR, null, false, true) || $lang->load($args['option'], JPATH_ADMINISTRATOR . '/components/' . $args['option'], null, false, true);
                 // Determine the component id.
                 $component = JComponentHelper::getComponent($args['option']);
                 if (isset($component->id)) {
                     $table->component_id = $component->id;
                 }
             }
             break;
     }
     // We have a valid type, inject it into the state for forms to use.
     $this->setState('item.type', $table->type);
     // Convert to the JObject before adding the params.
     $properties = $table->getProperties(1);
     $result = ArrayHelper::toObject($properties);
     // Convert the params field to an array.
     $registry = new Registry($table->params);
     $result->params = $registry->toArray();
     // Merge the request arguments in to the params for a component.
     if ($table->type == 'component') {
         // Note that all request arguments become reserved parameter names.
         $result->request = $args;
         $result->params = array_merge($result->params, $args);
         // Special case for the Login menu item.
         // Display the login or logout redirect URL fields if not empty
         if ($table->link == 'index.php?option=com_users&view=login') {
             if (!empty($result->params['login_redirect_url'])) {
                 $result->params['loginredirectchoice'] = '0';
             }
             if (!empty($result->params['logout_redirect_url'])) {
                 $result->params['logoutredirectchoice'] = '0';
             }
         }
     }
     if ($table->type == 'alias') {
         // Note that all request arguments become reserved parameter names.
         $result->params = array_merge($result->params, $args);
     }
     if ($table->type == 'url') {
         // Note that all request arguments become reserved parameter names.
         $result->params = array_merge($result->params, $args);
     }
     // Load associated menu items
     $assoc = JLanguageAssociations::isEnabled();
     if ($assoc) {
         if ($pk != null) {
             $result->associations = MenusHelper::getAssociations($pk);
         } else {
             $result->associations = array();
         }
     }
     $result->menuordering = $pk;
     return $result;
 }
Beispiel #18
0
 /**
  * Draws the html form element
  *
  * @param   array $data          to pre-populate element with
  * @param   int   $repeatCounter repeat group counter
  *
  * @return  string    elements html
  */
 public function render($data, $repeatCounter = 0)
 {
     // For repeating groups we need to unset this where each time the element is rendered
     unset($this->autocomplete_where);
     if ($this->isJoin()) {
         $this->hasSubElements = true;
     }
     $params = $this->getParams();
     $formModel = $this->getFormModel();
     $displayType = $this->getDisplayType();
     $default = (array) $this->getValue($data, $repeatCounter, array('raw' => true));
     $defaultLabels = (array) $this->getValue($data, $repeatCounter, array('raw' => false));
     $defaultLabels = array_values($defaultLabels);
     $tmp = $this->_getOptions($data, $repeatCounter);
     $w = new FabrikWorker();
     $default = $w->parseMessageForPlaceHolder($default);
     $id = $this->getHTMLId($repeatCounter);
     $html = array();
     if (!$formModel->isEditable() || !$this->isEditable()) {
         // Read only element formatting...
         if (FArrayHelper::getValue($defaultLabels, 0) === $params->get('database_join_noselectionlabel', FText::_('COM_FABRIK_PLEASE_SELECT'))) {
             // No point showing 'please select' for read only
             unset($defaultLabels[0]);
         }
         // Encrypted failed validations - only the raw value is retrieved, swap it with the option text
         if ($formModel->failedValidation()) {
             $newLabels = array();
             foreach ($tmp as $t) {
                 if (in_array($t->value, $defaultLabels)) {
                     $newLabels[] = $t->text;
                 }
             }
             if (!empty($newLabels)) {
                 $defaultLabels = $newLabels;
             }
         }
         /*
          * if it's a new form, labels won't be set for any defaults.
          */
         if ($formModel->getRowId() == '') {
             foreach ($defaultLabels as $key => $val) {
                 /*
                  * Calling getLabelForValue works, but it generates a database query for each one.
                  * We should already have what we need in $tmp (the result of _getOptions), so lets
                  * grab it from there.
                  */
                 // $defaultLabels[$key] = $this->getLabelForValue($default[$key], $default[$key], true);
                 if (!empty($val)) {
                     foreach ($tmp as $t) {
                         if ($t->value == $val) {
                             $defaultLabels[$key] = $t->text;
                             break;
                         }
                     }
                 }
             }
         }
         $targetIds = $this->multiOptionTargetIds($data, $repeatCounter);
         // $$$ hugh - no selection, and not new row, so Nothing To See Here, Move Along.
         if ($this->isJoin() && FArrayHelper::emptyIsh($targetIds, true) && $formModel->getRowId() != '') {
             return '';
         }
         $targetIds = $targetIds === false ? $default : $targetIds;
         // $$$ hugh - trying to fix issue with read only multiselects submitting wrong values
         $formModel->tmplData[$id . '_raw'] = $targetIds;
         $formModel->data[$id . '_raw'] = $targetIds;
         // Add icons
         // $$$ hugh - $targetId's isn't sequential for multiselect joins, but $defaultLabels is!
         //for ($i = 0; $i < count($targetIds); $i++)
         $i = 0;
         foreach ($targetIds as $tkey => $targetId) {
             $tmpLabel = FArrayHelper::getValue($defaultLabels, $i, 'unknown label');
             if ($this->emptyConcatString($tmpLabel)) {
                 $tmpLabel = '';
             }
             $defaultLabels[$i] = $this->getReadOnlyOutput($targetId, $tmpLabel);
             $i++;
         }
         $this->addReadOnlyLinks($defaultLabels, $targetIds);
         $html[] = count($defaultLabels) < 2 ? implode(' ', $defaultLabels) : '<ul><li>' . implode('<li>', $defaultLabels) . '</li></ul>';
     } else {
         // $$$rob should be canUse() otherwise if user set to view but not use the dd was shown
         if ($this->canUse()) {
             // If user can access the drop down
             switch ($displayType) {
                 case 'dropdown':
                 default:
                     $this->renderDropdownList($data, $repeatCounter, $html, $tmp, $default);
                     break;
                 case 'radio':
                     $this->renderRadioList($data, $repeatCounter, $html, $tmp, FArrayHelper::getValue($default, 0));
                     break;
                 case 'checkbox':
                     $this->renderCheckBoxList($data, $repeatCounter, $html, $tmp, $default);
                     break;
                 case 'multilist':
                     $this->renderMultiSelectList($data, $repeatCounter, $html, $tmp, $default);
                     break;
                 case 'auto-complete':
                     $this->renderAutoComplete($data, $repeatCounter, $html, $default);
                     break;
             }
             $html[] = $this->renderFrontEndSelect($data);
         } elseif ($this->canView()) {
             $oData = ArrayHelper::toObject($data);
             $html[] = $this->renderListData($default, $oData);
         }
     }
     $html[] = $this->renderDescription($tmp, $default);
     return implode("\n", $html);
 }
Beispiel #19
0
 /**
  * Method to get an object.
  *
  * @param   integer  $id  The id of the object to get.
  *
  * @return  mixed    Object on success, false on failure.
  */
 public function &getData($id = null)
 {
     if ($this->_item === null) {
         $this->_item = false;
         if (empty($id)) {
             $id = $this->getState('recipe.id');
         }
         // Get a level row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         if ($table->load($id)) {
             // Check published state.
             if ($published = $this->getState('filter.published')) {
                 if ($table->state != $published) {
                     return $this->_item;
                 }
             }
             // Convert the JTable to a clean JObject.
             $properties = $table->getProperties(1);
             $this->_item = ArrayHelper::toObject($properties, 'JObject');
         }
     }
     // try to get ingredients if it is set
     if (!empty($id)) {
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('a.*');
         $query->from('`#__akrecipes_recipe_ingredients` as a');
         $query->select('ing.name as ingredient_name, ing.description as ingredient_tooltip, ing.ingredient_url as ingredient_url, ing.image as ingredient_image ');
         $query->join('LEFT', '#__akrecipes_ingredient AS ing ON ing.id = a.ingredients_id');
         $query->where('a.recipe_id = ' . $id);
         $query->order(' a.sequence_no asc ');
         $db->setQuery($query);
         $result = $db->loadObjectList();
         if ($result) {
             $this->_item->qty = array();
             $this->_item->unit = array();
             $this->_item->ingredient = array();
             $this->_item->ingredient_description = array();
             $this->_item->ingredient_tooltip = array();
             $this->_item->ingredient_url = array();
             $this->_item->ingredient_image = array();
             foreach ($result as $key => $row) {
                 $this->_item->qty[] = $row->qty;
                 $this->_item->unit[] = $row->unit;
                 $this->_item->ingredient[] = $row->ingredient_name;
                 $this->_item->ingredient_description[] = $row->ingredient_description;
                 $this->_item->ingredient_tooltip[] = $row->ingredient_tooltip;
                 $this->_item->ingredient_url[] = $row->ingredient_url;
                 $this->_item->ingredient_image[] = $row->ingredient_image;
             }
         }
     }
     if (isset($this->_item->cuisines_id) && $this->_item->cuisines_id != '') {
         if (is_object($this->_item->cuisines_id)) {
             $this->_item->cuisines_id = JArrayHelper::fromObject($this->_item->cuisines_id);
         }
         $values = is_array($this->_item->cuisines_id) ? $this->_item->cuisines_id : explode(',', $this->_item->cuisines_id);
         $textValue = array();
         foreach ($values as $value) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('name')->from('`#__akrecipes_cuisines`')->where('id = ' . $db->quote($db->escape($value)));
             $db->setQuery($query);
             $results = $db->loadObject();
             if ($results) {
                 $textValue[] = $results->name;
             }
         }
         //$this->_item->cuisines_id = !empty($textValue) ? implode(', ', $textValue) : $this->_item->cuisines_id;
         $this->_item->cuisines = !empty($textValue) ? implode(', ', $textValue) : $this->_item->cuisines_id;
     }
     if (isset($this->_item->meal_course_id) && $this->_item->meal_course_id != '') {
         if (is_object($this->_item->meal_course_id)) {
             $this->_item->meal_course_id = JArrayHelper::fromObject($this->_item->meal_course_id);
         }
         $values = is_array($this->_item->meal_course_id) ? $this->_item->meal_course_id : explode(',', $this->_item->meal_course_id);
         $textValue = array();
         foreach ($values as $value) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('name')->from('`#__akrecipes_meal_course`')->where('id = ' . $db->quote($db->escape($value)));
             $db->setQuery($query);
             $results = $db->loadObject();
             if ($results) {
                 $textValue[] = $results->name;
             }
         }
         //$this->_item->meal_course_id = !empty($textValue) ? implode(', ', $textValue) : $this->_item->meal_course_id;
         $this->_item->meal_course = !empty($textValue) ? implode(', ', $textValue) : $this->_item->meal_course_id;
     }
     // get products used
     if (isset($this->_item->product_id) && $this->_item->product_id != '') {
         if (is_object($this->_item->product_id)) {
             $this->_item->product_id = JArrayHelper::fromObject($this->_item->product_id);
         }
         //$values = (is_array($this->_item->product_id)) ? $this->_item->product_id : explode(',',$this->_item->product_id);
         $values = is_array($this->_item->product_id) ? implode(',', $this->_item->product_id) : $this->_item->product_id;
         $textValue = array();
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('product_name, product_description, product_link, product_image, product_affiliate')->from('`#__akrecipes_products`')->where('id IN ( ' . $values . ' )');
         $db->setQuery($query);
         $results = $db->loadObjectList();
         if ($results) {
             $this->_item->products = $results;
         }
     }
     if (isset($this->_item->diet_id) && $this->_item->diet_id != '') {
         if (is_object($this->_item->diet_id)) {
             $this->_item->diet_id = JArrayHelper::fromObject($this->_item->diet_id);
         }
         $values = is_array($this->_item->diet_id) ? $this->_item->diet_id : explode(',', $this->_item->diet_id);
         $textValue = array();
         foreach ($values as $value) {
             $db = JFactory::getDbo();
             $query = $db->getQuery(true);
             $query->select('name')->from('`#__akrecipes_diets`')->where('id = ' . $db->quote($db->escape($value)));
             $db->setQuery($query);
             $results = $db->loadObject();
             if ($results) {
                 $textValue[] = $results->name;
             }
         }
         //$this->_item->diet_id = !empty($textValue) ? implode(', ', $textValue) : $this->_item->diet_id;
         $this->_item->diet = !empty($textValue) ? implode(', ', $textValue) : $this->_item->diet_id;
     }
     if (isset($this->_item->created_by)) {
         $this->_item->created_by_name = JFactory::getUser($this->_item->created_by)->name;
     }
     if (isset($this->_item->modified_by)) {
         $this->_item->modified_by_name = JFactory::getUser($this->_item->modified_by)->name;
     }
     // add user object to the item
     $this->_item->user = AkrecipesHelper::getUserObject($this->_item->created_by);
     // add brand object
     if (isset($this->_item->brand_id) && $this->_item->brand_id != '') {
         $this->_item->brand = AkrecipesHelper::getBrandObject($this->_item->brand_id);
         //error_log("Got brand object -> " . print_r($this->_item->brand,true));
     }
     // add contest object
     if (isset($this->_item->contest_id) && $this->_item->contest_id != '') {
         $this->_item->contest = AkrecipesHelper::getContestObject($this->_item->contest_id);
     }
     // add ratings data
     $rating = AkrecipesHelper::getRatingObject($this->_item->id);
     //error_log("Got rating object --> " . print_r($rating,true));
     if ($rating) {
         $this->_item->rating = $rating;
     }
     $stats = AkrecipesHelper::getStatsObject($this->_item->id);
     if ($stats) {
         $this->_item->stats = $stats;
     }
     return $this->_item;
 }
Beispiel #20
0
 /**
  * Method to get a menu item.
  *
  * @param   integer  $itemId  The id of the menu item to get.
  *
  * @return  mixed  Menu item data object on success, false on failure.
  *
  * @since   1.6
  */
 public function &getItem($itemId = null)
 {
     $itemId = !empty($itemId) ? $itemId : (int) $this->getState('menu.id');
     // Get a menu item row instance.
     $table = $this->getTable();
     // Attempt to load the row.
     $return = $table->load($itemId);
     // Check for a table object error.
     if ($return === false && $table->getError()) {
         $this->setError($table->getError());
         return false;
     }
     $properties = $table->getProperties(1);
     $value = ArrayHelper::toObject($properties, 'JObject');
     return $value;
 }
Beispiel #21
0
 /**
  * Method to get a list of content items to index.
  *
  * @param   integer         $offset  The list offset.
  * @param   integer         $limit   The list limit.
  * @param   JDatabaseQuery  $query   A JDatabaseQuery object. [optional]
  *
  * @return  array  An array of FinderIndexerResult objects.
  *
  * @since   2.5
  * @throws  Exception on database error.
  */
 protected function getItems($offset, $limit, $query = null)
 {
     $items = array();
     // Get the content items to index.
     $this->db->setQuery($this->getListQuery($query), $offset, $limit);
     $rows = $this->db->loadAssocList();
     // Convert the items to result objects.
     foreach ($rows as $row) {
         // Convert the item to a result object.
         $item = ArrayHelper::toObject((array) $row, 'FinderIndexerResult');
         // Set the item type.
         $item->type_id = $this->type_id;
         // Set the mime type.
         $item->mime = $this->mime;
         // Set the item layout.
         $item->layout = $this->layout;
         // Set the extension if present
         if (isset($row->extension)) {
             $item->extension = $row->extension;
         }
         // Add the item to the stack.
         $items[] = $item;
     }
     return $items;
 }
Beispiel #22
0
 /**
  * Method to bind an associative array or object to the AbstractDatabaseTable instance.  This
  * method only binds properties that are publicly accessible and optionally
  * takes an array of properties to ignore when binding.
  *
  * @param   mixed  $src     An associative array or object to bind to the AbstractDatabaseTable instance.
  * @param   mixed  $ignore  An optional array or space separated list of properties to ignore while binding.
  *
  * @return  $this  Method allows chaining
  *
  * @since   1.0
  * @throws  \InvalidArgumentException
  */
 public function bind($src, $ignore = array())
 {
     if ($this->id) {
         $oldValues = array();
         foreach ($this as $k => $v) {
             $oldValues[$k] = $v;
         }
         // Store the old values to compute the differences later.
         $this->oldObject = ArrayHelper::toObject($oldValues);
     }
     if (is_array($src)) {
         if (isset($src['fields'])) {
             // "Save" the field values and store them later.
             $this->fieldValues = $this->_cleanFields($src['fields']);
             unset($src['fields']);
         }
         return parent::bind($src, $ignore);
     } elseif ($src instanceof Input) {
         $data = new \stdClass();
         $data->id = $src->get('id');
         $this->fieldValues = $this->_cleanFields($src->get('fields', array(), 'array'));
         return parent::bind($data, $ignore);
     }
     throw new \InvalidArgumentException(sprintf('%1$s can not bind to %2$s', __METHOD__, gettype($src)));
 }
Beispiel #23
0
    /**
     * Build Page <script> tag for insertion into DOM
     *
     * @return string
     */
    public static function buildJs()
    {
        $session = JFactory::getSession();
        $config = (array) $session->get('fabrik.js.config', array());
        $config = implode("\n", $config);
        $js = (array) $session->get('fabrik.js.scripts', array());
        $js = implode("\n", $js);
        $jLayouts = (array) $session->get('fabrik.js.jlayouts', array());
        $jLayouts = json_encode(ArrayHelper::toObject($jLayouts));
        $js = str_replace('%%jLayouts%%', $jLayouts, $js);
        if ($config . $js !== '') {
            /*
             * Load requirejs into a DOM generated <script> tag - then load require.js code.
             * Avoids issues with previous implementation where we were loading requirejs at the end of the head and then
             * loading the code at the bottom of the page.
             * For example this previous method broke with the codemirror editor which first
             * tests if its inside requirejs (false) then loads scripts via <script> node creation. By the time the secondary
             * scripts were loaded, Fabrik had loaded requires js, and conflicts occurred.
             */
            $jsAssetBaseURI = FabrikHelperHTML::getJSAssetBaseURI();
            $rjs = $jsAssetBaseURI . 'media/com_fabrik/js/lib/require/require.js';
            $script = '<script>
            setTimeout(function(){
            jQuery.ajaxSetup({
  cache: true
});
				 jQuery.getScript( "' . $rjs . '", function() {
				' . "\n" . $config . "\n" . $js . "\n" . '
			});
			 }, 600);
			</script>
      ';
        } else {
            $script = '';
        }
        return $script;
    }
Beispiel #24
0
 /**
  * Method to get a single record.
  *
  * @param   integer  $pk  The id of the primary key.
  *
  * @return  mixed  Object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     $pk = !empty($pk) ? $pk : (int) $this->getState('style.id');
     if (!isset($this->_cache[$pk])) {
         // Get a row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && $table->getError()) {
             $this->setError($table->getError());
             return false;
         }
         // Convert to the JObject before adding other data.
         $properties = $table->getProperties(1);
         $this->_cache[$pk] = ArrayHelper::toObject($properties, 'JObject');
         // Convert the params field to an array.
         $registry = new Registry($table->params);
         $this->_cache[$pk]->params = $registry->toArray();
         // Get the template XML.
         $client = JApplicationHelper::getClientInfo($table->client_id);
         $path = JPath::clean($client->path . '/templates/' . $table->template . '/templateDetails.xml');
         if (file_exists($path)) {
             $this->_cache[$pk]->xml = simplexml_load_file($path);
         } else {
             $this->_cache[$pk]->xml = null;
         }
     }
     return $this->_cache[$pk];
 }
Beispiel #25
0
 /**
  * Method to get a single record.
  *
  * @param   integer  $pk  The id of the primary key.
  *
  * @return  mixed  Object on success, false on failure.
  *
  * @since   1.6
  */
 public function getItem($pk = null)
 {
     $pk = !empty($pk) ? (int) $pk : (int) $this->getState('module.id');
     $db = $this->getDbo();
     if (!isset($this->_cache[$pk])) {
         // Get a row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && ($error = $table->getError())) {
             $this->setError($error);
             return false;
         }
         // Check if we are creating a new extension.
         if (empty($pk)) {
             if ($extensionId = (int) $this->getState('extension.id')) {
                 $query = $db->getQuery(true)->select('element, client_id')->from('#__extensions')->where('extension_id = ' . $extensionId)->where('type = ' . $db->quote('module'));
                 $db->setQuery($query);
                 try {
                     $extension = $db->loadObject();
                 } catch (RuntimeException $e) {
                     $this->setError($e->getMessage());
                     return false;
                 }
                 if (empty($extension)) {
                     $this->setError('COM_MODULES_ERROR_CANNOT_FIND_MODULE');
                     return false;
                 }
                 // Extension found, prime some module values.
                 $table->module = $extension->element;
                 $table->client_id = $extension->client_id;
             } else {
                 $app = JFactory::getApplication();
                 $app->redirect(JRoute::_('index.php?option=com_modules&view=modules', false));
                 return false;
             }
         }
         // Convert to the JObject before adding other data.
         $properties = $table->getProperties(1);
         $this->_cache[$pk] = ArrayHelper::toObject($properties, 'JObject');
         // Convert the params field to an array.
         $registry = new Registry($table->params);
         $this->_cache[$pk]->params = $registry->toArray();
         // Determine the page assignment mode.
         $query = $db->getQuery(true)->select($db->quoteName('menuid'))->from($db->quoteName('#__modules_menu'))->where($db->quoteName('moduleid') . ' = ' . (int) $pk);
         $db->setQuery($query);
         $assigned = $db->loadColumn();
         if (empty($pk)) {
             // If this is a new module, assign to all pages.
             $assignment = 0;
         } elseif (empty($assigned)) {
             // For an existing module it is assigned to none.
             $assignment = '-';
         } else {
             if ($assigned[0] > 0) {
                 $assignment = 1;
             } elseif ($assigned[0] < 0) {
                 $assignment = -1;
             } else {
                 $assignment = 0;
             }
         }
         $this->_cache[$pk]->assigned = $assigned;
         $this->_cache[$pk]->assignment = $assignment;
         // Get the module XML.
         $client = JApplicationHelper::getClientInfo($table->client_id);
         $path = JPath::clean($client->path . '/modules/' . $table->module . '/' . $table->module . '.xml');
         if (file_exists($path)) {
             $this->_cache[$pk]->xml = simplexml_load_file($path);
         } else {
             $this->_cache[$pk]->xml = null;
         }
     }
     return $this->_cache[$pk];
 }
Beispiel #26
0
 public function createDb()
 {
     $this->options = array('host' => $this->config->get('host'), 'user' => $this->config->get('user'), 'password' => $this->config->get('password'), 'database' => $this->config->get('db'), 'prefix' => $this->config->get('dbprefix'), 'select' => false);
     $dbFactory = new DatabaseFactory();
     $this->db = $dbFactory->getDriver($this->config->get('dbtype'), $this->options);
     // Try to select the database
     try {
         $this->db->select($this->options['database']);
     } catch (RuntimeException $e) {
         // Get database's UTF support
         $utfSupport = $this->db->hasUTFSupport();
         $createDbConfig = array('db_name' => $this->options['database'], 'db_user' => $this->options['user']);
         // If the database could not be selected, attempt to create it and then select it.
         if ($this->createDatabase($this->db, ArrayHelper::toObject($createDbConfig), $utfSupport)) {
             $this->db->select($this->options['database']);
         } else {
             return false;
         }
     }
     $db_driver = $this->config->get('dbtype');
     if ($db_driver == 'mysqli') {
         $db_driver = 'mysql';
     }
     $schema = JPATH_INSTALLATION . "/sql/" . $db_driver . "/joomla.sql";
     // Get the contents of the schema file.
     if (!($buffer = file_get_contents($schema))) {
         $this->setError($this->db->getErrorMsg());
         return false;
     }
     // Get an array of queries from the schema and process them.
     $queries = $this->_splitQueries($buffer);
     foreach ($queries as $query) {
         // Trim any whitespace.
         $query = trim($query);
         // If the query isn't empty and is not a MySQL or PostgreSQL comment, execute it.
         if (!empty($query) && $query[0] != '#' && $query[0] != '-') {
             // Execute the query.
             $this->db->setQuery($query);
             try {
                 $this->db->execute();
             } catch (RuntimeException $e) {
                 $this->setError($e->getMessage());
                 $return = false;
             }
         }
     }
     return true;
 }
Beispiel #27
0
 /**
  * Override preprocessForm to load the user plugin group instead of content.
  *
  * @param   JForm   $form   A form object.
  * @param   mixed   $data   The data expected for the form.
  * @param   string  $group  The name of the plugin group to import (defaults to "content").
  *
  * @return  void
  *
  * @since   1.6
  * @throws  Exception if there is an error loading the form.
  */
 protected function preprocessForm(JForm $form, $data, $group = '')
 {
     $obj = is_array($data) ? ArrayHelper::toObject($data, 'JObject') : $data;
     if (isset($obj->parent_id) && $obj->parent_id == 0 && $obj->id > 0) {
         $form->setFieldAttribute('parent_id', 'type', 'hidden');
         $form->setFieldAttribute('parent_id', 'hidden', 'true');
     }
     parent::preprocessForm($form, $data, 'user');
 }
Beispiel #28
0
 /**
  * Method to get a single record.
  *
  * @param   integer  $pk  The id of the primary key.
  *
  * @return  mixed  Object on success, false on failure.
  */
 public function getItem($pk = null)
 {
     $pk = !empty($pk) ? $pk : (int) $this->getState('plugin.id');
     if (!isset($this->_cache[$pk])) {
         // Get a row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         $return = $table->load($pk);
         // Check for a table object error.
         if ($return === false && $table->getError()) {
             $this->setError($table->getError());
             return false;
         }
         // Convert to the JObject before adding other data.
         $properties = $table->getProperties(1);
         $this->_cache[$pk] = ArrayHelper::toObject($properties, 'JObject');
         // Convert the params field to an array.
         $registry = new Registry($table->params);
         $this->_cache[$pk]->params = $registry->toArray();
         // Get the plugin XML.
         $path = JPath::clean(JPATH_PLUGINS . '/' . $table->folder . '/' . $table->element . '/' . $table->element . '.xml');
         if (file_exists($path)) {
             $this->_cache[$pk]->xml = simplexml_load_file($path);
         } else {
             $this->_cache[$pk]->xml = null;
         }
     }
     return $this->_cache[$pk];
 }
 /**
  * Method to get an ojbect.
  *
  * @param   integer  $id  The id of the object to get.
  *
  * @return Object|boolean Object on success, false on failure.
  *
  * @throws Exception
  */
 public function &getData($id = null)
 {
     if ($this->item === null) {
         $this->item = false;
         if (empty($id)) {
             $id = $this->getState('einsatzfahrzeug.id');
         }
         // Get a level row instance.
         $table = $this->getTable();
         // Attempt to load the row.
         if ($table !== false && $table->load($id)) {
             $user = JFactory::getUser();
             $id = $table->id;
             if ($id) {
                 $canEdit = $user->authorise('core.edit', 'com_einsatzkomponente. einsatzfahrzeug.' . $id) || $user->authorise('core.create', 'com_einsatzkomponente. einsatzfahrzeug.' . $id);
             } else {
                 $canEdit = $user->authorise('core.edit', 'com_einsatzkomponente') || $user->authorise('core.create', 'com_einsatzkomponente');
             }
             if (!$canEdit && $user->authorise('core.edit.own', 'com_einsatzkomponente.einsatzfahrzeug.' . $id)) {
                 $canEdit = $user->id == $table->created_by;
             }
             if (!$canEdit) {
                 throw new Exception(JText::_('JERROR_ALERTNOAUTHOR'), 500);
             }
             // Check published state.
             if ($published = $this->getState('filter.published')) {
                 if ($table->state != $published) {
                     return $this->item;
                 }
             }
             // Convert the JTable to a clean JObject.
             $properties = $table->getProperties(1);
             $this->item = ArrayHelper::toObject($properties, 'JObject');
         }
     }
     return $this->item;
 }
 /**
  * Test convert array to object.
  *
  * @param   string  $input      The array being input
  * @param   string  $className  The class name to build
  * @param   string  $expect     The expected return value
  * @param   string  $message    The failure message
  *
  * @return  void
  *
  * @dataProvider  seedTestToObject
  * @covers        Joomla\Utilities\ArrayHelper::toObject
  * @since         1.0
  */
 public function testToObject($input, $className, $expect, $message)
 {
     $this->assertEquals($expect, ArrayHelper::toObject($input), $message);
 }