ArticleAttachment::GetAttachmentsByArticleNumber PHP Method

GetAttachmentsByArticleNumber() public static method

Get all the attachments that belong to this article.
public static GetAttachmentsByArticleNumber ( integer $p_articleNumber, integer $p_languageId = null ) : array
$p_articleNumber integer
$p_languageId integer
return array
    public static function GetAttachmentsByArticleNumber($p_articleNumber, $p_languageId = null)
    {
        global $g_ado_db;
        $tmpObj = new Attachment();
        $columnNames = implode(',', $tmpObj->getColumnNames());
        if (is_null($p_languageId)) {
            $langConstraint = "FALSE";
        } else {
            $langConstraint = "Attachments.fk_language_id = " . $g_ado_db->escape($p_languageId);
        }
        $queryStr = 'SELECT ' . $columnNames . ' FROM Attachments, ArticleAttachments' . ' WHERE ArticleAttachments.fk_article_number = ' . $g_ado_db->escape($p_articleNumber) . ' AND ArticleAttachments.fk_attachment_id=Attachments.id' . " AND (Attachments.fk_language_id IS NULL OR {$langConstraint})" . ' ORDER BY Attachments.time_created asc, Attachments.file_name asc';
        $rows = $g_ado_db->GetAll($queryStr);
        $returnArray = array();
        if (is_array($rows)) {
            foreach ($rows as $row) {
                $tmpAttachment = new Attachment();
                $tmpAttachment->fetch($row);
                $returnArray[] = $tmpAttachment;
            }
        }
        return $returnArray;
    }

Usage Example

 /**
  * Get all the files and directories of a relative path.
  *
  * @param string $p_articleId
  *
  * @return array of file and path information.
  * <code>
  *   array('url'=>'full url',
  *         'storage'=>'full file path')
  * </code>
  */
 function getFiles($p_articleId, $p_languageId = null)
 {
     $files = array();
     if ($this->isValidBase() == false) {
         return $files;
     }
     $articleAttachments = ArticleAttachment::GetAttachmentsByArticleNumber($p_articleId, $p_languageId);
     foreach ($articleAttachments as $articleAttachment) {
         if (!$this->m_config['validate_files']) {
             $file['attachment'] = $articleAttachment;
             $file['url'] = $articleAttachment->getAttachmentUrl();
             $file['storage'] = $articleAttachment->getStorageLocation();
             $files[$articleAttachment->getAttachmentId()] = $file;
         }
     }
     ksort($files);
     return $files;
 }
All Usage Examples Of ArticleAttachment::GetAttachmentsByArticleNumber