コード例 #1
0
 function findByName($name)
 {
     Validation::notEmpty($name, 'name');
     $em = $this->getManager();
     $outputs = $em->getRepository($this->entityClassName)->findByName($name);
     if (isset($outputs) && count($outputs) > 0) {
         return $outputs[0];
     }
     return NULL;
 }
コード例 #2
0
 /**
  * Set the section that is the owner of this settings.
  *
  * @param Newscoop\Entity\Section $section
  * 		The section that is the owner of this settings, must not be null or empty.
  *
  * @return Newscoop\Entity\OutputSettingsSection
  * 		This object for chaining purposes.
  */
 public function setSection(Section $section)
 {
     Validation::notEmpty($section, 'section');
     $this->section = $section;
     return $this;
 }
コード例 #3
0
ファイル: Search.php プロジェクト: nidzix/Newscoop
 /**
  * (DO NOT CALL THIS DIRECTLY)
  * Add an order by column for this search.
  *
  * @param Newscoop\Service\Model\Search\Column $column
  *		The column to order by, must not be null or empty.
  */
 public function addOrderBy(Column $column)
 {
     Validation::notEmpty($column, 'column');
     $this->orderBy[] = $column;
 }
コード例 #4
0
 function clearAllFor($path)
 {
     Validation::notEmpty($path, 'path');
     $em = $this->getEntityManager();
     $q = $em->createQueryBuilder();
     $q->delete(Resource::NAME, 'rsc')->where('rsc.path like :path');
     $q->setParameter('path', $path . '%');
     $q->getQuery()->execute();
 }
コード例 #5
0
ファイル: Resource.php プロジェクト: nidzix/Newscoop
 /**
  * Set the path of the resource.
  *
  * @param string $path
  * 		The path of the resource.
  *
  * @return Newscoop\Entity\Resource
  * 		This object for chaining purposes.
  */
 function setPath($path)
 {
     Validation::notEmpty($path, 'path');
     $this->path = str_replace('\\', '/', $path);
     return $this;
 }
コード例 #6
0
ファイル: Theme.php プロジェクト: sourcefabric/newscoop
 /**
  * Set the minimum newscoop version for this theme, this has to be a whell formated version name like '3.6'.
  *
  * @param string $minorNewscoopVersion
  *		The minimum newscoop version of the theme, must not be null or empty.
  *
  * @return Newscoop\Entity\Theme
  *		This object for chaining purposes.
  */
 public function setMinorNewscoopVersion($minorNewscoopVersion)
 {
     Validation::notEmpty($minorNewscoopVersion, 'minorNewscoopVersion');
     $this->minorNewscoopVersion = $minorNewscoopVersion;
     return $this;
 }
コード例 #7
0
 function getPresentationImages(Theme $theme)
 {
     Validation::notEmpty($theme, self::TAG_THEME);
     $xml = $this->loadXML($this->toFullPath($theme, $this->themeConfigFileName));
     $presentResources = array();
     if ($xml != NULL) {
         $nodes = $this->getNodes($xml, self::TAG_PRESENT);
         foreach ($nodes as $node) {
             /* @var $node \SimpleXMLElement */
             $rsc = new Resource();
             try {
                 $rsc->setName($this->readAttribute($node, self::ATTR_PRESENT_NAME));
                 $rsc->setPath($theme->getPath() . $this->readAttribute($node, self::ATTR_PRESENT_SRC));
                 $presentResources[] = $rsc;
             } catch (XMLMissingAttribueException $e) {
                 $this->getErrorHandler()->error(ThemeErrors::XML_MISSING_ATTRIBUTE, $e->getAttributeName(), $node->getName());
             }
         }
     }
     return $presentResources;
 }
コード例 #8
0
ファイル: ArticleType.php プロジェクト: nidzix/Newscoop
 /**
  * Set the name of the article type, must be a user frendly name used for displaying it on the UI.
  *
  * @param string $name
  *		The name of the article type, must not be null or empty.
  *
  * @return Newscoop\Entity\ArticleType
  *		This object for chaining purposes.
  */
 public function setName($name)
 {
     Validation::notEmpty($name, 'name');
     $this->name = $name;
     return $this;
 }
