Exemple #1
0
 /**
  * Called at end of form record save. Used for many-many join elements to save their data
  *
  * @param   array  &$data  Form data
  *
  * @since  3.1rc1
  *
  * @return  void
  */
 public function onFinalStoreRow(&$data)
 {
     $params = $this->getParams();
     $name = $this->getFullName(true, false);
     $rawName = $name . '_raw';
     $db = FabrikWorker::getDbo(true);
     $formData =& $this->getFormModel()->formDataWithTableName;
     $tagIds = (array) $formData[$rawName];
     if (!class_exists('TagsModelTag')) {
         require_once JPATH_ADMINISTRATOR . '/components/com_tags/models/tag.php';
     }
     foreach ($tagIds as $tagKey => &$tagId) {
         if (empty($tagId)) {
             unset($tagIds[$tagKey]);
             continue;
         }
         // New tag added
         if (strstr($tagId, '#fabrik#')) {
             $tagId = str_replace('#fabrik#', '', $tagId);
             /**
              * We need to use the J! com_tags model to save, so it can handle the nested set stuff
              */
             $tagsTableName = $params->get('tags_dbname', '');
             $jTagsTableName = $db->getPrefix() . 'tags';
             if ($tagsTableName === '' || $tagsTableName === $jTagsTableName) {
                 JTable::addIncludePath(COM_FABRIK_BASE . '/administrator/components/com_tags/tables');
                 $tagModel = new TagsModelTag();
                 /*
                  * JSONified list of form data from built in backed tag creation, from xdebug session
                  *
                  * Can get rid of this comment once we're sure the $data we set up has the required fields
                  *
                  * {"id":0,
                  * "hits":"0",
                  * "parent_id":"1",
                  * "title":"test102",
                  * "note":"",
                  * "description":"",
                  * "published":"1",
                  * "access":"1",
                  * "metadesc":"",
                  * "metakey":"",
                  * "alias":"",
                  * "created_user_id":"",
                  * "created_by_alias":"",
                  * "created_time":null,
                  * "modified_user_id":null,
                  * "modified_time":null,
                  * "language":"*",
                  * "version_note":"",
                  * "params":
                  *  {"tag_layout":"",
                  *      "tag_link_class":"label label-info"
                  * },
                  * "images":{
                  *  "image_intro":"",
                  *  "float_intro":"",
                  *  "image_intro_alt":"",
                  *  "image_intro_caption":"",
                  *  "image_fulltext":"",
                  *  "float_fulltext":"",
                  *  "image_fulltext_alt":"",
                  *  "image_fulltext_caption":""
                  * },
                  * "metadata":{
                  *  "author":"",
                  *  "robots":""
                  * },
                  * "tags":null}
                  */
                 $data = array('id' => '', 'level' => 1, 'published' => 1, 'parent_id' => 1, 'created_user_id' => (int) $this->user->get('id'), 'created_time' => $this->date->toSql(), 'language' => "*", 'version' => 1, 'path' => $tagId, 'title' => $tagId, 'alias' => $tagId);
                 $tagModel->save($data);
                 $tagId = $tagModel->getState($tagModel->getName() . '.id');
             } else {
                 /*
                  * For Jaanus's non J! tables, do it the "old" way
                  */
                 $tagId = $db->quote($tagId);
                 $query = $db->getQuery(true);
                 $query->insert($this->getDbName())->set('level = 1, published = 1, parent_id = 1, created_user_id = ' . (int) $this->user->get('id'))->set('created_time = ' . $db->q($this->date->toSql()), ', language = "*", version = 1')->set('path = ' . $tagId . ', title = ' . $tagId . ', alias = ' . $tagId);
                 $db->setQuery($query);
                 $db->execute();
                 $tagId = $db->insertid();
             }
         }
     }
     $formData[$name] = $tagIds;
     $formData[$rawName] = $tagIds;
     parent::onFinalStoreRow($data);
 }
 public function migrateK2Tags()
 {
     $db = $this->dbo;
     $query = "SELECT `name` from r2e0p_k2_tags ;";
     $db->setQuery($query);
     $rows = $db->loadObjectList();
     // Load the tags model.
     require_once JPATH_ADMINISTRATOR . '/components/com_tags/models/tag.php';
     JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tags/tables');
     $user = JFactory::getUser();
     $userId = $user->id;
     // For writting permissions
     foreach ($rows as $key => $row) {
         error_log("Creaing tag " . $row->name);
         $tagName = $row->name;
         $tagAlias = $tagPath = preg_replace('/[\\s\\W\\.]+/', '-', $tagName);
         // Tags alias filter
         $tagMetadata = array("author" => "", "robots" => "", "tags" => null);
         // Get an instance of the table for insertion the new tags
         $tagsModel = TagsModelTag::getInstance('Tag', 'TagsModel');
         // The data tag field row
         $data = array("parent_id" => 0, "path" => $tagPath, "title" => $tagName, "alias" => $tagAlias, "created_by_alias" => $user, "created_user_id" => $userId, "published" => 1, "checked_out" => 0, "metadata" => json_encode($tagMetadata));
         // Finally, store the tag if the user is granted for that
         $table = $tagsModel->getTable();
         $table->bind($data);
         $retVal = $table->store($data);
         error_log("Stored tag : . " . $table->id);
         $tags[] = $table->id;
         // And store the insert_id
     }
 }
