예제 #1
0
파일: VideoService.php 프로젝트: jay45/porn
 protected function __construct()
 {
     $em = MyEntityManagerFactory::getEntityManager();
     $this->_movieRepository = $em->getRepository('\\Models\\Entities\\Movie');
     $this->_movieViewRepository = $em->getRepository('\\Models\\Entities\\MovieView');
     $this->_em = $em;
 }
예제 #2
0
 public static function start()
 {
     $em = MyEntityManagerFactory::getEntityManager();
     /* @var $jp \My\Illusion\AopJoinpoint */
     $before = function ($jp) use($em) {
         TransactionManager::$_stateData[++TransactionManager::$_stateIndex] = 1;
         $em->flush();
         $em->beginTransaction();
     };
     $after = function ($jp) use($em) {
         if ($jp->getException() !== null) {
             TransactionManager::$_stateData[TransactionManager::$_stateIndex] = 2;
             $em->rollback();
         } else {
             if (TransactionManager::$_stateData[TransactionManager::$_stateIndex] === 1) {
                 $em->flush();
                 $em->commit();
             } else {
                 if (TransactionManager::$_stateData[TransactionManager::$_stateIndex] == 0) {
                     $em->rollback();
                 }
             }
             TransactionManager::$_stateIndex--;
         }
     };
     $namespace = '*Controller->*Action()';
     aop_add_before($namespace, $before);
     aop_add_after($namespace, $after);
     $namespace = 'public Models\\Services\\*Service->*()';
     aop_add_before($namespace, $before);
     aop_add_after($namespace, $after);
     $namespace = 'public Models\\Repositories\\*Repository->sav*()';
     aop_add_before($namespace, $before);
     aop_add_after($namespace, $after);
 }
예제 #3
0
파일: ImageService.php 프로젝트: jay45/porn
 /**
  * 
  * @return Image
  */
 public static function getImageByMd5UploadedByUser($md5, $userId)
 {
     $em = MyEntityManagerFactory::getEntityManager();
     $className = '\\Models\\Entities\\Image';
     $dql = "select distinct p from {$className} p" . ' left join p.referenceImage r' . ' join p.uploader pu' . ' join r.uploader ru' . ' where (p.md5 = ?1 or r.md5 = ?1) and pu.id = ?2';
     $query = $em->createQuery($dql);
     $query->setParameter(1, $md5);
     $query->setParameter(2, $md5);
     return current($query->getResult());
 }
예제 #4
0
 public function indexAction()
 {
     // action body
     /* @var $repo \Models\Repositories\MovieRepository */
     $repo = MyEntityManagerFactory::getEntityManager()->getRepository('\\Models\\Entities\\Movie');
     $this->view->movie = $repo->find($this->getParam('id'));
     if ($this->view->movie) {
         VideoService::getInstance()->viewMovie($this->getParam('id'));
         $this->view->relatedMovies = $repo->__findRandomRelatedMovies($this->getParam('id'));
     }
     $repo->clear();
 }
예제 #5
0
 /**
  * 
  * @return User
  */
 public function getMyUser()
 {
     if ($this->myUser == null) {
         $userId = $this->_getMyUserId();
         if (empty($userId)) {
             return null;
         }
         $userRepository = MyEntityManagerFactory::getEntityManager()->getRepository('\\Models\\Entities\\User');
         $this->myUser = $userRepository->find($userId);
     }
     return $this->myUser;
 }
예제 #6
0
 public function indexAction()
 {
     /*@var $repo \Models\Repositories\MovieRepository */
     $repo = MyEntityManagerFactory::getEntityManager()->getRepository('\\Models\\Entities\\Movie');
     $page = intval($this->getParam('page'));
     $page = $page > 0 ? $page : 1;
     $this->view->movies = $repo->__findByPageNavigation($page);
     $currentPage = $page;
     $maxPage = $repo->__findMaxPageNavigation();
     $baseNavigationUrl = Zend_Controller_Front::getInstance()->getBaseUrl() . '/latest-update';
     $navigationParameterPrefix = "/";
     $this->view->navigation = new BootstrapPageNavigationHelper($currentPage, $maxPage, $baseNavigationUrl, $navigationParameterPrefix);
 }
예제 #7
0
 public function indexAction()
 {
     // action body
     $kw = $this->getRequest()->getParam('keyword');
     $keywords = preg_split('/[^\\w]/', $kw);
     /* @var $repo \Models\Repositories\MovieRepository */
     $repo = MyEntityManagerFactory::getEntityManager()->getRepository('\\Models\\Entities\\Movie');
     $page = intval($this->getParam('page'));
     $page = $page > 0 ? $page : 1;
     $this->view->movies = $repo->__findByPageAndKeywords($page, $keywords);
     $currentPage = $page;
     $maxPage = $repo->__findMaxPageNavigationWithKeyword($keywords);
     $kw = urlencode($kw);
     $baseNavigationUrl = Zend_Controller_Front::getInstance()->getBaseUrl() . "/search?keyword={$kw}";
     $navigationParameterPrefix = "&page=";
     $this->view->navigation = new BootstrapPageNavigationHelper($currentPage, $maxPage, $baseNavigationUrl, $navigationParameterPrefix);
 }