コード例 #9
0
 /**
  * Provides the simple class name based on the provided full class name (namespace + simple class name).
  *
  * @param string $className
  *		The class name from where to extract the simple class name.
  * @return string
  *		The config path.
  */
 protected function extractSimpleClassName($className)
 {
     Validation::notEmpty($className, 'className');
     $pos = strrpos($className, '\\');
     if ($pos !== false) {
         return substr($className, $pos + 1);
     }
     return $className;
 }
コード例 #10
0
 /**
  * Creates more article types
  * @param array $articleTypes the array of types, optionally with fields
  * 		[ typeName => [ fields : [ name : fieldName, parentType : typeName, ignore : bool ], [...] ], [...] ]
  * @see self::create()
  */
 public function createMany($articleTypes)
 {
     Validation::notEmpty($articleTypes, 'articleTypes');
     foreach ($articleTypes as $typeName => $type) {
         $artType = $this->_create($typeName);
         if (isset($type['fields']) && is_array($type['fields'])) {
             foreach ($type['fields'] as $field) {
                 $this->_createField($field['name'], $artType);
             }
         }
     }
     try {
         $this->getEntityManager()->flush();
     } catch (\PDOException $e) {
         // duplicate keys, no worries
         if ($e->getCode() == 23000 && strpos($e->getMessage(), 'Duplicate') !== false) {
             return true;
         }
         throw $e;
     } catch (\Exception $e) {
         throw $e;
     }
     return true;
 }
コード例 #11
0
 /**
  * Set the path of the theme associated.
  *
  * @param Newscoop\Entity\Resource $themePath
  *		The path of the theme, must not be null or empty.
  *
  * @return Newscoop\Entity\PublicationTheme
  *		This object for chaining purposes.
  */
 public function setThemePath(Resource $themePath)
 {
     Validation::notEmpty($themePath, 'themePath');
     $this->themePath = $themePath;
     return $this;
 }
コード例 #12
0
ファイル: ResourceId.php プロジェクト: sourcefabric/newscoop
 /**
  * Provides the service for the requested service name.
  * The id should not be provided as a plain string it should be the actuall
  * class name ot the service API beeing requested. As a convention
  * this id should be obtain from the NAME contstant of a interface (ex: IThemeService::NAME),
  * where NAME is defined in the interface as 'const NAME = __CLASS__', if apllicable.
  *
  * @param string $serviceName
  *		The class name of the interface beeing requested, must not be null or empty.
  *
  * @return mixed
  *		The resource id obtained for this service request.
  */
 public function getService($serviceName)
 {
     Validation::notEmpty($serviceName, "serviceName");
     $serviceId = new ResourceId($serviceName, ResourceId::TYPE_SERVICE);
     $serviceId->parent = $this;
     return ResourceRepository::getInstance()->getResourceFor($serviceId);
 }
コード例 #13
0
 public function __construct($attributeName)
 {
     Validation::notEmpty($attributeName, 'attributeName');
     $this->attributeName = $attributeName;
 }
コード例 #14
0
ファイル: OutputSettings.php プロジェクト: nidzix/Newscoop
 /**
  * Set the output that is the owner of this settings.
  *
  * @param Newscoop\Entity\Output $output
  *		The output that is the owner of this settings, must not be null or empty.
  *
  * @return Newscoop\Entity\OutputSetting
  *		This object for chaining purposes.
  */
 function setOutput(Output $output)
 {
     Validation::notEmpty($output, 'output');
     $this->output = $output;
     return $this;
 }
コード例 #15
0
 function findById($id)
 {
     Validation::notEmpty($id, 'id');
     $em = $this->getEntityManager();
     return $em->find($this->entityClassName, $id);
 }
コード例 #16
0
 public function getUnthemedIssues($publication)
 {
     Validation::notEmpty($publication, 'publication');
     $issues = array();
     $em = $this->getManager();
     // we need to find if the theme is used by anyoane.
     $q = $em->createQueryBuilder();
     $q->select('iss')->from(Issue::NAME, 'iss')->leftJoin('iss.outputSettingsIssues', 'osi')->where('iss.publication = :publication')->andWhere('osi.id IS NULL')->setParameter('publication', $publication);
     $issues = $q->getQuery()->getResult();
     return $issues;
 }
