<?php $this->query("\n CREATE TABLE `push_apns_devices` (\n `device_id` int(11) NOT NULL AUTO_INCREMENT,\n `app_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `app_version` varchar(25) COLLATE utf8_unicode_ci DEFAULT NULL,\n `device_uid` varchar(50) COLLATE utf8_unicode_ci NOT NULL,\n `last_known_latitude` decimal(11,8) DEFAULT NULL,\n `last_known_longitude` decimal(11,8) DEFAULT NULL,\n `device_token` char(64) COLLATE utf8_unicode_ci NOT NULL,\n `device_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `device_model` varchar(100) COLLATE utf8_unicode_ci NOT NULL,\n `device_version` varchar(25) COLLATE utf8_unicode_ci NOT NULL,\n `push_badge` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n `push_alert` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n `push_sound` enum('disabled','enabled') COLLATE utf8_unicode_ci DEFAULT 'disabled',\n `status` enum('active','uninstalled') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'active',\n `created_at` datetime NOT NULL,\n `updated_at` timestamp NOT NULL,\n PRIMARY KEY (`device_id`),\n UNIQUE KEY `UNIQUE_KEY_APP_NAME_APP_VERSION_DEVICE_UID` (`app_name`,`app_version`,`device_uid`),\n KEY `KEY_DEVICE_TOKEN` (`device_token`),\n KEY `KEY_STATUS` (`status`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\n CREATE TABLE `push_delivered_message` (\n `deliver_id` int(11) NOT NULL AUTO_INCREMENT,\n `device_id` int(11) NOT NULL,\n `device_uid` text COLLATE utf8_unicode_ci NOT NULL,\n `device_type` tinyint(1) NOT NULL,\n `message_id` int(11) NOT NULL,\n `status` tinyint(1) NOT NULL DEFAULT '0',\n `is_read` tinyint(1) NOT NULL DEFAULT '0',\n `is_displayed` int(11) NOT NULL DEFAULT '0',\n `delivered_at` datetime NOT NULL,\n PRIMARY KEY (`deliver_id`),\n KEY `KEY_DEVICE_ID` (`device_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n"); $this->query("\n CREATE TABLE `push_gcm_devices` (\n `device_id` int(11) NOT NULL AUTO_INCREMENT,\n `app_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `registration_id` text COLLATE utf8_unicode_ci,\n `development` enum('production','sandbox') CHARACTER SET latin1 NOT NULL DEFAULT 'production',\n `status` enum('active','uninstalled') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'active',\n `created_at` datetime NOT NULL,\n `updated_at` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP,\n PRIMARY KEY (`device_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\n CREATE TABLE `push_messages` (\n `message_id` int(11) NOT NULL AUTO_INCREMENT,\n `title` varchar(30) COLLATE utf8_unicode_ci NOT NULL,\n `text` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n `latitude` decimal(11,8) DEFAULT NULL,\n `longitude` decimal(11,8) DEFAULT NULL,\n `radius` decimal(7,2) DEFAULT NULL,\n `send_at` datetime DEFAULT NULL,\n `send_until` datetime DEFAULT NULL,\n `delivered_at` datetime DEFAULT NULL,\n `status` enum('queued','delivered','sending','failed') COLLATE utf8_unicode_ci NOT NULL DEFAULT 'queued',\n `created_at` datetime NOT NULL,\n `updated_at` datetime NOT NULL,\n PRIMARY KEY (`message_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n"); $this->query("\n CREATE TABLE `push_certificate` (\n `certificate_id` int(11) NOT NULL AUTO_INCREMENT,\n `app_id` INT(11) NULL DEFAULT NULL,\n `type` varchar(30) NOT NULL,\n `path` varchar(255) NULL DEFAULT NULL,\n `created_at` datetime NOT NULL,\n `updated_at` datetime NOT NULL,\n PRIMARY KEY (`certificate_id`)\n ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n"); $library = new Media_Model_Library(); $library->setName('Push')->save(); $icon_paths = array('/push_notifications/push1.png', '/push_notifications/push2.png', '/push_notifications/push3.png', '/push_notifications/push4.png', '/push_notifications/push5.png', '/loyalty/loyalty6.png'); $icon_id = 0; foreach ($icon_paths as $key => $icon_path) { $datas = array('library_id' => $library->getId(), 'link' => $icon_path, 'can_be_colorized' => 1); $image = new Media_Model_Library_Image(); $image->setData($datas)->save(); if ($key == 0) { $icon_id = $image->getId(); } } $datas = array('library_id' => $library->getId(), 'icon_id' => $icon_id, 'code' => 'push_notification', 'name' => 'Push Notifications', 'model' => '', 'desktop_uri' => 'push/application/', 'mobile_uri' => 'push/mobile/', 'only_once' => 1, 'is_ajax' => 1, 'position' => 130); $option = new Application_Model_Option(); $option->setData($datas)->save();
public function addPictures() { if ($picture_list = $this->getPictureList()) { if (!($library_id = $this->getLibraryId())) { $library = new Media_Model_Library(); $library->setName("product_" . uniqid())->save(); $library_id = $library->getId(); $this->setLibraryId($library_id); } foreach ($picture_list as $picture) { if ($picture != "") { $image = new Media_Model_Library_Image(); $img_data = array("link" => $picture, "can_be_colorized" => 0, "library_id" => $library_id); $image->setData($img_data)->save(); } } } }
<?php $media_library = new Media_Model_Library(); $media_library->setName("Code Scan")->save(); $icon_id = null; $files_icon = new DirectoryIterator(Core_Model_Directory::getBasePathTo("images/library/code_scan")); foreach ($files_icon as $file) { if ($file->isDot()) { continue; } $icon = new Media_Model_Library_Image(); $icon_data = array("library_id" => $media_library->getId(), "link" => "/code_scan/" . $file->getFilename(), "can_be_colorized" => 1); $icon->setData($icon_data)->save(); if ($icon_id == null) { $icon_id = $icon->getId(); } } $option_data = array("code" => "code_scan", "name" => "Code Scan", "model" => "Codescan_Model_Codescan", "library_id" => $media_library->getId(), "icon_id" => $icon_id, "desktop_uri" => "codescan/application/", "mobile_uri" => "codescan/mobile_view/", "position" => 150); $option = new Application_Model_Option(); $option->setData($option_data)->save();
public function saveAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { $previews = $data["previews"]; $option_id = !empty($data["option_id"]) ? $data["option_id"] : null; $preview_id = !empty($data["preview_id"]) ? $data["preview_id"] : null; if (empty($previews)) { throw new Exception($this->_("An error occurred while saving your previews. Please try again later.")); } $preview = new Preview_Model_Preview(); if (!empty($option_id) and empty($preview_id)) { //No preview for this option yet, we create one if it doesn't exists. $preview->find($option_id, "option_id"); if ($preview->getId()) { throw new Exception($this->_("Sorry, but an existing preview for this feature has been found. Please edit existing one.")); } $preview->setData("option_id", $option_id); } else { //Existing preview if (!empty($preview_id)) { $preview->find($data["preview_id"]); } else { throw new Exception($this->_("An error occurred while saving your previews. Please try again later.")); } } $previews_language_data = array(); foreach ($previews as $language_code => $data) { $option = new Application_Model_Option(); $option->find($preview->getOptionId()); if ($preview->getId()) { $library_id = $preview->findLibraryIdByLanguageCode($language_code); } else { $library_id = null; } if (!$library_id) { $library = new Media_Model_Library(); $library->setName('preview_' . $language_code . '_' . $option->getCode())->save(); $data["library_id"] = $library->getId(); } else { $data["library_id"] = $library_id; } //IMAGES------------------------------------------------ foreach ($data["images"] as $key => $image) { $library_image = new Media_Model_Library_Image(); //We only copy new files if ($image["new"] == 1) { $old_path = Core_Model_Directory::getTmpDirectory(true); $new_path = Core_Model_Directory::getBasePathTo("images/previews/" . $language_code . "/" . $option->getCode()); $new_path_base = Core_Model_Directory::getPathTo("images/previews/" . $language_code . "/" . $option->getCode()); if (!is_dir($new_path)) { if (!@mkdir($new_path, 0777, true)) { throw new Exception($this->_("Unable to create the directory.")); } } if (!@rename($old_path . "/" . $image["filename"], $new_path . "/" . $image["filename"])) { throw new Exception($this->_("Unable to copy the file.")); } $data_image = array("library_id" => $data["library_id"], "link" => $new_path_base . "/" . $image["filename"], "can_be_colorized" => 0, "position" => $key); $library_image->setData($data_image)->save(); } else { //For existing images, we save position $library_image->find($image["id"]); if ($library_image->getImageId()) { $library_image->setPosition($key)->save(); } } //We delete images to delete if ($image["to_delete"] == 1 and $image["new"] == 0) { if (!@unlink(Core_Model_Directory::getBasePathTo($image["link"]))) { throw new Exception($this->_("Unable to delete the file.")); } $library_image = new Media_Model_Library_Image(); $library_image->find($image["id"]); $library_image->delete(); } } unset($data["images"]); //<--IMAGES------------------------------------------------ unset($data["from_database"]); $data['language_code'] = $language_code; $data['preview_id'] = $preview->getId(); $previews_language_data[] = $data; } $preview->setLanguageData($previews_language_data); $preview->save(); $data = array("success" => 1, "message" => $this->_("Preview successfully saved")); } catch (Exception $e) { $data = array("error" => 1, "message" => $e->getMessage()); } $this->_sendHtml($data); } }