예제 #8
0
 private static final function autowired()
 {
     /* @var $jp \My\Illusion\AopJoinpoint */
     if (self::$autowiredFlag) {
         $em = MyEntityManagerFactory::getEntityManager();
         $before = function ($jp) use($em) {
             // 				\Zend_Debug::dump($jp->getClassName());
             $reflection = new \ReflectionClass($jp->getClassName());
             $params = $reflection->getConstructor()->getParameters();
             $args = $jp->getArguments();
             foreach ($params as $key => $param) {
                 if ($param->getClass()) {
                     $entityName = '\\' . str_replace(array('Repositories', 'Repository'), array('Entities', ''), $param->getClass()->name);
                     $args[$key] = $em->getRepository($entityName);
                 }
             }
             // 				\Zend_Debug::dump($args);
             $jp->setArguments($args);
         };
         $namespace = 'Models\\Services\\*Service->__construct*()';
         aop_add_before($namespace, $before);
         self::$autowiredFlag = false;
     }
 }
예제 #9
0
 /**
  * 
  * @return \Doctrine\ORM\EntityManager
  */
 public static function getEntityManager()
 {
     if (null === static::$em) {
         $cache = MyCache::getInstance();
         self::$em = self::createNewEntityManager();
         if (static::$isUpdateSchema) {
             // 				$schemaTool = new SchemaTool(self::$em);
             $classes = self::$em->getMetadataFactory()->getAllMetadata();
             // 				$schemaTool->dropSchema($classes);
             // 				$schemaTool->createSchema($classes);
             // 				$schemaTool->updateSchema($classes);
         }
         /**
         				flush update before shutdown
         */
         $beforeShutdownFunction = function () {
             $em = MyEntityManagerFactory::getEntityManager();
             while (true) {
                 try {
                     $con = $em->getConnection();
                     if ($con->isTransactionActive()) {
                         $em->flush();
                         $con->commit();
                     } else {
                         break;
                     }
                 } catch (\Exception $e) {
                     break;
                 }
             }
         };
         register_shutdown_function($beforeShutdownFunction);
         self::$em->getConnection()->connect();
     }
     return self::$em;
 }
예제 #10
0
 public function updateMovieAction()
 {
     $id = $this->getRequest()->getParam("id");
     $this->view->movie = MyEntityManagerFactory::getEntityManager()->getRepository("\\Models\\Entities\\Movie")->find($id);
     $this->view->categories = MyEntityManagerFactory::getEntityManager()->getRepository('\\Models\\Entities\\Category')->findBy(array('isActive' => true));
 }
예제 #11
0
파일: index.php 프로젝트: jay45/porn
date_default_timezone_set('Asia/Bangkok');
// create autoloader
require_once 'Zend/Loader/Autoloader.php';
$loader = \Zend_Loader_Autoloader::getInstance();
$loader->registerNamespace('My\\');
$loader->registerNamespace('Helper\\');
$loader->registerNamespace("Doctrine\\");
$loader->registerNamespace("Models\\");
//setupAutoload();
/** Zend_Session */
// Zend_Session::setOptions(array(
// 'cookie_lifetime' => 1200,
// 'gc_maxlifetime'  => 1200));
Zend_Session::start();
/* setup Cache System */
MyEntityManagerFactory::$isUpdateSchema = true;
MyCache::$namespacePrefix = "ns7";
MyCache::setType(MyCache::$TYPE_ARRAY);
/** configure front controller */
$front = Zend_Controller_Front::getInstance()->registerPlugin(MyPlugin::getInstance())->setRouter(MyRouterConfiguration::getRouter());
// MyDatabaseConfiguration::$databaseHost = '127.0.0.1';
// MyDatabaseConfiguration::$databaseName = 'swim';
// MyDatabaseConfiguration::$databaseUserName = '******';
// MyDatabaseConfiguration::$databasePassword = '******';
MyDatabaseConfiguration::$databaseHost = 'localhost';
MyDatabaseConfiguration::$databaseName = 'mapz_porn';
MyDatabaseConfiguration::$databaseUserName = '******';
MyDatabaseConfiguration::$databasePassword = '******';
TransactionManager::start();
//$application->bootstrap()->run();
$front->addControllerDirectory(APPLICATION_PATH . '/controllers');
예제 #12
0
 public function loginAction()
 {
     $username = $this->getRequest()->getParam('username');
     $password = md5($this->getRequest()->getParam('password'));
     $user = MyEntityManagerFactory::getEntityManager()->getRepository("\\Models\\Entities\\User")->findOneBy(array('username' => $username, 'password' => $password));
     $session = SessionDataModel::getInstance();
     if ($user) {
         $session->setMyUser($user);
     }
     $url = '/manage/movies';
     $this->redirect($url);
 }