Example #1
0
 public function unread()
 {
     $this->findSub();
     $conditions = array();
     if (!empty($this->sub['Subscription']['viewed_on'])) {
         $conditions[] = es('Item.stored_on >= %s', $this->sub['Subscription']['viewed_on']);
     }
     $conditions[] = es('Item.feed_id = %s', $this->sub['Subscription']['feed_id']);
     $fields = null;
     $order = es('Item.created_on DESC, Item.id DESC');
     $limit = MAX_UNREAD_COUNT;
     $r = $this->Item->findAll($conditions, $fields, $order, $limit);
     $items = array();
     foreach ($r as $v) {
         $items[] = Item::toArray($v['Item']);
     }
     $result = array('subscribe_id' => $this->sub['Subscription']['id'], 'channel' => $this->sub['Feed'], 'items' => $items);
     if (count($items) > 0) {
         $result['last_stored_on'] = $r[count($items) - 1]['Item']['stored_on'];
     }
     if ($this->sub['Subscription']['ignore_notify']) {
         $result['ignore_notify'] = 1;
     }
     $this->renderJSON(json_encode($result));
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), array('company_id' => 'required', 'name' => 'required', 'description' => 'required', 'url' => 'required|url', 'photo' => 'required|image'));
     if ($validator->fails()) {
         return Response::json($validator->messages(), 400);
     }
     $item = new Item();
     $item->company_id = Input::get('company_id');
     $item->name = Input::get('name');
     $item->description = Input::get('description');
     $item->url = Input::get('url');
     //temporary for territory
     $item->territory_id = 1;
     $item->save();
     //save tags if available
     foreach (Input::get('tag') as $tagid) {
         $item->tags()->attach($tagid);
     }
     $image = Input::file('photo');
     $filename = $item->id;
     $saveBigUrl = base_path() . '/public/images/items/' . $filename . '.jpg';
     $saveMediumUrl = base_path() . '/public/images/items/' . $filename . '_medium.jpg';
     $saveSmallUrl = base_path() . '/public/images/items/' . $filename . '_small.jpg';
     Image::make($image->getRealPath())->fit(600, null, function ($constraint) {
         //for big image
         $constraint->upsize();
     })->save($saveBigUrl, 50)->fit(300)->save($saveMediumUrl, 50)->fit(100)->save($saveSmallUrl, 50);
     $item->big_image_url = url('images/items/' . $filename . '.jpg');
     $item->medium_image_url = url('images/items/' . $filename . '_medium.jpg');
     $item->small_image_url = url('images/items/' . $filename . '_small.jpg');
     $item->save();
     return Response::json(array('success_code' => 'OK', 'data' => $item->toArray()), 200);
 }
Example #3
0
 /**
  * Exports the object as an array.
  *
  * You can specify the key type of the array by passing one of the class
  * type constants.
  *
  * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  *                    Defaults to BasePeer::TYPE_PHPNAME.
  * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
  * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
  * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  *
  * @return    array an associative array containing the field names (as keys) and field values
  */
 public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 {
     if (isset($alreadyDumpedObjects['Item'][$this->getPrimaryKey()])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['Item'][$this->getPrimaryKey()] = true;
     $keys = ItemPeer::getFieldNames($keyType);
     $result = array($keys[0] => $this->getId(), $keys[1] => $this->getIsbn(), $keys[2] => $this->getPackageId(), $keys[3] => $this->getIsPackage(), $keys[4] => $this->getTitle(), $keys[5] => $this->getAuthor(), $keys[6] => $this->getEdition(), $keys[7] => $this->getPublisher(), $keys[8] => $this->getBNew(), $keys[9] => $this->getBUsed(), $keys[10] => $this->getBEbook(), $keys[11] => $this->getImageUrl(), $keys[12] => $this->getProductId(), $keys[13] => $this->getPartNumber(), $keys[14] => $this->getSpideredAt(), $keys[15] => $this->getShallowSpideredAt(), $keys[16] => $this->getTouched(), $keys[17] => $this->getBId(), $keys[18] => $this->getBookstoreType(), $keys[19] => $this->getCreatedAt(), $keys[20] => $this->getUpdatedAt());
     if ($includeForeignObjects) {
         if (null !== $this->aBook) {
             $result['Book'] = $this->aBook->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->aItemRelatedByPackageId) {
             $result['ItemRelatedByPackageId'] = $this->aItemRelatedByPackageId->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->collItemsRelatedById) {
             $result['ItemsRelatedById'] = $this->collItemsRelatedById->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
         }
         if (null !== $this->collSectionHasItems) {
             $result['SectionHasItems'] = $this->collSectionHasItems->toArray(null, true, $keyType, $includeLazyLoadColumns, $alreadyDumpedObjects);
         }
     }
     return $result;
 }
 /**
  * Exports the object as an array.
  *
  * You can specify the key type of the array by passing one of the class
  * type constants.
  *
  * @param     string  $keyType (optional) One of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  *                    BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  *                    Defaults to BasePeer::TYPE_PHPNAME.
  * @param     boolean $includeLazyLoadColumns (optional) Whether to include lazy loaded columns. Defaults to TRUE.
  * @param     array $alreadyDumpedObjects List of objects to skip to avoid recursion
  * @param     boolean $includeForeignObjects (optional) Whether to include hydrated related objects. Default to FALSE.
  *
  * @return    array an associative array containing the field names (as keys) and field values
  */
 public function toArray($keyType = BasePeer::TYPE_PHPNAME, $includeLazyLoadColumns = true, $alreadyDumpedObjects = array(), $includeForeignObjects = false)
 {
     if (isset($alreadyDumpedObjects['SectionHasItem'][$this->getPrimaryKey()])) {
         return '*RECURSION*';
     }
     $alreadyDumpedObjects['SectionHasItem'][$this->getPrimaryKey()] = true;
     $keys = SectionHasItemPeer::getFieldNames($keyType);
     $result = array($keys[0] => $this->getSectionId(), $keys[1] => $this->getItemId(), $keys[2] => $this->getRequiredStatus(), $keys[3] => $this->getSpideredAt(), $keys[4] => $this->getShallowSpideredAt(), $keys[5] => $this->getTouched(), $keys[6] => $this->getBId(), $keys[7] => $this->getBookstoreType(), $keys[8] => $this->getId(), $keys[9] => $this->getCreatedAt(), $keys[10] => $this->getUpdatedAt());
     if ($includeForeignObjects) {
         if (null !== $this->aSection) {
             $result['Section'] = $this->aSection->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
         if (null !== $this->aItem) {
             $result['Item'] = $this->aItem->toArray($keyType, $includeLazyLoadColumns, $alreadyDumpedObjects, true);
         }
     }
     return $result;
 }