示例#1
0
 /**
  * Method to get an array of data items
  *
  * @return  mixed An array of data on success, false on failure.
  */
 public function getItems()
 {
     $items = parent::getItems();
     //error_log("In AkrecipesModelRecipesbyuser::getItems Count == " . count($items) ) ;
     foreach ($items as $item) {
         //get the tags
         $item->tags = new JHelperTags();
         //$item->tags->getItemTags('com_akrecipes.recipe',$item->id);
         $item->tags->getItemTags($item->type_alias, $item->id);
         if (isset($item->catid)) {
             // Get the title of that particular template
             $title = AkrecipesFrontendHelper::getCategoryNameByCategoryId($item->catid);
             // Finally replace the data object with proper information
             $item->catid = !empty($title) ? $title : $item->catid;
         }
         if (isset($item->cuisines_id) && $item->cuisines_id != '') {
             if (is_object($item->cuisines_id)) {
                 $item->cuisines_id = ArrayHelper::fromObject($item->cuisines_id);
             }
             $values = is_array($item->cuisines_id) ? $item->cuisines_id : explode(',', $item->cuisines_id);
             $textValue = array();
             foreach ($values as $value) {
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->select($db->quoteName('name'))->from('`#__akrecipes_cuisines`')->where($db->quoteName('id') . ' = ' . $db->quote($db->escape($value)));
                 $db->setQuery($query);
                 $results = $db->loadObject();
                 if ($results) {
                     $textValue[] = $results->name;
                 }
             }
             $item->cuisines_id = !empty($textValue) ? implode(', ', $textValue) : $item->cuisines_id;
         }
         // set meal_course values
         if (isset($item->meal_course_id) && $item->meal_course_id != '') {
             if (is_object($item->meal_course_id)) {
                 $item->meal_course_id = ArrayHelper::fromObject($item->meal_course_id);
             }
             $values = is_array($item->meal_course_id) ? $item->meal_course_id : explode(',', $item->meal_course_id);
             $textValue = array();
             foreach ($values as $value) {
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->select($db->quoteName('name'))->from('`#__akrecipes_meal_course`')->where($db->quoteName('id') . ' = ' . $db->quote($db->escape($value)));
                 $db->setQuery($query);
                 $results = $db->loadObject();
                 if ($results) {
                     $textValue[] = $results->name;
                 }
             }
             $item->meal_course_id = !empty($textValue) ? implode(', ', $textValue) : $item->meal_course_id;
         }
         // set brand values
         if (isset($item->brand_id) && $item->brand_id != '') {
             if (is_object($item->brand_id)) {
                 $item->brand_id = ArrayHelper::fromObject($item->brand_id);
             }
             $values = is_array($item->brand_id) ? $item->brand_id : explode(',', $item->brand_id);
             $textValue = array();
             foreach ($values as $value) {
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->select($db->quoteName('brand_name'))->from('`#__akrecipes_brands`')->where($db->quoteName('id') . ' = ' . $db->quote($db->escape($value)));
                 $db->setQuery($query);
                 $results = $db->loadObject();
                 if ($results) {
                     $textValue[] = $results->brand_name;
                 }
             }
             $item->brand_id = !empty($textValue) ? implode(', ', $textValue) : $item->brand_id;
         }
     }
     return $items;
 }
示例#2
0
 /**
  * Method to get an array of data items
  *
  * @return  mixed An array of data on success, false on failure.
  */
 public function getItems()
 {
     $items = parent::getItems();
     foreach ($items as $item) {
         if (isset($item->tags)) {
             // Catch the item tags (string with ',' coma glue)
             $tags = explode(",", $item->tags);
             $db = JFactory::getDbo();
             // Cleaning and initalization of named tags array
             $namedTags = 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
             $item->tags = !empty($namedTags) ? implode(', ', $namedTags) : $item->tags;
         }
         if (isset($item->catid)) {
             // Get the title of that particular template
             $title = AkrecipesFrontendHelper::getCategoryNameByCategoryId($item->catid);
             // Finally replace the data object with proper information
             $item->catid = !empty($title) ? $title : $item->catid;
         }
         if (isset($item->cuisines_id) && $item->cuisines_id != '') {
             if (is_object($item->cuisines_id)) {
                 $item->cuisines_id = ArrayHelper::fromObject($item->cuisines_id);
             }
             $values = is_array($item->cuisines_id) ? $item->cuisines_id : explode(',', $item->cuisines_id);
             $textValue = array();
             foreach ($values as $value) {
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->select($db->quoteName('name'))->from('`#__akrecipes_cuisines`')->where($db->quoteName('id') . ' = ' . $db->quote($db->escape($value)));
                 $db->setQuery($query);
                 $results = $db->loadObject();
                 if ($results) {
                     $textValue[] = $results->name;
                 }
             }
             $item->cuisines_id = !empty($textValue) ? implode(', ', $textValue) : $item->cuisines_id;
         }
         if (isset($item->meal_course_id) && $item->meal_course_id != '') {
             if (is_object($item->meal_course_id)) {
                 $item->meal_course_id = ArrayHelper::fromObject($item->meal_course_id);
             }
             $values = is_array($item->meal_course_id) ? $item->meal_course_id : explode(',', $item->meal_course_id);
             $textValue = array();
             foreach ($values as $value) {
                 $db = JFactory::getDbo();
                 $query = $db->getQuery(true);
                 $query->select($db->quoteName('name'))->from('`#__akrecipes_meal_course`')->where($db->quoteName('id') . ' = ' . $db->quote($db->escape($value)));
                 $db->setQuery($query);
                 $results = $db->loadObject();
                 if ($results) {
                     $textValue[] = $results->name;
                 }
             }
             $item->meal_course_id = !empty($textValue) ? implode(', ', $textValue) : $item->meal_course_id;
         }
     }
     return $items;
 }