コード例 #17
0
 /**
  * Adds new mapping in the theme xml
  *
  * @param $articleTypes an array of mapping new values to old ones
  * 		[ oldTypeName => [
  * 			name : newTypeName,
  * 			ignore : boolean,
  * 			fields' : [ OldFieldName : [ name : new/oldType, parentType : existingSysType, ignore : boolean ], [...] ]
  * 			]
  * 		, [...] ]
  * 	parentType => existingSysType will be used for getting it's other props from db
  *
  * @return string the generated xml
  */
 function assignArticleTypes($articleTypes, Theme $theme)
 {
     Validation::notEmpty($articleTypes, 'articleTypes');
     Validation::notEmpty($theme, 'theme');
     $artServ = $this->getArticleTypeService();
     $artCache = array();
     /**
      * function purpose: not to make so many calls to db
      * @param string $parentType article type name
      * @param string $fieldName field name doh
      * @return ArticleTypeField|null
      */
     $getFieldByName = function ($parentType, $fieldName) use($artServ, &$artCache) {
         if (!isset($artCache[$parentType . $fieldName])) {
             $artType = $artServ->findTypeByName($parentType);
             if ($artType) {
                 $artCache[$parentType . $fieldName] = $artServ->findFieldByName($artType, $fieldName);
             }
         }
         return $artCache[$parentType . $fieldName];
     };
     $xml = $this->loadXML($xmlFileName = $this->toFullPath($theme, $this->themeConfigFileName));
     if ($xml == NULL) {
         throw new \Exception("Unknown theme path '.{$theme->gePath}().' to assign to.");
     }
     $updatedTypes = array();
     // used to check duplicate names for types
     $safeTypeCounter = null;
     // parse the mapping array
     foreach ($articleTypes as $typeName => $type) {
         $articleXPath = '/' . self::TAG_ROOT . '/' . self::TAG_ARTICLE_TYPE . '[@' . self::ATTR_ARTICLE_TYPE_NAME . '=(\'' . $typeName . '\')]';
         $fieldNodes = $xml->xpath("{$articleXPath}/*");
         $updatedFields = array();
         // used to check duplicate names for fields and such
         $safeFieldCounter = null;
         if (count($fieldNodes)) {
             foreach ($fieldNodes as $fieldNode) {
                 if (!isset($type['fields'][(string) $fieldNode[self::ATTR_ARTICLE_TYPE_FILED_NAME]]) || !($updateField = $type['fields'][(string) $fieldNode[self::ATTR_ARTICLE_TYPE_FILED_NAME]]) || $updateField['ignore'] == true) {
                     continue;
                 }
                 $updateFieldName = $updateField['name'];
                 // checking for duplicates
                 if (isset($updatedFields[$updateFieldName])) {
                     $updateFieldName = $updateField['name'] . ++$safeFieldCounter;
                 }
                 $fieldNode[self::ATTR_ARTICLE_TYPE_FILED_NAME] = $updateFieldName;
                 $updatedFields[$updateFieldName] = true;
                 $theField = $getFieldByName($updateField['parentType'], $updateField['name']);
                 /* @var $theField ArticleTypeField */
                 if ($theField) {
                     $fieldNode[self::ATTR_ARTICLE_TYPE_FILED_LENGTH] = $theField->getLength();
                     $fieldNode[self::ATTR_ARTICLE_TYPE_FILED_TYPE] = $theField->getType();
                 }
             }
             // end foreach fieldNodes
         }
         if ($type['ignore']) {
             continue;
         }
         // set new article type node
         $typeNode = $xml->xpath($articleXPath);
         if (!($typeNode = current($typeNode))) {
             continue;
         }
         /* @var $typeNode SimpleXMLElement */
         $updateTypeName = $type['name'];
         // checking for duplicates
         if (isset($updatedTypes[$updateTypeName])) {
             $updateTypeName = $type['name'] . ++$safeTypeCounter;
         }
         $typeNode[self::ATTR_ARTICLE_TYPE_NAME] = $updateTypeName;
         $updatedTypes[$updateTypeName] = true;
     }
     // end foreach articleTypes
     return $xml->asXML($xmlFileName);
 }
コード例 #18
0
 function error($key)
 {
     Validation::notEmpty($key, 'key');
     syslog(LOG_ERR, $this->compile($key, array_slice(func_get_args(), 1)));
 }
コード例 #19
0
ファイル: Column.php プロジェクト: sourcefabric/newscoop
 /**
  * Creates a new column.
  *
  * @param Newscoop\Service\Model\Search\Search $search
  *		The search instance that is the owner of this Column.
  */
 function __construct(Search $search)
 {
     Validation::notEmpty($search, 'search');
     $this->search = $search;
     $this->search->register($this);
 }