/**
  * @param array $options
  * @return array|bool
  */
 public static function addNotify($options = [])
 {
     if (isset($options['id'])) {
         $model = self::model()->findByPk((int) $options['id']);
     } else {
         $model = new self();
     }
     if (isset($options['url'])) {
         $model->setUrl($options['url']);
     }
     if (isset($options['image'])) {
         $model->setImage($options['image']);
     }
     $model->setAttributes($options, false);
     if ($model->save()) {
         if (isset($options['read']) && (isset($options['user_id']) && (int) $options['user_id'] > 0)) {
             self::changeReadStatusById($model->id, $options['user_id'], $options['read']);
         }
         if (isset($options['id'])) {
             $model->onUpdateNotify($model);
         } else {
             $model->onAddNotify($model);
         }
         return true;
     } else {
         return $model->getErrors();
     }
 }
 /**
  * @param $index
  * @param $title
  * @param $image
  * @param string $type
  * @param string $submitTitle
  * @param string $submitClass
  *
  * @return Panel
  *
  * @author Panagiotis Vagenas <*****@*****.**>
  * @since ${VERSION}
  */
 public function factory($index, $title, $image, $type = 'main', $submitTitle = 'Save', $submitClass = 'button pull-right')
 {
     $panel = new self($this->moduleInstance);
     $panel->setTab($index);
     $panel->setTitle($title);
     $this->title = $title;
     if ($image) {
         $panel->setImage($image);
     }
     $panel->setSubmit(array('title' => $submitTitle, 'class' => $submitClass));
     $panel->setType($type);
     return $panel;
 }
Example #3
0
 /**
  * Creates new Image object from image resource
  *
  * @param resource $resource Image resource
  * @throws ImageException
  * @return self
  */
 public static function fromResource($resource)
 {
     $newImage = new self();
     try {
         $newImage->setImage($resource);
     } catch (\Exception $e) {
         throw new ImageException($e->getMessage(), ImageException::UnsupportedFormatException, $e);
     }
     return $newImage;
 }
 public function load($path)
 {
     $newImage = new self();
     $newImage->setImage($this->manager->open($path));
     return $newImage;
 }
Example #5
0
 /**
  * @see CultureFeed_Cdb_IElement::parseFromCdbXml(SimpleXMLElement $xmlElement)
  * @return CultureFeed_Cdb_Item_Page
  */
 public static function parseFromCdbXml(SimpleXMLElement $xmlElement)
 {
     if (empty($xmlElement->uid)) {
         throw new CultureFeed_Cdb_ParseException('Uid missing for page element');
     }
     if (empty($xmlElement->name)) {
         throw new CultureFeed_Cdb_ParseException('Name missing for page element');
     }
     $page = new self();
     // Set ID + name.
     $page->setId((string) $xmlElement->uid);
     $page->setName((string) $xmlElement->name);
     $page->setOfficialPage(filter_var((string) $xmlElement->officialPage, FILTER_VALIDATE_BOOLEAN));
     // Set categories
     $categories = array();
     if (!empty($xmlElement->categoryIds->categoryId)) {
         foreach ($xmlElement->categoryIds->categoryId as $category) {
             $categories[] = (string) $category;
         }
     }
     $page->setCategories($categories);
     // Set keywords
     $keywords = array();
     if (!empty($xmlElement->keywords->keyword)) {
         foreach ($xmlElement->keywords->keyword as $keyword) {
             $keywords[] = (string) $keyword;
         }
     }
     $page->setKeywords($keywords);
     // Set description.
     if (!empty($xmlElement->description)) {
         $page->setDescription((string) $xmlElement->description);
     }
     // Set the image.
     if (!empty($xmlElement->image)) {
         $page->setImage((string) $xmlElement->image);
     }
     // Set the cover.
     if (!empty($xmlElement->cover)) {
         $page->setCover((string) $xmlElement->cover);
     }
     // Set the visibility.
     if (!empty($xmlElement->visible)) {
         $page->setVisibility((string) $xmlElement->visible);
     }
     // Set address.
     $address = new CultureFeed_Cdb_Data_Address_PhysicalAddress();
     $addressElement = $xmlElement->address;
     $has_address = FALSE;
     if (!empty($addressElement->city)) {
         $address->setCity((string) $addressElement->city);
         $has_address = TRUE;
     }
     if (!empty($addressElement->street)) {
         $address->setStreet((string) $addressElement->street);
         $has_address = TRUE;
     }
     if (!empty($addressElement->zip)) {
         $address->setZip((string) $addressElement->zip);
         $has_address = TRUE;
     }
     if (!empty($addressElement->country)) {
         $address->setCountry((string) $addressElement->country);
         $has_address = TRUE;
     }
     if (!empty($addressElement->lat) && !empty($addressElement->lon)) {
         $coordinates = $addressElement->lat . '-' . $addressElement->lon;
         if ($coordinates != '0.0-0.0') {
             $address->setGeoInformation(new CultureFeed_Cdb_Data_Address_GeoInformation((string) $addressElement->lon, (string) $addressElement->lat));
             $has_address = TRUE;
         }
     }
     if ($has_address) {
         $page->setAddress($address);
     }
     // Set contact info.
     if (!empty($xmlElement->contactInfo->email)) {
         $page->setEmail((string) $xmlElement->contactInfo->email);
     }
     if (!empty($xmlElement->contactInfo->telephone)) {
         $page->setTelephone((string) $xmlElement->contactInfo->telephone);
     }
     // Set links.
     $links = array();
     if (!empty($xmlElement->links)) {
         foreach ($xmlElement->links->children() as $link) {
             $url = (string) $link;
             if (empty($url)) {
                 continue;
             }
             // Make sure http is in front of the url.
             if (strpos($url, 'http://') !== 0 && strpos($url, 'https://') !== 0) {
                 $url = 'http://' . $url;
             }
             $links[$link->getName()] = $url;
         }
     }
     $page->setLinks($links);
     // Set the permissions.
     $page->setPermissions(CultureFeed_Cdb_Data_PagePermissions::parseFromCdbXml($xmlElement->permissions));
     // Set tagline.
     $page->setTagline((string) $xmlElement->tagline);
     return $page;
 }