/** * * @param AM_Controller_Action $oActionController * @param string $sName * @param int $iId * @param int $iClientId * @return void */ public function __construct(AM_Controller_Action $oActionController, $sName, $iId, $iClientId) { parent::__construct($oActionController, $sName, $iId, $iClientId); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'preview', 'Preview', array(array('numeric')))); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'description', 'Description', array(array('require')))); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'welcome', 'Welcome message', array(), 'welcome')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'welcome_part2', 'Welcome message under button', array(), 'welcome_part2')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'product_id', 'Product id', array(array('regexp', '/^[a-zA-Z0-9\\._]+$/')))); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'nm_twitter_ios', 'Message')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'nm_fbook_ios', 'Message')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'nt_email_ios', 'Title')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'nm_email_ios', 'Message')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'nm_twitter_android', 'Message')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'nm_fbook_android', 'Message')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'nt_email_android', 'Title')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'nm_email_android', 'Message')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'push_apple_enabled', 'Enable')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'push_boxcar_enabled', 'Enable')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'push_boxcar_provider_key', 'Key')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'push_boxcar_provider_secret', 'Secret')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'message_for_readers', 'For our readers')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'share_url', 'Share url')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'share_message', 'Share message', array(array('maximum length', 200)))); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'application_email', 'Application email')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'contact_email_subject', 'Contact email subject', array(array('maximum length', 200)))); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'contact_email_text', 'Contact email default text')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'subscribe_title', 'Subscribe popup title', array(), 'subscribe_title')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'subscribe_button', 'Subscribe button subtitle', array(), 'subscribe_button')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'application_password', 'Application password', array(), 'password')); $this->addControl(new Volcano_Component_Control_Database_Static($oActionController, 'updated', new Zend_Db_Expr('NOW()'))); $oApplication = AM_Model_Db_Table_Abstract::factory('application')->findOneBy('id', $iId); $sImageValue = !empty($oApplication->image) ? $oApplication->image : null; $this->addControl(new AM_Component_Control_Database_File($oActionController, 'newsstand_cover_image', 'Cover image', array(), 'newsstand_cover_image', AM_Tools::getContentPath(AM_Model_Db_Application::PRESET_APPLICATION_IMAGE) . DIRECTORY_SEPARATOR . '[ID]', TRUE, $sImageValue)); $this->postInitialize(); }
public function __construct(AM_Controller_Action $oActionController, $sName, $iIssueId, $iApplicationId) { parent::__construct($oActionController, $sName, $iIssueId, $iApplicationId); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'author', 'Author', array(array('require'), array('maximum length', 100)), 'author')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'words', 'Words', array(array('require'), array('integer'), array('minimum value', 1)), 'words')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'excerpt', 'Excerpt', array(array('require')), 'excerpt')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'title_short', 'Quick menu headline', array(), 'title_short')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'excerpt_short', 'Quick menu intro', array(array('maximum length', 180)), 'excerpt_short')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'category', 'Category', array(array('maximum length', 255)))); $this->addControl(new AM_Component_Control_Tags($oActionController, 'tags', 'Tags')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'pricing_plan', 'Pricing plan ', array(array('require')), 'pricing_plan')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'google_play_id', 'Google play ID', array(), 'google_play_id')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'itunes_id', 'ITunes ID', array(), 'itunes_id')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'subscribe_title', 'Subscribe popup title', array(), 'subscribe_title')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'subscribe_button', 'Subscribe button subtitle', array(), 'subscribe_button')); $this->addControl(new Volcano_Component_Control_Database($oActionController, 'exclude', 'Exclude issue from Android feed', array(), 'exclude')); $this->removeControl('product_id'); $this->removeControl('paid'); //TODO delete this code later $this->removeControl('subscribe_title'); $this->removeControl('subscribe_button'); //----- $validationsRules = array(); if (!$iIssueId) { $validationsRules[] = array('require'); } $oIssue = AM_Model_Db_Table_Abstract::factory('issue')->findOneBy('id', $iIssueId); $sImageValue = !empty($oIssue->image) ? $oIssue->image : null; $this->addControl(new AM_Component_Control_Database_File($oActionController, 'image', 'Image', $validationsRules, 'image', AM_Tools::getContentPath(AM_Model_Db_Issue::PRESET_ISSUE_IMAGE) . DIRECTORY_SEPARATOR . '[ID]', TRUE, $sImageValue)); $this->postInitialize(); }
public function testShouldCopyResource() { //GIVEN $oThumbnailerMock = $this->getMock('AM_Handler_Thumbnail', array('addSourceFile', 'loadAllPresets', 'createThumbnails', 'getSources')); AM_Handler_Locator::getInstance()->setHandler('thumbnail', $oThumbnailerMock); $oStandardMock = $this->getMock('AM_Tools_Standard', array('is_dir', 'mkdir', 'copy')); $oElement = AM_Model_Db_Table_Abstract::factory('element')->findOneBy('id', 1); $oResource = new AM_Model_Db_Element_Data_MockResource($oElement); $oResource->addAdditionalResourceKey('additional_key'); //Emulating the element copying $oElement->id = 2; //The current path of the resource $sOldDir = AM_Tools::getContentPath(AM_Model_Db_Element_Data_Resource::TYPE, 1); //The path of the resource after copying $sNewDir = AM_Tools::getContentPath(AM_Model_Db_Element_Data_Resource::TYPE, 2); //THEN //Checking all file operations $oStandardMock->expects($this->at(0))->method('is_dir')->with($this->equalTo($sOldDir))->will($this->returnValue(true)); $oStandardMock->expects($this->at(1))->method('is_dir')->with($this->equalTo($sNewDir))->will($this->returnValue(false)); $oStandardMock->expects($this->once())->method('mkdir')->with($this->equalTo($sNewDir), $this->equalTo(0777), $this->equalTo(true))->will($this->returnValue(true)); $sNewResourcePath = $sNewDir . DIRECTORY_SEPARATOR . 'resource.png'; $sOldResourcePath = $sOldDir . DIRECTORY_SEPARATOR . 'resource.png'; $sNewAdditionalResourcePath = $sNewDir . DIRECTORY_SEPARATOR . 'additional_key.png'; $sOldAdditionalResourcePath = $sOldDir . DIRECTORY_SEPARATOR . 'additional_key.png'; $oStandardMock->expects($this->at(3))->method('copy')->with($this->equalTo($sOldResourcePath), $this->equalTo($sNewResourcePath))->will($this->returnValue(true)); $oStandardMock->expects($this->at(4))->method('copy')->with($this->equalTo($sOldAdditionalResourcePath), $this->equalTo($sNewAdditionalResourcePath))->will($this->returnValue(true)); //Checking the init of the resizing operation $oThumbnailerMock->expects($this->any())->method('addSourceFile')->will($this->returnValue($oThumbnailerMock)); $oThumbnailerMock->expects($this->any())->method('loadAllPresets')->will($this->returnValue($oThumbnailerMock)); $oResourceMock = new AM_Resource_Concrete_Mock($sNewResourcePath); $oThumbnailerMock->expects($this->at(3))->method('getSources')->will($this->returnValue(array($oResourceMock))); $oAdditionalResourceMock = new AM_Resource_Concrete_Mock($sNewAdditionalResourcePath); $oThumbnailerMock->expects($this->at(7))->method('getSources')->will($this->returnValue(array($oAdditionalResourceMock))); //WHEN $oResource->copy(); //THEN $oGivenDataSet = $this->getConnection()->createQueryTable('element_data', 'SELECT id_element, key_name, value FROM element_data ORDER BY id'); $oExpectedDataSet = $this->createFlatXMLDataSet(dirname(__FILE__) . '/_dataset/ElementResourceCopyTest.xml')->getTable('element_data'); $this->assertTablesEqual($oExpectedDataSet, $oGivenDataSet); //Checking the background tasks $oTasks = AM_Model_Db_Table_Abstract::factory('task')->findAllBy(array('status' => AM_Task_Worker_Abstract::STATUS_NEW)); $this->assertEquals(2, $oTasks->count(), 'Precess should init 2 tasks'); $oTaskForResource = $oTasks[0]; $aExpectedParams = array('resource' => $sNewResourcePath, 'image_type' => 'png', 'zooming' => 0, 'resource_type' => 'element-vertical'); $this->assertEquals($aExpectedParams, $oTaskForResource->getOptions()); $oTaskForAdditionalResource = $oTasks[1]; $aExpectedParams = array('resource' => $sNewAdditionalResourcePath, 'image_type' => 'png', 'zooming' => 0, 'resource_type' => 'element-vertical'); $this->assertEquals($aExpectedParams, $oTaskForAdditionalResource->getOptions()); }
public function testShouldCopyResource() { //GIVEN $oResource = new AM_Model_Db_StaticPdf_Data_Resource($this->_oStaticPdf); $this->_oStaticPdf->id = 2; $this->_oStaticPdf->issue = 2; //THEN $sOldDir = AM_Tools::getContentPath(AM_Model_Db_StaticPdf_Data_Resource::TYPE, 1); $sNewDir = AM_Tools::getContentPath(AM_Model_Db_StaticPdf_Data_Resource::TYPE, 2); $this->_oStandardMock->expects($this->at(0))->method('is_dir')->with($this->equalTo($sOldDir))->will($this->returnValue(true)); $this->_oStandardMock->expects($this->at(1))->method('is_dir')->with($this->equalTo($sNewDir))->will($this->returnValue(false)); $this->_oStandardMock->expects($this->once())->method('mkdir')->with($this->equalTo($sNewDir), $this->equalTo(0777), $this->equalTo(true))->will($this->returnValue(true)); $this->_oStandardMock->expects($this->at(3))->method('copy')->with($this->equalTo($sOldDir . DIRECTORY_SEPARATOR . '1.pdfmock'), $this->equalTo($sNewDir . DIRECTORY_SEPARATOR . '2.pdfmock'))->will($this->returnValue(true)); //WHEN $oResource->copy(); }
/** * Resizes given image * @param string $sFileBaseName * @param object $oResource The instance of element | term | horisontal page * @param string $sResourceType The type of resource's parent (element, toc, cache-static-pdf) * @param string $sResourceKeyName The name of the resource type (resource, thumbnail, etc) * @param bool $bZoom * @return @void */ protected function _resizeImage($sFileBaseName, $oResource, $sResourceType, $sResourceKeyName, $sResourcePresetName = null, $bZoom = false) { if (is_null($sResourcePresetName)) { $sResourcePresetName = $sResourceType; } $sImageType = $oResource->getResources()->getImageType(); $sFileExtension = strtolower(pathinfo($sFileBaseName, PATHINFO_EXTENSION)); $sFilePath = AM_Tools::getContentPath($sResourceType, $oResource->id) . DIRECTORY_SEPARATOR . $sResourceKeyName . '.' . $sFileExtension; $this->_oThumbnailer->clearSources()->addSourceFile($sFilePath)->setImageType($sImageType)->setZooming($bZoom); if (empty($this->_sPreset)) { $this->_oThumbnailer->loadAllPresets($sResourcePresetName); } else { $this->_oThumbnailer->clearPresets()->addPreset($this->_sPreset); } $this->_oThumbnailer->createThumbnails(); $this->_echo(sprintf('%s', $sFilePath), 'success'); }
public function testShouldCopyResource() { //GIVEN $oResource = new AM_Model_Db_Term_Data_Resource($this->_oTerm); $this->_oTerm->id = 2; //THEN $sOldDir = AM_Tools::getContentPath(AM_Model_Db_Term_Data_Resource::TYPE, 1); $sNewDir = AM_Tools::getContentPath(AM_Model_Db_Term_Data_Resource::TYPE, 2); $this->_oStandardMock->expects($this->at(0))->method('is_dir')->with($this->equalTo($sOldDir))->will($this->returnValue(true)); //thumb_summary $this->_oStandardMock->expects($this->at(1))->method('is_dir')->with($this->equalTo($sNewDir))->will($this->returnValue(false)); $this->_oStandardMock->expects($this->once())->method('mkdir')->with($this->equalTo($sNewDir), $this->equalTo(0777), $this->equalTo(true))->will($this->returnValue(true)); $this->_oStandardMock->expects($this->at(3))->method('copy')->with($this->equalTo($sOldDir . DIRECTORY_SEPARATOR . 'summary.ext'), $this->equalTo($sNewDir . DIRECTORY_SEPARATOR . 'summary.ext'))->will($this->returnValue(true)); //thumb_stripe $this->_oStandardMock->expects($this->at(4))->method('is_dir')->with($this->equalTo($sNewDir))->will($this->returnValue(true)); $this->_oStandardMock->expects($this->at(5))->method('copy')->with($this->equalTo($sOldDir . DIRECTORY_SEPARATOR . 'stripe.ext'), $this->equalTo($sNewDir . DIRECTORY_SEPARATOR . 'stripe.ext'))->will($this->returnValue(true)); //WHEN $oResource->copy(); }
/** * Get resource path * @return string */ protected function _getResourceDir() { $sResourceDir = AM_Tools::getContentPath(self::TYPE, $this->getTerm()->id); return $sResourceDir; }
/** * Get resource path * @return string */ public function getResourceDir() { $sResourceDir = AM_Tools::getContentPath(self::TYPE, $this->_getHorizontalPdf()->issue); return $sResourceDir; }
/** * Get resource path * @return string */ public function getResourceDir() { $sResourceDir = AM_Tools::getContentPath(self::TYPE, $this->_getIssueSimplePdf()->id_issue); return $sResourceDir; }
/** * Get resource path * @return string */ public function getResourceDir() { $sResourceDir = AM_Tools::getContentPath($this->_getIssueHelpPage()->getThumbnailPresetType(), $this->_getIssueHelpPage()->id_issue); return $sResourceDir; }
/** * Resizes elements */ protected function _resizeElements() { $oQuery = AM_Model_Db_Table_Abstract::factory('element_data')->select()->setIntegrityCheck(false)->from('element_data')->joinInner('element', 'element.id = element_data.id_element')->joinInner('page', 'page.id = element.page')->joinInner('revision', 'revision.id = page.revision')->joinInner('issue', 'issue.id = revision.issue')->joinInner('application', 'application.id = issue.application')->joinInner('client', 'client.id = application.client')->where(sprintf('element_data.key_name IN ("%s", "%s", "%s")', AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE, AM_Model_Db_Element_Data_MiniArticle::DATA_KEY_THUMBNAIL, AM_Model_Db_Element_Data_MiniArticle::DATA_KEY_THUMBNAIL_SELECTED))->where('page.deleted = ?', 'no')->where('revision.deleted = ?', 'no')->where('issue.deleted = ?', 'no')->where('application.deleted = ?', 'no')->where('client.deleted = ?', 'no')->columns(array('id' => 'element_data.id_element'))->order('element_data.id_element ASC'); /* @var $oQuery Zend_Db_Table_Select */ if ($this->_iFromId > 0) { $oQuery->where('element_data.id_element > ?', $this->_iFromId); } if ($this->_iElementId > 0) { $oQuery->where('element_data.id_element = ?', $this->_iElementId); } if ($this->_iPageId > 0) { $oQuery->where('page.id = ?', $this->_iPageId); } if ($this->_iRevisionId > 0) { $oQuery->where('revision.id = ?', $this->_iRevisionId); } if ($this->_iIssueId > 0) { $oQuery->where('issue.id = ?', $this->_iIssueId); } if ($this->_iApplicationId > 0) { $oQuery->where('application.id = ?', $this->_iApplicationId); } $oElementDatas = AM_Model_Db_Table_Abstract::factory('element_data')->fetchAll($oQuery); $iCounter = 0; foreach ($oElementDatas as $oElementData) { try { $oData = $oElementData->getData(); $bZoom = (bool) $oElementData->getData()->getDataValue(AM_Model_Db_Element_Data_Gallery::DATA_KEY_ENABLE_ZOOM, false); if (!is_null($oData) && method_exists($oData, 'getThumbnailPresetName')) { $this->_resizeImage($oElementData->value, $oElementData->getElement(), AM_Model_Db_Element_Data_Resource::TYPE, $oElementData->key_name, $oElementData->getData()->getThumbnailPresetName(), $bZoom); $sFileExtension = strtolower(pathinfo($oElementData->value, PATHINFO_EXTENSION)); if ('pdf' == $sFileExtension && AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE == $oElementData->key_name) { $oData->delete(AM_Model_Db_Element_Data_Resource::PDF_INFO, false); $sFilePath = AM_Tools::getContentPath(AM_Model_Db_Element_Data_Resource::TYPE, $oElementData->getElement()->id) . DIRECTORY_SEPARATOR . AM_Model_Db_Element_Data_Resource::DATA_KEY_RESOURCE . '.' . $sFileExtension; $oResource = AM_Resource_Factory::create($sFilePath); $sPdfInfo = $oResource->getPdfInfo(); $oData->addKeyValue(AM_Model_Db_Element_Data_Resource::PDF_INFO, $sPdfInfo); } } } catch (Exception $oException) { $this->_echo(sprintf('%s', $oException->getMessage()), 'error'); } if ($iCounter++ > 100) { $iCounter = 0; AM_Handler_Temp::getInstance()->end(); } } }
/** * Get path to locate static pdfs compilled files * @return string */ protected function _getFilesPath() { $sPath = AM_Tools::getContentPath('cache-static-pdf', $this->getIssue()->id); return $sPath; }