Exemple #3
0
 /**
  * Overloaded bind function to pre-process the params.
  *
  * @param   array  $array   Named array
  * @param   mixed  $ignore  Optional array or list of parameters to ignore
  *
  * @return  null|string  null is operation was satisfactory, otherwise returns an error
  *
  * @see     JTable:bind
  * @since   1.5
  */
 public function bind($array, $ignore = '')
 {
     if (isset($array['tags']) && !empty($array['tags'])) {
         // Load the tags helper.
         require_once JPATH_ADMINISTRATOR . '/components/com_tags/helpers/tags.php';
         // Get the allowed actions for the user
         $canDo = TagsHelper::getActions('com_tags');
         // The helper get the user and the component name itself
         // Load the tags model.
         require_once JPATH_ADMINISTRATOR . '/components/com_tags/models/tag.php';
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tags/tables');
         // Get an instance of the table for insertion the new tags
         $tagsModel = TagsModelTag::getInstance('Tag', 'TagsModel');
         $tags = array();
         // Initialization of the tag container must be processed
         // If tags is an array, store-mode
         if (is_array($array['tags'])) {
             // "Allow user creation" mode must be activated (default) in the component creation field
             // Save the tags does not exist into the table tags and get its id for save the entire Item with the proper data
             foreach ($array['tags'] as $singleTag) {
                 // If there is any new tag... create it to get the id and save into the table #__COMPONENT_NAME_TABLE_NAME
                 if (strpos($singleTag, "#new#") !== FALSE) {
                     $user = JFactory::getUser();
                     $userId = $user->id;
                     // For writting permissions
                     $tagName = str_replace("#new#", "", $singleTag);
                     $tagAlias = $tagPath = preg_replace('/[\\s\\W\\.]+/', '-', $tagName);
                     // Tags alias filter
                     $tagMetadata = array("author" => "", "robots" => "", "tags" => null);
                     // The data tag field row
                     $data = array("parent_id" => 0, "path" => $tagPath, "title" => $tagName, "alias" => $tagAlias, "created_by_alias" => $user, "created_user_id" => $userId, "published" => 1, "checked_out" => 0, "metadata" => json_encode($tagMetadata));
                     // Finally, store the tag if the user is granted for that
                     if ($canDo->get('core.create')) {
                         $table = $tagsModel->getTable();
                         $table->bind($data) ? $table->store($data) : exit;
                         $tags[] = $table->id;
                         // And store the insert_id
                     }
                 } else {
                     $tags[] = intval($singleTag);
                 }
             }
             // Overrride the tags array, because we should need to change the id before field saving
             // The field in database will look like "299,345,567,567"
             $array['tags'] = implode(',', $tags);
         }
     } else {
         $array['tags'] = '';
     }
     // Support for multiple or not foreign key field: cuisines_id
     if (!empty($array['cuisines_id'])) {
         if (is_array($array['cuisines_id'])) {
             $array['cuisines_id'] = implode(',', $array['cuisines_id']);
         } else {
             if (strrpos($array['cuisines_id'], ',') != false) {
                 $array['cuisines_id'] = explode(',', $array['cuisines_id']);
             }
         }
     } else {
         $array['cuisines_id'] = '';
     }
     // Support for multiple or not foreign key field: meal_course_id
     if (!empty($array['meal_course_id'])) {
         if (is_array($array['meal_course_id'])) {
             $array['meal_course_id'] = implode(',', $array['meal_course_id']);
         } else {
             if (strrpos($array['meal_course_id'], ',') != false) {
                 $array['meal_course_id'] = explode(',', $array['meal_course_id']);
             }
         }
     } else {
         $array['meal_course_id'] = '';
     }
     $input = JFactory::getApplication()->input;
     $task = $input->getString('task', '');
     if (($task == 'save' || $task == 'apply') && (!JFactory::getUser()->authorise('core.edit.state', 'com_akrecipes') && $array['state'] == 1)) {
         $array['state'] = 0;
     }
     if ($array['id'] == 0) {
         $array['created_by'] = JFactory::getUser()->id;
     }
     if ($array['id'] == 0) {
         $array['modified_by'] = JFactory::getUser()->id;
     }
     // Support for checkbox field: sponsored
     if (!isset($array['sponsored'])) {
         $array['sponsored'] = 0;
     }
     // Support for checkbox field: featured
     if (!isset($array['featured'])) {
         $array['featured'] = 0;
     }
     if (isset($array['params']) && is_array($array['params'])) {
         $registry = new JRegistry();
         $registry->loadArray($array['params']);
         $array['params'] = (string) $registry;
     }
     if (isset($array['metadata']) && is_array($array['metadata'])) {
         $registry = new JRegistry();
         $registry->loadArray($array['metadata']);
         $array['metadata'] = (string) $registry;
     }
     if (!JFactory::getUser()->authorise('core.admin', 'com_akrecipes.recipe.' . $array['id'])) {
         $actions = JAccess::getActionsFromFile(JPATH_ADMINISTRATOR . '/components/com_akrecipes/access.xml', "/access/section[@name='recipe']/");
         $default_actions = JAccess::getAssetRules('com_akrecipes.recipe.' . $array['id'])->getData();
         $array_jaccess = array();
         foreach ($actions as $action) {
             $array_jaccess[$action->name] = $default_actions[$action->name];
         }
         $array['rules'] = $this->JAccessRulestoArray($array_jaccess);
     }
     // Bind the rules for ACL where supported.
     if (isset($array['rules']) && is_array($array['rules'])) {
         $this->setRules($array['rules']);
     }
     return parent::bind($array, $ignore);
 }